Merged
Show file tree
Hide file tree
Changes from 1 commit
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Next Next commit
Add a null check for attribute promotion
  • Loading branch information
@Fidget-Spinner
Fidget-Spinner committedJun 17, 2025
commit f24987a0aecf9eb1eb666fcc22ea18c04fbc9bbd
Original file line numberDiff line numberDiff line change
Expand Up@@ -2305,6 +2305,40 @@ def testfunc(n):
self.assertNotIn("_GUARD_TOS_INT", uops)
self.assertNotIn("_GUARD_NOS_INT", uops)

def test_attr_promotion_failure(self):
# We're not testing for any specific uops here, just
# testing it doesn't crash.
result = script_helper.run_python_until_end('-c', textwrap.dedent("""
import _testinternalcapi
import opcode
import _opcode

def get_first_executor(func):
code = func.__code__
co_code = code.co_code
for i in range(0, len(co_code), 2):
try:
return _opcode.get_executor(code, i)
except ValueError:
pass
return None

def get_opnames(ex):
return {item[0] for item in ex}

import email

def testfunc(n):
for _ in range(n):
email.jit_testing = None
prompt = email.jit_testing
del email.jit_testing


testfunc(_testinternalcapi.TIER2_THRESHOLD)
"""), PYTHON_JIT="1")
self.assertEqual(result[0].rc, 0, result)


def global_identity(x):
return x
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,6 +103,10 @@ convert_global_to_const(_PyUOpInstruction *inst, PyObject *obj, bool pop)
if ((int)index >= dict->ma_keys->dk_nentries) {
return NULL;
}
PyDictKeysObject *keys = dict->ma_keys;
if (keys->dk_version != inst->operand0) {
return NULL;
}
PyObject *res = entries[index].me_value;
if (res == NULL) {
return NULL;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -557,7 +557,13 @@ dummy_func(void) {
PyDict_Watch(GLOBALS_WATCHER_ID, dict);
_Py_BloomFilter_Add(dependencies, dict);
PyObject *res = convert_global_to_const(this_instr, dict, true);
attr = sym_new_const(ctx, res);
if (res == NULL) {
attr = sym_new_not_null(ctx);
}
else {
attr = sym_new_const(ctx, res);
}

}
}
}
Expand Down
Loading