diff --git a/moo/lib/main.c b/moo/lib/main.c index dcb2cde..8853964 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -542,8 +542,10 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags) if (!handle) { moo_bch_t* dash; - moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open(ext) DL %js - %hs", name, sys_dl_error()); - MOO_DEBUG3 (moo, "Failed to open(ext) DL %hs[%js] - %hs\n", &bufptr[len], name, sys_dl_error()); + const moo_bch_t* dl_errstr; + dl_errstr = sys_dl_error(); + MOO_DEBUG3 (moo, "Failed to open(ext) DL %hs[%js] - %hs\n", &bufptr[len], name, dl_errstr); + moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open(ext) DL %js - %hs", name, dl_errstr); dash = moo_rfindbchar(bufptr, moo_countbcstr(bufptr), '-'); if (dash) { @@ -580,8 +582,10 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags) handle = sys_dl_open(bufptr); if (!handle) { - moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open DL %js - %hs", name, sys_dl_error()); - MOO_DEBUG2 (moo, "Failed to open DL %hs - %hs\n", bufptr, sys_dl_error()); + const moo_bch_t* dl_errstr; + dl_errstr = sys_dl_error(); + MOO_DEBUG2 (moo, "Failed to open DL %hs - %hs\n", bufptr, dl_errstr); + moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open DL %js - %hs", name, dl_errstr); } else MOO_DEBUG2 (moo, "Opened DL %hs handle %p\n", bufptr, handle); } @@ -590,8 +594,10 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags) handle = sys_dl_openext(bufptr); if (!handle) { - moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open(ext) DL %js - %hs", name, sys_dl_error()); - MOO_DEBUG2 (moo, "Failed to open(ext) DL %hs - %hs\n", bufptr, sys_dl_error()); + const moo_bch_t* dl_errstr; + dl_errstr = sys_dl_error(); + MOO_DEBUG2 (moo, "Failed to open(ext) DL %hs - %hs\n", bufptr, dl_errstr); + moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open(ext) DL %js - %hs", name, dl_errstr); } else MOO_DEBUG2 (moo, "Opened(ext) DL %hs handle %p\n", bufptr, handle); } @@ -679,7 +685,10 @@ static void* dl_getsym (moo_t* moo, void* handle, const moo_ooch_t* name) sym = sys_dl_getsym(handle, symname); if (!sym) { - moo_seterrbfmt (moo, MOO_ENOENT, "unable to get module symbol %hs", symname); + const moo_bch_t* dl_errstr; + dl_errstr = sys_dl_error(); + MOO_DEBUG3 (moo, "Failed to get module symbol %js from handle %p - %hs\n", name, handle, dl_errstr); + moo_seterrbfmt (moo, MOO_ENOENT, "unable to get module symbol %hs - %hs", symname, dl_errstr); } } } diff --git a/moo/lib/moo.c b/moo/lib/moo.c index 0f6a764..e6f8039 100644 --- a/moo/lib/moo.c +++ b/moo/lib/moo.c @@ -496,7 +496,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel /* TODO: binary search ... */ for (n = 0; n < MOO_COUNTOF(static_modtab); n++) { - if (moo_compoocharsbcstr (name, namelen, static_modtab[n].modname) == 0) + if (moo_compoocharsbcstr(name, namelen, static_modtab[n].modname) == 0) { load = static_modtab[n].modload; break; @@ -513,7 +513,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel /* i copy-insert 'md' into the table before calling 'load'. * to pass the same address to load(), query(), etc */ - pair = moo_rbt_insert (&moo->modtab, (moo_ooch_t*)name, namelen, &md, MOO_SIZEOF(md)); + pair = moo_rbt_insert(&moo->modtab, (moo_ooch_t*)name, namelen, &md, MOO_SIZEOF(md)); if (pair == MOO_NULL) { moo_seterrnum (moo, MOO_ESYSMEM); @@ -523,7 +523,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); MOO_ASSERT (moo, MOO_SIZEOF(mdp->mod.hints) == MOO_SIZEOF(int)); mdp->mod.hints = hints; - if (load (moo, &mdp->mod) <= -1) + if (load(moo, &mdp->mod) <= -1) { moo_rbt_delete (&moo->modtab, (moo_ooch_t*)name, namelen); return MOO_NULL; @@ -555,7 +555,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel moo_copyoochars ((moo_ooch_t*)md.mod.name, name, namelen); if (moo->vmprim.dl_open && moo->vmprim.dl_getsym && moo->vmprim.dl_close) { - md.handle = moo->vmprim.dl_open (moo, &buf[MOD_PREFIX_LEN], MOO_VMPRIM_OPENDL_PFMOD); + md.handle = moo->vmprim.dl_open(moo, &buf[MOD_PREFIX_LEN], MOO_VMPRIM_OPENDL_PFMOD); } if (md.handle == MOO_NULL) @@ -566,11 +566,10 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel } /* attempt to get moo_mod_xxx where xxx is the module name*/ - load = moo->vmprim.dl_getsym (moo, md.handle, buf); + load = moo->vmprim.dl_getsym(moo, md.handle, buf); if (!load) { - const moo_ooch_t* oldmsg = moo_backuperrmsg (moo); - moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to get module symbol [%js] in [%.*js] - %js", buf,namelen, name, oldmsg); + moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to get module symbol [%js] in [%.*js] - %js", buf,namelen, name); MOO_DEBUG3 (moo, "Cannot get a module symbol [%js] in [%.*js]\n", buf, namelen, name); moo->vmprim.dl_close (moo, md.handle); return MOO_NULL; @@ -578,7 +577,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel /* i copy-insert 'md' into the table before calling 'load'. * to pass the same address to load(), query(), etc */ - pair = moo_rbt_insert (&moo->modtab, (void*)name, namelen, &md, MOO_SIZEOF(md)); + pair = moo_rbt_insert(&moo->modtab, (void*)name, namelen, &md, MOO_SIZEOF(md)); if (pair == MOO_NULL) { MOO_DEBUG2 (moo, "Cannot register a module [%.*js]\n", namelen, name); @@ -590,7 +589,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); MOO_ASSERT (moo, MOO_SIZEOF(mdp->mod.hints) == MOO_SIZEOF(int)); mdp->mod.hints = hints; - if (load (moo, &mdp->mod) <= -1) + if (load(moo, &mdp->mod) <= -1) { const moo_ooch_t* oldmsg = moo_backuperrmsg (moo); moo_seterrbfmt (moo, moo_geterrnum(moo), "module initializer [%js] returned failure in [%.*js] - %js", buf, namelen, name, oldmsg);