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

Skip to content

Commit 32c6cdf

Browse files
committed
Added STORE_GLOBAL and DELETE_GLOBAL.
Exceptions may now also be tuples.
1 parent 50afb7a commit 32c6cdf

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

Python/ceval.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ eval_code(co, globals, locals, arg)
523523
case RAISE_EXCEPTION:
524524
v = POP();
525525
w = POP();
526+
/* A tuple is equivalent to its first element here */
527+
while (is_tupleobject(w)) {
528+
u = w;
529+
w = gettupleitem(u, 0);
530+
DECREF(u);
531+
}
526532
if (!is_stringobject(w))
527533
err_setstr(TypeError,
528534
"exceptions must be strings");
@@ -630,7 +636,7 @@ eval_code(co, globals, locals, arg)
630636
why = WHY_EXCEPTION;
631637
}
632638
else if (gettuplesize(v) != oparg) {
633-
err_setstr(RuntimeError,
639+
err_setstr(ValueError,
634640
"unpack tuple of wrong size");
635641
why = WHY_EXCEPTION;
636642
}
@@ -651,7 +657,7 @@ eval_code(co, globals, locals, arg)
651657
why = WHY_EXCEPTION;
652658
}
653659
else if (getlistsize(v) != oparg) {
654-
err_setstr(RuntimeError,
660+
err_setstr(ValueError,
655661
"unpack list of wrong size");
656662
why = WHY_EXCEPTION;
657663
}
@@ -682,6 +688,19 @@ eval_code(co, globals, locals, arg)
682688
DECREF(v);
683689
break;
684690

691+
case STORE_GLOBAL:
692+
w = GETNAMEV(oparg);
693+
v = POP();
694+
err = dict2insert(f->f_globals, w, v);
695+
DECREF(v);
696+
break;
697+
698+
case DELETE_GLOBAL:
699+
w = GETNAMEV(oparg);
700+
if ((err = dict2remove(f->f_globals, w)) != 0)
701+
err_setstr(NameError, getstringvalue(w));
702+
break;
703+
685704
case LOAD_CONST:
686705
x = GETCONST(oparg);
687706
INCREF(x);
@@ -941,7 +960,7 @@ eval_code(co, globals, locals, arg)
941960
Python main loop. Don't do
942961
this for 'finally'. */
943962
if (b->b_type == SETUP_EXCEPT) {
944-
#if 0 /* Oops, this breaks too many things */
963+
#if 1 /* Oops, this breaks too many things */
945964
sysset("exc_traceback", v);
946965
#endif
947966
sysset("exc_value", val);
@@ -1539,7 +1558,8 @@ cmp_exception(err, v)
15391558
int i, n;
15401559
n = gettuplesize(v);
15411560
for (i = 0; i < n; i++) {
1542-
if (err == gettupleitem(v, i))
1561+
/* Test recursively */
1562+
if (cmp_exception(err, gettupleitem(v, i)))
15431563
return 1;
15441564
}
15451565
return 0;

0 commit comments

Comments
 (0)