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

Skip to content

Commit 1221c0a

Browse files
committed
Build obmalloc.c directly instead of #include'ing from object.c.
Also move all _PyMalloc_XXX entry points into obmalloc.c. The Windows build works fine. The Unix build is changed here (Makefile.pre.in), but not tested. No other platform's build process has been fiddled.
1 parent c24ea08 commit 1221c0a

4 files changed

Lines changed: 66 additions & 45 deletions

File tree

Makefile.pre.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ OBJECT_OBJS= \
263263
Objects/methodobject.o \
264264
Objects/moduleobject.o \
265265
Objects/object.o \
266+
Objects/obmalloc.o \
266267
Objects/rangeobject.o \
267268
Objects/sliceobject.o \
268269
Objects/stringobject.o \
@@ -424,8 +425,6 @@ Python/getplatform.o: $(srcdir)/Python/getplatform.c
424425
Python/importdl.o: $(srcdir)/Python/importdl.c
425426
$(CC) -c $(CFLAGS) $(CPPFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
426427

427-
Objects/object.o: $(srcdir)/Objects/object.c $(srcdir)/Objects/obmalloc.c
428-
429428
Objects/unicodectype.o: $(srcdir)/Objects/unicodectype.c \
430429
$(srcdir)/Objects/unicodetype_db.h
431430

Objects/object.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,46 +2090,3 @@ _PyTrash_destroy_chain(void)
20902090
--_PyTrash_delete_nesting;
20912091
}
20922092
}
2093-
2094-
#ifdef WITH_PYMALLOC
2095-
#include "obmalloc.c"
2096-
#else
2097-
void *_PyMalloc_Malloc(size_t n)
2098-
{
2099-
return PyMem_MALLOC(n);
2100-
}
2101-
2102-
void *_PyMalloc_Realloc(void *p, size_t n)
2103-
{
2104-
return PyMem_REALLOC(p, n);
2105-
}
2106-
2107-
void _PyMalloc_Free(void *p)
2108-
{
2109-
PyMem_FREE(p);
2110-
}
2111-
#endif /* !WITH_PYMALLOC */
2112-
2113-
PyObject *_PyMalloc_New(PyTypeObject *tp)
2114-
{
2115-
PyObject *op;
2116-
op = (PyObject *) _PyMalloc_MALLOC(_PyObject_SIZE(tp));
2117-
if (op == NULL)
2118-
return PyErr_NoMemory();
2119-
return PyObject_INIT(op, tp);
2120-
}
2121-
2122-
PyVarObject *_PyMalloc_NewVar(PyTypeObject *tp, int nitems)
2123-
{
2124-
PyVarObject *op;
2125-
const size_t size = _PyObject_VAR_SIZE(tp, nitems);
2126-
op = (PyVarObject *) _PyMalloc_MALLOC(size);
2127-
if (op == NULL)
2128-
return (PyVarObject *)PyErr_NoMemory();
2129-
return PyObject_INIT_VAR(op, tp, nitems);
2130-
}
2131-
2132-
void _PyMalloc_Del(PyObject *op)
2133-
{
2134-
_PyMalloc_FREE(op);
2135-
}

Objects/obmalloc.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#include "Python.h"
2+
3+
#ifdef WITH_PYMALLOC
4+
15
/* An object allocator for Python.
26
37
Here is an introduction to the layers of the Python memory architecture,
@@ -636,3 +640,49 @@ _PyMalloc_Calloc(size_t nbel, size_t elsz)
636640
}
637641
*/
638642

643+
#else /* ! WITH_PYMALLOC */
644+
void
645+
*_PyMalloc_Malloc(size_t n)
646+
{
647+
return PyMem_MALLOC(n);
648+
}
649+
650+
void
651+
*_PyMalloc_Realloc(void *p, size_t n)
652+
{
653+
return PyMem_REALLOC(p, n);
654+
}
655+
656+
void
657+
_PyMalloc_Free(void *p)
658+
{
659+
PyMem_FREE(p);
660+
}
661+
#endif /* WITH_PYMALLOC */
662+
663+
PyObject
664+
*_PyMalloc_New(PyTypeObject *tp)
665+
{
666+
PyObject *op;
667+
op = (PyObject *) _PyMalloc_MALLOC(_PyObject_SIZE(tp));
668+
if (op == NULL)
669+
return PyErr_NoMemory();
670+
return PyObject_INIT(op, tp);
671+
}
672+
673+
PyVarObject *
674+
_PyMalloc_NewVar(PyTypeObject *tp, int nitems)
675+
{
676+
PyVarObject *op;
677+
const size_t size = _PyObject_VAR_SIZE(tp, nitems);
678+
op = (PyVarObject *) _PyMalloc_MALLOC(size);
679+
if (op == NULL)
680+
return (PyVarObject *)PyErr_NoMemory();
681+
return PyObject_INIT_VAR(op, tp, nitems);
682+
}
683+
684+
void
685+
_PyMalloc_Del(PyObject *op)
686+
{
687+
_PyMalloc_FREE(op);
688+
}

PCbuild/pythoncore.dsp

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)