From 6c5d8bda0e15bd834dd3ab5bd4a2acbe6cd821df Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Sat, 4 Apr 2026 17:40:47 +0800 Subject: [PATCH] Fix uses of sym_is_not_null --- Python/optimizer_bytecodes.c | 19 ++++++++++++------- Python/optimizer_cases.c.h | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) 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++;