summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-05-03 23:44:39 (GMT)
committerGuido van Rossum <guido@python.org>2000-05-03 23:44:39 (GMT)
commitb18618dab7b6b85bb05b084693706e59211fa180 (patch)
tree785d51f6677da8366be2ad4b4296a62f53161276 /Objects/object.c
parent2808b744e8d94459f189e1d89c97072d6a1f53b6 (diff)
downloadcpython-b18618dab7b6b85bb05b084693706e59211fa180.zip
cpython-b18618dab7b6b85bb05b084693706e59211fa180.tar.gz
cpython-b18618dab7b6b85bb05b084693706e59211fa180.tar.bz2
Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c124
1 files changed, 60 insertions, 64 deletions
diff --git a/Objects/object.c b/Objects/object.c
index ed276e2..6195479 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -112,50 +112,68 @@ inc_count(tp)
}
#endif
-#ifndef MS_COREDLL
PyObject *
-_PyObject_New(tp)
- PyTypeObject *tp;
-#else
-PyObject *
-_PyObject_New(tp,op)
- PyTypeObject *tp;
+PyObject_Init(op, tp)
PyObject *op;
-#endif
+ PyTypeObject *tp;
{
-#ifndef MS_COREDLL
- PyObject *op = (PyObject *) malloc(tp->tp_basicsize);
-#endif
- if (op == NULL)
- return PyErr_NoMemory();
+ if (op == NULL) {
+ PyErr_SetString(PyExc_SystemError,
+ "NULL object passed to PyObject_Init");
+ return op;
+ }
+ /* Any changes should be reflected in PyObject_INIT (objimpl.h) */
op->ob_type = tp;
_Py_NewReference(op);
return op;
}
-#ifndef MS_COREDLL
PyVarObject *
-_PyObject_NewVar(tp, size)
+PyObject_InitVar(op, tp, size)
+ PyVarObject *op;
PyTypeObject *tp;
int size;
-#else
+{
+ if (op == NULL) {
+ PyErr_SetString(PyExc_SystemError,
+ "NULL object passed to PyObject_InitVar");
+ return op;
+ }
+ /* Any changes should be reflected in PyObject_INIT_VAR */
+ op->ob_size = size;
+ op->ob_type = tp;
+ _Py_NewReference((PyObject *)op);
+ return op;
+}
+
+PyObject *
+_PyObject_New(tp)
+ PyTypeObject *tp;
+{
+ PyObject *op;
+ op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp));
+ if (op == NULL)
+ return PyErr_NoMemory();
+ return PyObject_INIT(op, tp);
+}
+
PyVarObject *
-_PyObject_NewVar(tp, size, op)
+_PyObject_NewVar(tp, size)
PyTypeObject *tp;
int size;
- PyVarObject *op;
-#endif
{
-#ifndef MS_COREDLL
- PyVarObject *op = (PyVarObject *)
- malloc(tp->tp_basicsize + size * tp->tp_itemsize);
-#endif
+ PyVarObject *op;
+ op = (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE(tp, size));
if (op == NULL)
return (PyVarObject *)PyErr_NoMemory();
- op->ob_type = tp;
- op->ob_size = size;
- _Py_NewReference((PyObject *)op);
- return op;
+ return PyObject_INIT_VAR(op, tp, size);
+}
+
+void
+_PyObject_Del(op)
+ PyObject *op;
+{
+ PyObject_FREE(op);
}
int
@@ -888,30 +906,21 @@ PyTypeObject *_Py_cobject_hack = &PyCObject_Type;
int (*_Py_abstract_hack) Py_FPROTO((PyObject *)) = &PyObject_Length;
-/* Malloc wrappers (see mymalloc.h) */
-
-/* The Py_{Malloc,Realloc} wrappers call PyErr_NoMemory() on failure */
+/* Python's malloc wrappers (see mymalloc.h) */
ANY *
-Py_Malloc(nbytes)
+PyMem_Malloc(nbytes)
size_t nbytes;
{
- ANY *p;
#if _PyMem_EXTRA > 0
if (nbytes == 0)
nbytes = _PyMem_EXTRA;
#endif
- p = malloc(nbytes);
- if (p != NULL)
- return p;
- else {
- PyErr_NoMemory();
- return NULL;
- }
+ return PyMem_MALLOC(nbytes);
}
ANY *
-Py_Realloc(p, nbytes)
+PyMem_Realloc(p, nbytes)
ANY *p;
size_t nbytes;
{
@@ -919,52 +928,39 @@ Py_Realloc(p, nbytes)
if (nbytes == 0)
nbytes = _PyMem_EXTRA;
#endif
- p = realloc(p, nbytes);
- if (p != NULL)
- return p;
- else {
- PyErr_NoMemory();
- return NULL;
- }
+ return PyMem_REALLOC(p, nbytes);
}
void
-Py_Free(p)
+PyMem_Free(p)
ANY *p;
{
- free(p);
+ PyMem_FREE(p);
}
-/* The PyMem_{Malloc,Realloc} wrappers don't call anything on failure */
+
+/* Python's object malloc wrappers (see objimpl.h) */
ANY *
-PyMem_Malloc(nbytes)
+PyObject_Malloc(nbytes)
size_t nbytes;
{
-#if _PyMem_EXTRA > 0
- if (nbytes == 0)
- nbytes = _PyMem_EXTRA;
-#endif
- return malloc(nbytes);
+ return PyObject_MALLOC(nbytes);
}
ANY *
-PyMem_Realloc(p, nbytes)
+PyObject_Realloc(p, nbytes)
ANY *p;
size_t nbytes;
{
-#if _PyMem_EXTRA > 0
- if (nbytes == 0)
- nbytes = _PyMem_EXTRA;
-#endif
- return realloc(p, nbytes);
+ return PyObject_REALLOC(p, nbytes);
}
void
-PyMem_Free(p)
+PyObject_Free(p)
ANY *p;
{
- free(p);
+ PyObject_FREE(p);
}