added the syserrstrb and syserrstrb callback. either one must be supplied.
added some conditionals for nanosleep, strerror_r, pthread
This commit is contained in:
parent
741d45cf0a
commit
ca182c122c
@ -171,7 +171,8 @@ dnl check functions
|
||||
AC_CHECK_FUNCS([gettimeofday settimeofday clock_gettime clock_settime getitimer setitimer])
|
||||
AC_CHECK_FUNCS([backtrace backtrace_symbols])
|
||||
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
|
||||
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf])
|
||||
AC_CHECK_FUNCS([clock_nanosleep nanosleep usleep])
|
||||
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r])
|
||||
AC_CHECK_FUNCS([accept4])
|
||||
|
||||
AC_CHECK_LIB([dyncall_s], [dcNewCallVM],
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "moo-prv.h"
|
||||
|
||||
|
||||
|
||||
/* BEGIN: GENERATED WITH generr.moo */
|
||||
|
||||
static moo_ooch_t errstr_0[] = {'n','o',' ','e','r','r','o','r','\0'};
|
||||
@ -309,9 +308,18 @@ const moo_ooch_t* moo_geterrmsg (moo_t* moo)
|
||||
|
||||
void moo_seterrwithsyserr (moo_t* moo, int syserr)
|
||||
{
|
||||
strerror_r (syserr, moo->errmsg.tmpbuf.bch, MOO_COUNTOF(moo->errmsg.tmpbuf.bch));
|
||||
if (moo->vmprim.syserrstrb)
|
||||
{
|
||||
moo->vmprim.syserrstrb (moo, syserr, moo->errmsg.tmpbuf.bch, MOO_COUNTOF(moo->errmsg.tmpbuf.bch));
|
||||
moo_seterrbfmt (moo, moo_syserr_to_errnum(errno), "%hs", moo->errmsg.tmpbuf.bch);
|
||||
}
|
||||
else
|
||||
{
|
||||
MOO_ASSERT (moo, moo->vmprim.syserrstru != MOO_NULL);
|
||||
moo->vmprim.syserrstru (moo, syserr, moo->errmsg.tmpbuf.uch, MOO_COUNTOF(moo->errmsg.tmpbuf.uch));
|
||||
moo_seterrbfmt (moo, moo_syserr_to_errnum(errno), "%ls", moo->errmsg.tmpbuf.uch);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* ASSERTION FAILURE HANDLERsemaphore heap full
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <errno.h>
|
||||
#include <locale.h>
|
||||
|
||||
#if !defined(__DOS__)
|
||||
#if !defined(__DOS__) && defined(HAVE_PTHREAD) && defined(HAVE_STRERROR_R)
|
||||
# define USE_THREAD
|
||||
#endif
|
||||
|
||||
@ -818,6 +818,16 @@ static void log_write (moo_t* moo, moo_oow_t mask, const moo_ooch_t* msg, moo_oo
|
||||
#endif
|
||||
}
|
||||
|
||||
static void syserrstrb (moo_t* moo, int syserr, moo_bch_t* buf, moo_oow_t len)
|
||||
{
|
||||
#if defined(HAVE_STRERROR_R)
|
||||
strerror_r (syserr, buf, len);
|
||||
#else
|
||||
/* this is not thread safe */
|
||||
moo_copybcstr (buf, len, strerror(syserr));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
static int _add_poll_fd (moo_t* moo, int fd, int event_mask)
|
||||
{
|
||||
@ -1821,19 +1831,21 @@ static void vm_sleep (moo_t* moo, const moo_ntime_t* dur)
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#if defined(USE_THREAD)
|
||||
/* the sleep callback is called only if there is no IO semaphore
|
||||
* waiting. so i can safely call vm_muxwait() without a muxwait callback
|
||||
* when USE_THREAD is true */
|
||||
vm_muxwait (moo, dur, MOO_NULL);
|
||||
#else
|
||||
#elif defined(HAVE_NANOSLEEP)
|
||||
struct timespec ts;
|
||||
ts.tv_sec = dur->sec;
|
||||
ts.tv_nsec = dur->nsec;
|
||||
nanosleep (&ts, MOO_NULL);
|
||||
#elif defined(HAVE_USLEEP)
|
||||
usleep (MOO_SECNSEC_TO_USEC(dur->sec, dur->nsec));
|
||||
#else
|
||||
# error UNSUPPORT SLEEP
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
/* ========================================================================= */
|
||||
@ -2205,6 +2217,7 @@ int main (int argc, char* argv[])
|
||||
vmprim.dl_close = dl_close;
|
||||
vmprim.dl_getsym = dl_getsym;
|
||||
vmprim.log_write = log_write;
|
||||
vmprim.syserrstrb = syserrstrb;
|
||||
vmprim.vm_startup = vm_startup;
|
||||
vmprim.vm_cleanup = vm_cleanup;
|
||||
vmprim.vm_gettime = vm_gettime;
|
||||
|
@ -86,6 +86,12 @@ int moo_init (moo_t* moo, moo_mmgr_t* mmgr, moo_oow_t heapsz, const moo_vmprim_t
|
||||
{
|
||||
int modtab_inited = 0;
|
||||
|
||||
if (!vmprim->syserrstrb && !vmprim->syserrstru)
|
||||
{
|
||||
moo_seterrnum (moo, MOO_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
MOO_MEMSET (moo, 0, MOO_SIZEOF(*moo));
|
||||
moo->mmgr = mmgr;
|
||||
moo->cmgr = moo_getutf8cmgr ();
|
||||
|
@ -928,6 +928,8 @@ typedef void (*moo_vmprim_dlclose_t) (moo_t* moo, void* handle);
|
||||
typedef void* (*moo_vmprim_dlsym_t) (moo_t* moo, void* handle, const moo_ooch_t* name);
|
||||
|
||||
typedef void (*moo_log_write_t) (moo_t* moo, moo_oow_t mask, const moo_ooch_t* msg, moo_oow_t len);
|
||||
typedef void (*moo_syserrstrb_t) (moo_t* moo, int syserr, moo_bch_t* buf, moo_oow_t len);
|
||||
typedef void (*moo_syserrstru_t) (moo_t* moo, int syserr, moo_uch_t* buf, moo_oow_t len);
|
||||
|
||||
typedef int (*moo_vmprim_startup_t) (moo_t* moo);
|
||||
typedef void (*moo_vmprim_cleanup_t) (moo_t* moo);
|
||||
@ -973,6 +975,8 @@ struct moo_vmprim_t
|
||||
moo_vmprim_dlclose_t dl_close;
|
||||
moo_vmprim_dlsym_t dl_getsym;
|
||||
moo_log_write_t log_write;
|
||||
moo_syserrstrb_t syserrstrb;
|
||||
moo_syserrstru_t syserrstru;
|
||||
|
||||
moo_vmprim_startup_t vm_startup;
|
||||
moo_vmprim_cleanup_t vm_cleanup;
|
||||
|
Loading…
Reference in New Issue
Block a user