Ensure operator does not try to take ownership of string.
This commit is contained in:
parent
899ac31210
commit
c4a7117704
|
@ -135,8 +135,9 @@ void libab_behavior_free(libab_behavior* behavior);
|
|||
* @param associativity the associativity (left = -1, right = 1) of the
|
||||
* operator.
|
||||
* @param function the function this operator represents.
|
||||
* @result the result of the initialization.
|
||||
*/
|
||||
void libab_operator_init(libab_operator* op, libab_operator_variant variant,
|
||||
libab_result libab_operator_init(libab_operator* op, libab_operator_variant variant,
|
||||
int precedence, int associativity, const char* function);
|
||||
/**
|
||||
* Frees the given operator.
|
||||
|
|
11
src/custom.c
11
src/custom.c
|
@ -1,4 +1,5 @@
|
|||
#include "custom.h"
|
||||
#include "util.h"
|
||||
|
||||
void libab_behavior_init_internal(libab_behavior* behavior,
|
||||
libab_function_ptr func) {
|
||||
|
@ -26,16 +27,20 @@ void libab_behavior_free(libab_behavior* behavior) {
|
|||
}
|
||||
}
|
||||
|
||||
void libab_operator_init(libab_operator* op, libab_operator_variant variant,
|
||||
libab_result libab_operator_init(libab_operator* op, libab_operator_variant variant,
|
||||
int precedence, int associativity, const char* function) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
char* into;
|
||||
op->variant = variant;
|
||||
op->precedence = precedence;
|
||||
op->associativity = associativity;
|
||||
op->function = function;
|
||||
result = libab_copy_string(&into, function);
|
||||
op->function = into;
|
||||
return result;
|
||||
}
|
||||
|
||||
void libab_operator_free(libab_operator* op) {
|
||||
|
||||
free((char*) op->function);
|
||||
}
|
||||
|
||||
libab_result _function_init(libab_function* function, libab_ref* scope) {
|
||||
|
|
|
@ -102,7 +102,7 @@ libab_result _register_operator(libab* ab, const char* op,
|
|||
if ((new_entry = malloc(sizeof(*new_entry)))) {
|
||||
new_entry->variant = ENTRY_OP;
|
||||
new_operator = &(new_entry->data_u.op);
|
||||
libab_operator_init(new_operator, token_type, precedence, associativity,
|
||||
result = libab_operator_init(new_operator, token_type, precedence, associativity,
|
||||
function);
|
||||
} else {
|
||||
result = LIBAB_MALLOC;
|
||||
|
|
Loading…
Reference in New Issue
Block a user