Loading...
Searching...
No Matches
free.c File Reference

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"`
Include dependency graph for free.c:

## 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)

## Detailed Description

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.

## Recursion and stack usage

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.

## Function Documentation

## cyaml__free_mapping()

void cyaml__free_mapping | ( | const cyaml_config_t * | cfg,
|  | const cyaml_schema_value_t * | mapping_schema,
|  | uint8_t *const | data )

static

Internal function for freeing a CYAML-parsed mapping.

Parameters

  [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.

## cyaml__free_sequence()

void cyaml__free_sequence | ( | const cyaml_config_t * | cfg,
|  | const cyaml_schema_value_t * | sequence_schema,
|  | uint8_t *const | data,
|  | uint64_t | count )

static

Internal function for freeing a CYAML-parsed sequence.

Parameters

  [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.

## cyaml__free_value()

void cyaml__free_value | ( | const cyaml_config_t * | cfg,
|  | const cyaml_schema_value_t * | schema,
|  | uint8_t * | data,
|  | uint64_t | count )

static

Internal function for freeing a CYAML-parsed data structure.

Parameters

  [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_free()

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.

Note
  This is a recursive operation, freeing all nested data.

Parameters

  [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.

Returns
  CYAML_OK on success, or appropriate error code otherwise.