From bc5ab97ccfd1aa9a3a48844eaa24db244456d9ef Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Tue, 14 Feb 2017 14:00:14 +0000 Subject: [PATCH] added the main program to handle SIGINT --- moo/lib/exec.c | 3 ++- moo/lib/main.c | 13 +++++++++++++ moo/lib/moo.c | 6 +----- moo/lib/moo.h | 4 ++++ moo/mod/x11.c | 4 ++-- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/moo/lib/exec.c b/moo/lib/exec.c index df016a4..79b99db 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -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; } diff --git a/moo/lib/main.c b/moo/lib/main.c index 132dd8f..abf7906 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -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; diff --git a/moo/lib/moo.c b/moo/lib/moo.c index a55d56a..4e4366e 100644 --- a/moo/lib/moo.c +++ b/moo/lib/moo.c @@ -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,13 +834,12 @@ 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); } diff --git a/moo/lib/moo.h b/moo/lib/moo.h index 4c2a2ce..b3d76bd 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -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 * ========================================================================= */ diff --git a/moo/mod/x11.c b/moo/mod/x11.c index 40f3a67..82a30d4 100644 --- a/moo/mod/x11.c +++ b/moo/mod/x11.c @@ -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, " %p\n", x11->c);