[Patches] PyMem [7/8] - Modules/*

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Sun, 30 Apr 2000 21:45:26 +0200 (CEST)


[ Modules/* ]

Important: all object constructors and destructors in extension modules
use the functions PyObject_New/Del. Some extensions are enabled by default,
others aren't, so better be safe than sorry -- all PyObject_NEW/DEL have
been lowercase'd because each one of these modules may not belong to the
core. In terms of speed, this is fine, because there are no performance
critical objects in there (i.e. with intense alloc/dealloc rates).

Spread the word -- PyObject_NEW/DEL in extension modules is discouraged!

However, all existing PyMem_NEW/DEL have been left unchanged. Fine by me.
Someone may want to lowercase them too and see whether there's a
performance drop -- I have no time to dig further in this direction...

- Malloc cleanup + some "invisible bugs" corrected, like in nismodule.c

It turns out that people have used PyMem_NEW/DEL by assuming that they
correspond to standard malloc/free. Pfieu!

Calls to "malloc" must be spelled in the code as "malloc", so if
you're reading this and you're an author of an extension module in the
standard distrbution, and you feel like you could be the author of an
invisible bug, please double check your module. And if you're an author
of a module that is not in the standard distribution, just do the same!
I cannot track down invisible bugs. :-)

--
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252

--

Disclaimer:

I confirm that, to the best of my knowledge and belief, this contribution is
free of any claims of third parties under copyright, patent or other rights
or interests ("claims").  To the extent that I have any such claims, I
hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide
license to reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part of the
Python software and its related documentation, or any derivative versions
thereof, at no cost to CNRI or its licensed users, and to authorize others
to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or not
to incorporate this contribution in the Python software and its related
documentation.  I further grant CNRI permission to use my name and other
identifying information provided to CNRI by me for use in connection with
the Python software and its related documentation.

-------------------------------[ cut here ]---------------------------
diff -cr PyCVS/Modules/_localemodule.c PyMem/Modules/_localemodule.c
*** PyCVS/Modules/_localemodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/_localemodule.c	Sun Apr 30 03:37:37 2000
***************
*** 287,303 ****
       return NULL;
    /* assume no change in size, first */
    n1=strlen(s)+1;
!   buf=Py_Malloc(n1);
!   if(!buf)return NULL;
    n2=strxfrm(buf,s,n1);
    if(n2>n1){
      /* more space needed */
!     buf=Py_Realloc(buf,n2);
!     if(!buf)return NULL;
      strxfrm(buf,s,n2);
    }
    result=PyString_FromString(buf);
!   Py_Free(buf);
    return result;
  }
  
--- 287,303 ----
       return NULL;
    /* assume no change in size, first */
    n1=strlen(s)+1;
!   buf=PyMem_Malloc(n1);
!   if(!buf)return PyErr_NoMemory();
    n2=strxfrm(buf,s,n1);
    if(n2>n1){
      /* more space needed */
!     buf=PyMem_Realloc(buf,n2);
!     if(!buf)return PyErr_NoMemory();
      strxfrm(buf,s,n2);
    }
    result=PyString_FromString(buf);
!   PyMem_Free(buf);
    return result;
  }
  
diff -cr PyCVS/Modules/_sre.c PyMem/Modules/_sre.c
*** PyCVS/Modules/_sre.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/_sre.c	Sun Apr 30 03:43:27 2000
***************
*** 848,854 ****
                            &PyString_Type, &code, &groups, &groupindex))
  		return NULL;
  
! 	self = PyObject_NEW(PatternObject, &Pattern_Type);
  	if (self == NULL)
  		return NULL;
  
--- 848,854 ----
                            &PyString_Type, &code, &groups, &groupindex))
  		return NULL;
  
! 	self = PyObject_New(PatternObject, &Pattern_Type);
  	if (self == NULL)
  		return NULL;
  
***************
*** 886,892 ****
  	if (status > 0) {
  
  		/* create match object (with room for extra group marks) */
! 		match = PyObject_NEW_VAR(MatchObject, &Match_Type, 2*pattern->groups);
  		if (match == NULL)
  			return NULL;
  
--- 886,892 ----
  	if (status > 0) {
  
  		/* create match object (with room for extra group marks) */
! 		match = PyObject_NewVar(MatchObject, &Match_Type, 2*pattern->groups);
  		if (match == NULL)
  			return NULL;
  
***************
*** 1002,1008 ****
  	Py_XDECREF(self->code);
  	Py_XDECREF(self->pattern);
  	Py_XDECREF(self->groupindex);
! 	PyMem_DEL(self);
  }
  
  static PyObject*
--- 1002,1008 ----
  	Py_XDECREF(self->code);
  	Py_XDECREF(self->pattern);
  	Py_XDECREF(self->groupindex);
! 	PyObject_Del(self);
  }
  
  static PyObject*
***************
*** 1163,1169 ****
  {
  	Py_XDECREF(self->string);
  	Py_DECREF(self->pattern);
! 	PyMem_DEL(self);
  }
  
  static PyObject*
--- 1163,1169 ----
  {
  	Py_XDECREF(self->string);
  	Py_DECREF(self->pattern);
! 	PyObject_Del(self);
  }
  
  static PyObject*
diff -cr PyCVS/Modules/_tkinter.c PyMem/Modules/_tkinter.c
*** PyCVS/Modules/_tkinter.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/_tkinter.c	Sun Apr 30 03:49:00 2000
***************
*** 469,475 ****
  	TkappObject *v;
  	char *argv0;
    
! 	v = PyObject_NEW(TkappObject, &Tkapp_Type);
  	if (v == NULL)
  		return NULL;
  
--- 469,475 ----
  	TkappObject *v;
  	char *argv0;
    
! 	v = PyObject_New(TkappObject, &Tkapp_Type);
  	if (v == NULL)
  		return NULL;
  
***************
*** 1640,1646 ****
  {
  	TkttObject *v;
    
! 	v = PyObject_NEW(TkttObject, &Tktt_Type);
  	if (v == NULL)
  		return NULL;
  
--- 1640,1646 ----
  {
  	TkttObject *v;
    
! 	v = PyObject_New(TkttObject, &Tktt_Type);
  	if (v == NULL)
  		return NULL;
  
***************
*** 1662,1668 ****
  
  	Py_XDECREF(func);
  
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 1662,1668 ----
  
  	Py_XDECREF(func);
  
! 	PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 1910,1916 ****
  	ENTER_TCL
  	Tcl_DeleteInterp(Tkapp_Interp(self));
  	LEAVE_TCL
! 	PyMem_DEL(self);
  	DisableEventHook();
  }
  
--- 1910,1916 ----
  	ENTER_TCL
  	Tcl_DeleteInterp(Tkapp_Interp(self));
  	LEAVE_TCL
! 	PyObject_Del(self);
  	DisableEventHook();
  }
  
diff -cr PyCVS/Modules/almodule.c PyMem/Modules/almodule.c
*** PyCVS/Modules/almodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/almodule.c	Sun Apr 30 06:45:25 2000
***************
*** 648,654 ****
  {
  	alcobject *self;
  	
! 	self = PyObject_NEW(alcobject, &Alctype);
  	if (self == NULL)
  		return NULL;
  	/* XXXX Add your own initializers here */
--- 648,654 ----
  {
  	alcobject *self;
  	
! 	self = PyObject_New(alcobject, &Alctype);
  	if (self == NULL)
  		return NULL;
  	/* XXXX Add your own initializers here */
***************
*** 667,673 ****
  #else
  	(void) ALfreeconfig(self->config);	/* ignore errors */
  #endif
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 667,673 ----
  #else
  	(void) ALfreeconfig(self->config);	/* ignore errors */
  #endif
! 	PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 1421,1427 ****
  {
  	alpobject *self;
  	
! 	self = PyObject_NEW(alpobject, &Alptype);
  	if (self == NULL)
  		return NULL;
  	/* XXXX Add your own initializers here */
--- 1421,1427 ----
  {
  	alpobject *self;
  	
! 	self = PyObject_New(alpobject, &Alptype);
  	if (self == NULL)
  		return NULL;
  	/* XXXX Add your own initializers here */
***************
*** 1442,1448 ****
  		ALcloseport(self->port);
  #endif
  	}
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 1442,1448 ----
  		ALcloseport(self->port);
  #endif
  	}
! 	PyObject_Del(self);
  }
  
  static PyObject *
diff -cr PyCVS/Modules/arraymodule.c PyMem/Modules/arraymodule.c
*** PyCVS/Modules/arraymodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/arraymodule.c	Sun Apr 30 04:00:25 2000
***************
*** 346,352 ****
  	if (nbytes / descr->itemsize != (size_t)size) {
  		return PyErr_NoMemory();
  	}
! 	op = PyMem_NEW(arrayobject, 1);
  	if (op == NULL) {
  		return PyErr_NoMemory();
  	}
--- 346,352 ----
  	if (nbytes / descr->itemsize != (size_t)size) {
  		return PyErr_NoMemory();
  	}
! 	op = PyObject_NewVar(arrayobject, &Arraytype, size);
  	if (op == NULL) {
  		return PyErr_NoMemory();
  	}
***************
*** 356,369 ****
  	else {
  		op->ob_item = PyMem_NEW(char, nbytes);
  		if (op->ob_item == NULL) {
! 			PyMem_DEL(op);
  			return PyErr_NoMemory();
  		}
  	}
- 	op->ob_type = &Arraytype;
- 	op->ob_size = size;
  	op->ob_descr = descr;
- 	_Py_NewReference((PyObject *)op);
  	return (PyObject *) op;
  }
  
--- 356,366 ----
  	else {
  		op->ob_item = PyMem_NEW(char, nbytes);
  		if (op->ob_item == NULL) {
! 			PyObject_Del(op);
  			return PyErr_NoMemory();
  		}
  	}
  	op->ob_descr = descr;
  	return (PyObject *) op;
  }
  
***************
*** 466,472 ****
  {
  	if (op->ob_item != NULL)
  		PyMem_DEL(op->ob_item);
! 	PyMem_DEL(op);
  }
  
  static int
--- 463,469 ----
  {
  	if (op->ob_item != NULL)
  		PyMem_DEL(op->ob_item);
! 	PyObject_Del(op);
  }
  
  static int
diff -cr PyCVS/Modules/bsddbmodule.c PyMem/Modules/bsddbmodule.c
*** PyCVS/Modules/bsddbmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/bsddbmodule.c	Sun Apr 30 04:06:15 2000
***************
*** 89,95 ****
  	bsddbobject *dp;
  	HASHINFO info;
  
! 	if ((dp = PyObject_NEW(bsddbobject, &Bsddbtype)) == NULL)
  		return NULL;
  
  	info.bsize = bsize;
--- 89,95 ----
  	bsddbobject *dp;
  	HASHINFO info;
  
! 	if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
  		return NULL;
  
  	info.bsize = bsize;
***************
*** 143,149 ****
  	bsddbobject *dp;
  	BTREEINFO info;
  
! 	if ((dp = PyObject_NEW(bsddbobject, &Bsddbtype)) == NULL)
  		return NULL;
  
  	info.flags = btflags;
--- 143,149 ----
  	bsddbobject *dp;
  	BTREEINFO info;
  
! 	if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
  		return NULL;
  
  	info.flags = btflags;
***************
*** 200,206 ****
  	bsddbobject *dp;
  	RECNOINFO info;
  
! 	if ((dp = PyObject_NEW(bsddbobject, &Bsddbtype)) == NULL)
  		return NULL;
  
  	info.flags = rnflags;
--- 200,206 ----
  	bsddbobject *dp;
  	RECNOINFO info;
  
! 	if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL)
  		return NULL;
  
  	info.flags = rnflags;
***************
*** 261,267 ****
  				"Python bsddb: close errno %d in dealloc\n",
  				errno);
  	}
! 	PyMem_DEL(dp);
  }
  
  #ifdef WITH_THREAD
--- 261,267 ----
  				"Python bsddb: close errno %d in dealloc\n",
  				errno);
  	}
! 	PyObject_Del(dp);
  }
  
  #ifdef WITH_THREAD
diff -cr PyCVS/Modules/cPickle.c PyMem/Modules/cPickle.c
*** PyCVS/Modules/cPickle.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/cPickle.c	Sun Apr 30 04:10:32 2000
***************
*** 171,177 ****
  
      if (self->data) free(self->data);
  
!     PyMem_DEL(self);
  }
  
  static PyTypeObject PdataType = {
--- 171,177 ----
  
      if (self->data) free(self->data);
  
!     PyObject_Del(self);
  }
  
  static PyTypeObject PdataType = {
***************
*** 186,192 ****
  Pdata_New() {
      Pdata *self;
  
!     UNLESS (self = PyObject_NEW(Pdata, &PdataType)) return NULL;
      self->size=8;
      self->length=0;
      self->data=malloc(self->size * sizeof(PyObject*));
--- 186,192 ----
  Pdata_New() {
      Pdata *self;
  
!     UNLESS (self = PyObject_New(Pdata, &PdataType)) return NULL;
      self->size=8;
      self->length=0;
      self->data=malloc(self->size * sizeof(PyObject*));
***************
*** 2132,2138 ****
  newPicklerobject(PyObject *file, int bin) {
      Picklerobject *self;
  
!     UNLESS (self = PyObject_NEW(Picklerobject, &Picklertype))
          return NULL;
  
      self->fp = NULL;
--- 2132,2138 ----
  newPicklerobject(PyObject *file, int bin) {
      Picklerobject *self;
  
!     UNLESS (self = PyObject_New(Picklerobject, &Picklertype))
          return NULL;
  
      self->fp = NULL;
***************
*** 2243,2249 ****
          free(self->write_buf);
      }
  
!     PyMem_DEL(self);
  }
  
  
--- 2243,2249 ----
          free(self->write_buf);
      }
  
!     PyObject_Del(self);
  }
  
  
***************
*** 2885,2891 ****
                PyInstanceObject *inst;
  
                PyErr_Clear();
!               UNLESS (inst=PyObject_NEW(PyInstanceObject, &PyInstance_Type))
                  goto err;
                inst->in_class=(PyClassObject*)cls;
                Py_INCREF(cls);
--- 2885,2891 ----
                PyInstanceObject *inst;
  
                PyErr_Clear();
!               UNLESS (inst=PyObject_New(PyInstanceObject, &PyInstance_Type))
                  goto err;
                inst->in_class=(PyClassObject*)cls;
                Py_INCREF(cls);
***************
*** 4036,4042 ****
  newUnpicklerobject(PyObject *f) {
      Unpicklerobject *self;
  
!     UNLESS (self = PyObject_NEW(Unpicklerobject, &Unpicklertype))
          return NULL;
  
      self->file = NULL;
--- 4036,4042 ----
  newUnpicklerobject(PyObject *f) {
      Unpicklerobject *self;
  
!     UNLESS (self = PyObject_New(Unpicklerobject, &Unpicklertype))
          return NULL;
  
      self->file = NULL;
***************
*** 4141,4147 ****
          free(self->buf);
      }
      
!     PyMem_DEL(self);
  }
  
  
--- 4141,4147 ----
          free(self->buf);
      }
      
!     PyObject_Del(self);
  }
  
  
diff -cr PyCVS/Modules/cStringIO.c PyMem/Modules/cStringIO.c
*** PyCVS/Modules/cStringIO.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/cStringIO.c	Sun Apr 30 04:13:56 2000
***************
*** 56,62 ****
  "\n"
  "This module provides a simple useful replacement for\n"
  "the StringIO module that is written in C.  It does not provide the\n"
! "full generality if StringIO, but it provides anough for most\n"
  "applications and is especially useful in conjuction with the\n"
  "pickle module.\n"
  "\n"
--- 56,62 ----
  "\n"
  "This module provides a simple useful replacement for\n"
  "the StringIO module that is written in C.  It does not provide the\n"
! "full generality if StringIO, but it provides enough for most\n"
  "applications and is especially useful in conjuction with the\n"
  "pickle module.\n"
  "\n"
***************
*** 407,413 ****
  O_dealloc(Oobject *self) {
    if (self->buf != NULL)
      free(self->buf);
!   PyMem_DEL(self);
  }
  
  static PyObject *
--- 407,413 ----
  O_dealloc(Oobject *self) {
    if (self->buf != NULL)
      free(self->buf);
!   PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 465,471 ****
  newOobject(int  size) {
    Oobject *self;
  	
!   self = PyObject_NEW(Oobject, &Otype);
    if (self == NULL)
      return NULL;
    self->pos=0;
--- 465,471 ----
  newOobject(int  size) {
    Oobject *self;
  	
!   self = PyObject_New(Oobject, &Otype);
    if (self == NULL)
      return NULL;
    self->pos=0;
***************
*** 536,542 ****
  static void
  I_dealloc(Iobject *self) {
    Py_XDECREF(self->pbuf);
!   PyMem_DEL(self);
  }
  
  static PyObject *
--- 536,542 ----
  static void
  I_dealloc(Iobject *self) {
    Py_XDECREF(self->pbuf);
!   PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 586,592 ****
    }
    buf = PyString_AS_STRING(s);
    size = PyString_GET_SIZE(s);
!   UNLESS(self = PyObject_NEW(Iobject, &Itype)) return NULL;
    Py_INCREF(s);
    self->buf=buf;
    self->string_size=size;
--- 586,592 ----
    }
    buf = PyString_AS_STRING(s);
    size = PyString_GET_SIZE(s);
!   UNLESS(self = PyObject_New(Iobject, &Itype)) return NULL;
    Py_INCREF(s);
    self->buf=buf;
    self->string_size=size;
diff -cr PyCVS/Modules/cdmodule.c PyMem/Modules/cdmodule.c
*** PyCVS/Modules/cdmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/cdmodule.c	Sun Apr 30 04:16:08 2000
***************
*** 447,453 ****
  {
  	if (self->ob_cdplayer != NULL)
  		CDclose(self->ob_cdplayer);
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 447,453 ----
  {
  	if (self->ob_cdplayer != NULL)
  		CDclose(self->ob_cdplayer);
! 	PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 483,489 ****
  {
  	cdplayerobject *p;
  
! 	p = PyObject_NEW(cdplayerobject, &CdPlayertype);
  	if (p == NULL)
  		return NULL;
  	p->ob_cdplayer = cdp;
--- 483,489 ----
  {
  	cdplayerobject *p;
  
! 	p = PyObject_New(cdplayerobject, &CdPlayertype);
  	if (p == NULL)
  		return NULL;
  	p->ob_cdplayer = cdp;
***************
*** 761,767 ****
  		self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
  	}
  	CDdeleteparser(self->ob_cdparser);
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 761,767 ----
  		self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
  	}
  	CDdeleteparser(self->ob_cdparser);
! 	PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 799,805 ****
  	cdparserobject *p;
  	int i;
  
! 	p = PyObject_NEW(cdparserobject, &CdParsertype);
  	if (p == NULL)
  		return NULL;
  	p->ob_cdparser = cdp;
--- 799,805 ----
  	cdparserobject *p;
  	int i;
  
! 	p = PyObject_New(cdparserobject, &CdParsertype);
  	if (p == NULL)
  		return NULL;
  	p->ob_cdparser = cdp;
diff -cr PyCVS/Modules/clmodule.c PyMem/Modules/clmodule.c
*** PyCVS/Modules/clmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/clmodule.c	Sun Apr 30 04:18:47 2000
***************
*** 673,679 ****
  		else
  			clCloseDecompressor(SELF->ob_compressorHdl);
  	}
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 673,679 ----
  		else
  			clCloseDecompressor(SELF->ob_compressorHdl);
  	}
! 	PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 713,719 ****
  	if (!PyArg_Parse(args, "i", &scheme))
  		return NULL;
  
! 	new = PyObject_NEW(clobject, &Cltype);
  	if (new == NULL)
  		return NULL;
  
--- 713,719 ----
  	if (!PyArg_Parse(args, "i", &scheme))
  		return NULL;
  
! 	new = PyObject_New(clobject, &Cltype);
  	if (new == NULL)
  		return NULL;
  
diff -cr PyCVS/Modules/cursesmodule.c PyMem/Modules/cursesmodule.c
*** PyCVS/Modules/cursesmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/cursesmodule.c	Sun Apr 30 04:25:13 2000
***************
*** 273,279 ****
  	PyFileObject *in_fo;
  	PyFileObject *out_fo;
  	PyCursesScreenObject *xp;
! 	xp = PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
  	if (xp == NULL)
  		return NULL;
  	return (PyObject *)xp;
--- 273,279 ----
  	PyFileObject *in_fo;
  	PyFileObject *out_fo;
  	PyCursesScreenObject *xp;
! 	xp = PyObject_New(PyCursesScreenObject, &PyCursesScreen_Type);
  	if (xp == NULL)
  		return NULL;
  	return (PyObject *)xp;
***************
*** 289,295 ****
  {
  	PyCursesWindowObject *wo;
  
! 	wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
  	if (wo == NULL)
  		return NULL;
  	wo->win = win;
--- 289,295 ----
  {
  	PyCursesWindowObject *wo;
  
! 	wo = PyObject_New(PyCursesWindowObject, &PyCursesWindow_Type);
  	if (wo == NULL)
  		return NULL;
  	wo->win = win;
***************
*** 303,309 ****
  {
    if (wo->win != stdscr)
      delwin(wo->win);
!   PyMem_DEL(wo);
  }
  
  static PyObject *
--- 303,309 ----
  {
    if (wo->win != stdscr)
      delwin(wo->win);
!   PyObject_Del(wo);
  }
  
  static PyObject *
***************
*** 1125,1131 ****
  	WINDOW *pad;
  {
  	PyCursesPadObject *po;
! 	po = PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
  	if (po == NULL)
  		return NULL;
  	po->pad = pad;
--- 1125,1131 ----
  	WINDOW *pad;
  {
  	PyCursesPadObject *po;
! 	po = PyObject_New(PyCursesPadObject, &PyCursesPad_Type);
  	if (po == NULL)
  		return NULL;
  	po->pad = pad;
diff -cr PyCVS/Modules/dbmmodule.c PyMem/Modules/dbmmodule.c
*** PyCVS/Modules/dbmmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/dbmmodule.c	Sun Apr 30 04:25:55 2000
***************
*** 62,68 ****
  {
          dbmobject *dp;
  
! 	dp = PyObject_NEW(dbmobject, &Dbmtype);
  	if (dp == NULL)
  		return NULL;
  	dp->di_size = -1;
--- 62,68 ----
  {
          dbmobject *dp;
  
! 	dp = PyObject_New(dbmobject, &Dbmtype);
  	if (dp == NULL)
  		return NULL;
  	dp->di_size = -1;
***************
*** 82,88 ****
  {
          if ( dp->di_dbm )
  		dbm_close(dp->di_dbm);
! 	PyMem_DEL(dp);
  }
  
  static int
--- 82,88 ----
  {
          if ( dp->di_dbm )
  		dbm_close(dp->di_dbm);
! 	PyObject_Del(dp);
  }
  
  static int
diff -cr PyCVS/Modules/dlmodule.c PyMem/Modules/dlmodule.c
*** PyCVS/Modules/dlmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/dlmodule.c	Sun Apr 30 04:27:30 2000
***************
*** 54,60 ****
  	PyUnivPtr *handle;
  {
  	dlobject *xp;
! 	xp = PyObject_NEW(dlobject, &Dltype);
  	if (xp == NULL)
  		return NULL;
  	xp->dl_handle = handle;
--- 54,60 ----
  	PyUnivPtr *handle;
  {
  	dlobject *xp;
! 	xp = PyObject_New(dlobject, &Dltype);
  	if (xp == NULL)
  		return NULL;
  	xp->dl_handle = handle;
***************
*** 67,73 ****
  {
  	if (xp->dl_handle != NULL)
  		dlclose(xp->dl_handle);
! 	PyMem_DEL(xp);
  }
  
  static PyObject *
--- 67,73 ----
  {
  	if (xp->dl_handle != NULL)
  		dlclose(xp->dl_handle);
! 	PyObject_Del(xp);
  }
  
  static PyObject *
diff -cr PyCVS/Modules/flmodule.c PyMem/Modules/flmodule.c
*** PyCVS/Modules/flmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/flmodule.c	Sun Apr 30 04:30:00 2000
***************
*** 332,338 ****
  	fl_free_object(g->ob_generic);
  	Py_XDECREF(g->ob_callback);
  	Py_XDECREF(g->ob_callback_arg);
! 	PyMem_DEL(g);
  }
  
  #define OFF(x) offsetof(FL_OBJECT, x)
--- 332,338 ----
  	fl_free_object(g->ob_generic);
  	Py_XDECREF(g->ob_callback);
  	Py_XDECREF(g->ob_callback_arg);
! 	PyObject_Del(g);
  }
  
  #define OFF(x) offsetof(FL_OBJECT, x)
***************
*** 461,467 ****
  	PyMethodDef *methods;
  {
  	genericobject *g;
! 	g = PyObject_NEW(genericobject, &GenericObjecttype);
  	if (g == NULL)
  		return NULL;
  	g-> ob_generic = generic;
--- 461,467 ----
  	PyMethodDef *methods;
  {
  	genericobject *g;
! 	g = PyObject_New(genericobject, &GenericObjecttype);
  	if (g == NULL)
  		return NULL;
  	g-> ob_generic = generic;
***************
*** 1852,1858 ****
  	if (f->ob_form->visible)
  		fl_hide_form(f->ob_form);
  	fl_free_form(f->ob_form);
! 	PyMem_DEL(f);
  }
  
  #define OFF(x) offsetof(FL_FORM, x)
--- 1852,1858 ----
  	if (f->ob_form->visible)
  		fl_hide_form(f->ob_form);
  	fl_free_form(f->ob_form);
! 	PyObject_Del(f);
  }
  
  #define OFF(x) offsetof(FL_FORM, x)
***************
*** 1931,1937 ****
  	FL_FORM *form;
  {
  	formobject *f;
! 	f = PyObject_NEW(formobject, &Formtype);
  	if (f == NULL)
  		return NULL;
  	f->ob_form = form;
--- 1931,1937 ----
  	FL_FORM *form;
  {
  	formobject *f;
! 	f = PyObject_New(formobject, &Formtype);
  	if (f == NULL)
  		return NULL;
  	f->ob_form = form;
diff -cr PyCVS/Modules/fmmodule.c PyMem/Modules/fmmodule.c
*** PyCVS/Modules/fmmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/fmmodule.c	Sun Apr 30 04:30:39 2000
***************
*** 59,65 ****
  				"error creating new font handle");
  		return NULL;
  	}
! 	fhp = PyObject_NEW(fhobject, &Fhtype);
  	if (fhp == NULL)
  		return NULL;
  	fhp->fh_fh = fh;
--- 59,65 ----
  				"error creating new font handle");
  		return NULL;
  	}
! 	fhp = PyObject_New(fhobject, &Fhtype);
  	if (fhp == NULL)
  		return NULL;
  	fhp->fh_fh = fh;
***************
*** 196,202 ****
  	fhobject *fhp;
  {
  	fmfreefont(fhp->fh_fh);
! 	PyMem_DEL(fhp);
  }
  
  static PyTypeObject Fhtype = {
--- 196,202 ----
  	fhobject *fhp;
  {
  	fmfreefont(fhp->fh_fh);
! 	PyObject_Del(fhp);
  }
  
  static PyTypeObject Fhtype = {
diff -cr PyCVS/Modules/gdbmmodule.c PyMem/Modules/gdbmmodule.c
*** PyCVS/Modules/gdbmmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/gdbmmodule.c	Sun Apr 30 04:32:18 2000
***************
*** 93,99 ****
  {
          dbmobject *dp;
  
! 	dp = PyObject_NEW(dbmobject, &Dbmtype);
  	if (dp == NULL)
  		return NULL;
  	dp->di_size = -1;
--- 93,99 ----
  {
          dbmobject *dp;
  
! 	dp = PyObject_New(dbmobject, &Dbmtype);
  	if (dp == NULL)
  		return NULL;
  	dp->di_size = -1;
***************
*** 117,123 ****
  {
          if ( dp->di_dbm )
  		gdbm_close(dp->di_dbm);
! 	PyMem_DEL(dp);
  }
  
  static int
--- 117,123 ----
  {
          if ( dp->di_dbm )
  		gdbm_close(dp->di_dbm);
! 	PyObject_Del(dp);
  }
  
  static int
diff -cr PyCVS/Modules/getpath.c PyMem/Modules/getpath.c
*** PyCVS/Modules/getpath.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/getpath.c	Sun Apr 30 04:35:02 2000
***************
*** 529,535 ****
  	bufsz += strlen(exec_prefix) + 1;
  
  	/* This is the only malloc call in this file */
! 	buf = malloc(bufsz);
  
  	if (buf == NULL) {
  		/* We can't exit, so print a warning and limp along */
--- 529,535 ----
  	bufsz += strlen(exec_prefix) + 1;
  
  	/* This is the only malloc call in this file */
! 	buf = PyMem_Malloc(bufsz);
  
  	if (buf == NULL) {
  		/* We can't exit, so print a warning and limp along */
diff -cr PyCVS/Modules/linuxaudiodev.c PyMem/Modules/linuxaudiodev.c
*** PyCVS/Modules/linuxaudiodev.c	Sat Apr 29 00:24:07 2000
--- PyMem/Modules/linuxaudiodev.c	Sun Apr 30 04:38:45 2000
***************
*** 104,110 ****
    }
  
    /* Create and initialize the object */
!   if ((xp = PyObject_NEW(lad_t, &Ladtype)) == NULL) {
      close(fd);
      return NULL;
    }
--- 104,110 ----
    }
  
    /* Create and initialize the object */
!   if ((xp = PyObject_New(lad_t, &Ladtype)) == NULL) {
      close(fd);
      return NULL;
    }
***************
*** 118,124 ****
  lad_dealloc(lad_t *xp)
  {
    close(xp->x_fd);
!   PyMem_DEL(xp);
  }
  
  static PyObject *
--- 118,124 ----
  lad_dealloc(lad_t *xp)
  {
    close(xp->x_fd);
!   PyObject_Del(xp);
  }
  
  static PyObject *
diff -cr PyCVS/Modules/main.c PyMem/Modules/main.c
*** PyCVS/Modules/main.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/main.c	Sun Apr 30 04:40:41 2000
***************
*** 124,130 ****
  			/* -c is the last option; following arguments
  			   that look like options are left for the
  			   the command to interpret. */
! 			command = malloc(strlen(optarg) + 2);
  			if (command == NULL)
  				Py_FatalError(
  				   "not enough memory to copy -c argument");
--- 124,130 ----
  			/* -c is the last option; following arguments
  			   that look like options are left for the
  			   the command to interpret. */
! 			command = PyMem_Malloc(strlen(optarg) + 2);
  			if (command == NULL)
  				Py_FatalError(
  				   "not enough memory to copy -c argument");
***************
*** 277,283 ****
  
  	if (command) {
  		sts = PyRun_SimpleString(command) != 0;
! 		free(command);
  	}
  	else {
  		if (filename == NULL && stdin_is_interactive) {
--- 277,283 ----
  
  	if (command) {
  		sts = PyRun_SimpleString(command) != 0;
! 		PyMem_Free(command);
  	}
  	else {
  		if (filename == NULL && stdin_is_interactive) {
diff -cr PyCVS/Modules/md5module.c PyMem/Modules/md5module.c
*** PyCVS/Modules/md5module.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/md5module.c	Sun Apr 30 04:42:06 2000
***************
*** 56,62 ****
  {
  	md5object *md5p;
  
! 	md5p = PyObject_NEW(md5object, &MD5type);
  	if (md5p == NULL)
  		return NULL;
  
--- 56,62 ----
  {
  	md5object *md5p;
  
! 	md5p = PyObject_New(md5object, &MD5type);
  	if (md5p == NULL)
  		return NULL;
  
***************
*** 71,77 ****
  md5_dealloc(md5p)
  	md5object *md5p;
  {
! 	PyMem_DEL(md5p);
  }
  
  
--- 71,77 ----
  md5_dealloc(md5p)
  	md5object *md5p;
  {
! 	PyObject_Del(md5p);
  }
  
  
diff -cr PyCVS/Modules/mmapmodule.c PyMem/Modules/mmapmodule.c
*** PyCVS/Modules/mmapmodule.c	Sat Apr 29 00:24:07 2000
--- PyMem/Modules/mmapmodule.c	Sun Apr 30 04:48:32 2000
***************
*** 69,75 ****
  	}
  #endif /* UNIX */
  
! 	PyMem_DEL(m_obj);
  }
  
  static PyObject *
--- 69,75 ----
  	}
  #endif /* UNIX */
  
! 	PyObject_Del(m_obj);
  }
  
  static PyObject *
***************
*** 706,712 ****
  		)
  		return NULL;
    
! 	m_obj = PyObject_NEW (mmap_object, &mmap_object_type);
  	if (m_obj == NULL) {return NULL;}
  	m_obj->size = (size_t) map_size;
  	m_obj->pos = (size_t) 0;
--- 706,712 ----
  		)
  		return NULL;
    
! 	m_obj = PyObject_New (mmap_object, &mmap_object_type);
  	if (m_obj == NULL) {return NULL;}
  	m_obj->size = (size_t) map_size;
  	m_obj->pos = (size_t) 0;
***************
*** 757,763 ****
  		fseek(&_iob[fileno], 0, SEEK_SET);
  	}
  
! 	m_obj = PyObject_NEW (mmap_object, &mmap_object_type);
      
  	if (fh) {
  		m_obj->file_handle = fh;
--- 757,763 ----
  		fseek(&_iob[fileno], 0, SEEK_SET);
  	}
  
! 	m_obj = PyObject_New (mmap_object, &mmap_object_type);
      
  	if (fh) {
  		m_obj->file_handle = fh;
diff -cr PyCVS/Modules/mpzmodule.c PyMem/Modules/mpzmodule.c
*** PyCVS/Modules/mpzmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/mpzmodule.c	Sun Apr 30 04:49:32 2000
***************
*** 123,129 ****
  #ifdef MPZ_DEBUG
  	fputs( "mpz_object() called...\n", stderr );
  #endif /* def MPZ_DEBUG */
! 	mpzp = PyObject_NEW(mpzobject, &MPZtype);
  	if (mpzp == NULL)
  		return NULL;
  
--- 123,129 ----
  #ifdef MPZ_DEBUG
  	fputs( "mpz_object() called...\n", stderr );
  #endif /* def MPZ_DEBUG */
! 	mpzp = PyObject_New(mpzobject, &MPZtype);
  	if (mpzp == NULL)
  		return NULL;
  
***************
*** 285,291 ****
  	fputs( "mpz_dealloc() called...\n", stderr );
  #endif /* def MPZ_DEBUG */
  	mpz_clear(&mpzp->mpz);
! 	PyMem_DEL(mpzp);
  } /* mpz_dealloc() */
  
  
--- 285,291 ----
  	fputs( "mpz_dealloc() called...\n", stderr );
  #endif /* def MPZ_DEBUG */
  	mpz_clear(&mpzp->mpz);
! 	PyObject_Del(mpzp);
  } /* mpz_dealloc() */
  
  
diff -cr PyCVS/Modules/newmodule.c PyMem/Modules/newmodule.c
*** PyCVS/Modules/newmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/newmodule.c	Sun Apr 30 04:51:01 2000
***************
*** 49,55 ****
  			      &PyClass_Type, &klass,
  			      &PyDict_Type, &dict))
  		return NULL;
! 	inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type);
  	if (inst == NULL)
  		return NULL;
  	Py_INCREF(klass);
--- 49,55 ----
  			      &PyClass_Type, &klass,
  			      &PyDict_Type, &dict))
  		return NULL;
! 	inst = PyObject_New(PyInstanceObject, &PyInstance_Type);
  	if (inst == NULL)
  		return NULL;
  	Py_INCREF(klass);
diff -cr PyCVS/Modules/nismodule.c PyMem/Modules/nismodule.c
*** PyCVS/Modules/nismodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/nismodule.c	Sun Apr 30 05:01:16 2000
***************
*** 353,363 ****
  	if (list->stat != NIS_TRUE)
  		goto finally;
  
! 	PyMem_DEL(server);
  	return list->maps;
  
    finally:
! 	PyMem_DEL(server);
  	return NULL;
  }
  
--- 353,363 ----
  	if (list->stat != NIS_TRUE)
  		goto finally;
  
! 	free(server);
  	return list->maps;
  
    finally:
! 	free(server);
  	return NULL;
  }
  
diff -cr PyCVS/Modules/parsermodule.c PyMem/Modules/parsermodule.c
*** PyCVS/Modules/parsermodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/parsermodule.c	Sun Apr 30 05:38:03 2000
***************
*** 295,301 ****
  static PyObject*
  parser_newastobject(node *ast, int type)
  {
!     PyAST_Object* o = PyObject_NEW(PyAST_Object, &PyAST_Type);
  
      if (o != 0) {
          o->ast_node = ast;
--- 295,301 ----
  static PyObject*
  parser_newastobject(node *ast, int type)
  {
!     PyAST_Object* o = PyObject_New(PyAST_Object, &PyAST_Type);
  
      if (o != 0) {
          o->ast_node = ast;
***************
*** 317,323 ****
  parser_free(PyAST_Object *ast)
  {
      PyNode_Free(ast->ast_node);
!     PyMem_DEL(ast);
  }
  
  
--- 317,323 ----
  parser_free(PyAST_Object *ast)
  {
      PyNode_Free(ast->ast_node);
!     PyObject_Del(ast);
  }
  
  
***************
*** 790,799 ****
                  PyObject *temp = PySequence_GetItem(elem, 1);
  
                  /* check_terminal_tuple() already verified it's a string */
!                 strn = (char *)malloc(PyString_GET_SIZE(temp) + 1);
                  if (strn != NULL)
                      (void) strcpy(strn, PyString_AS_STRING(temp));
!                 Py_XDECREF(temp);
  
                  if (PyObject_Length(elem) == 3) {
                      PyObject* temp = PySequence_GetItem(elem, 2);
--- 790,799 ----
                  PyObject *temp = PySequence_GetItem(elem, 1);
  
                  /* check_terminal_tuple() already verified it's a string */
!                 strn = (char *)PyMem_MALLOC(PyString_GET_SIZE(temp) + 1);
                  if (strn != NULL)
                      (void) strcpy(strn, PyString_AS_STRING(temp));
!                 Py_DECREF(temp);
  
                  if (PyObject_Length(elem) == 3) {
                      PyObject* temp = PySequence_GetItem(elem, 2);
diff -cr PyCVS/Modules/pcremodule.c PyMem/Modules/pcremodule.c
*** PyCVS/Modules/pcremodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/pcremodule.c	Sun Apr 30 05:39:56 2000
***************
*** 79,85 ****
  	PyObject *arg;
  {
  	PcreObject *self;
! 	self = PyObject_NEW(PcreObject, &Pcre_Type);
  	if (self == NULL)
  		return NULL;
  	self->regex = NULL;
--- 79,85 ----
  	PyObject *arg;
  {
  	PcreObject *self;
! 	self = PyObject_New(PcreObject, &Pcre_Type);
  	if (self == NULL)
  		return NULL;
  	self->regex = NULL;
***************
*** 95,101 ****
  {
  	if (self->regex) (pcre_free)(self->regex);
  	if (self->regex_extra) (pcre_free)(self->regex_extra);
! 	PyMem_DEL(self);
  }
  
  
--- 95,101 ----
  {
  	if (self->regex) (pcre_free)(self->regex);
  	if (self->regex_extra) (pcre_free)(self->regex_extra);
! 	PyObject_Del(self);
  }
  
  
diff -cr PyCVS/Modules/pyexpat.c PyMem/Modules/pyexpat.c
*** PyCVS/Modules/pyexpat.c	Sat Apr 29 00:24:07 2000
--- PyMem/Modules/pyexpat.c	Sun Apr 30 05:44:08 2000
***************
*** 471,477 ****
          int i;
          xmlparseobject *self;
          
!         self = PyObject_NEW(xmlparseobject, &Xmlparsetype);
          if (self == NULL)
                  return NULL;
  
--- 471,477 ----
          int i;
          xmlparseobject *self;
          
!         self = PyObject_New(xmlparseobject, &Xmlparsetype);
          if (self == NULL)
                  return NULL;
  
***************
*** 512,518 ****
          for( i=0; handler_info[i].name!=NULL; i++ ){
                  Py_XDECREF( self->handlers[i] );
          }
!         PyMem_DEL(self);
  }
  
  static int handlername2int( const char *name ){
--- 512,518 ----
          for( i=0; handler_info[i].name!=NULL; i++ ){
                  Py_XDECREF( self->handlers[i] );
          }
!         PyObject_Del(self);
  }
  
  static int handlername2int( const char *name ){
diff -cr PyCVS/Modules/readline.c PyMem/Modules/readline.c
*** PyCVS/Modules/readline.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/readline.c	Sun Apr 30 05:53:32 2000
***************
*** 377,383 ****
  	char *prompt;
  {
  	int n;
! 	char *p;
  	RETSIGTYPE (*old_inthandler)();
  	old_inthandler = signal(SIGINT, onintr);
  	if (setjmp(jbuf)) {
--- 377,383 ----
  	char *prompt;
  {
  	int n;
! 	char *p, *q;
  	RETSIGTYPE (*old_inthandler)();
  	old_inthandler = signal(SIGINT, onintr);
  	if (setjmp(jbuf)) {
***************
*** 391,398 ****
  	rl_event_hook = PyOS_InputHook;
  	p = readline(prompt);
  	signal(SIGINT, old_inthandler);
  	if (p == NULL) {
! 		p = malloc(1);
  		if (p != NULL)
  			*p = '\0';
  		return p;
--- 391,400 ----
  	rl_event_hook = PyOS_InputHook;
  	p = readline(prompt);
  	signal(SIGINT, old_inthandler);
+ 
+ 	/* We must return a buffer allocated with PyMem_Malloc. */
  	if (p == NULL) {
! 		p = PyMem_Malloc(1);
  		if (p != NULL)
  			*p = '\0';
  		return p;
***************
*** 400,409 ****
  	n = strlen(p);
  	if (n > 0)
  		add_history(p);
! 	if ((p = realloc(p, n+2)) != NULL) {
  		p[n] = '\n';
  		p[n+1] = '\0';
  	}
  	return p;
  }
  
--- 402,417 ----
  	n = strlen(p);
  	if (n > 0)
  		add_history(p);
! 	/* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
! 	   release the original. */
! 	q = p;
! 	p = PyMem_Malloc(n+2);
! 	if (p != NULL) {
! 		strncpy(p, q, n);
  		p[n] = '\n';
  		p[n+1] = '\0';
  	}
+ 	free(q);
  	return p;
  }
  
diff -cr PyCVS/Modules/regexmodule.c PyMem/Modules/regexmodule.c
*** PyCVS/Modules/regexmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/regexmodule.c	Sun Apr 30 06:35:56 2000
***************
*** 64,76 ****
  reg_dealloc(re)
  	regexobject *re;
  {
! 	PyMem_XDEL(re->re_patbuf.buffer);
  	Py_XDECREF(re->re_translate);
  	Py_XDECREF(re->re_lastok);
  	Py_XDECREF(re->re_groupindex);
  	Py_XDECREF(re->re_givenpat);
  	Py_XDECREF(re->re_realpat);
! 	PyMem_DEL(re);
  }
  
  static PyObject *
--- 64,77 ----
  reg_dealloc(re)
  	regexobject *re;
  {
! 	if (re->re_patbuf.buffer)
! 		PyMem_DEL(re->re_patbuf.buffer);
  	Py_XDECREF(re->re_translate);
  	Py_XDECREF(re->re_lastok);
  	Py_XDECREF(re->re_groupindex);
  	Py_XDECREF(re->re_givenpat);
  	Py_XDECREF(re->re_realpat);
! 	PyObject_Del(re);
  }
  
  static PyObject *
***************
*** 418,424 ****
  				"translation table must be 256 bytes");
  		return NULL;
  	}
! 	re = PyObject_NEW(regexobject, &Regextype);
  	if (re != NULL) {
  		char *error;
  		re->re_patbuf.buffer = NULL;
--- 419,425 ----
  				"translation table must be 256 bytes");
  		return NULL;
  	}
! 	re = PyObject_New(regexobject, &Regextype);
  	if (re != NULL) {
  		char *error;
  		re->re_patbuf.buffer = NULL;
diff -cr PyCVS/Modules/rotormodule.c PyMem/Modules/rotormodule.c
*** PyCVS/Modules/rotormodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/rotormodule.c	Sun Apr 30 06:44:01 2000
***************
*** 178,184 ****
  {
  	Rotorobj *xp;
  
! 	xp = PyObject_NEW(Rotorobj, &Rotor_Type);
  	if (xp == NULL)
  		return NULL;
  	set_key(xp, key);
--- 178,184 ----
  {
  	Rotorobj *xp;
  
! 	xp = PyObject_New(Rotorobj, &Rotor_Type);
  	if (xp == NULL)
  		return NULL;
  	set_key(xp, key);
***************
*** 204,213 ****
  	return xp;
  
    finally:
! 	PyMem_XDEL(xp->e_rotor);
! 	PyMem_XDEL(xp->d_rotor);
! 	PyMem_XDEL(xp->positions);
! 	PyMem_XDEL(xp->advances);
  	Py_DECREF(xp);
  	return (Rotorobj*)PyErr_NoMemory();
  }
--- 204,217 ----
  	return xp;
  
    finally:
! 	if (xp->e_rotor)
! 		PyMem_DEL(xp->e_rotor);
! 	if (xp->d_rotor)
! 		PyMem_DEL(xp->d_rotor);
! 	if (xp->positions)
! 		PyMem_DEL(xp->positions);
! 	if (xp->advances)
! 		PyMem_DEL(xp->advances);
  	Py_DECREF(xp);
  	return (Rotorobj*)PyErr_NoMemory();
  }
***************
*** 473,483 ****
  rotor_dealloc(xp)
  	Rotorobj *xp;
  {
! 	PyMem_XDEL(xp->e_rotor);
! 	PyMem_XDEL(xp->d_rotor);
! 	PyMem_XDEL(xp->positions);
! 	PyMem_XDEL(xp->advances);
! 	PyMem_DEL(xp);
  }
  
  static PyObject * 
--- 477,491 ----
  rotor_dealloc(xp)
  	Rotorobj *xp;
  {
! 	if (xp->e_rotor)
! 		PyMem_DEL(xp->e_rotor);
! 	if (xp->d_rotor)
! 		PyMem_DEL(xp->d_rotor);
! 	if (xp->positions)
! 		PyMem_DEL(xp->positions);
! 	if (xp->advances)
! 		PyMem_DEL(xp->advances);
! 	PyObject_Del(xp);
  }
  
  static PyObject * 
diff -cr PyCVS/Modules/selectmodule.c PyMem/Modules/selectmodule.c
*** PyCVS/Modules/selectmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/selectmodule.c	Sun Apr 30 06:42:55 2000
***************
*** 278,286 ****
  	wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
  	efd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
  	if (rfd2obj == NULL || wfd2obj == NULL || efd2obj == NULL) {
! 		PyMem_XDEL(rfd2obj);
! 		PyMem_XDEL(wfd2obj);
! 		PyMem_XDEL(efd2obj);
  		return NULL;
  	}
  #endif
--- 278,286 ----
  	wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
  	efd2obj = PyMem_NEW(pylist, FD_SETSIZE + 3);
  	if (rfd2obj == NULL || wfd2obj == NULL || efd2obj == NULL) {
! 		if (rfd2obj) PyMem_DEL(rfd2obj);
! 		if (wfd2obj) PyMem_DEL(wfd2obj);
! 		if (efd2obj) PyMem_DEL(efd2obj);
  		return NULL;
  	}
  #endif
diff -cr PyCVS/Modules/shamodule.c PyMem/Modules/shamodule.c
*** PyCVS/Modules/shamodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/shamodule.c	Sun Apr 30 06:06:17 2000
***************
*** 380,386 ****
  static SHAobject *
  newSHAobject()
  {
! 	return (SHAobject *)PyObject_NEW(SHAobject, &SHAtype);
  }
  
  /* Internal methods for a hashing object */
--- 380,386 ----
  static SHAobject *
  newSHAobject()
  {
! 	return (SHAobject *)PyObject_New(SHAobject, &SHAtype);
  }
  
  /* Internal methods for a hashing object */
***************
*** 389,395 ****
  SHA_dealloc(ptr)
  	PyObject *ptr;
  {
! 	PyMem_DEL(ptr);
  }
  
  
--- 389,395 ----
  SHA_dealloc(ptr)
  	PyObject *ptr;
  {
! 	PyObject_Del(ptr);
  }
  
  
diff -cr PyCVS/Modules/socketmodule.c PyMem/Modules/socketmodule.c
*** PyCVS/Modules/socketmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/socketmodule.c	Sun Apr 30 06:13:35 2000
***************
*** 389,395 ****
  {
  	PySocketSockObject *s;
  	PySocketSock_Type.ob_type = &PyType_Type;
! 	s = PyObject_NEW(PySocketSockObject, &PySocketSock_Type);
  	if (s != NULL) {
  		s->sock_fd = fd;
  		s->sock_family = family;
--- 389,395 ----
  {
  	PySocketSockObject *s;
  	PySocketSock_Type.ob_type = &PyType_Type;
! 	s = PyObject_New(PySocketSockObject, &PySocketSock_Type);
  	if (s != NULL) {
  		s->sock_fd = fd;
  		s->sock_family = family;
***************
*** 1368,1374 ****
  {
  	if (s->sock_fd != -1)
  		(void) SOCKETCLOSE(s->sock_fd);
! 	PyMem_DEL(s);
  }
  
  
--- 1368,1374 ----
  {
  	if (s->sock_fd != -1)
  		(void) SOCKETCLOSE(s->sock_fd);
! 	PyObject_Del(s);
  }
  
  
***************
*** 1948,1954 ****
  	meth=SSLv2_client_method();
  #endif
  
! 	self = PyObject_NEW(SSLObject, &SSL_Type); /* Create new object */
  	if (self == NULL){
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("newSSLObject error"));
--- 1948,1954 ----
  	meth=SSLv2_client_method();
  #endif
  
! 	self = PyObject_New(SSLObject, &SSL_Type); /* Create new object */
  	if (self == NULL){
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("newSSLObject error"));
***************
*** 1962,1968 ****
  	if (self->ctx == NULL) {
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("SSL_CTX_new error"));
! 		PyMem_DEL(self);
  		return NULL;
  	}
  
--- 1962,1968 ----
  	if (self->ctx == NULL) {
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("SSL_CTX_new error"));
! 		PyObject_Del(self);
  		return NULL;
  	}
  
***************
*** 1971,1977 ****
  		PyErr_SetObject(SSLErrorObject,
  		      PyString_FromString(
  			"Both the key & certificate files must be specified"));
! 		PyMem_DEL(self);
  		return NULL;
  	}
  
--- 1971,1977 ----
  		PyErr_SetObject(SSLErrorObject,
  		      PyString_FromString(
  			"Both the key & certificate files must be specified"));
! 		PyObject_Del(self);
  		return NULL;
  	}
  
***************
*** 1983,1989 ****
  			PyErr_SetObject(SSLErrorObject,
  				PyString_FromString(
  				  "SSL_CTX_use_PrivateKey_file error"));
! 			PyMem_DEL(self);
  			return NULL;
  		}
  
--- 1983,1989 ----
  			PyErr_SetObject(SSLErrorObject,
  				PyString_FromString(
  				  "SSL_CTX_use_PrivateKey_file error"));
! 			PyObject_Del(self);
  			return NULL;
  		}
  
***************
*** 1993,1999 ****
  			PyErr_SetObject(SSLErrorObject,
  				PyString_FromString(
  				  "SSL_CTX_use_certificate_chain_file error"));
! 			PyMem_DEL(self);
  			return NULL;
  		}
  	}
--- 1993,1999 ----
  			PyErr_SetObject(SSLErrorObject,
  				PyString_FromString(
  				  "SSL_CTX_use_certificate_chain_file error"));
! 			PyObject_Del(self);
  			return NULL;
  		}
  	}
***************
*** 2008,2014 ****
  		/* Actually negotiate SSL connection */
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("SSL_connect error"));
! 		PyMem_DEL(self);
  		return NULL;
  	}
  	self->ssl->debug = 1;
--- 2008,2014 ----
  		/* Actually negotiate SSL connection */
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("SSL_connect error"));
! 		PyObject_Del(self);
  		return NULL;
  	}
  	self->ssl->debug = 1;
***************
*** 2079,2085 ****
  	SSL_free(self->ssl);
  	Py_XDECREF(self->x_attr);
  	Py_XDECREF(self->Socket);
! 	PyMem_DEL(self);
  }
  
  static PyObject *SSL_getattr(SSLObject *self, char *name)
--- 2079,2085 ----
  	SSL_free(self->ssl);
  	Py_XDECREF(self->x_attr);
  	Py_XDECREF(self->Socket);
! 	PyObject_Del(self);
  }
  
  static PyObject *SSL_getattr(SSLObject *self, char *name)
diff -cr PyCVS/Modules/stdwinmodule.c PyMem/Modules/stdwinmodule.c
*** PyCVS/Modules/stdwinmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/stdwinmodule.c	Sun Apr 30 06:17:59 2000
***************
*** 271,277 ****
  		Py_DECREF(dp->d_ref);
  		dp->d_ref = NULL;
  	}
! 	free((char *)dp);
  }
  
  static PyObject *
--- 271,277 ----
  		Py_DECREF(dp->d_ref);
  		dp->d_ref = NULL;
  	}
! 	PyObject_Del(dp);
  }
  
  static PyObject *
***************
*** 829,835 ****
  	int left, top, right, bottom;
  {
  	textobject *tp;
! 	tp = PyObject_NEW(textobject, &Texttype);
  	if (tp == NULL)
  		return NULL;
  	tp->t_attr = NULL;
--- 829,835 ----
  	int left, top, right, bottom;
  {
  	textobject *tp;
! 	tp = PyObject_New(textobject, &Texttype);
  	if (tp == NULL)
  		return NULL;
  	tp->t_attr = NULL;
***************
*** 853,859 ****
  		tefree(tp->t_text);
  	Py_XDECREF(tp->t_attr);
  	Py_XDECREF(tp->t_ref);
! 	PyMem_DEL(tp);
  }
  
  static PyObject *
--- 853,859 ----
  		tefree(tp->t_text);
  	Py_XDECREF(tp->t_attr);
  	Py_XDECREF(tp->t_ref);
! 	PyObject_Del(tp);
  }
  
  static PyObject *
***************
*** 1190,1196 ****
  	menu = wmenucreate(id + IDOFFSET, title);
  	if (menu == NULL)
  		return (menuobject *) PyErr_NoMemory();
! 	mp = PyObject_NEW(menuobject, &Menutype);
  	if (mp != NULL) {
  		mp->m_menu = menu;
  		mp->m_id = id + IDOFFSET;
--- 1190,1196 ----
  	menu = wmenucreate(id + IDOFFSET, title);
  	if (menu == NULL)
  		return (menuobject *) PyErr_NoMemory();
! 	mp = PyObject_New(menuobject, &Menutype);
  	if (mp != NULL) {
  		mp->m_menu = menu;
  		mp->m_id = id + IDOFFSET;
***************
*** 1216,1222 ****
  	if (mp->m_menu != NULL)
  		wmenudelete(mp->m_menu);
  	Py_XDECREF(mp->m_attr);
! 	PyMem_DEL(mp);
  }
  
  static PyObject *
--- 1216,1222 ----
  	if (mp->m_menu != NULL)
  		wmenudelete(mp->m_menu);
  	Py_XDECREF(mp->m_attr);
! 	PyObject_Del(mp);
  }
  
  static PyObject *
***************
*** 1386,1392 ****
  	bitmap = wnewbitmap(width, height);
  	if (bitmap == NULL)
  		return (bitmapobject *) PyErr_NoMemory();
! 	bp = PyObject_NEW(bitmapobject, &Bitmaptype);
  	if (bp != NULL) {
  		bp->b_bitmap = bitmap;
  		bp->b_attr = NULL;
--- 1386,1392 ----
  	bitmap = wnewbitmap(width, height);
  	if (bitmap == NULL)
  		return (bitmapobject *) PyErr_NoMemory();
! 	bp = PyObject_New(bitmapobject, &Bitmaptype);
  	if (bp != NULL) {
  		bp->b_bitmap = bitmap;
  		bp->b_attr = NULL;
***************
*** 1405,1411 ****
  	if (bp->b_bitmap != NULL)
  		wfreebitmap(bp->b_bitmap);
  	Py_XDECREF(bp->b_attr);
! 	PyMem_DEL(bp);
  }
  
  static PyObject *
--- 1405,1411 ----
  	if (bp->b_bitmap != NULL)
  		wfreebitmap(bp->b_bitmap);
  	Py_XDECREF(bp->b_attr);
! 	PyObject_Del(bp);
  }
  
  static PyObject *
***************
*** 1554,1560 ****
  	Py_DECREF(wp->w_title);
  	if (wp->w_attr != NULL)
  		Py_DECREF(wp->w_attr);
! 	free((char *)wp);
  }
  
  static PyObject *
--- 1554,1560 ----
  	Py_DECREF(wp->w_title);
  	if (wp->w_attr != NULL)
  		Py_DECREF(wp->w_attr);
! 	PyObject_Del(wp);
  }
  
  static PyObject *
***************
*** 1585,1591 ****
  		PyErr_SetString(StdwinError, "already drawing");
  		return NULL;
  	}
! 	dp = PyObject_NEW(drawingobject, &Drawingtype);
  	if (dp == NULL)
  		return NULL;
  	Drawing = dp;
--- 1585,1591 ----
  		PyErr_SetString(StdwinError, "already drawing");
  		return NULL;
  	}
! 	dp = PyObject_New(drawingobject, &Drawingtype);
  	if (dp == NULL)
  		return NULL;
  	Drawing = dp;
***************
*** 1986,1992 ****
  		PyErr_SetString(StdwinError, "creating too many windows");
  		return NULL;
  	}
! 	wp = PyObject_NEW(windowobject, &Windowtype);
  	if (wp == NULL)
  		return NULL;
  	Py_INCREF(title);
--- 1986,1992 ----
  		PyErr_SetString(StdwinError, "creating too many windows");
  		return NULL;
  	}
! 	wp = PyObject_New(windowobject, &Windowtype);
  	if (wp == NULL)
  		return NULL;
  	Py_INCREF(title);
diff -cr PyCVS/Modules/stropmodule.c PyMem/Modules/stropmodule.c
*** PyCVS/Modules/stropmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/stropmodule.c	Sun Apr 30 06:20:53 2000
***************
*** 1152,1158 ****
  		goto return_same;
  	new_len = len + nfound*(sub_len - pat_len);
  
! 	new_s = (char *)malloc(new_len);
  	if (new_s == NULL) return NULL;
  
  	*out_len = new_len;
--- 1152,1158 ----
  		goto return_same;
  	new_len = len + nfound*(sub_len - pat_len);
  
! 	new_s = (char *)PyMem_MALLOC(new_len);
  	if (new_s == NULL) return NULL;
  
  	*out_len = new_len;
***************
*** 1225,1231 ****
  	}
  	else {
  		new = PyString_FromStringAndSize(new_s, out_len);
! 		free(new_s);
  	}
  	return new;
  }
--- 1225,1231 ----
  	}
  	else {
  		new = PyString_FromStringAndSize(new_s, out_len);
! 		PyMem_FREE(new_s);
  	}
  	return new;
  }
diff -cr PyCVS/Modules/sunaudiodev.c PyMem/Modules/sunaudiodev.c
*** PyCVS/Modules/sunaudiodev.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/sunaudiodev.c	Sun Apr 30 06:23:26 2000
***************
*** 139,145 ****
  	PyMem_DEL(ctldev);
  
  	/* Create and initialize the object */
! 	xp = PyObject_NEW(sadobject, &Sadtype);
  	if (xp == NULL) {
  		close(fd);
  		return NULL;
--- 139,145 ----
  	PyMem_DEL(ctldev);
  
  	/* Create and initialize the object */
! 	xp = PyObject_New(sadobject, &Sadtype);
  	if (xp == NULL) {
  		close(fd);
  		return NULL;
***************
*** 158,164 ****
  	sadobject *xp;
  {
          close(xp->x_fd);
! 	PyMem_DEL(xp);
  }
  
  static PyObject *
--- 158,164 ----
  	sadobject *xp;
  {
          close(xp->x_fd);
! 	PyObject_Del(xp);
  }
  
  static PyObject *
***************
*** 412,418 ****
  
  static sadstatusobject *
  sads_alloc() {
! 	return PyObject_NEW(sadstatusobject, &Sadstatustype);
  }
  
  static void
--- 412,418 ----
  
  static sadstatusobject *
  sads_alloc() {
! 	return PyObject_New(sadstatusobject, &Sadstatustype);
  }
  
  static void
diff -cr PyCVS/Modules/svmodule.c PyMem/Modules/svmodule.c
*** PyCVS/Modules/svmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/svmodule.c	Sun Apr 30 06:25:02 2000
***************
*** 340,346 ****
  		Py_DECREF(self->ob_svideo);
  		self->ob_svideo = NULL;
  	}
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 340,346 ----
  		Py_DECREF(self->ob_svideo);
  		self->ob_svideo = NULL;
  	}
! 	PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 374,380 ****
  {
  	captureobject *p;
  
! 	p = PyObject_NEW(captureobject, &Capturetype);
  	if (p == NULL)
  		return NULL;
  	p->ob_svideo = self;
--- 374,380 ----
  {
  	captureobject *p;
  
! 	p = PyObject_New(captureobject, &Capturetype);
  	if (p == NULL)
  		return NULL;
  	p->ob_svideo = self;
***************
*** 994,1000 ****
  {
  	if (self->ob_svideo != NULL)
  		(void) svCloseVideo(self->ob_svideo);
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 994,1000 ----
  {
  	if (self->ob_svideo != NULL)
  		(void) svCloseVideo(self->ob_svideo);
! 	PyObject_Del(self);
  }
  
  static PyObject *
***************
*** 1026,1032 ****
  {
  	svobject *p;
  
! 	p = PyObject_NEW(svobject, &Svtype);
  	if (p == NULL)
  		return NULL;
  	p->ob_svideo = svp;
--- 1026,1032 ----
  {
  	svobject *p;
  
! 	p = PyObject_New(svobject, &Svtype);
  	if (p == NULL)
  		return NULL;
  	p->ob_svideo = svp;
diff -cr PyCVS/Modules/threadmodule.c PyMem/Modules/threadmodule.c
*** PyCVS/Modules/threadmodule.c	Sat Apr 29 00:24:06 2000
--- PyMem/Modules/threadmodule.c	Sun Apr 30 06:27:33 2000
***************
*** 58,69 ****
  newlockobject()
  {
  	lockobject *self;
! 	self = PyObject_NEW(lockobject, &Locktype);
  	if (self == NULL)
  		return NULL;
  	self->lock_lock = PyThread_allocate_lock();
  	if (self->lock_lock == NULL) {
! 		PyMem_DEL(self);
  		self = NULL;
  		PyErr_SetString(ThreadError, "can't allocate lock");
  	}
--- 58,69 ----
  newlockobject()
  {
  	lockobject *self;
! 	self = PyObject_New(lockobject, &Locktype);
  	if (self == NULL)
  		return NULL;
  	self->lock_lock = PyThread_allocate_lock();
  	if (self->lock_lock == NULL) {
! 		PyObject_Del(self);
  		self = NULL;
  		PyErr_SetString(ThreadError, "can't allocate lock");
  	}
***************
*** 79,85 ****
  	PyThread_release_lock(self->lock_lock);
  	
  	PyThread_free_lock(self->lock_lock);
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 79,85 ----
  	PyThread_release_lock(self->lock_lock);
  	
  	PyThread_free_lock(self->lock_lock);
! 	PyObject_Del(self);
  }
  
  static PyObject *
diff -cr PyCVS/Modules/xxmodule.c PyMem/Modules/xxmodule.c
*** PyCVS/Modules/xxmodule.c	Sat Apr 29 00:24:07 2000
--- PyMem/Modules/xxmodule.c	Sun Apr 30 06:32:10 2000
***************
*** 62,68 ****
  	PyObject *arg;
  {
  	XxoObject *self;
! 	self = PyObject_NEW(XxoObject, &Xxo_Type);
  	if (self == NULL)
  		return NULL;
  	self->x_attr = NULL;
--- 62,68 ----
  	PyObject *arg;
  {
  	XxoObject *self;
! 	self = PyObject_New(XxoObject, &Xxo_Type);
  	if (self == NULL)
  		return NULL;
  	self->x_attr = NULL;
***************
*** 76,82 ****
  	XxoObject *self;
  {
  	Py_XDECREF(self->x_attr);
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 76,82 ----
  	XxoObject *self;
  {
  	Py_XDECREF(self->x_attr);
! 	PyObject_Del(self);
  }
  
  static PyObject *
diff -cr PyCVS/Modules/zlibmodule.c PyMem/Modules/zlibmodule.c
*** PyCVS/Modules/zlibmodule.c	Sat Apr 29 00:24:07 2000
--- PyMem/Modules/zlibmodule.c	Sun Apr 30 06:34:28 2000
***************
*** 46,52 ****
       PyTypeObject *type;
  {
          compobject *self;
!         self = PyObject_NEW(compobject, type);
          if (self == NULL)
                  return NULL;
  	self->is_initialised = 0;
--- 46,52 ----
       PyTypeObject *type;
  {
          compobject *self;
!         self = PyObject_New(compobject, type);
          if (self == NULL)
                  return NULL;
  	self->is_initialised = 0;
***************
*** 369,375 ****
      if (self->is_initialised)
        deflateEnd(&self->zst);
      Py_XDECREF(self->unused_data);
!     PyMem_DEL(self);
  }
  
  static void
--- 369,375 ----
      if (self->is_initialised)
        deflateEnd(&self->zst);
      Py_XDECREF(self->unused_data);
!     PyObject_Del(self);
  }
  
  static void
***************
*** 378,384 ****
  {
      inflateEnd(&self->zst);
      Py_XDECREF(self->unused_data);
!     PyMem_DEL(self);
  }
  
  static char comp_compress__doc__[] =
--- 378,384 ----
  {
      inflateEnd(&self->zst);
      Py_XDECREF(self->unused_data);
!     PyObject_Del(self);
  }
  
  static char comp_compress__doc__[] =