Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c5df06

Browse files
committed
Change the control flow for error handling in the function prelude to
jump to the "Kill locals" section at the end. Add #ifdef macintosh bandaid to make sure we call sigcheck() on the Mac.
1 parent 43f1b8d commit 8c5df06

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

Python/ceval.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ eval_code2(co, globals, locals,
409409
kwdict = newmappingobject();
410410
if (kwdict == NULL)
411411
goto fail;
412+
i = co->co_argcount;
413+
if (co->co_flags & CO_VARARGS)
414+
i++;
415+
SETLOCAL(i, kwdict);
412416
}
413417
if (argcount > co->co_argcount) {
414418
if (!(co->co_flags & CO_VARARGS)) {
@@ -424,12 +428,14 @@ eval_code2(co, globals, locals,
424428
}
425429
if (co->co_flags & CO_VARARGS) {
426430
u = newtupleobject(argcount - n);
431+
if (u == NULL)
432+
goto fail;
433+
SETLOCAL(co->co_argcount, u);
427434
for (i = n; i < argcount; i++) {
428435
x = args[i];
429436
INCREF(x);
430437
SETTUPLEITEM(u, i-n, x);
431438
}
432-
SETLOCAL(co->co_argcount, u);
433439
}
434440
for (i = 0; i < kwcount; i++) {
435441
object *keyword = kws[2*i];
@@ -479,25 +485,11 @@ eval_code2(co, globals, locals,
479485
}
480486
}
481487
}
482-
if (kwdict != NULL) {
483-
i = co->co_argcount;
484-
if (co->co_flags & CO_VARARGS)
485-
i++;
486-
SETLOCAL(i, kwdict);
487-
}
488-
if (0) {
489-
fail:
490-
XDECREF(kwdict);
491-
goto fail2;
492-
}
493488
}
494489
else {
495490
if (argcount > 0 || kwcount > 0) {
496491
err_setstr(TypeError, "no arguments expected");
497-
fail2:
498-
current_frame = f->f_back;
499-
DECREF(f);
500-
return NULL;
492+
goto fail;
501493
}
502494
}
503495

@@ -517,9 +509,7 @@ eval_code2(co, globals, locals,
517509
if (call_trace(&sys_trace, &f->f_trace, f, "call",
518510
None/*XXX how to compute arguments now?*/)) {
519511
/* Trace function raised an error */
520-
current_frame = f->f_back;
521-
DECREF(f);
522-
return NULL;
512+
goto fail;
523513
}
524514
}
525515

@@ -528,9 +518,7 @@ eval_code2(co, globals, locals,
528518
itself and isn't called for "line" events */
529519
if (call_trace(&sys_profile, (object**)0, f, "call",
530520
None/*XXX*/)) {
531-
current_frame = f->f_back;
532-
DECREF(f);
533-
return NULL;
521+
goto fail;
534522
}
535523
}
536524

@@ -567,6 +555,9 @@ eval_code2(co, globals, locals,
567555
goto on_error;
568556
}
569557
}
558+
#ifdef macintosh
559+
#undef HAVE_SIGNAL_H
560+
#endif
570561
#ifndef HAVE_SIGNAL_H /* Is this the right #define? */
571562
/* If we have true signals, the signal handler will call
572563
Py_AddPendingCall() so we don't have to call sigcheck().
@@ -1697,6 +1688,10 @@ eval_code2(co, globals, locals,
16971688
}
16981689
}
16991690

1691+
--recursion_depth;
1692+
1693+
fail: /* Jump here from prelude on failure */
1694+
17001695
/* Kill all local variables */
17011696

17021697
{
@@ -1713,7 +1708,6 @@ eval_code2(co, globals, locals,
17131708

17141709
current_frame = f->f_back;
17151710
DECREF(f);
1716-
--recursion_depth;
17171711

17181712
return retval;
17191713
}

0 commit comments

Comments
 (0)