]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
PyObject_Init[Var] is almost always called from the PyObject_NEW[_VAR]
authorGuido van Rossum <guido@python.org>
Fri, 11 Oct 2002 20:37:24 +0000 (20:37 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 11 Oct 2002 20:37:24 +0000 (20:37 +0000)
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.

Objects/object.c

index 523a8818ec477affa0cb5a8ea61d4895d3cd69f7..20a6a936c1c79a911684d7dda4fbd630a365f765 100644 (file)
@@ -109,11 +109,8 @@ _Py_NegativeRefcount(const char *fname, int lineno, PyObject *op)
 PyObject *
 PyObject_Init(PyObject *op, PyTypeObject *tp)
 {
-       if (op == NULL) {
-               PyErr_SetString(PyExc_SystemError,
-                               "NULL object passed to PyObject_Init");
-               return op;
-       }
+       if (op == NULL)
+               return PyErr_NoMemory();
        /* Any changes should be reflected in PyObject_INIT (objimpl.h) */
        op->ob_type = tp;
        _Py_NewReference(op);
@@ -123,11 +120,8 @@ PyObject_Init(PyObject *op, PyTypeObject *tp)
 PyVarObject *
 PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, int size)
 {
-       if (op == NULL) {
-               PyErr_SetString(PyExc_SystemError,
-                               "NULL object passed to PyObject_InitVar");
-               return op;
-       }
+       if (op == NULL)
+               return (PyVarObject *) PyErr_NoMemory();
        /* Any changes should be reflected in PyObject_INIT_VAR */
        op->ob_size = size;
        op->ob_type = tp;