reordered actions in moo_fini()
This commit is contained in:
parent
c0d86a8f0e
commit
fe1731519e
@ -2069,6 +2069,8 @@ static int handle_logopt (moo_t* moo, const moo_bch_t* str)
|
||||
cm = moo_findbcharinbcstr (xstr, ',');
|
||||
if (cm)
|
||||
{
|
||||
/* i duplicate this string for open() below as open() doesn't
|
||||
* accept a length-bounded string */
|
||||
xstr = moo_dupbchars (moo, str, moo_countbcstr(str));
|
||||
if (!xstr)
|
||||
{
|
||||
@ -2105,6 +2107,13 @@ static int handle_logopt (moo_t* moo, const moo_bch_t* str)
|
||||
else if (moo_compbcstr(flt, "warn+") == 0) xtn->logmask |= MOO_LOG_FATAL | MOO_LOG_ERROR | MOO_LOG_WARN;
|
||||
else if (moo_compbcstr(flt, "info+") == 0) xtn->logmask |= MOO_LOG_FATAL | MOO_LOG_ERROR | MOO_LOG_WARN | MOO_LOG_INFO;
|
||||
else if (moo_compbcstr(flt, "debug+") == 0) xtn->logmask |= MOO_LOG_FATAL | MOO_LOG_ERROR | MOO_LOG_WARN | MOO_LOG_INFO | MOO_LOG_DEBUG;
|
||||
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "ERROR: unknown log option value - %s\n", flt);
|
||||
if (str != xstr) moo_freemem (moo, xstr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (cm);
|
||||
|
||||
@ -2150,7 +2159,11 @@ static int handle_dbgopt (moo_t* moo, const moo_bch_t* str)
|
||||
len = cm? (cm - flt): moo_countbcstr(flt);
|
||||
if (moo_compbcharsbcstr (flt, len, "gc") == 0) dbgopt |= MOO_DEBUG_GC;
|
||||
else if (moo_compbcharsbcstr (flt, len, "bigint") == 0) dbgopt |= MOO_DEBUG_BIGINT;
|
||||
/* TODO: error handling for unknown options */
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "ERROR: unknown debug option value - %.*s\n", (int)len, flt);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (cm);
|
||||
|
||||
|
@ -168,6 +168,35 @@ void moo_fini (moo_t* moo)
|
||||
moo_cb_t* cb;
|
||||
moo_oow_t i;
|
||||
|
||||
moo_rbt_walk (&moo->modtab, unload_module, moo); /* unload all modules */
|
||||
moo_rbt_fini (&moo->modtab);
|
||||
|
||||
if (moo->log.ptr)
|
||||
{
|
||||
/* flush pending log messages just in case. */
|
||||
moo->vmprim.log_write (moo, moo->log.last_mask, moo->log.ptr, moo->log.len);
|
||||
}
|
||||
|
||||
for (cb = moo->cblist; cb; cb = cb->next)
|
||||
{
|
||||
/* execute callbacks for finalization */
|
||||
if (cb->fini) cb->fini (moo);
|
||||
}
|
||||
|
||||
if (moo->log.ptr)
|
||||
{
|
||||
/* flush pending log message that could be generated by the fini
|
||||
* callbacks. however, the actual logging might not be produced at
|
||||
* this point because one of the callbacks could arrange to stop
|
||||
* logging */
|
||||
moo->vmprim.log_write (moo, moo->log.last_mask, moo->log.ptr, moo->log.len);
|
||||
}
|
||||
|
||||
/* deregister all callbacks */
|
||||
while (moo->cblist) moo_deregcb (moo, moo->cblist);
|
||||
|
||||
/* free up internal data structures. this is done after all callbacks
|
||||
* are completed */
|
||||
if (moo->sem_list)
|
||||
{
|
||||
moo_freemem (moo, moo->sem_list);
|
||||
@ -203,23 +232,12 @@ void moo_fini (moo_t* moo)
|
||||
moo->proc_map_free_last = -1;
|
||||
}
|
||||
|
||||
moo_rbt_walk (&moo->modtab, unload_module, moo); /* unload all modules */
|
||||
moo_rbt_fini (&moo->modtab);
|
||||
|
||||
for (cb = moo->cblist; cb; cb = cb->next)
|
||||
{
|
||||
if (cb->fini) cb->fini (moo);
|
||||
}
|
||||
|
||||
/* TOOD: persistency? storing objects to image file? */
|
||||
|
||||
moo_killheap (moo, moo->newheap);
|
||||
moo_killheap (moo, moo->curheap);
|
||||
moo_killheap (moo, moo->permheap);
|
||||
|
||||
/* deregister all callbacks */
|
||||
while (moo->cblist) moo_deregcb (moo, moo->cblist);
|
||||
|
||||
for (i = 0; i < MOO_COUNTOF(moo->sbuf); i++)
|
||||
{
|
||||
if (moo->sbuf[i].ptr)
|
||||
@ -233,9 +251,6 @@ void moo_fini (moo_t* moo)
|
||||
|
||||
if (moo->log.ptr)
|
||||
{
|
||||
/* make sure to flush your log message */
|
||||
/* TODO: flush unwritten message */
|
||||
|
||||
moo_freemem (moo, moo->log.ptr);
|
||||
moo->log.capa = 0;
|
||||
moo->log.len = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user