示例#1
0
// {{{ simple_vector_t *simple_vector_new(size_t capacity, size_t elem_size)
simple_vector_t *
simple_vector_new(size_t capacity, size_t elem_size)
{
	simple_vector_t *sv;

	if (elem_size == 0) {
		errno = EFAULT;
		return NULL;
	}

	if ((sv = calloc(1, sizeof(simple_vector_t))) == NULL) {
		errno = ENOMEM;
		return NULL;
	}

	sv->size = 0;
	sv->capacity = capacity == 0 ? 1 : capacity;
	sv->elem_size = elem_size;

	if ((sv->elements = calloc(sv->capacity, sv->elem_size)) == NULL) {
		simple_vector_free(sv, 0, NULL);
		errno = ENOMEM;
		return NULL;
	}

	return sv;

} // }}}
示例#2
0
static inline void json_path_free(json_path *path)
{
    int i;

    efree(path->name);

    for (i=0; i < path->components.len; i++) {
        json_path_component *c = simple_vector_get(&path->components, 
            json_path_component, i);
        if (c->type == COMPONENT_MAP_KEY) {
            efree(c->key);
        }
    }

    simple_vector_free(&path->components);
    simple_vector_free(&path->collection_stack);
}
示例#3
0
static inline void json_path_vector_free(simple_vector *paths)
{
    int i;

    for (i=0; i < paths->len; i++) {
        json_path_free(simple_vector_get(paths, json_path, i));
    }

    simple_vector_free(paths);
}
示例#4
0
static inline void json_path_stack_free(simple_vector *path_stack)
{
    int i;

    for (i=0; i < path_stack->len; i++) {
        json_path_stack_elem *elem = simple_vector_get(path_stack, 
            json_path_stack_elem, i);
        if (elem->type == TYPE_OBJECT) {
            efree(elem->key);
        }
    }

    simple_vector_free(path_stack);
}