Mailing List Archive

python/dist/src/Objects obmalloc.c,2.34,2.35
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv19336/Objects

Modified Files:
obmalloc.c
Log Message:
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
PyMalloc_ prefix and use PyObject_ instead. I'm not sure about the
debugging functions. Perhaps they should stay as PyMalloc_.


Index: obmalloc.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/obmalloc.c,v
retrieving revision 2.34
retrieving revision 2.35
diff -C2 -d -r2.34 -r2.35
*** obmalloc.c 11 Apr 2002 06:36:45 -0000 2.34
--- obmalloc.c 12 Apr 2002 03:10:20 -0000 2.35
***************
*** 566,571 ****
*/

void *
! _PyMalloc_Malloc(size_t nbytes)
{
block *bp;
--- 566,572 ----
*/

+ #undef PyObject_Malloc
void *
! PyObject_Malloc(size_t nbytes)
{
block *bp;
***************
*** 707,712 ****
/* free */

void
! _PyMalloc_Free(void *p)
{
poolp pool;
--- 708,714 ----
/* free */

+ #undef PyObject_Free
void
! PyObject_Free(void *p)
{
poolp pool;
***************
*** 792,797 ****
*/

void *
! _PyMalloc_Realloc(void *p, size_t nbytes)
{
void *bp;
--- 794,800 ----
*/

+ #undef PyObject_Realloc
void *
! PyObject_Realloc(void *p, size_t nbytes)
{
void *bp;
***************
*** 800,804 ****

if (p == NULL)
! return _PyMalloc_Malloc(nbytes);

pool = POOL_ADDR(p);
--- 803,807 ----

if (p == NULL)
! return PyObject_Malloc(nbytes);

pool = POOL_ADDR(p);
***************
*** 812,819 ****
/* We need more memory. */
assert(nbytes != 0);
! bp = _PyMalloc_Malloc(nbytes);
if (bp != NULL) {
memcpy(bp, p, size);
! _PyMalloc_Free(p);
}
return bp;
--- 815,822 ----
/* We need more memory. */
assert(nbytes != 0);
! bp = PyObject_Malloc(nbytes);
if (bp != NULL) {
memcpy(bp, p, size);
! PyObject_Free(p);
}
return bp;
***************
*** 823,827 ****
if (nbytes <= SMALL_REQUEST_THRESHOLD) {
/* Take over this block. */
! bp = _PyMalloc_Malloc(nbytes ? nbytes : 1);
if (bp != NULL) {
memcpy(bp, p, nbytes);
--- 826,830 ----
if (nbytes <= SMALL_REQUEST_THRESHOLD) {
/* Take over this block. */
! bp = PyObject_Malloc(nbytes ? nbytes : 1);
if (bp != NULL) {
memcpy(bp, p, nbytes);
***************
*** 846,853 ****

/*==========================================================================*/
! /* pymalloc not enabled: Redirect the entry points to the PyMem family. */

void *
! _PyMalloc_Malloc(size_t n)
{
return PyMem_MALLOC(n);
--- 849,857 ----

/*==========================================================================*/
! /* pymalloc not enabled: Redirect the entry points to malloc. These will
! * only be used by extensions that are compiled with pymalloc enabled. */

void *
! PyObject_Malloc(size_t n)
{
return PyMem_MALLOC(n);
***************
*** 855,859 ****

void *
! _PyMalloc_Realloc(void *p, size_t n)
{
return PyMem_REALLOC(p, n);
--- 859,863 ----

void *
! PyObject_Realloc(void *p, size_t n)
{
return PyMem_REALLOC(p, n);
***************
*** 861,865 ****

void
! _PyMalloc_Free(void *p)
{
PyMem_FREE(p);
--- 865,869 ----

void
! PyObject_Free(void *p)
{
PyMem_FREE(p);
***************
*** 867,902 ****
#endif /* WITH_PYMALLOC */

- /*==========================================================================*/
- /* Regardless of whether pymalloc is enabled, export entry points for
- * the object-oriented pymalloc functions.
- */
-
- PyObject *
- _PyMalloc_New(PyTypeObject *tp)
- {
- PyObject *op;
- op = (PyObject *) _PyMalloc_MALLOC(_PyObject_SIZE(tp));
- if (op == NULL)
- return PyErr_NoMemory();
- return PyObject_INIT(op, tp);
- }
-
- PyVarObject *
- _PyMalloc_NewVar(PyTypeObject *tp, int nitems)
- {
- PyVarObject *op;
- const size_t size = _PyObject_VAR_SIZE(tp, nitems);
- op = (PyVarObject *) _PyMalloc_MALLOC(size);
- if (op == NULL)
- return (PyVarObject *)PyErr_NoMemory();
- return PyObject_INIT_VAR(op, tp, nitems);
- }
-
- void
- _PyMalloc_Del(PyObject *op)
- {
- _PyMalloc_FREE(op);
- }
-
#ifdef PYMALLOC_DEBUG
/*==========================================================================*/
--- 871,874 ----
***************
*** 956,960 ****
The requested memory, filled with copies of PYMALLOC_CLEANBYTE.
Used to catch reference to uninitialized memory.
! &p[8] is returned. Note that this is 8-byte aligned if PyMalloc
handled the request itself.
p[8+n:8+n+4]
--- 928,932 ----
The requested memory, filled with copies of PYMALLOC_CLEANBYTE.
Used to catch reference to uninitialized memory.
! &p[8] is returned. Note that this is 8-byte aligned if pymalloc
handled the request itself.
p[8+n:8+n+4]
***************
*** 962,967 ****
and reads.
p[8+n+4:8+n+8]
! A serial number, incremented by 1 on each call to _PyMalloc_DebugMalloc
! and _PyMalloc_DebugRealloc.
4-byte unsigned integer, big-endian.
If "bad memory" is detected later, the serial number gives an
--- 934,939 ----
and reads.
p[8+n+4:8+n+8]
! A serial number, incremented by 1 on each call to _PyObject_DebugMalloc
! and _PyObject_DebugRealloc.
4-byte unsigned integer, big-endian.
If "bad memory" is detected later, the serial number gives an
***************
*** 971,975 ****

void *
! _PyMalloc_DebugMalloc(size_t nbytes)
{
uchar *p; /* base address of malloc'ed block */
--- 943,947 ----

void *
! _PyObject_DebugMalloc(size_t nbytes)
{
uchar *p; /* base address of malloc'ed block */
***************
*** 988,992 ****
}

! p = _PyMalloc_Malloc(total);
if (p == NULL)
return NULL;
--- 960,964 ----
}

! p = PyObject_Malloc(total);
if (p == NULL)
return NULL;
***************
*** 1011,1015 ****
*/
void
! _PyMalloc_DebugFree(void *p)
{
uchar *q = (uchar *)p;
--- 983,987 ----
*/
void
! _PyObject_DebugFree(void *p)
{
uchar *q = (uchar *)p;
***************
*** 1018,1030 ****
if (p == NULL)
return;
! _PyMalloc_DebugCheckAddress(p);
nbytes = read4(q-8);
if (nbytes > 0)
memset(q, PYMALLOC_DEADBYTE, nbytes);
! _PyMalloc_Free(q-8);
}

void *
! _PyMalloc_DebugRealloc(void *p, size_t nbytes)
{
uchar *q = (uchar *)p;
--- 990,1002 ----
if (p == NULL)
return;
! _PyObject_DebugCheckAddress(p);
nbytes = read4(q-8);
if (nbytes > 0)
memset(q, PYMALLOC_DEADBYTE, nbytes);
! PyObject_Free(q-8);
}

void *
! _PyObject_DebugRealloc(void *p, size_t nbytes)
{
uchar *q = (uchar *)p;
***************
*** 1033,1039 ****

if (p == NULL)
! return _PyMalloc_DebugMalloc(nbytes);

! _PyMalloc_DebugCheckAddress(p);
original_nbytes = read4(q-8);
if (nbytes == original_nbytes) {
--- 1005,1011 ----

if (p == NULL)
! return _PyObject_DebugMalloc(nbytes);

! _PyObject_DebugCheckAddress(p);
original_nbytes = read4(q-8);
if (nbytes == original_nbytes) {
***************
*** 1062,1070 ****
/* More memory is needed: get it, copy over the first original_nbytes
of the original data, and free the original memory. */
! fresh = _PyMalloc_DebugMalloc(nbytes);
if (fresh != NULL) {
if (original_nbytes > 0)
memcpy(fresh, p, original_nbytes);
! _PyMalloc_DebugFree(p);
}
return fresh;
--- 1034,1042 ----
/* More memory is needed: get it, copy over the first original_nbytes
of the original data, and free the original memory. */
! fresh = _PyObject_DebugMalloc(nbytes);
if (fresh != NULL) {
if (original_nbytes > 0)
memcpy(fresh, p, original_nbytes);
! _PyObject_DebugFree(p);
}
return fresh;
***************
*** 1072,1080 ****

/* Check the forbidden bytes on both ends of the memory allocated for p.
! * If anything is wrong, print info to stderr via _PyMalloc_DebugDumpAddress,
* and call Py_FatalError to kill the program.
*/
void
! _PyMalloc_DebugCheckAddress(const void *p)
{
const uchar *q = (const uchar *)p;
--- 1044,1052 ----

/* Check the forbidden bytes on both ends of the memory allocated for p.
! * If anything is wrong, print info to stderr via _PyObject_DebugDumpAddress,
* and call Py_FatalError to kill the program.
*/
void
! _PyObject_DebugCheckAddress(const void *p)
{
const uchar *q = (const uchar *)p;
***************
*** 1108,1112 ****

error:
! _PyMalloc_DebugDumpAddress(p);
Py_FatalError(msg);
}
--- 1080,1084 ----

error:
! _PyObject_DebugDumpAddress(p);
Py_FatalError(msg);
}
***************
*** 1114,1118 ****
/* Display info to stderr about the memory block at p. */
void
! _PyMalloc_DebugDumpAddress(const void *p)
{
const uchar *q = (const uchar *)p;
--- 1086,1090 ----
/* Display info to stderr about the memory block at p. */
void
! _PyObject_DebugDumpAddress(const void *p)
{
const uchar *q = (const uchar *)p;
***************
*** 1237,1241 ****
/* Print summary info to stderr about the state of pymalloc's structures. */
void
! _PyMalloc_DebugDumpStats(void)
{
uint i;
--- 1209,1213 ----
/* Print summary info to stderr about the state of pymalloc's structures. */
void
! _PyObject_DebugDumpStats(void)
{
uint i;