[Python-checkins] CVS: python/dist/src/Objects bufferobject.c,2.6,2.7 classobject.c,2.85,2.86 cobject.c,2.7,2.8 complexobject.c,2.23,2.24 dictobject.c,2.51,2.52 fileobject.c,2.72,2.73 floatobject.c,2.56,2.57 frameobject.c,2.38,2.39 funcobject.c,2.19,2.20 intobject.c,2.40,2.41 listobject.c,2.68,2.69 longobject.c,1.56,1.57 methodobject.c,2.25,2.26 moduleobject.c,2.24,2.25 object.c,2.69,2.70 rangeobject.c,2.11,2.12 sliceobject.c,2.3,2.4 stringobject.c,2.62,2.63 tupleobject.c,2.32,2.33 unicodeobject.c,2.15,2.16 xxobject.c,2.14,2.15

Guido van Rossum python-dev@python.org
Wed, 3 May 2000 19:45:13 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Objects
In directory eric:/projects/python/develop/guido/clean/Objects

Modified Files:
	bufferobject.c classobject.c cobject.c complexobject.c 
	dictobject.c fileobject.c floatobject.c frameobject.c 
	funcobject.c intobject.c listobject.c longobject.c 
	methodobject.c moduleobject.c object.c rangeobject.c 
	sliceobject.c stringobject.c tupleobject.c unicodeobject.c 
	xxobject.c 
Log Message:
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.)



Index: bufferobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/bufferobject.c,v
retrieving revision 2.6
retrieving revision 2.7
diff -C2 -r2.6 -r2.7
*** bufferobject.c	1999/08/04 13:08:19	2.6
--- bufferobject.c	2000/05/03 23:44:34	2.7
***************
*** 189,197 ****
  		return NULL;
  	}
! 	b = (PyBufferObject *)malloc(sizeof(*b) + size);
  	if ( b == NULL )
  		return PyErr_NoMemory();
! 	b->ob_type = &PyBuffer_Type;
! 	_Py_NewReference((PyObject *)b);
  
  	b->b_base = NULL;
--- 189,197 ----
  		return NULL;
  	}
! 	/* PyObject_New is inlined */
! 	b = (PyBufferObject *) PyObject_MALLOC(sizeof(*b) + size);
  	if ( b == NULL )
  		return PyErr_NoMemory();
! 	PyObject_INIT((PyObject *)b, &PyBuffer_Type);
  
  	b->b_base = NULL;
***************
*** 213,217 ****
  {
  	Py_XDECREF(self->b_base);
! 	free((void *)self);
  }
  
--- 213,217 ----
  {
  	Py_XDECREF(self->b_base);
! 	PyObject_DEL(self);
  }
  

Index: classobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/classobject.c,v
retrieving revision 2.85
retrieving revision 2.86
diff -C2 -r2.85 -r2.86
*** classobject.c	2000/04/26 20:39:20	2.85
--- classobject.c	2000/05/03 23:44:34	2.86
***************
*** 148,152 ****
  	Py_XDECREF(op->cl_setattr);
  	Py_XDECREF(op->cl_delattr);
! 	free((ANY *)op);
  }
  
--- 148,152 ----
  	Py_XDECREF(op->cl_setattr);
  	Py_XDECREF(op->cl_delattr);
! 	PyObject_DEL(op);
  }
  
***************
*** 562,566 ****
  	Py_DECREF(inst->in_class);
  	Py_XDECREF(inst->in_dict);
! 	free((ANY *)inst);
  }
  
--- 562,566 ----
  	Py_DECREF(inst->in_class);
  	Py_XDECREF(inst->in_dict);
! 	PyObject_DEL(inst);
  }
  
***************
*** 1499,1504 ****
  	if (im != NULL) {
  		free_list = (PyMethodObject *)(im->im_self);
! 		im->ob_type = &PyMethod_Type;
! 		_Py_NewReference((PyObject *)im);
  	}
  	else {
--- 1499,1503 ----
  	if (im != NULL) {
  		free_list = (PyMethodObject *)(im->im_self);
! 		PyObject_INIT(im, &PyMethod_Type);
  	}
  	else {
***************
*** 1692,1698 ****
  {
  	while (free_list) {
! 		PyMethodObject *v = free_list;
! 		free_list = (PyMethodObject *)(v->im_self);
! 		PyMem_DEL(v);
  	}
  }
--- 1691,1697 ----
  {
  	while (free_list) {
! 		PyMethodObject *im = free_list;
! 		free_list = (PyMethodObject *)(im->im_self);
! 		PyObject_DEL(im);
  	}
  }

Index: cobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/cobject.c,v
retrieving revision 2.7
retrieving revision 2.8
diff -C2 -r2.7 -r2.8
*** cobject.c	1997/10/21 19:48:35	2.7
--- cobject.c	2000/05/03 23:44:34	2.8
***************
*** 152,156 ****
  	          (self->destructor)(self->cobject);
  	  }
! 	PyMem_DEL(self);
  }
  
--- 152,156 ----
  	          (self->destructor)(self->cobject);
  	  }
! 	PyObject_DEL(self);
  }
  

Index: complexobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/complexobject.c,v
retrieving revision 2.23
retrieving revision 2.24
diff -C2 -r2.23 -r2.24
*** complexobject.c	2000/02/29 13:59:28	2.23
--- complexobject.c	2000/05/03 23:44:34	2.24
***************
*** 167,177 ****
  	Py_complex cval;
  {
! 	register PyComplexObject *op =
! 		(PyComplexObject *) malloc(sizeof(PyComplexObject));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	op->ob_type = &PyComplex_Type;
  	op->cval = cval;
- 	_Py_NewReference((PyObject *)op);
  	return (PyObject *) op;
  }
--- 167,178 ----
  	Py_complex cval;
  {
! 	register PyComplexObject *op;
! 
! 	/* PyObject_New is inlined */
! 	op = (PyComplexObject *) PyObject_MALLOC(sizeof(PyComplexObject));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	PyObject_INIT(op, &PyComplex_Type);
  	op->cval = cval;
  	return (PyObject *) op;
  }
***************
*** 227,231 ****
  	PyObject *op;
  {
! 	PyMem_DEL(op);
  }
  
--- 228,232 ----
  	PyObject *op;
  {
! 	PyObject_DEL(op);
  }
  

Index: dictobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.51
retrieving revision 2.52
diff -C2 -r2.51 -r2.52
*** dictobject.c	2000/03/30 22:27:31	2.51
--- dictobject.c	2000/05/03 23:44:34	2.52
***************
*** 278,282 ****
  		}
  	}
! 	newtable = (dictentry *) malloc(sizeof(dictentry) * newsize);
  	if (newtable == NULL) {
  		PyErr_NoMemory();
--- 278,282 ----
  		}
  	}
! 	newtable = PyMem_NEW(dictentry, newsize);
  	if (newtable == NULL) {
  		PyErr_NoMemory();
***************
*** 302,306 ****
  	}
  
! 	PyMem_XDEL(oldtable);
  	return 0;
  }
--- 302,307 ----
  	}
  
! 	if (oldtable != NULL)
! 		PyMem_DEL(oldtable);
  	return 0;
  }
***************
*** 489,494 ****
  		}
  	}
! 	PyMem_XDEL(mp->ma_table);
! 	PyMem_DEL(mp);
  	Py_TRASHCAN_SAFE_END(mp)
  }
--- 490,496 ----
  		}
  	}
! 	if (mp->ma_table != NULL)
! 		PyMem_DEL(mp->ma_table);
! 	PyObject_DEL(mp);
  	Py_TRASHCAN_SAFE_END(mp)
  }

Index: fileobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.72
retrieving revision 2.73
diff -C2 -r2.72 -r2.73
*** fileobject.c	2000/03/13 16:27:06	2.72
--- fileobject.c	2000/05/03 23:44:34	2.73
***************
*** 216,220 ****
  		Py_DECREF(f->f_mode);
  	}
! 	free((char *)f);
  }
  
--- 216,220 ----
  		Py_DECREF(f->f_mode);
  	}
! 	PyObject_DEL(f);
  }
  

Index: floatobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.56
retrieving revision 2.57
diff -C2 -r2.56 -r2.57
*** floatobject.c	2000/04/05 20:11:20	2.56
--- floatobject.c	2000/05/03 23:44:34	2.57
***************
*** 99,105 ****
  #define N_FLOATOBJECTS	((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyFloatObject))
  
- #define PyMem_MALLOC	malloc
- #define PyMem_FREE	free
- 
  struct _floatblock {
  	struct _floatblock *next;
--- 99,102 ----
***************
*** 116,122 ****
  {
  	PyFloatObject *p, *q;
! 	p = (PyFloatObject *)PyMem_MALLOC(sizeof(PyFloatBlock));
  	if (p == NULL)
! 		return (PyFloatObject *)PyErr_NoMemory();
  	((PyFloatBlock *)p)->next = block_list;
  	block_list = (PyFloatBlock *)p;
--- 113,120 ----
  {
  	PyFloatObject *p, *q;
! 	/* XXX Float blocks escape the object heap. Use PyObject_MALLOC ??? */
! 	p = (PyFloatObject *) PyMem_MALLOC(sizeof(PyFloatBlock));
  	if (p == NULL)
! 		return (PyFloatObject *) PyErr_NoMemory();
  	((PyFloatBlock *)p)->next = block_list;
  	block_list = (PyFloatBlock *)p;
***************
*** 142,150 ****
  			return NULL;
  	}
  	op = free_list;
  	free_list = (PyFloatObject *)op->ob_type;
! 	op->ob_type = &PyFloat_Type;
  	op->ob_fval = fval;
- 	_Py_NewReference((PyObject *)op);
  	return (PyObject *) op;
  }
--- 140,148 ----
  			return NULL;
  	}
+ 	/* PyObject_New is inlined */
  	op = free_list;
  	free_list = (PyFloatObject *)op->ob_type;
! 	PyObject_INIT(op, &PyFloat_Type);
  	op->ob_fval = fval;
  	return (PyObject *) op;
  }
***************
*** 780,784 ****
  		}
  		else {
! 			PyMem_FREE(list);
  			bf++;
  		}
--- 778,782 ----
  		}
  		else {
! 			PyMem_FREE(list); /* XXX PyObject_FREE ??? */
  			bf++;
  		}

Index: frameobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/frameobject.c,v
retrieving revision 2.38
retrieving revision 2.39
diff -C2 -r2.38 -r2.39
*** frameobject.c	2000/03/13 16:01:29	2.38
--- frameobject.c	2000/05/03 23:44:34	2.39
***************
*** 181,191 ****
  		builtins = NULL;
  	if (free_list == NULL) {
  		f = (PyFrameObject *)
! 			malloc(sizeof(PyFrameObject) +
! 			       extras*sizeof(PyObject *));
  		if (f == NULL)
  			return (PyFrameObject *)PyErr_NoMemory();
! 		f->ob_type = &PyFrame_Type;
! 		_Py_NewReference((PyObject *)f);
  	}
  	else {
--- 181,191 ----
  		builtins = NULL;
  	if (free_list == NULL) {
+ 		/* PyObject_New is inlined */
  		f = (PyFrameObject *)
! 			PyObject_MALLOC(sizeof(PyFrameObject) +
! 					extras*sizeof(PyObject *));
  		if (f == NULL)
  			return (PyFrameObject *)PyErr_NoMemory();
! 		PyObject_INIT(f, &PyFrame_Type);
  	}
  	else {
***************
*** 194,199 ****
  		if (f->f_nlocals + f->f_stacksize < extras) {
  			f = (PyFrameObject *)
! 				realloc(f, sizeof(PyFrameObject) +
! 					extras*sizeof(PyObject *));
  			if (f == NULL)
  				return (PyFrameObject *)PyErr_NoMemory();
--- 194,199 ----
  		if (f->f_nlocals + f->f_stacksize < extras) {
  			f = (PyFrameObject *)
! 				PyObject_REALLOC(f, sizeof(PyFrameObject) +
! 						 extras*sizeof(PyObject *));
  			if (f == NULL)
  				return (PyFrameObject *)PyErr_NoMemory();
***************
*** 201,206 ****
  		else
  			extras = f->f_nlocals + f->f_stacksize;
! 		f->ob_type = &PyFrame_Type;
! 		_Py_NewReference((PyObject *)f);
  	}
  	if (builtins == NULL) {
--- 201,205 ----
  		else
  			extras = f->f_nlocals + f->f_stacksize;
! 		PyObject_INIT(f, &PyFrame_Type);
  	}
  	if (builtins == NULL) {
***************
*** 377,381 ****
  		PyFrameObject *f = free_list;
  		free_list = free_list->f_back;
! 		PyMem_DEL(f);
  	}
  }
--- 376,380 ----
  		PyFrameObject *f = free_list;
  		free_list = free_list->f_back;
! 		PyObject_DEL(f);
  	}
  }

Index: funcobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/funcobject.c,v
retrieving revision 2.19
retrieving revision 2.20
diff -C2 -r2.19 -r2.20
*** funcobject.c	2000/04/27 20:14:13	2.19
--- funcobject.c	2000/05/03 23:44:35	2.20
***************
*** 192,196 ****
  	Py_XDECREF(op->func_defaults);
  	Py_XDECREF(op->func_doc);
! 	PyMem_DEL(op);
  }
  
--- 192,196 ----
  	Py_XDECREF(op->func_defaults);
  	Py_XDECREF(op->func_doc);
! 	PyObject_DEL(op);
  }
  

Index: intobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/intobject.c,v
retrieving revision 2.40
retrieving revision 2.41
diff -C2 -r2.40 -r2.41
*** intobject.c	2000/04/05 20:11:20	2.40
--- intobject.c	2000/05/03 23:44:35	2.41
***************
*** 95,101 ****
  #define N_INTOBJECTS	((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyIntObject))
  
- #define PyMem_MALLOC	malloc
- #define PyMem_FREE	free
- 
  struct _intblock {
  	struct _intblock *next;
--- 95,98 ----
***************
*** 112,118 ****
  {
  	PyIntObject *p, *q;
! 	p = (PyIntObject *)PyMem_MALLOC(sizeof(PyIntBlock));
  	if (p == NULL)
! 		return (PyIntObject *)PyErr_NoMemory();
  	((PyIntBlock *)p)->next = block_list;
  	block_list = (PyIntBlock *)p;
--- 109,116 ----
  {
  	PyIntObject *p, *q;
! 	/* XXX Int blocks escape the object heap. Use PyObject_MALLOC ??? */
! 	p = (PyIntObject *) PyMem_MALLOC(sizeof(PyIntBlock));
  	if (p == NULL)
! 		return (PyIntObject *) PyErr_NoMemory();
  	((PyIntBlock *)p)->next = block_list;
  	block_list = (PyIntBlock *)p;
***************
*** 165,173 ****
  			return NULL;
  	}
  	v = free_list;
  	free_list = (PyIntObject *)v->ob_type;
! 	v->ob_type = &PyInt_Type;
  	v->ob_ival = ival;
- 	_Py_NewReference((PyObject *)v);
  #if NSMALLNEGINTS + NSMALLPOSINTS > 0
  	if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
--- 163,171 ----
  			return NULL;
  	}
+ 	/* PyObject_New is inlined */
  	v = free_list;
  	free_list = (PyIntObject *)v->ob_type;
! 	PyObject_INIT(v, &PyInt_Type);
  	v->ob_ival = ival;
  #if NSMALLNEGINTS + NSMALLPOSINTS > 0
  	if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
***************
*** 934,938 ****
  		}
  		else {
! 			PyMem_FREE(list);
  			bf++;
  		}
--- 932,936 ----
  		}
  		else {
! 			PyMem_FREE(list); /* XXX PyObject_FREE ??? */
  			bf++;
  		}

Index: listobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/listobject.c,v
retrieving revision 2.68
retrieving revision 2.69
diff -C2 -r2.68 -r2.69
*** listobject.c	2000/04/27 21:41:03	2.68
--- listobject.c	2000/05/03 23:44:35	2.69
***************
*** 71,75 ****
  		return PyErr_NoMemory();
  	}
! 	op = (PyListObject *) malloc(sizeof(PyListObject));
  	if (op == NULL) {
  		return PyErr_NoMemory();
--- 71,76 ----
  		return PyErr_NoMemory();
  	}
! 	/* PyObject_NewVar is inlined */
! 	op = (PyListObject *) PyObject_MALLOC(sizeof(PyListObject));
  	if (op == NULL) {
  		return PyErr_NoMemory();
***************
*** 79,93 ****
  	}
  	else {
! 		op->ob_item = (PyObject **) malloc(nbytes);
  		if (op->ob_item == NULL) {
! 			free((ANY *)op);
  			return PyErr_NoMemory();
  		}
  	}
! 	op->ob_type = &PyList_Type;
! 	op->ob_size = size;
  	for (i = 0; i < size; i++)
  		op->ob_item[i] = NULL;
- 	_Py_NewReference((PyObject *)op);
  	return (PyObject *) op;
  }
--- 80,92 ----
  	}
  	else {
! 		op->ob_item = (PyObject **) PyMem_MALLOC(nbytes);
  		if (op->ob_item == NULL) {
! 			PyObject_FREE(op);
  			return PyErr_NoMemory();
  		}
  	}
! 	PyObject_INIT_VAR(op, &PyList_Type, size);
  	for (i = 0; i < size; i++)
  		op->ob_item[i] = NULL;
  	return (PyObject *) op;
  }
***************
*** 226,232 ****
  			Py_XDECREF(op->ob_item[i]);
  		}
! 		free((ANY *)op->ob_item);
  	}
! 	free((ANY *)op);
  	Py_TRASHCAN_SAFE_END(op)
  }
--- 225,231 ----
  			Py_XDECREF(op->ob_item[i]);
  		}
! 		PyMem_FREE(op->ob_item);
  	}
! 	PyObject_DEL(op);
  	Py_TRASHCAN_SAFE_END(op)
  }
***************
*** 502,506 ****
  		NRESIZE(item, PyObject *, a->ob_size + d);
  		if (item == NULL) {
! 			PyMem_XDEL(recycle);
  			PyErr_NoMemory();
  			return -1;
--- 501,506 ----
  		NRESIZE(item, PyObject *, a->ob_size + d);
  		if (item == NULL) {
! 			if (recycle != NULL)
! 				PyMem_DEL(recycle);
  			PyErr_NoMemory();
  			return -1;

Index: longobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/longobject.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -C2 -r1.56 -r1.57
*** longobject.c	2000/04/10 17:31:58	1.56
--- longobject.c	2000/05/03 23:44:35	1.57
***************
*** 996,1000 ****
  	PyObject *v;
  {
! 	PyMem_DEL(v);
  }
  
--- 996,1000 ----
  	PyObject *v;
  {
! 	PyObject_DEL(v);
  }
  

Index: methodobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/methodobject.c,v
retrieving revision 2.25
retrieving revision 2.26
diff -C2 -r2.25 -r2.26
*** methodobject.c	2000/01/20 22:32:54	2.25
--- methodobject.c	2000/05/03 23:44:35	2.26
***************
*** 47,52 ****
  	if (op != NULL) {
  		free_list = (PyCFunctionObject *)(op->m_self);
! 		op->ob_type = &PyCFunction_Type;
! 		_Py_NewReference((PyObject *)op);
  	}
  	else {
--- 47,51 ----
  	if (op != NULL) {
  		free_list = (PyCFunctionObject *)(op->m_self);
! 		PyObject_INIT(op, &PyCFunction_Type);
  	}
  	else {
***************
*** 289,293 ****
  		PyCFunctionObject *v = free_list;
  		free_list = (PyCFunctionObject *)(v->m_self);
! 		PyMem_DEL(v);
  	}
  }
--- 288,292 ----
  		PyCFunctionObject *v = free_list;
  		free_list = (PyCFunctionObject *)(v->m_self);
! 		PyObject_DEL(v);
  	}
  }

Index: moduleobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/moduleobject.c,v
retrieving revision 2.24
retrieving revision 2.25
diff -C2 -r2.24 -r2.25
*** moduleobject.c	1999/02/15 14:47:16	2.24
--- moduleobject.c	2000/05/03 23:44:35	2.25
***************
*** 171,175 ****
  		Py_DECREF(m->md_dict);
  	}
! 	free((char *)m);
  }
  
--- 171,175 ----
  		Py_DECREF(m->md_dict);
  	}
! 	PyObject_DEL(m);
  }
  

Index: object.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/object.c,v
retrieving revision 2.69
retrieving revision 2.70
diff -C2 -r2.69 -r2.70
*** object.c	2000/04/24 15:40:53	2.69
--- object.c	2000/05/03 23:44:35	2.70
***************
*** 113,132 ****
  #endif
  
- #ifndef MS_COREDLL
  PyObject *
! _PyObject_New(tp)
! 	PyTypeObject *tp;
! #else
! PyObject *
! _PyObject_New(tp,op)
! 	PyTypeObject *tp;
  	PyObject *op;
! #endif
  {
! #ifndef MS_COREDLL
! 	PyObject *op = (PyObject *) malloc(tp->tp_basicsize);
! #endif
! 	if (op == NULL)
! 		return PyErr_NoMemory();
  	op->ob_type = tp;
  	_Py_NewReference(op);
--- 113,127 ----
  #endif
  
  PyObject *
! PyObject_Init(op, tp)
  	PyObject *op;
! 	PyTypeObject *tp;
  {
! 	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);
***************
*** 134,162 ****
  }
  
- #ifndef MS_COREDLL
  PyVarObject *
! _PyObject_NewVar(tp, size)
  	PyTypeObject *tp;
  	int size;
! #else
  PyVarObject *
! _PyObject_NewVar(tp, size, op)
  	PyTypeObject *tp;
  	int size;
- 	PyVarObject *op;
- #endif
  {
! #ifndef MS_COREDLL
! 	PyVarObject *op = (PyVarObject *)
! 		malloc(tp->tp_basicsize + size * tp->tp_itemsize);
! #endif
  	if (op == NULL)
  		return (PyVarObject *)PyErr_NoMemory();
! 	op->ob_type = tp;
! 	op->ob_size = size;
! 	_Py_NewReference((PyObject *)op);
! 	return op;
  }
  
  int
  PyObject_Print(op, fp, flags)
--- 129,180 ----
  }
  
  PyVarObject *
! PyObject_InitVar(op, tp, size)
! 	PyVarObject *op;
  	PyTypeObject *tp;
  	int size;
! {
! 	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)
  	PyTypeObject *tp;
  	int size;
  {
! 	PyVarObject *op;
! 	op = (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE(tp, size));
  	if (op == NULL)
  		return (PyVarObject *)PyErr_NoMemory();
! 	return PyObject_INIT_VAR(op, tp, size);
  }
  
+ void
+ _PyObject_Del(op)
+ 	PyObject *op;
+ {
+ 	PyObject_FREE(op);
+ }
+ 
  int
  PyObject_Print(op, fp, flags)
***************
*** 888,916 ****
  int (*_Py_abstract_hack) Py_FPROTO((PyObject *)) = &PyObject_Length;
  
- 
- /* Malloc wrappers (see mymalloc.h) */
  
! /* The Py_{Malloc,Realloc} wrappers call PyErr_NoMemory() on failure */
  
  ANY *
! Py_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;
! 	}
  }
  
  ANY *
! Py_Realloc(p, nbytes)
  	ANY *p;
  	size_t nbytes;
--- 906,925 ----
  int (*_Py_abstract_hack) Py_FPROTO((PyObject *)) = &PyObject_Length;
  
  
! /* Python's malloc wrappers (see mymalloc.h) */
  
  ANY *
! PyMem_Malloc(nbytes)
  	size_t nbytes;
  {
  #if _PyMem_EXTRA > 0
  	if (nbytes == 0)
  		nbytes = _PyMem_EXTRA;
  #endif
! 	return PyMem_MALLOC(nbytes);
  }
  
  ANY *
! PyMem_Realloc(p, nbytes)
  	ANY *p;
  	size_t nbytes;
***************
*** 920,969 ****
  		nbytes = _PyMem_EXTRA;
  #endif
! 	p = realloc(p, nbytes);
! 	if (p != NULL)
! 		return p;
! 	else {
! 		PyErr_NoMemory();
! 		return NULL;
! 	}
  }
  
  void
! Py_Free(p)
  	ANY *p;
  {
! 	free(p);
  }
  
- /* The PyMem_{Malloc,Realloc} wrappers don't call anything on failure */
  
  ANY *
! PyMem_Malloc(nbytes)
  	size_t nbytes;
  {
! #if _PyMem_EXTRA > 0
! 	if (nbytes == 0)
! 		nbytes = _PyMem_EXTRA;
! #endif
! 	return malloc(nbytes);
  }
  
  ANY *
! PyMem_Realloc(p, nbytes)
  	ANY *p;
  	size_t nbytes;
  {
! #if _PyMem_EXTRA > 0
! 	if (nbytes == 0)
! 		nbytes = _PyMem_EXTRA;
! #endif
! 	return realloc(p, nbytes);
  }
  
  void
! PyMem_Free(p)
  	ANY *p;
  {
! 	free(p);
  }
  
--- 929,965 ----
  		nbytes = _PyMem_EXTRA;
  #endif
! 	return PyMem_REALLOC(p, nbytes);
  }
  
  void
! PyMem_Free(p)
  	ANY *p;
  {
! 	PyMem_FREE(p);
  }
  
  
+ /* Python's object malloc wrappers (see objimpl.h) */
+ 
  ANY *
! PyObject_Malloc(nbytes)
  	size_t nbytes;
  {
! 	return PyObject_MALLOC(nbytes);
  }
  
  ANY *
! PyObject_Realloc(p, nbytes)
  	ANY *p;
  	size_t nbytes;
  {
! 	return PyObject_REALLOC(p, nbytes);
  }
  
  void
! PyObject_Free(p)
  	ANY *p;
  {
! 	PyObject_FREE(p);
  }
  

Index: rangeobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/rangeobject.c,v
retrieving revision 2.11
retrieving revision 2.12
diff -C2 -r2.11 -r2.12
*** rangeobject.c	1999/01/09 21:40:35	2.11
--- rangeobject.c	2000/05/03 23:44:35	2.12
***************
*** 62,66 ****
  	rangeobject *r;
  {
! 	PyMem_DEL(r);
  }
  
--- 62,66 ----
  	rangeobject *r;
  {
! 	PyObject_DEL(r);
  }
  

Index: sliceobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/sliceobject.c,v
retrieving revision 2.3
retrieving revision 2.4
diff -C2 -r2.3 -r2.4
*** sliceobject.c	1996/10/11 16:25:09	2.3
--- sliceobject.c	2000/05/03 23:44:35	2.4
***************
*** 58,63 ****
  	PyObject *step;
  {
! 	PySliceObject *obj =
! 		(PySliceObject *) PyObject_NEW(PySliceObject, &PySlice_Type);
  
  	if (step == NULL) step = Py_None;
--- 58,62 ----
  	PyObject *step;
  {
! 	PySliceObject *obj = PyObject_NEW(PySliceObject, &PySlice_Type);
  
  	if (step == NULL) step = Py_None;
***************
*** 116,120 ****
  	Py_DECREF(r->start);
  	Py_DECREF(r->stop);
! 	PyMem_DEL(r);
  }
  
--- 115,119 ----
  	Py_DECREF(r->start);
  	Py_DECREF(r->stop);
! 	PyObject_DEL(r);
  }
  

Index: stringobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.62
retrieving revision 2.63
diff -C2 -r2.62 -r2.63
*** stringobject.c	2000/04/11 15:39:26	2.62
--- stringobject.c	2000/05/03 23:44:35	2.63
***************
*** 93,102 ****
  	}
  #endif /* DONT_SHARE_SHORT_STRINGS */
  	op = (PyStringObject *)
! 		malloc(sizeof(PyStringObject) + size * sizeof(char));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	op->ob_type = &PyString_Type;
! 	op->ob_size = size;
  #ifdef CACHE_HASH
  	op->ob_shash = -1;
--- 93,103 ----
  	}
  #endif /* DONT_SHARE_SHORT_STRINGS */
+ 
+ 	/* PyObject_NewVar is inlined */
  	op = (PyStringObject *)
! 		PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	PyObject_INIT_VAR(op, &PyString_Type, size);
  #ifdef CACHE_HASH
  	op->ob_shash = -1;
***************
*** 105,109 ****
  	op->ob_sinterned = NULL;
  #endif
- 	_Py_NewReference((PyObject *)op);
  	if (str != NULL)
  		memcpy(op->ob_sval, str, size);
--- 106,109 ----
***************
*** 143,152 ****
  	}
  #endif /* DONT_SHARE_SHORT_STRINGS */
  	op = (PyStringObject *)
! 		malloc(sizeof(PyStringObject) + size * sizeof(char));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	op->ob_type = &PyString_Type;
! 	op->ob_size = size;
  #ifdef CACHE_HASH
  	op->ob_shash = -1;
--- 143,153 ----
  	}
  #endif /* DONT_SHARE_SHORT_STRINGS */
+ 
+ 	/* PyObject_NewVar is inlined */
  	op = (PyStringObject *)
! 		PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	PyObject_INIT_VAR(op, &PyString_Type, size);
  #ifdef CACHE_HASH
  	op->ob_shash = -1;
***************
*** 155,159 ****
  	op->ob_sinterned = NULL;
  #endif
- 	_Py_NewReference((PyObject *)op);
  	strcpy(op->ob_sval, str);
  #ifndef DONT_SHARE_SHORT_STRINGS
--- 156,159 ----
***************
*** 173,177 ****
  	PyObject *op;
  {
! 	PyMem_DEL(op);
  }
  
--- 173,177 ----
  	PyObject *op;
  {
! 	PyObject_DEL(op);
  }
  
***************
*** 308,317 ****
  	}
  	size = a->ob_size + b->ob_size;
  	op = (PyStringObject *)
! 		malloc(sizeof(PyStringObject) + size * sizeof(char));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	op->ob_type = &PyString_Type;
! 	op->ob_size = size;
  #ifdef CACHE_HASH
  	op->ob_shash = -1;
--- 308,317 ----
  	}
  	size = a->ob_size + b->ob_size;
+ 	/* PyObject_NewVar is inlined */
  	op = (PyStringObject *)
! 		PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	PyObject_INIT_VAR(op, &PyString_Type, size);
  #ifdef CACHE_HASH
  	op->ob_shash = -1;
***************
*** 320,324 ****
  	op->ob_sinterned = NULL;
  #endif
- 	_Py_NewReference((PyObject *)op);
  	memcpy(op->ob_sval, a->ob_sval, (int) a->ob_size);
  	memcpy(op->ob_sval + a->ob_size, b->ob_sval, (int) b->ob_size);
--- 320,323 ----
***************
*** 343,352 ****
  		return (PyObject *)a;
  	}
  	op = (PyStringObject *)
! 		malloc(sizeof(PyStringObject) + size * sizeof(char));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	op->ob_type = &PyString_Type;
! 	op->ob_size = size;
  #ifdef CACHE_HASH
  	op->ob_shash = -1;
--- 342,351 ----
  		return (PyObject *)a;
  	}
+ 	/* PyObject_NewVar is inlined */
  	op = (PyStringObject *)
! 		PyObject_MALLOC(sizeof(PyStringObject) + size * sizeof(char));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	PyObject_INIT_VAR(op, &PyString_Type, size);
  #ifdef CACHE_HASH
  	op->ob_shash = -1;
***************
*** 355,359 ****
  	op->ob_sinterned = NULL;
  #endif
- 	_Py_NewReference((PyObject *)op);
  	for (i = 0; i < size; i += a->ob_size)
  		memcpy(op->ob_sval+i, a->ob_sval, (int) a->ob_size);
--- 354,357 ----
***************
*** 1499,1503 ****
  	new_len = len + nfound*(sub_len - pat_len);
  
! 	new_s = (char *)malloc(new_len);
  	if (new_s == NULL) return NULL;
  
--- 1497,1501 ----
  	new_len = len + nfound*(sub_len - pat_len);
  
! 	new_s = (char *)PyMem_MALLOC(new_len);
  	if (new_s == NULL) return NULL;
  
***************
*** 1594,1598 ****
  	else {
  		new = PyString_FromStringAndSize(new_s, out_len);
! 		free(new_s);
  	}
  	return new;
--- 1592,1596 ----
  	else {
  		new = PyString_FromStringAndSize(new_s, out_len);
! 		PyMem_FREE(new_s);
  	}
  	return new;
***************
*** 2274,2281 ****
  	_Py_ForgetReference(v);
  	*pv = (PyObject *)
! 		realloc((char *)v,
  			sizeof(PyStringObject) + newsize * sizeof(char));
  	if (*pv == NULL) {
! 		PyMem_DEL(v);
  		PyErr_NoMemory();
  		return -1;
--- 2272,2279 ----
  	_Py_ForgetReference(v);
  	*pv = (PyObject *)
! 		PyObject_REALLOC((char *)v,
  			sizeof(PyStringObject) + newsize * sizeof(char));
  	if (*pv == NULL) {
! 		PyObject_DEL(v);
  		PyErr_NoMemory();
  		return -1;

Index: tupleobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.32
retrieving revision 2.33
diff -C2 -r2.32 -r2.33
*** tupleobject.c	2000/04/27 21:41:03	2.32
--- tupleobject.c	2000/05/03 23:44:36	2.33
***************
*** 81,88 ****
  		fast_tuple_allocs++;
  #endif
  #ifdef Py_TRACE_REFS
- 		op->ob_type = &PyTuple_Type;
  		op->ob_size = size;
  #endif
  	}
  	else
--- 81,90 ----
  		fast_tuple_allocs++;
  #endif
+ 		/* PyObject_InitVar is inlined */
  #ifdef Py_TRACE_REFS
  		op->ob_size = size;
+ 		op->ob_type = &PyTuple_Type;
  #endif
+ 		_Py_NewReference((PyObject *)op);
  	}
  	else
***************
*** 97,111 ****
  			return PyErr_NoMemory();
  		}
! 		;
! 		op = (PyTupleObject *) malloc(nbytes);
  		if (op == NULL)
  			return PyErr_NoMemory();
  
! 		op->ob_type = &PyTuple_Type;
! 		op->ob_size = size;
  	}
  	for (i = 0; i < size; i++)
  		op->ob_item[i] = NULL;
- 	_Py_NewReference((PyObject *)op);
  #if MAXSAVESIZE > 0
  	if (size == 0) {
--- 99,111 ----
  			return PyErr_NoMemory();
  		}
! 		/* PyObject_NewVar is inlined */
! 		op = (PyTupleObject *) PyObject_MALLOC(nbytes);
  		if (op == NULL)
  			return PyErr_NoMemory();
  
! 		PyObject_INIT_VAR(op, &PyTuple_Type, size);
  	}
  	for (i = 0; i < size; i++)
  		op->ob_item[i] = NULL;
  #if MAXSAVESIZE > 0
  	if (size == 0) {
***************
*** 194,198 ****
  #endif
  	}
! 	free((ANY *)op);
  done:
  	Py_TRASHCAN_SAFE_END(op)
--- 194,198 ----
  #endif
  	}
! 	PyObject_DEL(op);
  done:
  	Py_TRASHCAN_SAFE_END(op)
***************
*** 531,539 ****
  	{
  		sv = (PyTupleObject *)
! 			realloc((char *)v,
  				sizeof(PyTupleObject) + newsize * sizeof(PyObject *));
  		*pv = (PyObject *) sv;
  		if (sv == NULL) {
! 			PyMem_DEL(v);
  			PyErr_NoMemory();
  			return -1;
--- 531,539 ----
  	{
  		sv = (PyTupleObject *)
! 			PyObject_REALLOC((char *)v,
  				sizeof(PyTupleObject) + newsize * sizeof(PyObject *));
  		*pv = (PyObject *) sv;
  		if (sv == NULL) {
! 			PyObject_DEL(v);
  			PyErr_NoMemory();
  			return -1;
***************
*** 570,574 ****
  			q = p;
  			p = (PyTupleObject *)(p->ob_item[0]);
! 			PyMem_DEL(q);
  		}
  	}
--- 570,574 ----
  			q = p;
  			p = (PyTupleObject *)(p->ob_item[0]);
! 			PyObject_DEL(q);
  		}
  	}

Index: unicodeobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.15
retrieving revision 2.16
diff -C2 -r2.15 -r2.16
*** unicodeobject.c	2000/05/03 12:27:22	2.15
--- unicodeobject.c	2000/05/03 23:44:36	2.16
***************
*** 201,206 ****
          unicode_freelist = *(PyUnicodeObject **)unicode_freelist;
          unicode_freelist_size--;
!         unicode->ob_type = &PyUnicode_Type;
!         _Py_NewReference((PyObject *)unicode);
  	if (unicode->str) {
  	    /* Keep-Alive optimization: we only upsize the buffer,
--- 201,205 ----
          unicode_freelist = *(PyUnicodeObject **)unicode_freelist;
          unicode_freelist_size--;
! 	PyObject_INIT(unicode, &PyUnicode_Type);
  	if (unicode->str) {
  	    /* Keep-Alive optimization: we only upsize the buffer,
***************
*** 208,212 ****
  	    if ((unicode->length < length) &&
  		_PyUnicode_Resize(unicode, length)) {
! 		free(unicode->str);
  		goto onError;
  	    }
--- 207,211 ----
  	    if ((unicode->length < length) &&
  		_PyUnicode_Resize(unicode, length)) {
! 		PyMem_DEL(unicode->str);
  		goto onError;
  	    }
***************
*** 234,238 ****
   onError:
      _Py_ForgetReference((PyObject *)unicode);
!     PyMem_DEL(unicode);
      return NULL;
  }
--- 233,237 ----
   onError:
      _Py_ForgetReference((PyObject *)unicode);
!     PyObject_DEL(unicode);
      return NULL;
  }
***************
*** 244,248 ****
          /* Keep-Alive optimization */
  	if (unicode->length >= KEEPALIVE_SIZE_LIMIT) {
! 	    free(unicode->str);
  	    unicode->str = NULL;
  	    unicode->length = 0;
--- 243,247 ----
          /* Keep-Alive optimization */
  	if (unicode->length >= KEEPALIVE_SIZE_LIMIT) {
! 	    PyMem_DEL(unicode->str);
  	    unicode->str = NULL;
  	    unicode->length = 0;
***************
*** 258,264 ****
      }
      else {
! 	free(unicode->str);
  	Py_XDECREF(unicode->utf8str);
!         PyMem_DEL(unicode);
      }
  }
--- 257,263 ----
      }
      else {
! 	PyMem_DEL(unicode->str);
  	Py_XDECREF(unicode->utf8str);
! 	PyObject_DEL(unicode);
      }
  }
***************
*** 4663,4669 ****
  	u = *(PyUnicodeObject **)u;
  	if (v->str)
! 	    free(v->str);
  	Py_XDECREF(v->utf8str);
! 	free(v);
      }
      Py_XDECREF(unicode_empty);
--- 4662,4668 ----
  	u = *(PyUnicodeObject **)u;
  	if (v->str)
! 	    PyMem_DEL(v->str);
  	Py_XDECREF(v->utf8str);
! 	PyObject_DEL(v);
      }
      Py_XDECREF(unicode_empty);

Index: xxobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/xxobject.c,v
retrieving revision 2.14
retrieving revision 2.15
diff -C2 -r2.14 -r2.15
*** xxobject.c	1999/01/29 14:39:12	2.14
--- xxobject.c	2000/05/03 23:44:36	2.15
***************
*** 72,76 ****
  {
  	Py_XDECREF(xp->x_attr);
! 	PyMem_DEL(xp);
  }
  
--- 72,76 ----
  {
  	Py_XDECREF(xp->x_attr);
! 	PyObject_DEL(xp);
  }