mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
C API: update docs based on PR feedback
This commit is contained in:
parent
7c602d9f01
commit
c49b88b066
7 changed files with 18 additions and 12 deletions
|
@ -54,7 +54,7 @@ int main() {
|
||||||
|
|
||||||
nix_gc_decref(NULL, value);
|
nix_gc_decref(NULL, value);
|
||||||
nix_state_free(state);
|
nix_state_free(state);
|
||||||
nix_store_unref(store);
|
nix_store_free(store);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*
|
*
|
||||||
* nix_gc_decref(NULL, value);
|
* nix_gc_decref(NULL, value);
|
||||||
* nix_state_free(state);
|
* nix_state_free(state);
|
||||||
* nix_store_unref(store);
|
* nix_store_free(store);
|
||||||
* return 0;
|
* return 0;
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
|
|
|
@ -269,6 +269,11 @@ const char * nix_get_attr_name_byidx(nix_c_context * context, const Value * valu
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
/** @name Initializers
|
/** @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
|
/** @brief Set boolean value
|
||||||
|
|
|
@ -50,7 +50,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
|
||||||
NIXC_CATCH_ERRS_NULL
|
NIXC_CATCH_ERRS_NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
void nix_store_unref(Store * store)
|
void nix_store_free(Store * store)
|
||||||
{
|
{
|
||||||
delete store;
|
delete store;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,23 +48,24 @@ nix_err nix_init_plugins(nix_c_context * context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Open a nix store
|
* @brief Open a nix store
|
||||||
|
* Store instances may share state and resources behind the scenes.
|
||||||
* @param[out] context Optional, stores error information
|
* @param[out] context Optional, stores error information
|
||||||
* @param[in] uri URI of the nix store, copied
|
* @param[in] uri URI of the nix store, copied
|
||||||
* @param[in] params optional, array of key-value pairs, {{"endpoint",
|
* @param[in] params optional, array of key-value pairs, {{"endpoint",
|
||||||
* "https://s3.local"}}
|
* "https://s3.local"}}
|
||||||
* @return ref-counted Store pointer, NULL in case of errors
|
* @return a Store pointer, NULL in case of errors
|
||||||
* @see nix_store_unref
|
* @see nix_store_free
|
||||||
*/
|
*/
|
||||||
Store * nix_store_open(nix_c_context *, const char * uri, const char *** params);
|
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.
|
* 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
|
* @brief get the URI of a nix store
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
};
|
};
|
||||||
~nix_api_store_test() override
|
~nix_api_store_test() override
|
||||||
{
|
{
|
||||||
nix_store_unref(store);
|
nix_store_free(store);
|
||||||
|
|
||||||
for (auto & path : fs::recursive_directory_iterator(nixStoreDir)) {
|
for (auto & path : fs::recursive_directory_iterator(nixStoreDir)) {
|
||||||
fs::permissions(path, fs::perms::owner_all);
|
fs::permissions(path, fs::perms::owner_all);
|
||||||
|
|
|
@ -69,7 +69,7 @@ TEST_F(nix_api_util_context, nix_store_open_dummy)
|
||||||
nix_store_get_version(ctx, store, value, 256);
|
nix_store_get_version(ctx, store, value, 256);
|
||||||
ASSERT_STREQ("", value);
|
ASSERT_STREQ("", value);
|
||||||
|
|
||||||
nix_store_unref(store);
|
nix_store_free(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(nix_api_util_context, nix_store_open_invalid)
|
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);
|
Store * store = nix_store_open(ctx, "invalid://", nullptr);
|
||||||
ASSERT_EQ(NIX_ERR_NIX_ERROR, ctx->last_err_code);
|
ASSERT_EQ(NIX_ERR_NIX_ERROR, ctx->last_err_code);
|
||||||
ASSERT_EQ(nullptr, store);
|
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)
|
TEST_F(nix_api_store_test, nix_store_is_valid_path_not_in_store)
|
||||||
|
|
Loading…
Reference in a new issue