changed the implemation of the previous commit

This commit is contained in:
hyung-hwan 2022-06-03 06:01:52 +00:00
parent 13f314fba3
commit 4eca91258c
4 changed files with 16 additions and 25 deletions

View File

@ -214,7 +214,7 @@ static int fnc_function_exists (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
/* hawk_query_module_with_name() may update some shared data under /* hawk_query_module_with_name() may update some shared data under
* the hawk object. use a mutex for shared data safety */ * the hawk object. use a mutex for shared data safety */
hawk_mtx_lock (&md->mq_mtx, HAWK_NULL); hawk_mtx_lock (&md->mq_mtx, HAWK_NULL);
rx = (hawk_querymodulewithname(hawk_rtx_gethawk(rtx), &name, &sym) != HAWK_NULL); rx = (hawk_querymodulewithname(hawk_rtx_gethawk(rtx), name.ptr, &sym) != HAWK_NULL);
hawk_mtx_unlock (&md->mq_mtx); hawk_mtx_unlock (&md->mq_mtx);
} }
} }

View File

@ -118,9 +118,9 @@ void hawk_clearsionames (
hawk_mod_t* hawk_querymodulewithname ( hawk_mod_t* hawk_querymodulewithname (
hawk_t* hawk, hawk_t* hawk,
const hawk_oocs_t* name, hawk_ooch_t* name, /* this must be a mutable null-terminated string */
hawk_mod_sym_t* sym hawk_mod_sym_t* sym
); );
#if defined(__cplusplus) #if defined(__cplusplus)

View File

@ -7555,43 +7555,34 @@ done:
} }
hawk_mod_t* hawk_querymodulewithname (hawk_t* hawk, const hawk_oocs_t* name, hawk_mod_sym_t* sym) hawk_mod_t* hawk_querymodulewithname (hawk_t* hawk, hawk_ooch_t* name, hawk_mod_sym_t* sym)
{ {
const hawk_ooch_t* dc; const hawk_ooch_t* dc;
hawk_oocs_t segs[2]; hawk_oocs_t segs[2];
hawk_mod_t* mod; hawk_mod_t* mod;
hawk_oow_t name_len;
hawk_ooch_t tmp; hawk_ooch_t tmp;
/*TOOD: non-module builtin function? fnc? */ /*TOOD: non-module builtin function? fnc? */
dc = hawk_find_oochars_in_oochars(name->ptr, name->len, HAWK_T("::"), 2, 0); name_len = hawk_count_oocstr(name);
dc = hawk_find_oochars_in_oochars(name, name_len, HAWK_T("::"), 2, 0);
if (!dc) if (!dc)
{ {
hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EINVAL, HAWK_T("invalid module name - %js"), name); hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EINVAL, HAWK_T("invalid module name - %js"), name);
return HAWK_NULL; return HAWK_NULL;
} }
#if 1 segs[0].len = dc - name;
segs[0].len = dc - name->ptr; segs[0].ptr = name;
segs[0].ptr = hawk_dupoochars(hawk, name->ptr, segs[0].len); tmp = name[segs[0].len];
if (!segs[0].ptr) return HAWK_NULL; name[segs[0].len] = '\0';
#else
segs[0].len = dc - name->ptr;
segs[0].ptr = name->ptr;
tmp = name->ptr[segs[0].len];
name->ptr[segs[0].len] = '\0';
#endif
segs[1].len = name->len - segs[0].len - 2; segs[1].len = name_len - segs[0].len - 2;
segs[1].ptr = name->ptr + segs[0].len + 2; segs[1].ptr = (hawk_ooch_t*)name + segs[0].len + 2;
mod = query_module(hawk, segs, 2, sym); mod = query_module(hawk, segs, 2, sym);
#if 1 name[segs[0].len] = tmp;
hawk_freemem (hawk, segs[0].ptr);
#else
name->ptr[segs[0].len] = tmp;
#endif
return mod; return mod;
} }

View File

@ -2863,7 +2863,7 @@ hawk_fnc_t* hawk_rtx_valtofnc (hawk_rtx_t* rtx, hawk_val_t* v, hawk_fnc_t* rfnc)
hawk_mod_t* mod; hawk_mod_t* mod;
hawk_mod_sym_t sym; hawk_mod_sym_t sym;
mod = hawk_querymodulewithname(hawk, &x, &sym); mod = hawk_querymodulewithname(hawk, x.ptr, &sym);
hawk_rtx_freevaloocstr (rtx, v, x.ptr); hawk_rtx_freevaloocstr (rtx, v, x.ptr);
if (!mod) return HAWK_NULL; if (!mod) return HAWK_NULL;