mirror of
https://github.com/NixOS/nix
synced 2025-06-26 07:31:15 +02:00
C API: reformat according to proposed clang-format file
This commit is contained in:
parent
91e53de7d3
commit
e1bb799da9
13 changed files with 1115 additions and 1078 deletions
|
@ -20,17 +20,17 @@ extern "C" {
|
|||
|
||||
// Type definitions
|
||||
typedef enum {
|
||||
NIX_TYPE_THUNK,
|
||||
NIX_TYPE_INT,
|
||||
NIX_TYPE_FLOAT,
|
||||
NIX_TYPE_BOOL,
|
||||
NIX_TYPE_STRING,
|
||||
NIX_TYPE_PATH,
|
||||
NIX_TYPE_NULL,
|
||||
NIX_TYPE_ATTRS,
|
||||
NIX_TYPE_LIST,
|
||||
NIX_TYPE_FUNCTION,
|
||||
NIX_TYPE_EXTERNAL
|
||||
NIX_TYPE_THUNK,
|
||||
NIX_TYPE_INT,
|
||||
NIX_TYPE_FLOAT,
|
||||
NIX_TYPE_BOOL,
|
||||
NIX_TYPE_STRING,
|
||||
NIX_TYPE_PATH,
|
||||
NIX_TYPE_NULL,
|
||||
NIX_TYPE_ATTRS,
|
||||
NIX_TYPE_LIST,
|
||||
NIX_TYPE_FUNCTION,
|
||||
NIX_TYPE_EXTERNAL
|
||||
} ValueType;
|
||||
|
||||
// forward declarations
|
||||
|
@ -67,11 +67,12 @@ typedef struct ExternalValue ExternalValue;
|
|||
/** @brief Function pointer for primops
|
||||
* @param[in] state Evaluator state
|
||||
* @param[in] pos Call position, opaque index into the state's position table.
|
||||
* @param[in] args list of arguments. Note that these can be thunks and should be forced using nix_value_force before use.
|
||||
* @param[in] args list of arguments. Note that these can be thunks and should be forced using nix_value_force before
|
||||
* use.
|
||||
* @param[out] ret return value
|
||||
* @see nix_alloc_primop, nix_set_primop
|
||||
*/
|
||||
typedef void (*PrimOpFun)(State *state, int pos, Value **args, Value *ret);
|
||||
typedef void (*PrimOpFun)(State * state, int pos, Value ** args, Value * ret);
|
||||
|
||||
/** @brief Allocate a PrimOp
|
||||
*
|
||||
|
@ -87,8 +88,8 @@ typedef void (*PrimOpFun)(State *state, int pos, Value **args, Value *ret);
|
|||
* @return primop, or null in case of errors
|
||||
* @see nix_set_primop
|
||||
*/
|
||||
PrimOp *nix_alloc_primop(nix_c_context *context, PrimOpFun fun, int arity,
|
||||
const char *name, const char **args, const char *doc);
|
||||
PrimOp * nix_alloc_primop(
|
||||
nix_c_context * context, PrimOpFun fun, int arity, const char * name, const char ** args, const char * doc);
|
||||
|
||||
/** @brief add a primop to the `builtins` attribute set
|
||||
*
|
||||
|
@ -102,7 +103,7 @@ PrimOp *nix_alloc_primop(nix_c_context *context, PrimOpFun fun, int arity,
|
|||
* @return primop, or null in case of errors
|
||||
*
|
||||
*/
|
||||
nix_err nix_register_primop(nix_c_context *context, PrimOp *primOp);
|
||||
nix_err nix_register_primop(nix_c_context * context, PrimOp * primOp);
|
||||
/** @} */
|
||||
|
||||
// Function prototypes
|
||||
|
@ -115,7 +116,7 @@ nix_err nix_register_primop(nix_c_context *context, PrimOp *primOp);
|
|||
* @return value, or null in case of errors
|
||||
*
|
||||
*/
|
||||
Value *nix_alloc_value(nix_c_context *context, State *state);
|
||||
Value * nix_alloc_value(nix_c_context * context, State * state);
|
||||
/** @addtogroup value_manip Manipulating values
|
||||
* @brief Functions to inspect and change Nix language values, represented by Value.
|
||||
* @{
|
||||
|
@ -128,65 +129,65 @@ Value *nix_alloc_value(nix_c_context *context, State *state);
|
|||
* @param[in] value Nix value to inspect
|
||||
* @return type of nix value
|
||||
*/
|
||||
ValueType nix_get_type(nix_c_context *context, const Value *value);
|
||||
ValueType nix_get_type(nix_c_context * context, const Value * value);
|
||||
/** @brief Get type name of value as defined in the evaluator
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return type name, owned string
|
||||
* @todo way to free the result
|
||||
*/
|
||||
const char *nix_get_typename(nix_c_context *context, const Value *value);
|
||||
const char * nix_get_typename(nix_c_context * context, const Value * value);
|
||||
|
||||
/** @brief Get boolean value
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return true or false, error info via context
|
||||
*/
|
||||
bool nix_get_bool(nix_c_context *context, const Value *value);
|
||||
bool nix_get_bool(nix_c_context * context, const Value * value);
|
||||
/** @brief Get string
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return string
|
||||
* @return NULL in case of error.
|
||||
*/
|
||||
const char *nix_get_string(nix_c_context *context, const Value *value);
|
||||
const char * nix_get_string(nix_c_context * context, const Value * value);
|
||||
/** @brief Get path as string
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return string
|
||||
* @return NULL in case of error.
|
||||
*/
|
||||
const char *nix_get_path_string(nix_c_context *context, const Value *value);
|
||||
const char * nix_get_path_string(nix_c_context * context, const Value * value);
|
||||
/** @brief Get the length of a list
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return length of list, error info via context
|
||||
*/
|
||||
unsigned int nix_get_list_size(nix_c_context *context, const Value *value);
|
||||
unsigned int nix_get_list_size(nix_c_context * context, const Value * value);
|
||||
/** @brief Get the element count of an attrset
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return attrset element count, error info via context
|
||||
*/
|
||||
unsigned int nix_get_attrs_size(nix_c_context *context, const Value *value);
|
||||
unsigned int nix_get_attrs_size(nix_c_context * context, const Value * value);
|
||||
/** @brief Get float value in 64 bits
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return float contents, error info via context
|
||||
*/
|
||||
double nix_get_float(nix_c_context *context, const Value *value);
|
||||
double nix_get_float(nix_c_context * context, const Value * value);
|
||||
/** @brief Get int value
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return int contents, error info via context
|
||||
*/
|
||||
int64_t nix_get_int(nix_c_context *context, const Value *value);
|
||||
int64_t nix_get_int(nix_c_context * context, const Value * value);
|
||||
/** @brief Get external reference
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return reference to external, NULL in case of error
|
||||
*/
|
||||
ExternalValue *nix_get_external(nix_c_context *context, Value *);
|
||||
ExternalValue * nix_get_external(nix_c_context * context, Value *);
|
||||
|
||||
/** @brief Get the ix'th element of a list
|
||||
*
|
||||
|
@ -197,8 +198,7 @@ ExternalValue *nix_get_external(nix_c_context *context, Value *);
|
|||
* @param[in] ix list element to get
|
||||
* @return value, NULL in case of errors
|
||||
*/
|
||||
Value *nix_get_list_byidx(nix_c_context *context, const Value *value,
|
||||
State *state, unsigned int ix);
|
||||
Value * nix_get_list_byidx(nix_c_context * context, const Value * value, State * state, unsigned int ix);
|
||||
/** @brief Get an attr by name
|
||||
*
|
||||
* Owned by the GC. Use nix_gc_decref when you're done with the pointer
|
||||
|
@ -208,8 +208,7 @@ Value *nix_get_list_byidx(nix_c_context *context, const Value *value,
|
|||
* @param[in] name attribute name
|
||||
* @return value, NULL in case of errors
|
||||
*/
|
||||
Value *nix_get_attr_byname(nix_c_context *context, const Value *value,
|
||||
State *state, const char *name);
|
||||
Value * nix_get_attr_byname(nix_c_context * context, const Value * value, State * state, const char * name);
|
||||
|
||||
/** @brief Check if an attribute name exists on a value
|
||||
* @param[out] context Optional, stores error information
|
||||
|
@ -218,8 +217,7 @@ Value *nix_get_attr_byname(nix_c_context *context, const Value *value,
|
|||
* @param[in] name attribute name
|
||||
* @return value, error info via context
|
||||
*/
|
||||
bool nix_has_attr_byname(nix_c_context *context, const Value *value,
|
||||
State *state, const char *name);
|
||||
bool nix_has_attr_byname(nix_c_context * context, const Value * value, State * state, const char * name);
|
||||
|
||||
/** @brief Get an attribute by index in the sorted bindings
|
||||
*
|
||||
|
@ -233,8 +231,8 @@ bool nix_has_attr_byname(nix_c_context *context, const Value *value,
|
|||
* @param[out] name will store a pointer to the attribute name
|
||||
* @return value, NULL in case of errors
|
||||
*/
|
||||
Value *nix_get_attr_byidx(nix_c_context *context, const Value *value,
|
||||
State *state, unsigned int i, const char **name);
|
||||
Value *
|
||||
nix_get_attr_byidx(nix_c_context * context, const Value * value, State * state, unsigned int i, const char ** name);
|
||||
|
||||
/** @brief Get an attribute name by index in the sorted bindings
|
||||
*
|
||||
|
@ -247,8 +245,7 @@ Value *nix_get_attr_byidx(nix_c_context *context, const Value *value,
|
|||
* @param[in] i attribute index
|
||||
* @return name, NULL in case of errors
|
||||
*/
|
||||
const char *nix_get_attr_name_byidx(nix_c_context *context, const Value *value,
|
||||
State *state, unsigned int i);
|
||||
const char * nix_get_attr_name_byidx(nix_c_context * context, const Value * value, State * state, unsigned int i);
|
||||
/**@}*/
|
||||
/** @name Setters
|
||||
*/
|
||||
|
@ -259,58 +256,55 @@ const char *nix_get_attr_name_byidx(nix_c_context *context, const Value *value,
|
|||
* @param[in] b the boolean value
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_bool(nix_c_context *context, Value *value, bool b);
|
||||
nix_err nix_set_bool(nix_c_context * context, Value * value, bool b);
|
||||
/** @brief Set a string
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] str the string, copied
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_string(nix_c_context *context, Value *value, const char *str);
|
||||
nix_err nix_set_string(nix_c_context * context, Value * value, const char * str);
|
||||
/** @brief Set a path
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] str the path string, copied
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_path_string(nix_c_context *context, Value *value,
|
||||
const char *str);
|
||||
nix_err nix_set_path_string(nix_c_context * context, Value * value, const char * str);
|
||||
/** @brief Set a float
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] d the float, 64-bits
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_float(nix_c_context *context, Value *value, double d);
|
||||
nix_err nix_set_float(nix_c_context * context, Value * value, double d);
|
||||
/** @brief Set an int
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] i the int
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_int(nix_c_context *context, Value *value, int64_t i);
|
||||
nix_err nix_set_int(nix_c_context * context, Value * value, int64_t i);
|
||||
/** @brief Set null
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_null(nix_c_context *context, Value *value);
|
||||
nix_err nix_set_null(nix_c_context * context, Value * value);
|
||||
/** @brief Set an external value
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] val the external value to set. Will be GC-referenced by the value.
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_external(nix_c_context *context, Value *value,
|
||||
ExternalValue *val);
|
||||
nix_err nix_set_external(nix_c_context * context, Value * value, ExternalValue * val);
|
||||
/** @brief Allocate a list
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] size size of list
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_make_list(nix_c_context *context, State *s, Value *value,
|
||||
unsigned int size);
|
||||
nix_err nix_make_list(nix_c_context * context, State * s, Value * value, unsigned int size);
|
||||
/** @brief Manipulate a list by index
|
||||
*
|
||||
* Don't do this mid-computation.
|
||||
|
@ -321,16 +315,14 @@ nix_err nix_make_list(nix_c_context *context, State *s, Value *value,
|
|||
* @param[in] elem the value to set, will be gc-referenced by the value
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_list_byidx(nix_c_context *context, Value *value,
|
||||
unsigned int ix, Value *elem);
|
||||
nix_err nix_set_list_byidx(nix_c_context * context, Value * value, unsigned int ix, Value * elem);
|
||||
/** @brief Create an attribute set from a bindings builder
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] b bindings builder to use. Make sure to unref this afterwards.
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_make_attrs(nix_c_context *context, Value *value,
|
||||
BindingsBuilder *b);
|
||||
nix_err nix_make_attrs(nix_c_context * context, Value * value, BindingsBuilder * b);
|
||||
/** @brief Set primop
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
|
@ -338,14 +330,14 @@ nix_err nix_make_attrs(nix_c_context *context, Value *value,
|
|||
* @see nix_alloc_primop
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_set_primop(nix_c_context *context, Value *value, PrimOp *op);
|
||||
nix_err nix_set_primop(nix_c_context * context, Value * value, PrimOp * op);
|
||||
/** @brief Copy from another value
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] source value to copy from
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_copy_value(nix_c_context *context, Value *value, Value *source);
|
||||
nix_err nix_copy_value(nix_c_context * context, Value * value, Value * source);
|
||||
/**@}*/
|
||||
|
||||
/** @brief Create a bindings builder
|
||||
|
@ -356,8 +348,7 @@ nix_err nix_copy_value(nix_c_context *context, Value *value, Value *source);
|
|||
* @return owned reference to a bindings builder. Make sure to unref when you're
|
||||
done.
|
||||
*/
|
||||
BindingsBuilder *nix_make_bindings_builder(nix_c_context *context, State *state,
|
||||
size_t capacity);
|
||||
BindingsBuilder * nix_make_bindings_builder(nix_c_context * context, State * state, size_t capacity);
|
||||
/** @brief Insert bindings into a builder
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] builder BindingsBuilder to insert into
|
||||
|
@ -365,15 +356,14 @@ BindingsBuilder *nix_make_bindings_builder(nix_c_context *context, State *state,
|
|||
* @param[in] value value to give the binding
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err nix_bindings_builder_insert(nix_c_context *context,
|
||||
BindingsBuilder *builder, const char *name,
|
||||
Value *value);
|
||||
nix_err
|
||||
nix_bindings_builder_insert(nix_c_context * context, BindingsBuilder * builder, const char * name, Value * value);
|
||||
/** @brief Free a bindings builder
|
||||
*
|
||||
* Does not fail.
|
||||
* @param[in] builder the builder to free
|
||||
*/
|
||||
void nix_bindings_builder_free(BindingsBuilder *builder);
|
||||
void nix_bindings_builder_free(BindingsBuilder * builder);
|
||||
/**@}*/
|
||||
|
||||
// cffi end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue