[gjs] Allow aborting when running out of memory



commit 0bf18867ec7f5cc69b6ec59026fede38d2380d9b
Author: Johan Bilien <jobi litl com>
Date:   Tue Jun 2 20:58:44 2009 +0100

    Allow aborting when running out of memory
    
    Aborts if GJS_ABORT_ON_OOM is set.
    
    Since glib is aborting on failed malloc, we probably want to do the same
    on failed JS_malloc, rather than continuing in an undefined state.

 gjs/jsapi-util.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index 14df955..629c9d3 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -25,11 +25,14 @@
 
 #include <util/log.h>
 #include <util/glib.h>
+#include <util/misc.h>
 
 #include "jsapi-util.h"
 #include "context-jsapi.h"
 
 #include <string.h>
+#include <jscntxt.h>
+
 
 typedef struct {
     GHashTable *dynamic_classes;
@@ -876,6 +879,14 @@ gjs_error_reporter(JSContext     *context,
 {
     const char *warning;
 
+    if (gjs_environment_variable_is_set("GJS_ABORT_ON_OOM") &&
+        report->flags == JSREPORT_ERROR &&
+        report->errorNumber == JSMSG_OUT_OF_MEMORY) {
+        g_error("GJS ran out of memory at %s: %i.",
+                report->filename,
+                report->lineno);
+    }
+
     if ((report->flags & JSREPORT_WARNING) != 0) {
         /* We manually insert "WARNING" into the output instead of
          * having GJS_DEBUG_WARNING because it's convenient to



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]