mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
GH-121459: Streamline PyObject* to PyStackRef conversions by disallowing NULL pointers. (GH-124894)
This commit is contained in:
parent
10094a533a
commit
d1453f60c2
4 changed files with 63 additions and 57 deletions
|
@ -1922,9 +1922,10 @@ dummy_func(
|
|||
DECREF_INPUTS();
|
||||
ERROR_IF(super == NULL, error);
|
||||
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
|
||||
attr = PyStackRef_FromPyObjectSteal(PyObject_GetAttr(super, name));
|
||||
PyObject *attr_o = PyObject_GetAttr(super, name);
|
||||
Py_DECREF(super);
|
||||
ERROR_IF(PyStackRef_IsNull(attr), error);
|
||||
ERROR_IF(attr_o == NULL, error);
|
||||
attr = PyStackRef_FromPyObjectSteal(attr_o);
|
||||
null = PyStackRef_NULL;
|
||||
}
|
||||
|
||||
|
@ -2740,9 +2741,10 @@ dummy_func(
|
|||
|
||||
inst(GET_ITER, (iterable -- iter)) {
|
||||
/* before: [obj]; after [getiter(obj)] */
|
||||
iter = PyStackRef_FromPyObjectSteal(PyObject_GetIter(PyStackRef_AsPyObjectBorrow(iterable)));
|
||||
PyObject *iter_o = PyObject_GetIter(PyStackRef_AsPyObjectBorrow(iterable));
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(PyStackRef_IsNull(iter), error);
|
||||
ERROR_IF(iter_o == NULL, error);
|
||||
iter = PyStackRef_FromPyObjectSteal(iter_o);
|
||||
}
|
||||
|
||||
inst(GET_YIELD_FROM_ITER, (iterable -- iter)) {
|
||||
|
@ -3052,16 +3054,18 @@ dummy_func(
|
|||
PyObject *owner_o = PyStackRef_AsPyObjectSteal(owner);
|
||||
PyObject *name = _Py_SpecialMethods[oparg].name;
|
||||
PyObject *self_or_null_o;
|
||||
attr = PyStackRef_FromPyObjectSteal(_PyObject_LookupSpecialMethod(owner_o, name, &self_or_null_o));
|
||||
if (PyStackRef_IsNull(attr)) {
|
||||
PyObject *attr_o = _PyObject_LookupSpecialMethod(owner_o, name, &self_or_null_o);
|
||||
if (attr_o == NULL) {
|
||||
if (!_PyErr_Occurred(tstate)) {
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
_Py_SpecialMethods[oparg].error,
|
||||
Py_TYPE(owner_o)->tp_name);
|
||||
}
|
||||
ERROR_IF(true, error);
|
||||
}
|
||||
ERROR_IF(PyStackRef_IsNull(attr), error);
|
||||
self_or_null = PyStackRef_FromPyObjectSteal(self_or_null_o);
|
||||
attr = PyStackRef_FromPyObjectSteal(attr_o);
|
||||
self_or_null = self_or_null_o == NULL ?
|
||||
PyStackRef_NULL : PyStackRef_FromPyObjectSteal(self_or_null_o);
|
||||
}
|
||||
|
||||
inst(WITH_EXCEPT_START, (exit_func, exit_self, lasti, unused, val -- exit_func, exit_self, lasti, unused, val, res)) {
|
||||
|
@ -3092,9 +3096,10 @@ dummy_func(
|
|||
(void)lasti; // Shut up compiler warning if asserts are off
|
||||
PyObject *stack[5] = {NULL, PyStackRef_AsPyObjectBorrow(exit_self), exc, val_o, tb};
|
||||
int has_self = !PyStackRef_IsNull(exit_self);
|
||||
res = PyStackRef_FromPyObjectSteal(PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
|
||||
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL));
|
||||
ERROR_IF(PyStackRef_IsNull(res), error);
|
||||
PyObject *res_o = PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
|
||||
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
|
||||
ERROR_IF(res_o == NULL, error);
|
||||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
||||
pseudo(SETUP_FINALLY, (-- unused), (HAS_ARG)) = {
|
||||
|
@ -4539,9 +4544,10 @@ dummy_func(
|
|||
/* If value is a unicode object, then we know the result
|
||||
* of format(value) is value itself. */
|
||||
if (!PyUnicode_CheckExact(value_o)) {
|
||||
res = PyStackRef_FromPyObjectSteal(PyObject_Format(value_o, NULL));
|
||||
PyObject *res_o = PyObject_Format(value_o, NULL);
|
||||
PyStackRef_CLOSE(value);
|
||||
ERROR_IF(PyStackRef_IsNull(res), error);
|
||||
ERROR_IF(res_o == NULL, error);
|
||||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
else {
|
||||
res = value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue