Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C API: nix_get_string now accepts a callback to return the value #10523

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

jlesquembre
Copy link
Member

Motivation

As suggested by @roberth in #8699 (comment),
use the callback approach to simplify GC and avoid breaking changes if we change the internal representation of strings.

Context

Stabilize the C interface introduced in #8699

Milestone: https://github.com/NixOS/nix/milestone/52

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Comment on lines +49 to +52
void my_get_string_cb(const char * start, unsigned int n, char ** user_data)
{
*user_data = strdup(start);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could provide this function as part of the C interface. It's an obvious choice for C code, and I think most FFIs have something for dealing with malloced memory.

@roberth roberth merged commit db94839 into NixOS:master Apr 17, 2024
8 of 9 checks passed
@jlesquembre jlesquembre deleted the jl/c-api_nix_get_string branch April 17, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants