Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e08c14

Browse files
committed
PyObject_Init[Var] is almost always called from the PyObject_NEW[_VAR]
macros. The 'op' argument is then the result from PyObject_MALLOC, and that can of course be NULL. In that case, PyObject_Init[Var] would raise a SystemError with "NULL object passed to PyObject_Init[Var]". But there's nothing the caller of the macro can do about this. So PyObject_Init[Var] should call just PyErr_NoMemory. Will backport.
1 parent c78462f commit 6e08c14

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

Objects/object.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,8 @@ _Py_NegativeRefcount(const char *fname, int lineno, PyObject *op)
109109
PyObject *
110110
PyObject_Init(PyObject *op, PyTypeObject *tp)
111111
{
112-
if (op == NULL) {
113-
PyErr_SetString(PyExc_SystemError,
114-
"NULL object passed to PyObject_Init");
115-
return op;
116-
}
112+
if (op == NULL)
113+
return PyErr_NoMemory();
117114
/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
118115
op->ob_type = tp;
119116
_Py_NewReference(op);
@@ -123,11 +120,8 @@ PyObject_Init(PyObject *op, PyTypeObject *tp)
123120
PyVarObject *
124121
PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, int size)
125122
{
126-
if (op == NULL) {
127-
PyErr_SetString(PyExc_SystemError,
128-
"NULL object passed to PyObject_InitVar");
129-
return op;
130-
}
123+
if (op == NULL)
124+
return (PyVarObject *) PyErr_NoMemory();
131125
/* Any changes should be reflected in PyObject_INIT_VAR */
132126
op->ob_size = size;
133127
op->ob_type = tp;

0 commit comments

Comments
 (0)