comparison src/eval.c @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents a86b2b5e0111
children b8cc9ab3f761
comparison
equal deleted inserted replaced
403:9f011ab08d48 404:2f8bb876ab1d
265 in. 265 in.
266 */ 266 */
267 static Lisp_Object Vcondition_handlers; 267 static Lisp_Object Vcondition_handlers;
268 268
269 269
270 #if 0 /* no longer used */ 270 #define DEFEND_AGAINST_THROW_RECURSION
271
272 #ifdef DEFEND_AGAINST_THROW_RECURSION
271 /* Used for error catching purposes by throw_or_bomb_out */ 273 /* Used for error catching purposes by throw_or_bomb_out */
272 static int throw_level; 274 static int throw_level;
273 #endif /* unused */ 275 #endif
276
277 #ifdef ERROR_CHECK_TYPECHECK
278 void check_error_state_sanity (void);
279 #endif
274 280
275 281
276 /************************************************************************/ 282 /************************************************************************/
277 /* The subr object type */ 283 /* The subr object type */
278 /************************************************************************/ 284 /************************************************************************/
1302 return c.val; 1308 return c.val;
1303 } 1309 }
1304 c.val = (*func) (arg); 1310 c.val = (*func) (arg);
1305 if (threw) *threw = 0; 1311 if (threw) *threw = 0;
1306 catchlist = c.next; 1312 catchlist = c.next;
1313 #ifdef ERROR_CHECK_TYPECHECK
1314 check_error_state_sanity ();
1315 #endif
1307 return c.val; 1316 return c.val;
1308 } 1317 }
1309 1318
1310 1319
1311 /* Unwind the specbind, catch, and handler stacks back to CATCH, and 1320 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1358 /* Unwind the specpdl stack, and then restore the proper set of 1367 /* Unwind the specpdl stack, and then restore the proper set of
1359 handlers. */ 1368 handlers. */
1360 unbind_to (catchlist->pdlcount, Qnil); 1369 unbind_to (catchlist->pdlcount, Qnil);
1361 handlerlist = catchlist->handlerlist; 1370 handlerlist = catchlist->handlerlist;
1362 catchlist = catchlist->next; 1371 catchlist = catchlist->next;
1372 #ifdef ERROR_CHECK_TYPECHECK
1373 check_error_state_sanity ();
1374 #endif
1363 } 1375 }
1364 while (! last_time); 1376 while (! last_time);
1365 #else /* Actual XEmacs code */ 1377 #else /* Actual XEmacs code */
1366 /* Unwind the specpdl stack */ 1378 /* Unwind the specpdl stack */
1367 unbind_to (c->pdlcount, Qnil); 1379 unbind_to (c->pdlcount, Qnil);
1368 catchlist = c->next; 1380 catchlist = c->next;
1381 #ifdef ERROR_CHECK_TYPECHECK
1382 check_error_state_sanity ();
1383 #endif
1369 #endif 1384 #endif
1370 1385
1371 gcprolist = c->gcpro; 1386 gcprolist = c->gcpro;
1372 backtrace_list = c->backlist; 1387 backtrace_list = c->backlist;
1373 lisp_eval_depth = c->lisp_eval_depth; 1388 lisp_eval_depth = c->lisp_eval_depth;
1374 1389
1375 #if 0 /* no longer used */ 1390 #ifdef DEFEND_AGAINST_THROW_RECURSION
1376 throw_level = 0; 1391 throw_level = 0;
1377 #endif 1392 #endif
1378 LONGJMP (c->jmp, 1); 1393 LONGJMP (c->jmp, 1);
1379 } 1394 }
1380 1395
1381 static DOESNT_RETURN 1396 static DOESNT_RETURN
1382 throw_or_bomb_out (Lisp_Object tag, Lisp_Object val, int bomb_out_p, 1397 throw_or_bomb_out (Lisp_Object tag, Lisp_Object val, int bomb_out_p,
1383 Lisp_Object sig, Lisp_Object data) 1398 Lisp_Object sig, Lisp_Object data)
1384 { 1399 {
1385 #if 0 1400 #ifdef DEFEND_AGAINST_THROW_RECURSION
1386 /* die if we recurse more than is reasonable */ 1401 /* die if we recurse more than is reasonable */
1387 if (++throw_level > 20) 1402 if (++throw_level > 20)
1388 abort(); 1403 abort();
1389 #endif 1404 #endif
1390 1405
1633 ungcpro, restoring catchlist and condition_handlers are actually 1648 ungcpro, restoring catchlist and condition_handlers are actually
1634 redundant since unbind_to now restores them. But it looks funny not to 1649 redundant since unbind_to now restores them. But it looks funny not to
1635 have this code here, and it doesn't cost anything, so I'm leaving it.*/ 1650 have this code here, and it doesn't cost anything, so I'm leaving it.*/
1636 UNGCPRO; 1651 UNGCPRO;
1637 catchlist = c.next; 1652 catchlist = c.next;
1653 #ifdef ERROR_CHECK_TYPECHECK
1654 check_error_state_sanity ();
1655 #endif
1638 Vcondition_handlers = XCDR (c.tag); 1656 Vcondition_handlers = XCDR (c.tag);
1639 1657
1640 return unbind_to (speccount, c.val); 1658 return unbind_to (speccount, c.val);
1641 } 1659 }
1642 1660
1849 1867
1850 if (!initialized) 1868 if (!initialized)
1851 { 1869 {
1852 /* who knows how much has been initialized? Safest bet is 1870 /* who knows how much has been initialized? Safest bet is
1853 just to bomb out immediately. */ 1871 just to bomb out immediately. */
1872 /* let's not use stderr_out() here, because that does a bunch of
1873 things that might not be safe yet. */
1854 fprintf (stderr, "Error before initialization is complete!\n"); 1874 fprintf (stderr, "Error before initialization is complete!\n");
1855 abort (); 1875 abort ();
1856 } 1876 }
1857 1877
1858 if (gc_in_progress || in_display) 1878 if (gc_in_progress || in_display)
2034 signal_error (Lisp_Object sig, Lisp_Object data) 2054 signal_error (Lisp_Object sig, Lisp_Object data)
2035 { 2055 {
2036 for (;;) 2056 for (;;)
2037 Fsignal (sig, data); 2057 Fsignal (sig, data);
2038 } 2058 }
2059 #ifdef ERROR_CHECK_TYPECHECK
2060 void
2061 check_error_state_sanity (void)
2062 {
2063 struct catchtag *c;
2064 int found_error_tag = 0;
2065
2066 for (c = catchlist; c; c = c->next)
2067 {
2068 if (EQ (c->tag, Qunbound_suspended_errors_tag))
2069 {
2070 found_error_tag = 1;
2071 break;
2072 }
2073 }
2074
2075 assert (found_error_tag || NILP (Vcurrent_error_state));
2076 }
2077 #endif
2078
2079 static Lisp_Object
2080 restore_current_warning_class (Lisp_Object warning_class)
2081 {
2082 Vcurrent_warning_class = warning_class;
2083 return Qnil;
2084 }
2085
2086 static Lisp_Object
2087 restore_current_error_state (Lisp_Object error_state)
2088 {
2089 Vcurrent_error_state = error_state;
2090 return Qnil;
2091 }
2039 2092
2040 static Lisp_Object 2093 static Lisp_Object
2041 call_with_suspended_errors_1 (Lisp_Object opaque_arg) 2094 call_with_suspended_errors_1 (Lisp_Object opaque_arg)
2042 { 2095 {
2043 Lisp_Object val; 2096 Lisp_Object val;
2044 Lisp_Object *kludgy_args = (Lisp_Object *) get_opaque_ptr (opaque_arg); 2097 Lisp_Object *kludgy_args = (Lisp_Object *) get_opaque_ptr (opaque_arg);
2098 Lisp_Object no_error = kludgy_args[2];
2099 int speccount = specpdl_depth ();
2100
2101 if (!EQ (Vcurrent_error_state, no_error))
2102 {
2103 record_unwind_protect (restore_current_error_state,
2104 Vcurrent_error_state);
2105 Vcurrent_error_state = no_error;
2106 }
2045 PRIMITIVE_FUNCALL (val, get_opaque_ptr (kludgy_args[0]), 2107 PRIMITIVE_FUNCALL (val, get_opaque_ptr (kludgy_args[0]),
2046 kludgy_args + 2, XINT (kludgy_args[1])); 2108 kludgy_args + 3, XINT (kludgy_args[1]));
2047 return val; 2109 return unbind_to (speccount, val);
2048 }
2049
2050 static Lisp_Object
2051 restore_current_warning_class (Lisp_Object warning_class)
2052 {
2053 Vcurrent_warning_class = warning_class;
2054 return Qnil;
2055 }
2056
2057 static Lisp_Object
2058 restore_current_error_state (Lisp_Object error_state)
2059 {
2060 Vcurrent_error_state = error_state;
2061 return Qnil;
2062 } 2110 }
2063 2111
2064 /* Many functions would like to do one of three things if an error 2112 /* Many functions would like to do one of three things if an error
2065 occurs: 2113 occurs:
2066 2114
2081 Lisp_Object class, Error_behavior errb, 2129 Lisp_Object class, Error_behavior errb,
2082 int nargs, ...) 2130 int nargs, ...)
2083 { 2131 {
2084 va_list vargs; 2132 va_list vargs;
2085 int speccount; 2133 int speccount;
2086 Lisp_Object kludgy_args[22]; 2134 Lisp_Object kludgy_args[23];
2087 Lisp_Object *args = kludgy_args + 2; 2135 Lisp_Object *args = kludgy_args + 3;
2088 int i; 2136 int i;
2089 Lisp_Object no_error; 2137 Lisp_Object no_error;
2090 2138
2091 assert (SYMBOLP (class)); /* sanity-check */ 2139 assert (SYMBOLP (class)); /* sanity-check */
2092 assert (!NILP (class)); 2140 assert (!NILP (class));
2124 Lisp_Object val; 2172 Lisp_Object val;
2125 PRIMITIVE_FUNCALL (val, fun, args, nargs); 2173 PRIMITIVE_FUNCALL (val, fun, args, nargs);
2126 return val; 2174 return val;
2127 } 2175 }
2128 2176
2129 speccount = specpdl_depth(); 2177 speccount = specpdl_depth ();
2130 if (NILP (class) || NILP (Vcurrent_warning_class)) 2178 if (NILP (class) || NILP (Vcurrent_warning_class))
2131 { 2179 {
2132 /* If we're currently calling for no warnings, then make it so. 2180 /* If we're currently calling for no warnings, then make it so.
2133 If we're currently calling for warnings and we weren't 2181 If we're currently calling for warnings and we weren't
2134 previously, then set our warning class; otherwise, leave 2182 previously, then set our warning class; otherwise, leave
2135 the existing one alone. */ 2183 the existing one alone. */
2136 record_unwind_protect (restore_current_warning_class, 2184 record_unwind_protect (restore_current_warning_class,
2137 Vcurrent_warning_class); 2185 Vcurrent_warning_class);
2138 Vcurrent_warning_class = class; 2186 Vcurrent_warning_class = class;
2139 } 2187 }
2140 if (!EQ (Vcurrent_error_state, no_error))
2141 {
2142 record_unwind_protect (restore_current_error_state,
2143 Vcurrent_error_state);
2144 Vcurrent_error_state = no_error;
2145 }
2146 2188
2147 { 2189 {
2148 int threw; 2190 int threw;
2149 Lisp_Object the_retval; 2191 Lisp_Object the_retval;
2150 Lisp_Object opaque1 = make_opaque_ptr (kludgy_args); 2192 Lisp_Object opaque1 = make_opaque_ptr (kludgy_args);
2152 struct gcpro gcpro1, gcpro2; 2194 struct gcpro gcpro1, gcpro2;
2153 2195
2154 GCPRO2 (opaque1, opaque2); 2196 GCPRO2 (opaque1, opaque2);
2155 kludgy_args[0] = opaque2; 2197 kludgy_args[0] = opaque2;
2156 kludgy_args[1] = make_int (nargs); 2198 kludgy_args[1] = make_int (nargs);
2199 kludgy_args[2] = no_error;
2157 the_retval = internal_catch (Qunbound_suspended_errors_tag, 2200 the_retval = internal_catch (Qunbound_suspended_errors_tag,
2158 call_with_suspended_errors_1, 2201 call_with_suspended_errors_1,
2159 opaque1, &threw); 2202 opaque1, &threw);
2160 free_opaque_ptr (opaque1); 2203 free_opaque_ptr (opaque1);
2161 free_opaque_ptr (opaque2); 2204 free_opaque_ptr (opaque2);
5055 specpdl_size = 50; 5098 specpdl_size = 50;
5056 specpdl = xnew_array (struct specbinding, specpdl_size); 5099 specpdl = xnew_array (struct specbinding, specpdl_size);
5057 /* XEmacs change: increase these values. */ 5100 /* XEmacs change: increase these values. */
5058 max_specpdl_size = 3000; 5101 max_specpdl_size = 3000;
5059 max_lisp_eval_depth = 500; 5102 max_lisp_eval_depth = 500;
5060 #if 0 /* no longer used */ 5103 #ifdef DEFEND_AGAINST_THROW_RECURSION
5061 throw_level = 0; 5104 throw_level = 0;
5062 #endif 5105 #endif
5063 } 5106 }
5064 5107
5065 void 5108 void