1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 05:21:16 +02:00

C API: Safer function pointer casting

See https://github.com/NixOS/nix/pull/8699#discussion_r1554312181

Casting a function pointer to `void*` is undefined behavior in the C
spec, since there are platforms with different sizes for these two kinds
of pointers. A safe alternative might be `void (*callback)()`
This commit is contained in:
José Luis Lafuente 2024-04-12 21:41:15 +02:00
parent 5b9cb8b372
commit 01bad63c72
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A
8 changed files with 79 additions and 29 deletions

View file

@ -175,7 +175,11 @@ nix_err nix_libutil_init(nix_c_context * context);
* @return NIX_ERR_KEY if the setting is unknown, or NIX_OK if the setting was retrieved
* successfully.
*/
nix_err nix_setting_get(nix_c_context * context, const char * key, void * callback, void * user_data);
nix_err nix_setting_get(
nix_c_context * context,
const char * key,
void (*callback)(const char * start, unsigned int n, void * user_data),
void * user_data);
/**
* @brief Sets a setting in the nix global configuration.
@ -241,8 +245,11 @@ const char * nix_err_msg(nix_c_context * context, const nix_c_context * ctx, uns
* @see nix_get_string_callback
* @return NIX_OK if there were no errors, an error code otherwise.
*/
nix_err
nix_err_info_msg(nix_c_context * context, const nix_c_context * read_context, void * callback, void * user_data);
nix_err nix_err_info_msg(
nix_c_context * context,
const nix_c_context * read_context,
void (*callback)(const char * start, unsigned int n, void * user_data),
void * user_data);
/**
* @brief Retrieves the error name from a context.
@ -260,7 +267,11 @@ nix_err_info_msg(nix_c_context * context, const nix_c_context * read_context, vo
* @see nix_get_string_callback
* @return NIX_OK if there were no errors, an error code otherwise.
*/
nix_err nix_err_name(nix_c_context * context, const nix_c_context * read_context, void * callback, void * user_data);
nix_err nix_err_name(
nix_c_context * context,
const nix_c_context * read_context,
void (*callback)(const char * start, unsigned int n, void * user_data),
void * user_data);
/**
* @brief Retrieves the most recent error code from a nix_c_context