Browse Source

Merge pull request #8 from ouellettetech/logfatal

Adding Error Handling to output the errors to the stdio
Lazar 4 years ago
parent
commit
f18ec3c1cf

+ 2 - 2
oboo-clock-cards/Makefile

@@ -7,8 +7,8 @@
 
 include $(TOPDIR)/rules.mk
 PKG_NAME:=oboo-clock-cards
-PKG_VERSION:=0.2.8
-PKG_RELEASE:=1
+PKG_VERSION:=0.2.9
+PKG_RELEASE:=0
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 

+ 9 - 1
oboo-clock-cards/src/oboo-runtime/duktape/duk_config.h

@@ -2813,6 +2813,15 @@ typedef struct duk_hthread duk_context;
 #error __FAST_MATH__ defined, refusing to compile
 #endif
 
+#define DUK_USE_FATAL_HANDLER(udata,msg) do { \
+        const char *fatal_msg = (msg); /* avoid double evaluation */ \
+        (void) udata; \
+        fprintf(stderr, "*** FATAL ERROR: %s\n", fatal_msg ? fatal_msg : "no message"); \
+        fflush(stderr); \
+        abort(); \
+    } while (0)
+
+
 /*
  *  Autogenerated defaults
  */
@@ -2883,7 +2892,6 @@ typedef struct duk_hthread duk_context;
 #undef DUK_USE_EXTSTR_INTERN_CHECK
 #undef DUK_USE_FASTINT
 #define DUK_USE_FAST_REFCOUNT_DEFAULT
-#undef DUK_USE_FATAL_HANDLER
 #define DUK_USE_FATAL_MAXLEN 128
 #define DUK_USE_FINALIZER_SUPPORT
 #undef DUK_USE_FINALIZER_TORTURE

+ 11 - 1
oboo-clock-cards/src/oboo-runtime/runtime.c

@@ -31,6 +31,16 @@ struct callbacks {
 struct callbacksq q;
 TAILQ_HEAD(callbacksq, callbacks);
 
+static void duktape_fatal_handler(void *udata, const char *msg) {
+  (void) udata;  /* ignored in this case, silence warning */
+    /* Note that 'msg' may be NULL. */
+  fprintf(stderr, "*** FATAL ERROR: %s\n", msg ? msg : "no message");
+  fprintf(stderr, "Causing intentional segfault...\n");
+  fflush(stderr);
+  *((volatile unsigned int *) 0) = (unsigned int) 0xdeadbeefUL;
+  abort();
+}
+
 void initRuntime() {
   int status = 0;
   time_t t;
@@ -39,7 +49,7 @@ void initRuntime() {
   srand((unsigned) time(&t));
 
   /* Init Duktape */
-  ctx = duk_create_heap_default();
+  ctx = duk_create_heap(NULL, NULL, NULL, NULL, duktape_fatal_handler);
 
   /* Init Module Loader */
   // TODO: implement module search function