added the main program to handle SIGINT

This commit is contained in:
hyunghwan.chung 2017-02-14 14:00:14 +00:00
parent f89d809cdc
commit bc5ab97ccf
5 changed files with 22 additions and 8 deletions

View File

@ -1374,6 +1374,7 @@ static MOO_INLINE moo_pfrc_t pf_basic_new (moo_t* moo, moo_ooi_t nargs)
}
}
if (MOO_OOP_IS_SMOOI(((moo_oop_class_t)_class)->trsize))
{
obj = moo_instantiatewithtrailer (moo, _class, size, MOO_NULL, MOO_OOP_TO_SMOOI(((moo_oop_class_t)_class)->trsize));
@ -4307,7 +4308,7 @@ oops:
return -1;
}
int moo_abort (moo_t* moo)
void moo_abort (moo_t* moo)
{
moo->abort_req = 1;
}

View File

@ -978,6 +978,18 @@ static void cancel_tick (void)
#endif
}
static void handle_term (int sig)
{
if (g_moo) moo_abort (g_moo);
}
static void setup_term (void)
{
struct sigaction sa;
sa.sa_handler = handle_term;
sigaction (SIGINT, &sa, MOO_NULL);
}
/* ========================================================================= */
int main (int argc, char* argv[])
@ -1139,6 +1151,7 @@ int main (int argc, char* argv[])
xret = 0;
g_moo = moo;
setup_tick ();
setup_term ();
objname.ptr = str_my_object;
objname.len = 8;

View File

@ -799,7 +799,6 @@ moo_pfimpl_t moo_findpfimpl (moo_t* moo, const moo_pfinfo_t* pfinfo, moo_oow_t p
return MOO_NULL;
}
/* -------------------------------------------------------------------------- */
int moo_setclasstrsize (moo_t* moo, moo_oop_t _class, moo_oow_t size)
@ -835,14 +834,13 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_t _class, moo_oow_t size)
if (c->trsize != moo->_nil)
{
MOO_DEBUG3 (moo, "Not allowed to reset trailer size to %zu on the %.*js class\n",
MOO_DEBUG3 (moo, "Not allowed to re-set trailer size to %zu on the %.*js class\n",
size,
MOO_OBJ_GET_SIZE(c->name),
MOO_OBJ_GET_CHAR_SLOT(c->name));
goto eperm;
}
sc = (moo_oop_class_t)c->superclass;
if (MOO_OOP_IS_SMOOI(sc->trsize) && size < MOO_OOP_TO_SMOOI(sc->trsize))
{
@ -869,11 +867,9 @@ eperm:
return -1;
}
void* moo_getobjtrailer (moo_t* moo, moo_oop_t obj, moo_oow_t* size)
{
if (!MOO_OBJ_IS_OOP_POINTER(obj) || !MOO_OBJ_GET_FLAGS_TRAILER(obj)) return MOO_NULL;
if (size) *size = MOO_OBJ_GET_TRAILER_SIZE(obj);
return MOO_OBJ_GET_TRAILER_BYTE(obj);
}

View File

@ -1394,6 +1394,10 @@ MOO_EXPORT int moo_invoke (
const moo_oocs_t* mthname
);
MOO_EXPORT void moo_abort (
moo_t* moo
);
/* =========================================================================
* COMMON OBJECT MANAGEMENT FUNCTIONS
* ========================================================================= */

View File

@ -62,7 +62,7 @@ static moo_pfrc_t pf_connect (moo_t* moo, moo_ooi_t nargs)
goto softfail;
}
x11 = (x11_t*)MOO_STACK_GETRCV(moo, nargs);
x11 = (x11_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
/*
name = MOO_STACK_GETARG(moo, nargs, 0);
@ -100,7 +100,7 @@ static moo_pfrc_t pf_disconnect (moo_t* moo, moo_ooi_t nargs)
goto softfail;
}
x11 = (x11_t*)MOO_STACK_GETRCV(moo, nargs);
x11 = (x11_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
MOO_DEBUG1 (moo, "<x11.disconnect> %p\n", x11->c);