diff options
Diffstat (limited to 'src/env.c')
-rw-r--r-- | src/env.c | 16 |
1 files changed, 6 insertions, 10 deletions
@@ -3,7 +3,7 @@ #include "common.h" #include "env.h" -#include "hashtable.h" +#include "value.h" #define ENV_TABLE_CAP (1 << 8) @@ -32,17 +32,13 @@ static bool equal(void *key1, void *key2) return false; } -static void env_add_ref(env_t env); - env_t env_create(env_t parent, env_destroy_func destroy_func) { env_t env = malloc(sizeof(*env)); env->destroy_func = destroy_func; env->parent = parent; - env->refs = 0; + env->refs = 1; - env_add_ref(env); - ERR_Z(env->table = hashtable_create(ENV_TABLE_CAP, hash, equal), env_destroy(env)); @@ -58,7 +54,6 @@ void env_destroy(env_t env) if(env->refs > 0) return; - hashtable_for_each_item(env->table, item, i) { env->destroy_func((char *)item->key, (value_t)item->data); } @@ -67,12 +62,13 @@ void env_destroy(env_t env) free(env); } - -static void env_add_ref(env_t env) +env_t env_copy(env_t env) { env->refs++; if(env->parent) { - env_add_ref(env->parent); + env_copy(env->parent); } + + return env; } |