diff --git a/moo/lib/comp.c b/moo/lib/comp.c index 819880e..8c1c47d 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -7728,9 +7728,9 @@ static int __compile_class_definition (moo_t* moo, int extend) * this extra module name, i'm free from GC headache */ if (moo_importmod (moo, moo->c->cls.self_oop, moo->c->cls.modname.ptr, moo->c->cls.modname.len) <= -1) { - moo_copyoocstr (moo->errmsg.tmpbuf.ooch, MOO_COUNTOF(moo->errmsg.tmpbuf.ooch), moo->errmsg.buf); + const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); set_syntax_errbfmt (moo, MOO_SYNERR_MODIMPFAIL, &moo->c->cls.modname_loc, &moo->c->cls.modname, - "unable to import %.*js - %js", moo->c->cls.modname.len, moo->c->cls.modname.ptr, moo->errmsg.tmpbuf.ooch); + "unable to import %.*js - %js", moo->c->cls.modname.len, moo->c->cls.modname.ptr, oldmsg); return -1; } } diff --git a/moo/lib/err.c b/moo/lib/err.c index aefc4de..5299a1b 100644 --- a/moo/lib/err.c +++ b/moo/lib/err.c @@ -306,6 +306,12 @@ const moo_ooch_t* moo_geterrmsg (moo_t* moo) return moo->errmsg.buf; } +const moo_ooch_t* moo_backuperrmsg (moo_t* moo) +{ + moo_copyoocstr (moo->errmsg.tmpbuf.ooch, MOO_COUNTOF(moo->errmsg.tmpbuf.ooch), moo->errmsg.buf); + return moo->errmsg.tmpbuf.ooch; +} + void moo_seterrwithsyserr (moo_t* moo, int syserr) { if (moo->vmprim.syserrstrb) diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 542cd71..2123b8c 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -1140,8 +1140,8 @@ static int add_to_sem_io (moo_t* moo, moo_oop_semaphore_t sem, moo_ooi_t io_hand tmp = moo_reallocmem (moo, moo->sem_io_map, MOO_SIZEOF(*tmp) * new_capa); if (!tmp) { - moo_copyoocstr (moo->errmsg.tmpbuf.ooch, MOO_COUNTOF(moo->errmsg.tmpbuf.ooch), moo->errmsg.buf); - moo_seterrbfmt (moo, moo->errnum, "handle %zd out of supported range - %js", moo->errmsg.tmpbuf.ooch); + const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); + moo_seterrbfmt (moo, moo->errnum, "handle %zd out of supported range - %js", oldmsg); return -1; } @@ -2555,8 +2555,8 @@ static moo_pfrc_t __system_add_io_semaphore (moo_t* moo, moo_ooi_t nargs, moo_se if (add_to_sem_io(moo, sem, MOO_OOP_TO_SMOOI(fd), io_type) <= -1) { - moo_copyoocstr (moo->errmsg.tmpbuf.ooch, MOO_COUNTOF(moo->errmsg.tmpbuf.ooch), moo->errmsg.buf); - moo_seterrbfmt (moo, moo->errnum, "cannot add the handle %zd to the multiplexer - %js", MOO_OOP_TO_SMOOI(fd), moo->errmsg.tmpbuf.ooch); + const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); + moo_seterrbfmt (moo, moo->errnum, "cannot add the handle %zd to the multiplexer - %js", MOO_OOP_TO_SMOOI(fd), oldmsg); return MOO_PF_FAILURE; } @@ -2615,8 +2615,8 @@ static moo_pfrc_t pf_system_remove_semaphore (moo_t* moo, moo_ooi_t nargs) if (delete_from_sem_io (moo, sem) <= -1) { - moo_copyoocstr (moo->errmsg.tmpbuf.ooch, MOO_COUNTOF(moo->errmsg.tmpbuf.ooch), moo->errmsg.buf); - moo_seterrbfmt (moo, moo->errnum, "cannot delete the handle %zd from the multiplexer - %js", MOO_OOP_TO_SMOOI(sem->io_handle), moo->errmsg.tmpbuf.ooch); + const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); + moo_seterrbfmt (moo, moo->errnum, "cannot delete the handle %zd from the multiplexer - %js", MOO_OOP_TO_SMOOI(sem->io_handle), oldmsg); return MOO_PF_FAILURE; } diff --git a/moo/lib/moo.h b/moo/lib/moo.h index 100b020..9457d50 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -1670,11 +1670,15 @@ MOO_EXPORT void moo_seterrwithsyserr ( int syserr ); +MOO_EXPORT const moo_ooch_t* moo_geterrstr ( + moo_t* moo +); + MOO_EXPORT const moo_ooch_t* moo_geterrmsg ( moo_t* moo ); -MOO_EXPORT const moo_ooch_t* moo_geterrstr ( +MOO_EXPORT const moo_ooch_t* moo_backuperrmsg ( moo_t* moo );