CYAML Internals
|
Free data structures created by the CYAML load functions. More...
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include "data.h"
#include "util.h"
#include "mem.h"
Functions | |
static void | cyaml__free_value (const cyaml_config_t *cfg, const cyaml_schema_value_t *schema, uint8_t *data, uint64_t count) |
static void | cyaml__free_sequence (const cyaml_config_t *cfg, const cyaml_schema_value_t *sequence_schema, uint8_t *const data, uint64_t count) |
static void | cyaml__free_mapping (const cyaml_config_t *cfg, const cyaml_schema_value_t *mapping_schema, uint8_t *const data) |
cyaml_err_t | cyaml_free (const cyaml_config_t *config, const cyaml_schema_value_t *schema, cyaml_data_t *data, unsigned seq_count) |
Free data structures created by the CYAML load functions.
As described in the public API for cyaml_free(), it is preferable for clients to write their own free routines, tailored for their data structure.
This generic CYAML free routine is implemented using recursion, rather than iteration with a heap-allocated stack. This is because recursion seems less bad than allocating within the free code, and the stack-cost of these functions isn't huge. The maximum recursion depth is of course bound by the schema, however schemas for recursively nesting data structures are unbound, e.g. for a data tree structure.
|
static |
Internal function for freeing a CYAML-parsed mapping.
[in] | cfg | The client's CYAML library config. |
[in] | mapping_schema | The schema describing how to free data . |
[in] | data | The data structure to be freed. |
|
static |
Internal function for freeing a CYAML-parsed sequence.
[in] | cfg | The client's CYAML library config. |
[in] | sequence_schema | The schema describing how to free data . |
[in] | data | The data structure to be freed. |
[in] | count | The sequence's entry count. |
|
static |
Internal function for freeing a CYAML-parsed data structure.
[in] | cfg | The client's CYAML library config. |
[in] | schema | The schema describing how to free data . |
[in] | data | The data structure to be freed. |
[in] | count | If data is of type CYAML_SEQUENCE, this is the number of entries in the sequence. |
cyaml_err_t cyaml_free | ( | const cyaml_config_t * | config, |
const cyaml_schema_value_t * | schema, | ||
cyaml_data_t * | data, | ||
unsigned | seq_count | ||
) |
Free data returned by a CYAML load function.
This is a convenience function, which is here purely to minimise the amount of code required in clients. Clients would be better off writing their own free function for the specific data once loaded.
[in] | config | The client's CYAML library config. |
[in] | schema | The schema describing the content of data. Must match the schema given to the CYAML load function used to load the data. |
[in] | data | The data structure to free. |
[in] | seq_count | If top level type is sequence, this should be the entry count, otherwise it is ignored. |