Commits

Anonymous committed 436af1c Merge

Automated merge with ssh://team@pocoo.org/arana-main

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__))