added HCL_MOD_LIBDIRS
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-05 15:01:59 +09:00
parent 15a8f142f1
commit 9bc90c4d60
10 changed files with 286 additions and 110 deletions

View File

@ -188,6 +188,7 @@ static hcl_rbt_walk_t unload_module (hcl_rbt_t* rbt, hcl_rbt_pair_t* pair, void*
void hcl_fini (hcl_t* hcl)
{
hcl_cb_t* cb;
hcl_oow_t i;
hcl_rbt_walk (&hcl->modtab, unload_module, hcl);
hcl_rbt_fini (&hcl->modtab);
@ -217,7 +218,6 @@ void hcl_fini (hcl_t* hcl)
/* deregister all callbacks */
while (hcl->cblist) hcl_deregcb (hcl, hcl->cblist);
/* detach the user data io handlers just in case */
hcl_detachudio (hcl);
@ -311,6 +311,11 @@ void hcl_fini (hcl_t* hcl)
hcl->option.log_target_b = HCL_NULL;
}
for (i = 0; i < HCL_COUNTOF(hcl->option.mod); i++)
{
if (hcl->option.mod[i].ptr) hcl_freemem (hcl, hcl->option.mod[i].ptr);
}
if (hcl->inttostr.xbuf.ptr)
{
hcl_freemem (hcl, hcl->inttostr.xbuf.ptr);
@ -363,6 +368,22 @@ void hcl_reset (hcl_t* hcl)
hcl_gc (hcl, 1);
}
static int dup_str_opt (hcl_t* hcl, const void* value, hcl_oocs_t* tmp)
{
if (value)
{
tmp->ptr = hcl_dupoocstr(hcl, value, &tmp->len);
if (HCL_UNLIKELY(!tmp->ptr)) return -1;
}
else
{
tmp->ptr = HCL_NULL;
tmp->len = 0;
}
return 0;
}
int hcl_setoption (hcl_t* hcl, hcl_option_t id, const void* value)
{
hcl_cb_t* cb;
@ -500,11 +521,26 @@ int hcl_setoption (hcl_t* hcl, hcl_option_t id, const void* value)
break;
}
case HCL_MOD_LIBDIRS:
case HCL_MOD_PREFIX:
case HCL_MOD_POSTFIX:
{
hcl_oocs_t tmp;
int idx;
if (dup_str_opt(hcl, value, &tmp) <= -1) return -1;
idx = id - HCL_MOD_LIBDIRS;
if (hcl->option.mod[idx].ptr) hcl_freemem (hcl, hcl->option.mod[idx].ptr);
hcl->option.mod[idx] = tmp;
return 0;
}
case HCL_MOD_INCTX:
hcl->option.mod_inctx = *(void**)value;
break;
default:
goto einval;
}
@ -567,6 +603,12 @@ int hcl_getoption (hcl_t* hcl, hcl_option_t id, void* value)
*(hcl_oow_t*)value = hcl->option.dfl_procstk_size;
return 0;
case HCL_MOD_LIBDIRS:
case HCL_MOD_PREFIX:
case HCL_MOD_POSTFIX:
*(const hcl_ooch_t**)value = hcl->option.mod[id - HCL_MOD_LIBDIRS].ptr;
return 0;
case HCL_MOD_INCTX:
*(void**)value = hcl->option.mod_inctx;
return 0;