Add functions to allocate function structs.
This commit is contained in:
parent
85f88b909b
commit
e7f3a9384e
|
@ -89,6 +89,24 @@ libab_result libab_create_value_ref(libab_ref* into, libab_ref* data, libab_ref*
|
||||||
* @return the result of necessary allocations.
|
* @return the result of necessary allocations.
|
||||||
*/
|
*/
|
||||||
libab_result libab_create_value_raw(libab_ref* into, void* data, libab_ref* type);
|
libab_result libab_create_value_raw(libab_ref* into, void* data, libab_ref* type);
|
||||||
|
/**
|
||||||
|
* Allocates a function that uses internal code to run.
|
||||||
|
* @param into the reference into which to store the new function.
|
||||||
|
* @param type the type of the function.
|
||||||
|
* @param fun the function implementation.
|
||||||
|
* @return libab_result the result of any necessary allocations.
|
||||||
|
*/
|
||||||
|
libab_result libab_create_function_internal(libab_ref* into, libab_ref* type,
|
||||||
|
libab_function_ptr fun);
|
||||||
|
/**
|
||||||
|
* Allocates a function that uses a tree to run.
|
||||||
|
* @param into the reference into which to store the new function.
|
||||||
|
* @param type the type of the function.
|
||||||
|
* @param tree the function implementation.
|
||||||
|
* @return libab_result the result of any necessary allocations.
|
||||||
|
*/
|
||||||
|
libab_result libab_create_function_tree(libab_ref* into, libab_ref* type,
|
||||||
|
libab_tree* tree);
|
||||||
/**
|
/**
|
||||||
* Creates a function list object, storing it in to the given reference.
|
* Creates a function list object, storing it in to the given reference.
|
||||||
* @param into the reference to store into.
|
* @param into the reference to store into.
|
||||||
|
|
53
src/util.c
53
src/util.c
|
@ -200,6 +200,59 @@ libab_result libab_create_value_raw(libab_ref* into, void* data, libab_ref* type
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
libab_result libab_create_function_internal(libab_ref* into, libab_ref* type,
|
||||||
|
libab_function_ptr fun) {
|
||||||
|
libab_function* new_function;
|
||||||
|
libab_result result = LIBAB_SUCCESS;
|
||||||
|
|
||||||
|
if((new_function = malloc(sizeof(*new_function)))) {
|
||||||
|
result = libab_function_init_internal(new_function, type, fun);
|
||||||
|
} else {
|
||||||
|
result = LIBAB_MALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result == LIBAB_SUCCESS) {
|
||||||
|
result = libab_ref_new(into, new_function,
|
||||||
|
((libab_parsetype*) libab_ref_get(type))->data_u.base->free_function);
|
||||||
|
if(result != LIBAB_SUCCESS) {
|
||||||
|
libab_function_free(new_function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result != LIBAB_SUCCESS) {
|
||||||
|
libab_ref_null(into);
|
||||||
|
free(new_function);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
libab_result libab_create_function_tree(libab_ref* into, libab_ref* type,
|
||||||
|
libab_tree* tree) {
|
||||||
|
libab_function* new_function;
|
||||||
|
libab_result result = LIBAB_SUCCESS;
|
||||||
|
|
||||||
|
if((new_function = malloc(sizeof(*new_function)))) {
|
||||||
|
result = libab_function_init_tree(new_function, type, tree);
|
||||||
|
} else {
|
||||||
|
result = LIBAB_MALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result == LIBAB_SUCCESS) {
|
||||||
|
result = libab_ref_new(into, new_function, ((libab_parsetype*) libab_ref_get(type))->data_u.base->free_function);
|
||||||
|
if(result != LIBAB_SUCCESS) {
|
||||||
|
libab_function_free(new_function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result != LIBAB_SUCCESS) {
|
||||||
|
libab_ref_null(into);
|
||||||
|
free(new_function);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
libab_result libab_create_function_list(libab_ref* into, libab_ref* type) {
|
libab_result libab_create_function_list(libab_ref* into, libab_ref* type) {
|
||||||
libab_function_list* list;
|
libab_function_list* list;
|
||||||
libab_result result = LIBAB_SUCCESS;
|
libab_result result = LIBAB_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user