1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

C API: update docs based on PR feedback

This commit is contained in:
José Luis Lafuente 2024-02-25 14:20:57 +01:00 committed by José Luis Lafuente
parent 7c602d9f01
commit c49b88b066
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A
7 changed files with 18 additions and 12 deletions

View file

@ -54,7 +54,7 @@ int main() {
nix_gc_decref(NULL, value);
nix_state_free(state);
nix_store_unref(store);
nix_store_free(store);
return 0;
}
```

View file

@ -18,7 +18,7 @@
*
* nix_gc_decref(NULL, value);
* nix_state_free(state);
* nix_store_unref(store);
* nix_store_free(store);
* return 0;
* }
* @endcode

View file

@ -269,6 +269,11 @@ const char * nix_get_attr_name_byidx(nix_c_context * context, const Value * valu
/**@}*/
/** @name Initializers
*
* Values are typically "returned" by initializing already allocated memory that serves as the return value.
* For this reason, the construction of values is not tied their allocation.
* Nix is a language with immutable values. Respect this property by only initializing Values once; and only initialize
* Values that are meant to be initialized by you. Failing to adhere to these rules may lead to undefined behavior.
*/
/**@{*/
/** @brief Set boolean value

View file

@ -50,7 +50,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
NIXC_CATCH_ERRS_NULL
}
void nix_store_unref(Store * store)
void nix_store_free(Store * store)
{
delete store;
}

View file

@ -48,23 +48,24 @@ nix_err nix_init_plugins(nix_c_context * context);
/**
* @brief Open a nix store
* Store instances may share state and resources behind the scenes.
* @param[out] context Optional, stores error information
* @param[in] uri URI of the nix store, copied
* @param[in] params optional, array of key-value pairs, {{"endpoint",
* "https://s3.local"}}
* @return ref-counted Store pointer, NULL in case of errors
* @see nix_store_unref
* @return a Store pointer, NULL in case of errors
* @see nix_store_free
*/
Store * nix_store_open(nix_c_context *, const char * uri, const char *** params);
/**
* @brief Unref a nix store
* @brief Deallocate a nix store and free any resources if not also held by other Store instances.
*
* Does not fail.
* It'll be closed and deallocated when all references are gone.
* @param[in] builder the store to unref
*
* @param[in] store the store to free
*/
void nix_store_unref(Store * store);
void nix_store_free(Store * store);
/**
* @brief get the URI of a nix store

View file

@ -27,7 +27,7 @@ public:
};
~nix_api_store_test() override
{
nix_store_unref(store);
nix_store_free(store);
for (auto & path : fs::recursive_directory_iterator(nixStoreDir)) {
fs::permissions(path, fs::perms::owner_all);

View file

@ -69,7 +69,7 @@ TEST_F(nix_api_util_context, nix_store_open_dummy)
nix_store_get_version(ctx, store, value, 256);
ASSERT_STREQ("", value);
nix_store_unref(store);
nix_store_free(store);
}
TEST_F(nix_api_util_context, nix_store_open_invalid)
@ -78,7 +78,7 @@ TEST_F(nix_api_util_context, nix_store_open_invalid)
Store * store = nix_store_open(ctx, "invalid://", nullptr);
ASSERT_EQ(NIX_ERR_NIX_ERROR, ctx->last_err_code);
ASSERT_EQ(nullptr, store);
nix_store_unref(store);
nix_store_free(store);
}
TEST_F(nix_api_store_test, nix_store_is_valid_path_not_in_store)