コード例 #1
0
// {{{ void simple_vector_free(simple_vector_t *sv, int free_elems, free_fn fn)
void
simple_vector_free(simple_vector_t *sv, int free_elems, free_fn fn)
{
	void *elem;
	size_t i;

	if (sv != NULL) {

		if (free_elems) {
			if (fn == NULL) {
				for (i = 0; i < sv->size; i++) {
					if (simple_vector_get(sv, i, &elem) == 0) {
						free(elem);
					}
				}
			} else {
				for (i = 0; i < sv->size; i++) {
					if (simple_vector_get(sv, i, &elem) == 0) {
						fn(elem);
					}
				}
			}
		}

		free(sv->elements);
		free(sv);

	}

} // }}}
コード例 #2
0
ファイル: json_path.c プロジェクト: baron314159/json_path
static void json_path_check_for_matches(json_path_object *intern)
{
    int i;

    for (i=0; i < intern->paths.len; i++) {
        json_path *curr_path = simple_vector_get(&intern->paths, json_path, i);
        if (curr_path->status == STATUS_MATCHING &&
            curr_path->components.len == intern->path_stack.len) {
            int j;

            for (j=0; j < curr_path->components.len; j++) {
                json_path_component *curr_comp = simple_vector_get(
                    &curr_path->components, json_path_component, j);
                json_path_stack_elem *curr_elem = simple_vector_get(
                    &intern->path_stack, json_path_stack_elem, j);

                if (!json_path_check_match(curr_comp, curr_elem)) {
                    break;
                }
            }

            if (j == curr_path->components.len) {
                curr_path->status = STATUS_COLLECTING;
            }
        }
    }
}
コード例 #3
0
ファイル: json_path.c プロジェクト: baron314159/json_path
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
ファイル: json_path.c プロジェクト: baron314159/json_path
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);
}
コード例 #5
0
ファイル: json_path.c プロジェクト: baron314159/json_path
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);
}