Anonymous avatar Anonymous committed d472a14

Out of memory object is now stored on the interpreter so that it's not accidentally shared but available if needed.

Comments (0)

Files changed (6)

         if (seq->free == 0) {                                           \
             seq = AR_REALLOCTE(seq, Ar##tp##Seq,                        \
                                sizeof(ArAstNode *)*(seq->count*2));     \
-            if (!seq) arana_out_of_memory(ps->AI, ps->CF);              \
+            if (!seq) arana_out_of_meory(ps->AI, ps->CF);               \
             seq->free = seq->count;                                     \
             seq->count *= 2;                                            \
         }                                                               \
     return (AR)self;
 }
 
+void
+arana_out_of_meory(AR_SIG)
+{
+    AR_RAISE(AI->_out_of_memory_error);
+}
+
 AR
 arana_stop_iteration_error_new(AR_SIG)
 {
     return (AR)self;
 }
 
-void
-arana_out_of_memory(AR_SIG)
-{
-    static AR instance = AR_NULL;
-    if (instance == AR_NULL)
-        instance = AR_MEMORY_ERROR("Out of Memory");
-    AR_RAISE(instance);
-}
-
 ArObjectType ArErrorType = {
     .name = "Error"
 };
 AR_API_FUNC(void) arana_default_error_handler(AR_SIG);
 AR_API_FUNC(void *) arana_rescue(AR_SIG, ArTryFunc try_func,
                                 ArRescueFunc rescue_func, void *closure);
-AR_API_FUNC(void) arana_out_of_memory(AR_SIG);
 AR_API_FUNC(AR) arana_create_error_module(AR_SIG);
 
 AR_API_FUNC(AR) arana_new_error(AR_SIG, AR message);
                                           AR message);
 AR_API_FUNC(AR) arana_stop_iteration_error_new(AR_SIG);
 AR_API_FUNC(AR) arana_io_error_new(AR_SIG, AR message);
+AR_API_FUNC(void) arana_out_of_meory(AR_SIG);
 
 AR_API_DATA(ArObjectType) ArErrorType;
 AR_API_DATA(ArObjectType) ArInternalErrorType;

arana/interpreter.c

     static int initialized = 0;
     if (initialized)
         return;
+
     GC_INIT();
     initialized = 1;
 }
     if (!(AI = AR_ALLOCT(struct _ArInterpreter)))
         AR_FATAL("Could not initialize interpreter.\n");
 
+    /* create the out of memory object for AR_RAISE_OOM */
+    AI->_out_of_memory_error = AR_MEMORY_ERROR("Out of Memory");
+
+    /* create modules and type map */
     AI->modules = AR_STRINGMAP();
     AI->type_map = AR_ALLOCT(kh_ArTypeMap_t);
     if (!AI->type_map) {
         AR_FREE(AI);
         AR_RAISE_OOM();
     }
-
     AR builtins = arana_initialize_builtins(AR_ISIG);
     AR exceptions = arana_create_error_module(AR_ISIG);
     AR_MODULE_REGISTER(builtins);
     AR_MODULE_REGISTER(exceptions);
+
     *ai_out = AI;
     *f_out = CF;
 }

arana/interpreter.h

     struct _ArTraceback *traceback;
     jmp_buf _error_env;
     int _error_managed;
+    AR _out_of_memory_error;
     kh_ArTypeMap_t *type_map;
 };
 
         arana_traceback_push(AR_ISIG, __FILE__, __LINE__, __func__);    \
         arana_error_jump(AR_ISIG);                                      \
     } while(0)
-#define AR_RAISE_OOM() arana_out_of_memory(AR_ISIG)
+#define AR_RAISE_OOM() arana_out_of_meory(AR_ISIG)
 #define AR_CALL(x, a) arana_call(AR_ISIG, x, a)
 #define AR_CALL_METHODA(o, m, a) arana_call_method(AR_ISIG, o, m, a)
 #define AR_CALL_METHOD(o, m, ...) AR_CALL_METHODA(o, m, AR_TUPLE_PACK(__VA_ARGS__))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.