Skip to content

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

Merged
roberth merged 1 commit into
NixOS:masterfrom
tweag:jl/c-api_nix_get_string
Apr 17, 2024
Merged

C API: nix_get_string now accepts a callback to return the value#10523
roberth merged 1 commit into
NixOS:masterfrom
tweag:jl/c-api_nix_get_string

Conversation

@jlesquembre

Copy link
Copy Markdown
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.

@jlesquembre jlesquembre requested a review from edolstra as a code owner April 16, 2024 20:46
@edolstra edolstra requested a review from roberth April 17, 2024 10:18
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
Copy Markdown
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
@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