Skip to content

Commit 66d7b8f

Browse files
authored
Merge pull request #14396 from roberth/c-api-docs
doc: Improve libexpr-c docs
2 parents e3c4140 + f301669 commit 66d7b8f

File tree

6 files changed

+237
-78
lines changed

6 files changed

+237
-78
lines changed

doc/manual/source/development/documentation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,9 @@ $ configurePhase
240240
$ ninja src/external-api-docs/html
241241
$ xdg-open src/external-api-docs/html/index.html
242242
```
243+
244+
If you use direnv, or otherwise want to run `configurePhase` in a transient shell, use:
245+
246+
```bash
247+
nix-shell -A devShells.x86_64-linux.native-clangStdenv --command 'appendToVar mesonFlags "-Ddoc-gen=true"; mesonConfigurePhase'
248+
```

src/external-api-docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ programmatically:
1515
1. Embedding the evaluator
1616
2. Writing language plug-ins
1717

18-
Embedding means you link the Nix C libraries in your program and use them from
18+
Embedding means you link the Nix C API libraries in your program and use them from
1919
there. Adding a plug-in means you make a library that gets loaded by the Nix
2020
language evaluator, specified through a configuration option.
2121

src/libexpr-c/nix_api_expr.h

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
* @brief Bindings to the Nix language evaluator
55
*
66
* See *[Embedding the Nix Evaluator](@ref nix_evaluator_example)* for an example.
7-
* @{
87
*/
98
/** @file
109
* @brief Main entry for the libexpr C bindings
1110
*/
11+
/** @defgroup libexpr_init Initialization
12+
* @ingroup libexpr
13+
* @{
14+
*/
1215

1316
#include "nix_api_store.h"
1417
#include "nix_api_util.h"
@@ -45,7 +48,10 @@ typedef struct nix_eval_state_builder nix_eval_state_builder;
4548
*/
4649
typedef struct EvalState EvalState; // nix::EvalState
4750

51+
/** @} */
52+
4853
/** @brief A Nix language value, or thunk that may evaluate to a value.
54+
* @ingroup value
4955
*
5056
* Values are the primary objects manipulated in the Nix language.
5157
* They are considered to be immutable from a user's perspective, but the process of evaluating a value changes its
@@ -56,7 +62,8 @@ typedef struct EvalState EvalState; // nix::EvalState
5662
*
5763
* The evaluator manages its own memory, but your use of the C API must follow the reference counting rules.
5864
*
59-
* @see value_manip
65+
* @struct nix_value
66+
* @see value_create, value_extract
6067
* @see nix_value_incref, nix_value_decref
6168
*/
6269
typedef struct nix_value nix_value;
@@ -65,6 +72,7 @@ NIX_DEPRECATED("use nix_value instead") typedef nix_value Value;
6572
// Function prototypes
6673
/**
6774
* @brief Initialize the Nix language evaluator.
75+
* @ingroup libexpr_init
6876
*
6977
* This function must be called at least once,
7078
* at some point before constructing a EvalState for the first time.
@@ -77,6 +85,7 @@ nix_err nix_libexpr_init(nix_c_context * context);
7785

7886
/**
7987
* @brief Parses and evaluates a Nix expression from a string.
88+
* @ingroup value_create
8089
*
8190
* @param[out] context Optional, stores error information
8291
* @param[in] state The state of the evaluation.
@@ -93,6 +102,7 @@ nix_err nix_expr_eval_from_string(
93102

94103
/**
95104
* @brief Calls a Nix function with an argument.
105+
* @ingroup value_create
96106
*
97107
* @param[out] context Optional, stores error information
98108
* @param[in] state The state of the evaluation.
@@ -107,6 +117,7 @@ nix_err nix_value_call(nix_c_context * context, EvalState * state, nix_value * f
107117

108118
/**
109119
* @brief Calls a Nix function with multiple arguments.
120+
* @ingroup value_create
110121
*
111122
* Technically these are functions that return functions. It is common for Nix
112123
* functions to be curried, so this function is useful for calling them.
@@ -126,10 +137,12 @@ nix_err nix_value_call_multi(
126137

127138
/**
128139
* @brief Calls a Nix function with multiple arguments.
140+
* @ingroup value_create
129141
*
130142
* Technically these are functions that return functions. It is common for Nix
131143
* functions to be curried, so this function is useful for calling them.
132144
*
145+
* @def NIX_VALUE_CALL
133146
* @param[out] context Optional, stores error information
134147
* @param[in] state The state of the evaluation.
135148
* @param[out] value The result of the function call.
@@ -147,6 +160,7 @@ nix_err nix_value_call_multi(
147160

148161
/**
149162
* @brief Forces the evaluation of a Nix value.
163+
* @ingroup value_create
150164
*
151165
* The Nix interpreter is lazy, and not-yet-evaluated values can be
152166
* of type NIX_TYPE_THUNK instead of their actual value.
@@ -180,18 +194,20 @@ nix_err nix_value_force_deep(nix_c_context * context, EvalState * state, nix_val
180194

181195
/**
182196
* @brief Create a new nix_eval_state_builder
197+
* @ingroup libexpr_init
183198
*
184199
* The settings are initialized to their default value.
185200
* Values can be sourced elsewhere with nix_eval_state_builder_load.
186201
*
187202
* @param[out] context Optional, stores error information
188203
* @param[in] store The Nix store to use.
189-
* @return A new nix_eval_state_builder or NULL on failure.
204+
* @return A new nix_eval_state_builder or NULL on failure. Call nix_eval_state_builder_free() when you're done.
190205
*/
191206
nix_eval_state_builder * nix_eval_state_builder_new(nix_c_context * context, Store * store);
192207

193208
/**
194209
* @brief Read settings from the ambient environment
210+
* @ingroup libexpr_init
195211
*
196212
* Settings are sourced from environment variables and configuration files,
197213
* as documented in the Nix manual.
@@ -204,6 +220,7 @@ nix_err nix_eval_state_builder_load(nix_c_context * context, nix_eval_state_buil
204220

205221
/**
206222
* @brief Set the lookup path for `<...>` expressions
223+
* @ingroup libexpr_init
207224
*
208225
* @param[in] context Optional, stores error information
209226
* @param[in] builder The builder to modify.
@@ -214,18 +231,21 @@ nix_err nix_eval_state_builder_set_lookup_path(
214231

215232
/**
216233
* @brief Create a new Nix language evaluator state
234+
* @ingroup libexpr_init
217235
*
218-
* Remember to nix_eval_state_builder_free after building the state.
236+
* The builder becomes unusable after this call. Remember to call nix_eval_state_builder_free()
237+
* after building the state.
219238
*
220239
* @param[out] context Optional, stores error information
221240
* @param[in] builder The builder to use and free
222-
* @return A new Nix state or NULL on failure.
241+
* @return A new Nix state or NULL on failure. Call nix_state_free() when you're done.
223242
* @see nix_eval_state_builder_new, nix_eval_state_builder_free
224243
*/
225244
EvalState * nix_eval_state_build(nix_c_context * context, nix_eval_state_builder * builder);
226245

227246
/**
228247
* @brief Free a nix_eval_state_builder
248+
* @ingroup libexpr_init
229249
*
230250
* Does not fail.
231251
*
@@ -235,19 +255,21 @@ void nix_eval_state_builder_free(nix_eval_state_builder * builder);
235255

236256
/**
237257
* @brief Create a new Nix language evaluator state
258+
* @ingroup libexpr_init
238259
*
239260
* For more control, use nix_eval_state_builder
240261
*
241262
* @param[out] context Optional, stores error information
242263
* @param[in] lookupPath Null-terminated array of strings corresponding to entries in NIX_PATH.
243264
* @param[in] store The Nix store to use.
244-
* @return A new Nix state or NULL on failure.
265+
* @return A new Nix state or NULL on failure. Call nix_state_free() when you're done.
245266
* @see nix_state_builder_new
246267
*/
247268
EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath, Store * store);
248269

249270
/**
250271
* @brief Frees a Nix state.
272+
* @ingroup libexpr_init
251273
*
252274
* Does not fail.
253275
*
@@ -256,6 +278,7 @@ EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath,
256278
void nix_state_free(EvalState * state);
257279

258280
/** @addtogroup GC
281+
* @ingroup libexpr
259282
* @brief Reference counting and garbage collector operations
260283
*
261284
* The Nix language evaluator uses a garbage collector. To ease C interop, we implement
@@ -286,6 +309,9 @@ nix_err nix_gc_incref(nix_c_context * context, const void * object);
286309
/**
287310
* @brief Decrement the garbage collector reference counter for the given object
288311
*
312+
* @deprecated We are phasing out the general nix_gc_decref() in favor of type-specified free functions, such as
313+
* nix_value_decref().
314+
*
289315
* We also provide typed `nix_*_decref` functions, which are
290316
* - safer to use
291317
* - easier to integrate when deriving bindings
@@ -314,12 +340,11 @@ void nix_gc_now();
314340
*/
315341
void nix_gc_register_finalizer(void * obj, void * cd, void (*finalizer)(void * obj, void * cd));
316342

317-
/** @} */
343+
/** @} */ // doxygen group GC
344+
318345
// cffi end
319346
#ifdef __cplusplus
320347
}
321348
#endif
322349

323-
/** @} */
324-
325350
#endif // NIX_API_EXPR_H

src/libexpr-c/nix_api_external.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#define NIX_API_EXTERNAL_H
33
/** @ingroup libexpr
44
* @addtogroup Externals
5-
* @brief Deal with external values
5+
* @brief Externals let Nix expressions work with foreign values that aren't part of the normal Nix value data model
66
* @{
77
*/
88
/** @file
99
* @brief libexpr C bindings dealing with external values
10+
* @see Externals
1011
*/
1112

1213
#include "nix_api_expr.h"
@@ -115,7 +116,7 @@ typedef struct NixCExternalValueDesc
115116
* @brief Try to compare two external values
116117
*
117118
* Optional, the default is always false.
118-
* If the other object was not a Nix C external value, this comparison will
119+
* If the other object was not a Nix C API external value, this comparison will
119120
* also return false
120121
* @param[in] self the void* passed to nix_create_external_value
121122
* @param[in] other the void* passed to the other object's
@@ -168,7 +169,7 @@ typedef struct NixCExternalValueDesc
168169
/**
169170
* @brief Create an external value, that can be given to nix_init_external
170171
*
171-
* Owned by the GC. Use nix_gc_decref when you're done with the pointer.
172+
* Call nix_gc_decref() when you're done with the pointer.
172173
*
173174
* @param[out] context Optional, stores error information
174175
* @param[in] desc a NixCExternalValueDesc, you should keep this alive as long
@@ -180,10 +181,11 @@ typedef struct NixCExternalValueDesc
180181
ExternalValue * nix_create_external_value(nix_c_context * context, NixCExternalValueDesc * desc, void * v);
181182

182183
/**
183-
* @brief Extract the pointer from a nix c external value.
184+
* @brief Extract the pointer from a Nix C API external value.
184185
* @param[out] context Optional, stores error information
185186
* @param[in] b The external value
186-
* @returns The pointer, or null if the external value was not from nix c.
187+
* @returns The pointer, valid while the external value is valid, or null if the external value was not from the Nix C
188+
* API.
187189
* @see nix_get_external
188190
*/
189191
void * nix_get_external_value_content(nix_c_context * context, ExternalValue * b);

0 commit comments

Comments
 (0)