Skip to content

Commit 93d91b8

Browse files
committed
Updated STORE_FAST; Changed magic number; Added test
1 parent ed1b971 commit 93d91b8

File tree

5 files changed

+63
-26
lines changed

5 files changed

+63
-26
lines changed

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Known values:
292292
Python 3.15a4 3659 (Add CALL_FUNCTION_EX specialization)
293293
Python 3.15a4 3660 (Change generator preamble code)
294294
Python 3.15a4 3661 (Lazy imports IMPORT_NAME opcode changes)
295+
Python 3.15a7+ 3662 (Replace DELETE_FAST with PUSH_NULL; STORE_FAST)
295296
296297
297298
Python 3.16 will start with 3700
@@ -305,7 +306,7 @@ PC/launcher.c must also be updated.
305306
306307
*/
307308

308-
#define PYC_MAGIC_NUMBER 3661
309+
#define PYC_MAGIC_NUMBER 3662
309310
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
310311
(little-endian) and then appending b'\r\n'. */
311312
#define PYC_MAGIC_NUMBER_TOKEN \

Lib/test/test_compiler_codegen.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,15 @@ def test_syntax_error__return_not_in_function(self):
161161
self.assertIsNone(cm.exception.text)
162162
self.assertEqual(cm.exception.offset, 1)
163163
self.assertEqual(cm.exception.end_offset, 10)
164+
165+
def test_del_for_store_name(self):
166+
snippet = "del x"
167+
expected = [
168+
('RESUME', 0),
169+
('ANNOTATIONS_PLACEHOLDER', None),
170+
('PUSH_NULL', None),
171+
('STORE_NAME', 0),
172+
('LOAD_CONST', 0),
173+
('RETURN_VALUE', None),
174+
]
175+
self.codegen_test(snippet, expected)

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 18 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,18 +1628,26 @@ dummy_func(
16281628
inst(STORE_NAME, (v -- )) {
16291629
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
16301630
PyObject *ns = LOCALS();
1631+
int deletion = PyStackRef_IsNull(v);
16311632
int err;
16321633
if (ns == NULL) {
1633-
_PyErr_Format(tstate, PyExc_SystemError,
1634-
"no locals found when storing %R", name);
1635-
PyStackRef_CLOSE(v);
1634+
const char *msg = deletion
1635+
? "no locals found when deleting %R"
1636+
: "no locals found when storing %R";
1637+
_PyErr_Format(tstate, PyExc_SystemError, msg, name);
1638+
if (deletion) {
1639+
DEAD(v);
1640+
}
1641+
else {
1642+
PyStackRef_CLOSE(v);
1643+
}
16361644
ERROR_IF(true);
16371645
}
16381646

1639-
if (PyStackRef_IsNull(v)) {
1647+
if (deletion) {
16401648
DEAD(v);
16411649
err = PyObject_DelItem(ns, name);
1642-
if (err != 0) {
1650+
if (err) {
16431651
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
16441652
NAME_ERROR_MSG,
16451653
name);

Python/generated_cases.c.h

Lines changed: 18 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)