aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c202
1 files changed, 58 insertions, 144 deletions
diff --git a/src/eval.c b/src/eval.c
index 4b2e256a722..77b1db95397 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -104,7 +104,7 @@ union specbinding *backtrace_next (union specbinding *) EXTERNALLY_VISIBLE;
104union specbinding *backtrace_top (void) EXTERNALLY_VISIBLE; 104union specbinding *backtrace_top (void) EXTERNALLY_VISIBLE;
105 105
106static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *); 106static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
107static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args); 107static Lisp_Object apply_lambda (Lisp_Object, Lisp_Object, ptrdiff_t);
108 108
109static Lisp_Object 109static Lisp_Object
110specpdl_symbol (union specbinding *pdl) 110specpdl_symbol (union specbinding *pdl)
@@ -172,17 +172,11 @@ backtrace_debug_on_exit (union specbinding *pdl)
172/* Functions to modify slots of backtrace records. */ 172/* Functions to modify slots of backtrace records. */
173 173
174static void 174static void
175set_backtrace_args (union specbinding *pdl, Lisp_Object *args) 175set_backtrace_args (union specbinding *pdl, Lisp_Object *args, ptrdiff_t nargs)
176{ 176{
177 eassert (pdl->kind == SPECPDL_BACKTRACE); 177 eassert (pdl->kind == SPECPDL_BACKTRACE);
178 pdl->bt.args = args; 178 pdl->bt.args = args;
179} 179 pdl->bt.nargs = nargs;
180
181static void
182set_backtrace_nargs (union specbinding *pdl, ptrdiff_t n)
183{
184 eassert (pdl->kind == SPECPDL_BACKTRACE);
185 pdl->bt.nargs = n;
186} 180}
187 181
188static void 182static void
@@ -334,10 +328,10 @@ call_debugger (Lisp_Object arg)
334} 328}
335 329
336static void 330static void
337do_debug_on_call (Lisp_Object code) 331do_debug_on_call (Lisp_Object code, ptrdiff_t count)
338{ 332{
339 debug_on_next_call = 0; 333 debug_on_next_call = 0;
340 set_backtrace_debug_on_exit (specpdl_ptr - 1, true); 334 set_backtrace_debug_on_exit (specpdl + count, true);
341 call_debugger (list1 (code)); 335 call_debugger (list1 (code));
342} 336}
343 337
@@ -1272,8 +1266,11 @@ internal_lisp_condition_case (volatile Lisp_Object var, Lisp_Object bodyform,
1272 1266
1273 { /* The first clause is the one that should be checked first, so it should 1267 { /* The first clause is the one that should be checked first, so it should
1274 be added to handlerlist last. So we build in `clauses' a table that 1268 be added to handlerlist last. So we build in `clauses' a table that
1275 contains `handlers' but in reverse order. */ 1269 contains `handlers' but in reverse order. SAFE_ALLOCA won't work
1276 Lisp_Object *clauses = alloca (clausenb * sizeof (Lisp_Object *)); 1270 here due to the setjmp, so impose a MAX_ALLOCA limit. */
1271 if (MAX_ALLOCA / word_size < clausenb)
1272 memory_full (SIZE_MAX);
1273 Lisp_Object *clauses = alloca (clausenb * sizeof *clauses);
1277 Lisp_Object *volatile clauses_volatile = clauses; 1274 Lisp_Object *volatile clauses_volatile = clauses;
1278 int i = clausenb; 1275 int i = clausenb;
1279 for (val = handlers; CONSP (val); val = XCDR (val)) 1276 for (val = handlers; CONSP (val); val = XCDR (val))
@@ -1311,7 +1308,7 @@ internal_lisp_condition_case (volatile Lisp_Object var, Lisp_Object bodyform,
1311 return val; 1308 return val;
1312 } 1309 }
1313 } 1310 }
1314 } 1311 }
1315 1312
1316 val = eval_sub (bodyform); 1313 val = eval_sub (bodyform);
1317 handlerlist = oldhandlerlist; 1314 handlerlist = oldhandlerlist;
@@ -2032,9 +2029,11 @@ grow_specpdl (void)
2032 } 2029 }
2033} 2030}
2034 2031
2035void 2032ptrdiff_t
2036record_in_backtrace (Lisp_Object function, Lisp_Object *args, ptrdiff_t nargs) 2033record_in_backtrace (Lisp_Object function, Lisp_Object *args, ptrdiff_t nargs)
2037{ 2034{
2035 ptrdiff_t count = SPECPDL_INDEX ();
2036
2038 eassert (nargs >= UNEVALLED); 2037 eassert (nargs >= UNEVALLED);
2039 specpdl_ptr->bt.kind = SPECPDL_BACKTRACE; 2038 specpdl_ptr->bt.kind = SPECPDL_BACKTRACE;
2040 specpdl_ptr->bt.debug_on_exit = false; 2039 specpdl_ptr->bt.debug_on_exit = false;
@@ -2042,6 +2041,8 @@ record_in_backtrace (Lisp_Object function, Lisp_Object *args, ptrdiff_t nargs)
2042 specpdl_ptr->bt.args = args; 2041 specpdl_ptr->bt.args = args;
2043 specpdl_ptr->bt.nargs = nargs; 2042 specpdl_ptr->bt.nargs = nargs;
2044 grow_specpdl (); 2043 grow_specpdl ();
2044
2045 return count;
2045} 2046}
2046 2047
2047/* Eval a sub-expression of the current expression (i.e. in the same 2048/* Eval a sub-expression of the current expression (i.e. in the same
@@ -2052,6 +2053,7 @@ eval_sub (Lisp_Object form)
2052 Lisp_Object fun, val, original_fun, original_args; 2053 Lisp_Object fun, val, original_fun, original_args;
2053 Lisp_Object funcar; 2054 Lisp_Object funcar;
2054 struct gcpro gcpro1, gcpro2, gcpro3; 2055 struct gcpro gcpro1, gcpro2, gcpro3;
2056 ptrdiff_t count;
2055 2057
2056 if (SYMBOLP (form)) 2058 if (SYMBOLP (form))
2057 { 2059 {
@@ -2089,10 +2091,10 @@ eval_sub (Lisp_Object form)
2089 original_args = XCDR (form); 2091 original_args = XCDR (form);
2090 2092
2091 /* This also protects them from gc. */ 2093 /* This also protects them from gc. */
2092 record_in_backtrace (original_fun, &original_args, UNEVALLED); 2094 count = record_in_backtrace (original_fun, &original_args, UNEVALLED);
2093 2095
2094 if (debug_on_next_call) 2096 if (debug_on_next_call)
2095 do_debug_on_call (Qt); 2097 do_debug_on_call (Qt, count);
2096 2098
2097 /* At this point, only original_fun and original_args 2099 /* At this point, only original_fun and original_args
2098 have values that will be used below. */ 2100 have values that will be used below. */
@@ -2144,8 +2146,7 @@ eval_sub (Lisp_Object form)
2144 gcpro3.nvars = argnum; 2146 gcpro3.nvars = argnum;
2145 } 2147 }
2146 2148
2147 set_backtrace_args (specpdl_ptr - 1, vals); 2149 set_backtrace_args (specpdl + count, vals, XINT (numargs));
2148 set_backtrace_nargs (specpdl_ptr - 1, XINT (numargs));
2149 2150
2150 val = (XSUBR (fun)->function.aMANY) (XINT (numargs), vals); 2151 val = (XSUBR (fun)->function.aMANY) (XINT (numargs), vals);
2151 UNGCPRO; 2152 UNGCPRO;
@@ -2166,8 +2167,7 @@ eval_sub (Lisp_Object form)
2166 2167
2167 UNGCPRO; 2168 UNGCPRO;
2168 2169
2169 set_backtrace_args (specpdl_ptr - 1, argvals); 2170 set_backtrace_args (specpdl + count, argvals, XINT (numargs));
2170 set_backtrace_nargs (specpdl_ptr - 1, XINT (numargs));
2171 2171
2172 switch (i) 2172 switch (i)
2173 { 2173 {
@@ -2220,7 +2220,7 @@ eval_sub (Lisp_Object form)
2220 } 2220 }
2221 } 2221 }
2222 else if (COMPILEDP (fun)) 2222 else if (COMPILEDP (fun))
2223 val = apply_lambda (fun, original_args); 2223 val = apply_lambda (fun, original_args, count);
2224 else 2224 else
2225 { 2225 {
2226 if (NILP (fun)) 2226 if (NILP (fun))
@@ -2237,7 +2237,7 @@ eval_sub (Lisp_Object form)
2237 } 2237 }
2238 if (EQ (funcar, Qmacro)) 2238 if (EQ (funcar, Qmacro))
2239 { 2239 {
2240 ptrdiff_t count = SPECPDL_INDEX (); 2240 ptrdiff_t count1 = SPECPDL_INDEX ();
2241 Lisp_Object exp; 2241 Lisp_Object exp;
2242 /* Bind lexical-binding during expansion of the macro, so the 2242 /* Bind lexical-binding during expansion of the macro, so the
2243 macro can know reliably if the code it outputs will be 2243 macro can know reliably if the code it outputs will be
@@ -2245,19 +2245,19 @@ eval_sub (Lisp_Object form)
2245 specbind (Qlexical_binding, 2245 specbind (Qlexical_binding,
2246 NILP (Vinternal_interpreter_environment) ? Qnil : Qt); 2246 NILP (Vinternal_interpreter_environment) ? Qnil : Qt);
2247 exp = apply1 (Fcdr (fun), original_args); 2247 exp = apply1 (Fcdr (fun), original_args);
2248 unbind_to (count, Qnil); 2248 unbind_to (count1, Qnil);
2249 val = eval_sub (exp); 2249 val = eval_sub (exp);
2250 } 2250 }
2251 else if (EQ (funcar, Qlambda) 2251 else if (EQ (funcar, Qlambda)
2252 || EQ (funcar, Qclosure)) 2252 || EQ (funcar, Qclosure))
2253 val = apply_lambda (fun, original_args); 2253 val = apply_lambda (fun, original_args, count);
2254 else 2254 else
2255 xsignal1 (Qinvalid_function, original_fun); 2255 xsignal1 (Qinvalid_function, original_fun);
2256 } 2256 }
2257 check_cons_list (); 2257 check_cons_list ();
2258 2258
2259 lisp_eval_depth--; 2259 lisp_eval_depth--;
2260 if (backtrace_debug_on_exit (specpdl_ptr - 1)) 2260 if (backtrace_debug_on_exit (specpdl + count))
2261 val = call_debugger (list2 (Qexit, val)); 2261 val = call_debugger (list2 (Qexit, val));
2262 specpdl_ptr--; 2262 specpdl_ptr--;
2263 2263
@@ -2271,12 +2271,10 @@ Thus, (apply '+ 1 2 '(3 4)) returns 10.
2271usage: (apply FUNCTION &rest ARGUMENTS) */) 2271usage: (apply FUNCTION &rest ARGUMENTS) */)
2272 (ptrdiff_t nargs, Lisp_Object *args) 2272 (ptrdiff_t nargs, Lisp_Object *args)
2273{ 2273{
2274 ptrdiff_t i; 2274 ptrdiff_t i, numargs, funcall_nargs;
2275 EMACS_INT numargs;
2276 register Lisp_Object spread_arg; 2275 register Lisp_Object spread_arg;
2277 register Lisp_Object *funcall_args; 2276 register Lisp_Object *funcall_args;
2278 Lisp_Object fun, retval; 2277 Lisp_Object fun, retval;
2279 struct gcpro gcpro1;
2280 USE_SAFE_ALLOCA; 2278 USE_SAFE_ALLOCA;
2281 2279
2282 fun = args [0]; 2280 fun = args [0];
@@ -2317,10 +2315,9 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2317 /* Avoid making funcall cons up a yet another new vector of arguments 2315 /* Avoid making funcall cons up a yet another new vector of arguments
2318 by explicitly supplying nil's for optional values. */ 2316 by explicitly supplying nil's for optional values. */
2319 SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args); 2317 SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args);
2320 for (i = numargs; i < XSUBR (fun)->max_args;) 2318 for (i = numargs; i < XSUBR (fun)->max_args; /* nothing */)
2321 funcall_args[++i] = Qnil; 2319 funcall_args[++i] = Qnil;
2322 GCPRO1 (*funcall_args); 2320 funcall_nargs = 1 + XSUBR (fun)->max_args;
2323 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
2324 } 2321 }
2325 } 2322 }
2326 funcall: 2323 funcall:
@@ -2329,8 +2326,7 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2329 if (!funcall_args) 2326 if (!funcall_args)
2330 { 2327 {
2331 SAFE_ALLOCA_LISP (funcall_args, 1 + numargs); 2328 SAFE_ALLOCA_LISP (funcall_args, 1 + numargs);
2332 GCPRO1 (*funcall_args); 2329 funcall_nargs = 1 + numargs;
2333 gcpro1.nvars = 1 + numargs;
2334 } 2330 }
2335 2331
2336 memcpy (funcall_args, args, nargs * word_size); 2332 memcpy (funcall_args, args, nargs * word_size);
@@ -2343,11 +2339,10 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2343 spread_arg = XCDR (spread_arg); 2339 spread_arg = XCDR (spread_arg);
2344 } 2340 }
2345 2341
2346 /* By convention, the caller needs to gcpro Ffuncall's args. */ 2342 /* Ffuncall gcpro's all of its args. */
2347 retval = Ffuncall (gcpro1.nvars, funcall_args); 2343 retval = Ffuncall (funcall_nargs, funcall_args);
2348 UNGCPRO;
2349 SAFE_FREE ();
2350 2344
2345 SAFE_FREE ();
2351 return retval; 2346 return retval;
2352} 2347}
2353 2348
@@ -2555,41 +2550,22 @@ run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2555void 2550void
2556run_hook_with_args_2 (Lisp_Object hook, Lisp_Object arg1, Lisp_Object arg2) 2551run_hook_with_args_2 (Lisp_Object hook, Lisp_Object arg1, Lisp_Object arg2)
2557{ 2552{
2558 Lisp_Object temp[3]; 2553 Frun_hook_with_args (3, ((Lisp_Object []) { hook, arg1, arg2 }));
2559 temp[0] = hook;
2560 temp[1] = arg1;
2561 temp[2] = arg2;
2562
2563 Frun_hook_with_args (3, temp);
2564} 2554}
2565 2555
2566/* Apply fn to arg. */ 2556/* Apply fn to arg. */
2567Lisp_Object 2557Lisp_Object
2568apply1 (Lisp_Object fn, Lisp_Object arg) 2558apply1 (Lisp_Object fn, Lisp_Object arg)
2569{ 2559{
2570 struct gcpro gcpro1; 2560 return (NILP (arg) ? Ffuncall (1, &fn)
2571 2561 : Fapply (2, ((Lisp_Object []) { fn, arg })));
2572 GCPRO1 (fn);
2573 if (NILP (arg))
2574 RETURN_UNGCPRO (Ffuncall (1, &fn));
2575 gcpro1.nvars = 2;
2576 {
2577 Lisp_Object args[2];
2578 args[0] = fn;
2579 args[1] = arg;
2580 gcpro1.var = args;
2581 RETURN_UNGCPRO (Fapply (2, args));
2582 }
2583} 2562}
2584 2563
2585/* Call function fn on no arguments. */ 2564/* Call function fn on no arguments. */
2586Lisp_Object 2565Lisp_Object
2587call0 (Lisp_Object fn) 2566call0 (Lisp_Object fn)
2588{ 2567{
2589 struct gcpro gcpro1; 2568 return Ffuncall (1, &fn);
2590
2591 GCPRO1 (fn);
2592 RETURN_UNGCPRO (Ffuncall (1, &fn));
2593} 2569}
2594 2570
2595/* Call function fn with 1 argument arg1. */ 2571/* Call function fn with 1 argument arg1. */
@@ -2597,14 +2573,7 @@ call0 (Lisp_Object fn)
2597Lisp_Object 2573Lisp_Object
2598call1 (Lisp_Object fn, Lisp_Object arg1) 2574call1 (Lisp_Object fn, Lisp_Object arg1)
2599{ 2575{
2600 struct gcpro gcpro1; 2576 return Ffuncall (2, ((Lisp_Object []) { fn, arg1 }));
2601 Lisp_Object args[2];
2602
2603 args[0] = fn;
2604 args[1] = arg1;
2605 GCPRO1 (args[0]);
2606 gcpro1.nvars = 2;
2607 RETURN_UNGCPRO (Ffuncall (2, args));
2608} 2577}
2609 2578
2610/* Call function fn with 2 arguments arg1, arg2. */ 2579/* Call function fn with 2 arguments arg1, arg2. */
@@ -2612,14 +2581,7 @@ call1 (Lisp_Object fn, Lisp_Object arg1)
2612Lisp_Object 2581Lisp_Object
2613call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2) 2582call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2)
2614{ 2583{
2615 struct gcpro gcpro1; 2584 return Ffuncall (3, ((Lisp_Object []) { fn, arg1, arg2 }));
2616 Lisp_Object args[3];
2617 args[0] = fn;
2618 args[1] = arg1;
2619 args[2] = arg2;
2620 GCPRO1 (args[0]);
2621 gcpro1.nvars = 3;
2622 RETURN_UNGCPRO (Ffuncall (3, args));
2623} 2585}
2624 2586
2625/* Call function fn with 3 arguments arg1, arg2, arg3. */ 2587/* Call function fn with 3 arguments arg1, arg2, arg3. */
@@ -2627,15 +2589,7 @@ call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2)
2627Lisp_Object 2589Lisp_Object
2628call3 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) 2590call3 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
2629{ 2591{
2630 struct gcpro gcpro1; 2592 return Ffuncall (4, ((Lisp_Object []) { fn, arg1, arg2, arg3 }));
2631 Lisp_Object args[4];
2632 args[0] = fn;
2633 args[1] = arg1;
2634 args[2] = arg2;
2635 args[3] = arg3;
2636 GCPRO1 (args[0]);
2637 gcpro1.nvars = 4;
2638 RETURN_UNGCPRO (Ffuncall (4, args));
2639} 2593}
2640 2594
2641/* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */ 2595/* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
@@ -2644,16 +2598,7 @@ Lisp_Object
2644call4 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, 2598call4 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2645 Lisp_Object arg4) 2599 Lisp_Object arg4)
2646{ 2600{
2647 struct gcpro gcpro1; 2601 return Ffuncall (5, ((Lisp_Object []) { fn, arg1, arg2, arg3, arg4 }));
2648 Lisp_Object args[5];
2649 args[0] = fn;
2650 args[1] = arg1;
2651 args[2] = arg2;
2652 args[3] = arg3;
2653 args[4] = arg4;
2654 GCPRO1 (args[0]);
2655 gcpro1.nvars = 5;
2656 RETURN_UNGCPRO (Ffuncall (5, args));
2657} 2602}
2658 2603
2659/* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */ 2604/* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
@@ -2662,17 +2607,7 @@ Lisp_Object
2662call5 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, 2607call5 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2663 Lisp_Object arg4, Lisp_Object arg5) 2608 Lisp_Object arg4, Lisp_Object arg5)
2664{ 2609{
2665 struct gcpro gcpro1; 2610 return Ffuncall (6, ((Lisp_Object []) { fn, arg1, arg2, arg3, arg4, arg5 }));
2666 Lisp_Object args[6];
2667 args[0] = fn;
2668 args[1] = arg1;
2669 args[2] = arg2;
2670 args[3] = arg3;
2671 args[4] = arg4;
2672 args[5] = arg5;
2673 GCPRO1 (args[0]);
2674 gcpro1.nvars = 6;
2675 RETURN_UNGCPRO (Ffuncall (6, args));
2676} 2611}
2677 2612
2678/* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */ 2613/* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
@@ -2681,18 +2616,8 @@ Lisp_Object
2681call6 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, 2616call6 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2682 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6) 2617 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6)
2683{ 2618{
2684 struct gcpro gcpro1; 2619 return Ffuncall (7, ((Lisp_Object [])
2685 Lisp_Object args[7]; 2620 { fn, arg1, arg2, arg3, arg4, arg5, arg6 }));
2686 args[0] = fn;
2687 args[1] = arg1;
2688 args[2] = arg2;
2689 args[3] = arg3;
2690 args[4] = arg4;
2691 args[5] = arg5;
2692 args[6] = arg6;
2693 GCPRO1 (args[0]);
2694 gcpro1.nvars = 7;
2695 RETURN_UNGCPRO (Ffuncall (7, args));
2696} 2621}
2697 2622
2698/* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */ 2623/* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
@@ -2701,19 +2626,8 @@ Lisp_Object
2701call7 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, 2626call7 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2702 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7) 2627 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7)
2703{ 2628{
2704 struct gcpro gcpro1; 2629 return Ffuncall (8, ((Lisp_Object [])
2705 Lisp_Object args[8]; 2630 { fn, arg1, arg2, arg3, arg4, arg5, arg6, arg7 }));
2706 args[0] = fn;
2707 args[1] = arg1;
2708 args[2] = arg2;
2709 args[3] = arg3;
2710 args[4] = arg4;
2711 args[5] = arg5;
2712 args[6] = arg6;
2713 args[7] = arg7;
2714 GCPRO1 (args[0]);
2715 gcpro1.nvars = 8;
2716 RETURN_UNGCPRO (Ffuncall (8, args));
2717} 2631}
2718 2632
2719/* The caller should GCPRO all the elements of ARGS. */ 2633/* The caller should GCPRO all the elements of ARGS. */
@@ -2740,7 +2654,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2740 Lisp_Object lisp_numargs; 2654 Lisp_Object lisp_numargs;
2741 Lisp_Object val; 2655 Lisp_Object val;
2742 register Lisp_Object *internal_args; 2656 register Lisp_Object *internal_args;
2743 ptrdiff_t i; 2657 ptrdiff_t i, count;
2744 2658
2745 QUIT; 2659 QUIT;
2746 2660
@@ -2753,13 +2667,13 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2753 } 2667 }
2754 2668
2755 /* This also GCPROs them. */ 2669 /* This also GCPROs them. */
2756 record_in_backtrace (args[0], &args[1], nargs - 1); 2670 count = record_in_backtrace (args[0], &args[1], nargs - 1);
2757 2671
2758 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */ 2672 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2759 maybe_gc (); 2673 maybe_gc ();
2760 2674
2761 if (debug_on_next_call) 2675 if (debug_on_next_call)
2762 do_debug_on_call (Qlambda); 2676 do_debug_on_call (Qlambda, count);
2763 2677
2764 check_cons_list (); 2678 check_cons_list ();
2765 2679
@@ -2789,10 +2703,11 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2789 val = (XSUBR (fun)->function.aMANY) (numargs, args + 1); 2703 val = (XSUBR (fun)->function.aMANY) (numargs, args + 1);
2790 else 2704 else
2791 { 2705 {
2706 Lisp_Object internal_argbuf[8];
2792 if (XSUBR (fun)->max_args > numargs) 2707 if (XSUBR (fun)->max_args > numargs)
2793 { 2708 {
2794 internal_args = alloca (XSUBR (fun)->max_args 2709 eassert (XSUBR (fun)->max_args <= ARRAYELTS (internal_argbuf));
2795 * sizeof *internal_args); 2710 internal_args = internal_argbuf;
2796 memcpy (internal_args, args + 1, numargs * word_size); 2711 memcpy (internal_args, args + 1, numargs * word_size);
2797 for (i = numargs; i < XSUBR (fun)->max_args; i++) 2712 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2798 internal_args[i] = Qnil; 2713 internal_args[i] = Qnil;
@@ -2878,14 +2793,14 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2878 } 2793 }
2879 check_cons_list (); 2794 check_cons_list ();
2880 lisp_eval_depth--; 2795 lisp_eval_depth--;
2881 if (backtrace_debug_on_exit (specpdl_ptr - 1)) 2796 if (backtrace_debug_on_exit (specpdl + count))
2882 val = call_debugger (list2 (Qexit, val)); 2797 val = call_debugger (list2 (Qexit, val));
2883 specpdl_ptr--; 2798 specpdl_ptr--;
2884 return val; 2799 return val;
2885} 2800}
2886 2801
2887static Lisp_Object 2802static Lisp_Object
2888apply_lambda (Lisp_Object fun, Lisp_Object args) 2803apply_lambda (Lisp_Object fun, Lisp_Object args, ptrdiff_t count)
2889{ 2804{
2890 Lisp_Object args_left; 2805 Lisp_Object args_left;
2891 ptrdiff_t i; 2806 ptrdiff_t i;
@@ -2912,15 +2827,14 @@ apply_lambda (Lisp_Object fun, Lisp_Object args)
2912 2827
2913 UNGCPRO; 2828 UNGCPRO;
2914 2829
2915 set_backtrace_args (specpdl_ptr - 1, arg_vector); 2830 set_backtrace_args (specpdl + count, arg_vector, i);
2916 set_backtrace_nargs (specpdl_ptr - 1, i);
2917 tem = funcall_lambda (fun, numargs, arg_vector); 2831 tem = funcall_lambda (fun, numargs, arg_vector);
2918 2832
2919 /* Do the debug-on-exit now, while arg_vector still exists. */ 2833 /* Do the debug-on-exit now, while arg_vector still exists. */
2920 if (backtrace_debug_on_exit (specpdl_ptr - 1)) 2834 if (backtrace_debug_on_exit (specpdl + count))
2921 { 2835 {
2922 /* Don't do it again when we return to eval. */ 2836 /* Don't do it again when we return to eval. */
2923 set_backtrace_debug_on_exit (specpdl_ptr - 1, false); 2837 set_backtrace_debug_on_exit (specpdl + count, false);
2924 tem = call_debugger (list2 (Qexit, tem)); 2838 tem = call_debugger (list2 (Qexit, tem));
2925 } 2839 }
2926 SAFE_FREE (); 2840 SAFE_FREE ();