https://github.com/python/cpython/commit/c50d6cd01215b72282221845ea4831a104f12c4c
commit: c50d6cd01215b72282221845ea4831a104f12c4c
branch: main
author: Ken Jin <[email protected]>
committer: Fidget-Spinner <[email protected]>
date: 2026-04-04T18:16:23+08:00
summary:
gh-148078: Fix uses of sym_is_not_null in JIT optimizer (GH-148079)
files:
M Python/optimizer_bytecodes.c
M Python/optimizer_cases.c.h
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index 4f16fa7a5ff4bf..dfb97625bf924f 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -979,7 +979,7 @@ dummy_func(void) {
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
PyFunctionObject *func = (PyFunctionObject
*)sym_get_const(ctx, callable);
PyCodeObject *co = (PyCodeObject *)func->func_code;
- if (co->co_argcount == oparg + !sym_is_null(self_or_null)) {
+ if (co->co_argcount == oparg + sym_is_not_null(self_or_null)) {
ADD_OP(_NOP, 0 ,0);
}
}
@@ -1266,9 +1266,10 @@ dummy_func(void) {
op(_GUARD_CALLABLE_BUILTIN_O, (callable, self_or_null, args[oparg] --
callable, self_or_null, args[oparg])) {
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyCFunction_Type)) {
+ if (callable_o && sym_matches_type(callable, &PyCFunction_Type) &&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
- if (!sym_is_null(self_or_null)) {
+ if (sym_is_not_null(self_or_null)) {
total_args++;
}
if (total_args == 1 && PyCFunction_GET_FLAGS(callable_o) ==
METH_O) {
@@ -1321,7 +1322,8 @@ dummy_func(void) {
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_O, (callable, self_or_null,
args[oparg] -- callable, self_or_null, args[oparg])) {
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
+ if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type) &&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
if (sym_is_not_null(self_or_null)) {
total_args++;
@@ -1347,7 +1349,8 @@ dummy_func(void) {
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS, (callable,
self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
+ if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type) &&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
if (sym_is_not_null(self_or_null)) {
total_args++;
@@ -1373,7 +1376,8 @@ dummy_func(void) {
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null,
args[oparg] -- callable, self_or_null, args[oparg])) {
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
+ if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type) &&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
if (sym_is_not_null(self_or_null)) {
total_args++;
@@ -1439,7 +1443,8 @@ dummy_func(void) {
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_FAST, (callable, self_or_null,
args[oparg] -- callable, self_or_null, args[oparg])) {
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
+ if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type) &&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
if (sym_is_not_null(self_or_null)) {
total_args++;
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 2b0efd9db252d7..4643a0ed0c5f9d 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -3565,7 +3565,7 @@
if (sym_is_null(self_or_null) ||
sym_is_not_null(self_or_null)) {
PyFunctionObject *func = (PyFunctionObject
*)sym_get_const(ctx, callable);
PyCodeObject *co = (PyCodeObject *)func->func_code;
- if (co->co_argcount == oparg + !sym_is_null(self_or_null))
{
+ if (co->co_argcount == oparg +
sym_is_not_null(self_or_null)) {
ADD_OP(_NOP, 0 ,0);
}
}
@@ -3835,9 +3835,10 @@
self_or_null = stack_pointer[-1 - oparg];
callable = stack_pointer[-2 - oparg];
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyCFunction_Type)) {
+ if (callable_o && sym_matches_type(callable, &PyCFunction_Type) &&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
- if (!sym_is_null(self_or_null)) {
+ if (sym_is_not_null(self_or_null)) {
total_args++;
}
if (total_args == 1 && PyCFunction_GET_FLAGS(callable_o) ==
METH_O) {
@@ -4072,7 +4073,8 @@
self_or_null = stack_pointer[-1 - oparg];
callable = stack_pointer[-2 - oparg];
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type))
{
+ if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)
&&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
if (sym_is_not_null(self_or_null)) {
total_args++;
@@ -4171,7 +4173,8 @@
self_or_null = stack_pointer[-1 - oparg];
callable = stack_pointer[-2 - oparg];
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type))
{
+ if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)
&&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
if (sym_is_not_null(self_or_null)) {
total_args++;
@@ -4235,7 +4238,8 @@
self_or_null = stack_pointer[-1 - oparg];
callable = stack_pointer[-2 - oparg];
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type))
{
+ if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)
&&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
if (sym_is_not_null(self_or_null)) {
total_args++;
@@ -4299,7 +4303,8 @@
self_or_null = stack_pointer[-1 - oparg];
callable = stack_pointer[-2 - oparg];
PyObject *callable_o = sym_get_const(ctx, callable);
- if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type))
{
+ if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)
&&
+ (sym_is_not_null(self_or_null) || sym_is_null(self_or_null))) {
int total_args = oparg;
if (sym_is_not_null(self_or_null)) {
total_args++;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]