txlyre 5 дней назад
Родитель
Сommit
ceb68ddc4b
1 измененных файлов с 9 добавлено и 8 удалено
  1. 9 8
      qirt.c

+ 9 - 8
qirt.c

@@ -8,6 +8,7 @@
 
 static qi_bool __debug_enabled = false;
 static pthread_t __main_tid;
+static char *__recerror_msg = NULL;
 
 void *qi_malloc(qi_size_t size)
 {
@@ -1468,9 +1469,9 @@ void qi_fatal(qi_state_t *state, char *format, ...)
   {
     for (qi_ssize_t i = (qi_ssize_t)qi_list_length(state->exceptions) - 2; i >= 0; i--)
     {
-      qi_value_t *value = qi_list_data(state->exceptions, i);
+      char *s = qi_list_data(state->exceptions, i);
 
-      fprintf(stderr, "  While handling an exception: %s\n", qi_repr(state, value, false));
+      fprintf(stderr, "  While handling an exception: %s\n", s);
     }
   }
 
@@ -1547,11 +1548,10 @@ void qi_unset_trap(qi_state_t *state, qi_trap_t *trap)
 
 void qi_throw(qi_state_t *state, qi_value_t *value)
 {
-  qi_list_push(state->exceptions, value);
-
   if (qi_list_empty(state->traps))
   {
-    char *s = value == state->recursionerror ? "RecursionError: max. recursion depth reached" : qi_repr(state, value, false);
+    char *s = value == state->recursionerror ? __recerror_msg : qi_repr(state, value, false);
+    qi_list_push(state->exceptions, s);
 
     while (qi_old_scope(state))
       ;
@@ -1559,8 +1559,6 @@ void qi_throw(qi_state_t *state, qi_value_t *value)
     qi_fatal(state, "uncaught exception: %s", s);
   }
 
-  qi_list_pop(state->exceptions);
-
   qi_trap_t *trap = qi_list_last(state->traps);
   trap->value = value;
 
@@ -5082,6 +5080,8 @@ static void qi_state_setup(qi_state_t *state)
     qi_table_set(state->intern_strs, s, value);
   }
 
+  qi_table_set(state->intern_strs, __recerror_msg, qi_make_string(state, __recerror_msg));
+
   state->pseudomethods = qi_table_make();
   state->pseudomethods_mutex = qi_mutex_create();
 
@@ -5240,7 +5240,7 @@ static void qi_state_setup(qi_state_t *state)
     state->recursionerror = qi_get(state, "RecursionError");
 
     qi_list_t *pargs = qi_list_make_n(1);
-    qi_list_data(pargs, 0) = qi_make_string_copy(state, "max. recursion depth limit reached");
+    qi_list_data(pargs, 0) = qi_make_string(state, __recerror_msg);
 
     state->recursionerror = qi_call(state, state->recursionerror, pargs);
   }
@@ -5255,6 +5255,7 @@ static void _qi_state_init(qi_state_t **state, qi_bool enable_debug)
   GC_set_java_finalization(1);
   *state = qi_malloc(sizeof(qi_state_t));
   __debug_enabled = enable_debug;
+  __recerror_msg = qi_strdup("RecursionError: max. recursion depth reached");
   qi_state_setup(*state);
   __main_tid = pthread_self();
 }