https://github.com/python/cpython/commit/1e4ed932109c4f8ee4f43bc3e6fdb7710a3606bd
commit: 1e4ed932109c4f8ee4f43bc3e6fdb7710a3606bd
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-03-18T17:23:05+01:00
summary:
gh-146092: Fix error handling in _BINARY_OP_ADD_UNICODE opcode (#146117)
Fix also error handling in _BINARY_OP_ADD_FLOAT,
_BINARY_OP_SUBTRACT_FLOAT and _BINARY_OP_MULTIPLY_FLOAT opcodes.
PyStackRef_FromPyObjectSteal() must not be called with a NULL
pointer.
files:
M Modules/_testinternalcapi/test_cases.c.h
M Python/bytecodes.c
M Python/executor_cases.c.h
M Python/generated_cases.c.h
diff --git a/Modules/_testinternalcapi/test_cases.c.h
b/Modules/_testinternalcapi/test_cases.c.h
index 948a413d98ddcd..12480e2cb1962f 100644
--- a/Modules/_testinternalcapi/test_cases.c.h
+++ b/Modules/_testinternalcapi/test_cases.c.h
@@ -141,10 +141,11 @@
double dres =
((PyFloatObject *)left_o)->ob_fval +
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
JUMP_TO_LABEL(error);
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
}
@@ -289,10 +290,10 @@
assert(PyUnicode_CheckExact(right_o));
STAT_INC(BINARY_OP, hit);
PyObject *res_o = PyUnicode_Concat(left_o, right_o);
- res = PyStackRef_FromPyObjectSteal(res_o);
- if (PyStackRef_IsNull(res)) {
+ if (res_o == NULL) {
JUMP_TO_LABEL(error);
}
+ res = PyStackRef_FromPyObjectSteal(res_o);
l = left;
r = right;
}
@@ -521,10 +522,11 @@
double dres =
((PyFloatObject *)left_o)->ob_fval *
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
JUMP_TO_LABEL(error);
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
}
@@ -1270,10 +1272,11 @@
double dres =
((PyFloatObject *)left_o)->ob_fval -
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
JUMP_TO_LABEL(error);
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
}
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 2fb2c33428255a..e170fd65a20f64 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -710,10 +710,11 @@ dummy_func(
double dres =
((PyFloatObject *)left_o)->ob_fval *
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
ERROR_NO_POP();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
INPUTS_DEAD();
@@ -729,10 +730,11 @@ dummy_func(
double dres =
((PyFloatObject *)left_o)->ob_fval +
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
ERROR_NO_POP();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
INPUTS_DEAD();
@@ -748,10 +750,11 @@ dummy_func(
double dres =
((PyFloatObject *)left_o)->ob_fval -
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
ERROR_NO_POP();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
INPUTS_DEAD();
@@ -772,10 +775,10 @@ dummy_func(
STAT_INC(BINARY_OP, hit);
PyObject *res_o = PyUnicode_Concat(left_o, right_o);
- res = PyStackRef_FromPyObjectSteal(res_o);
- if (PyStackRef_IsNull(res)) {
+ if (res_o == NULL) {
ERROR_NO_POP();
}
+ res = PyStackRef_FromPyObjectSteal(res_o);
l = left;
r = right;
INPUTS_DEAD();
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index d89d512fd5630a..d33c67dd745bbf 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -4620,11 +4620,12 @@
double dres =
((PyFloatObject *)left_o)->ob_fval *
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4656,14 +4657,15 @@
double dres =
((PyFloatObject *)left_o)->ob_fval *
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
stack_pointer[0] = right;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4696,8 +4698,8 @@
double dres =
((PyFloatObject *)left_o)->ob_fval *
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
stack_pointer[0] = left;
stack_pointer[1] = right;
stack_pointer += 2;
@@ -4705,6 +4707,7 @@
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4733,11 +4736,12 @@
double dres =
((PyFloatObject *)left_o)->ob_fval +
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4769,14 +4773,15 @@
double dres =
((PyFloatObject *)left_o)->ob_fval +
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
stack_pointer[0] = right;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4809,8 +4814,8 @@
double dres =
((PyFloatObject *)left_o)->ob_fval +
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
stack_pointer[0] = left;
stack_pointer[1] = right;
stack_pointer += 2;
@@ -4818,6 +4823,7 @@
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4846,11 +4852,12 @@
double dres =
((PyFloatObject *)left_o)->ob_fval -
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4882,14 +4889,15 @@
double dres =
((PyFloatObject *)left_o)->ob_fval -
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
stack_pointer[0] = right;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4922,8 +4930,8 @@
double dres =
((PyFloatObject *)left_o)->ob_fval -
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
stack_pointer[0] = left;
stack_pointer[1] = right;
stack_pointer += 2;
@@ -4931,6 +4939,7 @@
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
_tos_cache2 = r;
@@ -4957,11 +4966,11 @@
assert(PyUnicode_CheckExact(right_o));
STAT_INC(BINARY_OP, hit);
PyObject *res_o = PyUnicode_Concat(left_o, right_o);
- res = PyStackRef_FromPyObjectSteal(res_o);
- if (PyStackRef_IsNull(res)) {
+ if (res_o == NULL) {
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(res_o);
l = left;
r = right;
_tos_cache2 = r;
@@ -4991,14 +5000,14 @@
assert(PyUnicode_CheckExact(right_o));
STAT_INC(BINARY_OP, hit);
PyObject *res_o = PyUnicode_Concat(left_o, right_o);
- res = PyStackRef_FromPyObjectSteal(res_o);
- if (PyStackRef_IsNull(res)) {
+ if (res_o == NULL) {
stack_pointer[0] = right;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(res_o);
l = left;
r = right;
_tos_cache2 = r;
@@ -5029,8 +5038,7 @@
assert(PyUnicode_CheckExact(right_o));
STAT_INC(BINARY_OP, hit);
PyObject *res_o = PyUnicode_Concat(left_o, right_o);
- res = PyStackRef_FromPyObjectSteal(res_o);
- if (PyStackRef_IsNull(res)) {
+ if (res_o == NULL) {
stack_pointer[0] = left;
stack_pointer[1] = right;
stack_pointer += 2;
@@ -5038,6 +5046,7 @@
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
+ res = PyStackRef_FromPyObjectSteal(res_o);
l = left;
r = right;
_tos_cache2 = r;
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index a66d6ccff2d82d..628f0cc4d37310 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -141,10 +141,11 @@
double dres =
((PyFloatObject *)left_o)->ob_fval +
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
JUMP_TO_LABEL(error);
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
}
@@ -289,10 +290,10 @@
assert(PyUnicode_CheckExact(right_o));
STAT_INC(BINARY_OP, hit);
PyObject *res_o = PyUnicode_Concat(left_o, right_o);
- res = PyStackRef_FromPyObjectSteal(res_o);
- if (PyStackRef_IsNull(res)) {
+ if (res_o == NULL) {
JUMP_TO_LABEL(error);
}
+ res = PyStackRef_FromPyObjectSteal(res_o);
l = left;
r = right;
}
@@ -521,10 +522,11 @@
double dres =
((PyFloatObject *)left_o)->ob_fval *
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
JUMP_TO_LABEL(error);
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
}
@@ -1270,10 +1272,11 @@
double dres =
((PyFloatObject *)left_o)->ob_fval -
((PyFloatObject *)right_o)->ob_fval;
- res = PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(dres));
- if (PyStackRef_IsNull(res)) {
+ PyObject *d = PyFloat_FromDouble(dres);
+ if (d == NULL) {
JUMP_TO_LABEL(error);
}
+ res = PyStackRef_FromPyObjectSteal(d);
l = left;
r = right;
}
_______________________________________________
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]