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

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Fri, 25 Feb 2000 13:35:08 +0100 (CET)


- The extensions continue to use they're malloc of choice for internal
  purposes, but were rewritten to mention PyObject_NEW/DEL explicitely
  when they deal with Python objects.

- The readline module takes care to feed PyOS_Readline with a buffer
  allocated via PyMem_Malloc.

- Another buglet in the regexmodule obj finalization (the regex code
  uses primarily malloc for its buffers -- the latter need to be
  released via free())

- Overall niceties and cleanups...

When and what gets in, please test thoroughly.
Linux (RH6.1) and AIX seem to do fine with it.

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

--
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 ]---------------------------  
Only in PyMem/Modules/: Setup.local
diff -cr PyCVS/Modules/_tkinter.c PyMem/Modules/_tkinter.c
*** PyCVS/Modules/_tkinter.c	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/_tkinter.c	Fri Feb 25 05:38:33 2000
***************
*** 1562,1568 ****
  
  	Py_XDECREF(func);
  
! 	PyMem_DEL(self);
  }
  
  static PyObject *
--- 1562,1568 ----
  
  	Py_XDECREF(func);
  
! 	PyObject_DEL(self);
  }
  
  static PyObject *
***************
*** 1810,1816 ****
  	ENTER_TCL
  	Tcl_DeleteInterp(Tkapp_Interp(self));
  	LEAVE_TCL
! 	PyMem_DEL(self);
  	DisableEventHook();
  }
  
--- 1810,1816 ----
  	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	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/almodule.c	Fri Feb 25 02:45:35 2000
***************
*** 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 *
diff -cr PyCVS/Modules/arraymodule.c PyMem/Modules/arraymodule.c
*** PyCVS/Modules/arraymodule.c	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/arraymodule.c	Fri Feb 25 02:50:34 2000
***************
*** 346,354 ****
  	if (nbytes / descr->itemsize != (size_t)size) {
  		return PyErr_NoMemory();
  	}
! 	op = PyMem_NEW(arrayobject, 1);
  	if (op == NULL) {
! 		return PyErr_NoMemory();
  	}
  	if (size <= 0) {
  		op->ob_item = NULL;
--- 346,354 ----
  	if (nbytes / descr->itemsize != (size_t)size) {
  		return PyErr_NoMemory();
  	}
! 	op = PyObject_NEW(arrayobject, &Arraytype);
  	if (op == NULL) {
! 		return NULL;
  	}
  	if (size <= 0) {
  		op->ob_item = NULL;
***************
*** 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,367 ----
  	else {
  		op->ob_item = PyMem_NEW(char, nbytes);
  		if (op->ob_item == NULL) {
! 			PyObject_DEL(op);
  			return PyErr_NoMemory();
  		}
  	}
  	op->ob_size = size;
  	op->ob_descr = descr;
  	return (PyObject *) op;
  }
  
***************
*** 466,472 ****
  {
  	if (op->ob_item != NULL)
  		PyMem_DEL(op->ob_item);
! 	PyMem_DEL(op);
  }
  
  static int
--- 464,470 ----
  {
  	if (op->ob_item != NULL)
  		PyMem_DEL(op->ob_item);
! 	PyObject_DEL(op);
  }
  
  static int
diff -cr PyCVS/Modules/audioop.c PyMem/Modules/audioop.c
*** PyCVS/Modules/audioop.c	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/audioop.c	Fri Feb 25 02:56:40 2000
***************
*** 1010,1017 ****
  	inrate /= d;
  	outrate /= d;
  
! 	prev_i = (int *) malloc(nchannels * sizeof(int));
! 	cur_i = (int *) malloc(nchannels * sizeof(int));
  	len /= size * nchannels;	/* # of frames */
  	if (prev_i == NULL || cur_i == NULL) {
  		(void) PyErr_NoMemory();
--- 1010,1017 ----
  	inrate /= d;
  	outrate /= d;
  
! 	prev_i = PyMem_NEW(int, nchannels);
! 	cur_i = PyMem_NEW(int, nchannels);
  	len /= size * nchannels;	/* # of frames */
  	if (prev_i == NULL || cur_i == NULL) {
  		(void) PyErr_NoMemory();
***************
*** 1104,1112 ****
  	}
    exit:
  	if (prev_i != NULL)
! 		free(prev_i);
  	if (cur_i != NULL)
! 		free(cur_i);
  	return rv;
  }
  
--- 1104,1112 ----
  	}
    exit:
  	if (prev_i != NULL)
! 		PyMem_DEL(prev_i);
  	if (cur_i != NULL)
! 		PyMem_DEL(cur_i);
  	return rv;
  }
  
diff -cr PyCVS/Modules/bsddbmodule.c PyMem/Modules/bsddbmodule.c
*** PyCVS/Modules/bsddbmodule.c	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/bsddbmodule.c	Fri Feb 25 03:01:32 2000
***************
*** 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	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/cPickle.c	Fri Feb 25 03:19:40 2000
***************
*** 169,175 ****
  
      if (self->data) free(self->data);
  
!     PyMem_DEL(self);
  }
  
  static PyTypeObject PdataType = {
--- 169,175 ----
  
      if (self->data) free(self->data);
  
!     PyObject_DEL(self);
  }
  
  static PyTypeObject PdataType = {
***************
*** 2156,2162 ****
          free(self->write_buf);
      }
  
!     PyMem_DEL(self);
  }
  
  
--- 2156,2162 ----
          free(self->write_buf);
      }
  
!     PyObject_DEL(self);
  }
  
  
***************
*** 3995,4001 ****
          free(self->buf);
      }
      
!     PyMem_DEL(self);
  }
  
  
--- 3995,4001 ----
          free(self->buf);
      }
      
!     PyObject_DEL(self);
  }
  
  
diff -cr PyCVS/Modules/cStringIO.c PyMem/Modules/cStringIO.c
*** PyCVS/Modules/cStringIO.c	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/cStringIO.c	Fri Feb 25 03:23:41 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 of 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 *
***************
*** 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 *
diff -cr PyCVS/Modules/cdmodule.c PyMem/Modules/cdmodule.c
*** PyCVS/Modules/cdmodule.c	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/cdmodule.c	Fri Feb 25 03:04:22 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 *
***************
*** 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 *
diff -cr PyCVS/Modules/clmodule.c PyMem/Modules/clmodule.c
*** PyCVS/Modules/clmodule.c	Thu Feb 24 14:49:43 2000
--- PyMem/Modules/clmodule.c	Fri Feb 25 03:09:02 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 *
diff -cr PyCVS/Modules/cursesmodule.c PyMem/Modules/cursesmodule.c
*** PyCVS/Modules/cursesmodule.c	Thu Feb 24 14:49:43 2000
--- PyMem/Modules/cursesmodule.c	Fri Feb 25 03:29:29 2000
***************
*** 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 *
diff -cr PyCVS/Modules/dbmmodule.c PyMem/Modules/dbmmodule.c
*** PyCVS/Modules/dbmmodule.c	Thu Feb 24 14:49:43 2000
--- PyMem/Modules/dbmmodule.c	Fri Feb 25 03:30:58 2000
***************
*** 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	Thu Feb 24 14:49:43 2000
--- PyMem/Modules/dlmodule.c	Fri Feb 25 03:31:55 2000
***************
*** 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	Thu Feb 24 14:49:44 2000
--- PyMem/Modules/flmodule.c	Fri Feb 25 03:36:11 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)
***************
*** 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)
diff -cr PyCVS/Modules/fmmodule.c PyMem/Modules/fmmodule.c
*** PyCVS/Modules/fmmodule.c	Thu Feb 24 14:49:44 2000
--- PyMem/Modules/fmmodule.c	Fri Feb 25 03:38:01 2000
***************
*** 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	Thu Feb 24 14:49:44 2000
--- PyMem/Modules/gdbmmodule.c	Fri Feb 25 03:40:41 2000
***************
*** 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	Thu Feb 24 14:49:44 2000
--- PyMem/Modules/getpath.c	Fri Feb 25 03:45:34 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/main.c PyMem/Modules/main.c
*** PyCVS/Modules/main.c	Thu Feb 24 14:49:45 2000
--- PyMem/Modules/main.c	Fri Feb 25 02:34:56 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	Thu Feb 24 14:49:45 2000
--- PyMem/Modules/md5module.c	Fri Feb 25 03:52:09 2000
***************
*** 71,77 ****
  md5_dealloc(md5p)
  	md5object *md5p;
  {
! 	PyMem_DEL(md5p);
  }
  
  
--- 71,77 ----
  md5_dealloc(md5p)
  	md5object *md5p;
  {
! 	PyObject_DEL(md5p);
  }
  
  
diff -cr PyCVS/Modules/mpzmodule.c PyMem/Modules/mpzmodule.c
*** PyCVS/Modules/mpzmodule.c	Thu Feb 24 14:49:45 2000
--- PyMem/Modules/mpzmodule.c	Fri Feb 25 03:56:42 2000
***************
*** 284,290 ****
  	fputs( "mpz_dealloc() called...\n", stderr );
  #endif /* def MPZ_DEBUG */
  	mpz_clear(&mpzp->mpz);
! 	PyMem_DEL(mpzp);
  } /* mpz_dealloc() */
  
  
--- 284,290 ----
  	fputs( "mpz_dealloc() called...\n", stderr );
  #endif /* def MPZ_DEBUG */
  	mpz_clear(&mpzp->mpz);
! 	PyObject_DEL(mpzp);
  } /* mpz_dealloc() */
  
  
diff -cr PyCVS/Modules/parsermodule.c PyMem/Modules/parsermodule.c
*** PyCVS/Modules/parsermodule.c	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/parsermodule.c	Fri Feb 25 02:29:57 2000
***************
*** 332,338 ****
       PyAST_Object *ast;
  {
      PyNode_Free(ast->ast_node);
!     PyMem_DEL(ast);
  
  }   /* parser_free() */
  
--- 332,338 ----
       PyAST_Object *ast;
  {
      PyNode_Free(ast->ast_node);
!     PyObject_DEL(ast);
  
  }   /* parser_free() */
  
***************
*** 850,856 ****
  		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);
--- 850,856 ----
  		PyObject *temp = PySequence_GetItem(elem, 1);
  
  		/* check_terminal_tuple() already verified it's a string */
! 		strn = PyMem_NEW(char, PyString_GET_SIZE(temp) + 1);
  		if (strn != NULL)
  		    (void) strcpy(strn, PyString_AS_STRING(temp));
  		Py_XDECREF(temp);
diff -cr PyCVS/Modules/pcremodule.c PyMem/Modules/pcremodule.c
*** PyCVS/Modules/pcremodule.c	Thu Feb 24 14:49:42 2000
--- PyMem/Modules/pcremodule.c	Fri Feb 25 04:07:45 2000
***************
*** 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/readline.c PyMem/Modules/readline.c
*** PyCVS/Modules/readline.c	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/readline.c	Fri Feb 25 02:25:39 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	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/regexmodule.c	Fri Feb 25 08:24:30 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 != NULL)
! 		free(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 *
diff -cr PyCVS/Modules/rotormodule.c PyMem/Modules/rotormodule.c
*** PyCVS/Modules/rotormodule.c	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/rotormodule.c	Fri Feb 25 04:38:58 2000
***************
*** 477,483 ****
  	PyMem_XDEL(xp->d_rotor);
  	PyMem_XDEL(xp->positions);
  	PyMem_XDEL(xp->advances);
! 	PyMem_DEL(xp);
  }
  
  static PyObject * 
--- 477,483 ----
  	PyMem_XDEL(xp->d_rotor);
  	PyMem_XDEL(xp->positions);
  	PyMem_XDEL(xp->advances);
! 	PyObject_DEL(xp);
  }
  
  static PyObject * 
diff -cr PyCVS/Modules/shamodule.c PyMem/Modules/shamodule.c
*** PyCVS/Modules/shamodule.c	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/shamodule.c	Fri Feb 25 04:42:23 2000
***************
*** 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	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/socketmodule.c	Fri Feb 25 04:47:59 2000
***************
*** 1350,1356 ****
  BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s)
  {
  	(void) close(s->sock_fd);
! 	PyMem_DEL(s);
  }
  
  
--- 1350,1356 ----
  BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s)
  {
  	(void) close(s->sock_fd);
! 	PyObject_DEL(s);
  }
  
  
***************
*** 1943,1949 ****
  	if (self->ctx == NULL) {
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("SSL_CTX_new error"));
! 		PyMem_DEL(self);
  		return NULL;
  	}
  
--- 1943,1949 ----
  	if (self->ctx == NULL) {
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("SSL_CTX_new error"));
! 		PyObject_DEL(self);
  		return NULL;
  	}
  
***************
*** 1952,1958 ****
  		PyErr_SetObject(SSLErrorObject,
  		      PyString_FromString(
  			"Both the key & certificate files must be specified"));
! 		PyMem_DEL(self);
  		return NULL;
  	}
  
--- 1952,1958 ----
  		PyErr_SetObject(SSLErrorObject,
  		      PyString_FromString(
  			"Both the key & certificate files must be specified"));
! 		PyObject_DEL(self);
  		return NULL;
  	}
  
***************
*** 1964,1970 ****
  			PyErr_SetObject(SSLErrorObject,
  				PyString_FromString(
  				  "SSL_CTX_use_PrivateKey_file error"));
! 			PyMem_DEL(self);
  			return NULL;
  		}
  
--- 1964,1970 ----
  			PyErr_SetObject(SSLErrorObject,
  				PyString_FromString(
  				  "SSL_CTX_use_PrivateKey_file error"));
! 			PyObject_DEL(self);
  			return NULL;
  		}
  
***************
*** 1974,1980 ****
  			PyErr_SetObject(SSLErrorObject,
  				PyString_FromString(
  				  "SSL_CTX_use_certificate_chain_file error"));
! 			PyMem_DEL(self);
  			return NULL;
  		}
  	}
--- 1974,1980 ----
  			PyErr_SetObject(SSLErrorObject,
  				PyString_FromString(
  				  "SSL_CTX_use_certificate_chain_file error"));
! 			PyObject_DEL(self);
  			return NULL;
  		}
  	}
***************
*** 1989,1995 ****
  		/* Actually negotiate SSL connection */
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("SSL_connect error"));
! 		PyMem_DEL(self);
  		return NULL;
  	}
  	self->ssl->debug = 1;
--- 1989,1995 ----
  		/* Actually negotiate SSL connection */
  		PyErr_SetObject(SSLErrorObject,
  				PyString_FromString("SSL_connect error"));
! 		PyObject_DEL(self);
  		return NULL;
  	}
  	self->ssl->debug = 1;
***************
*** 2060,2066 ****
  	SSL_free(self->ssl);
  	Py_XDECREF(self->x_attr);
  	Py_XDECREF(self->Socket);
! 	PyMem_DEL(self);
  }
  
  static PyObject *SSL_getattr(SSLObject *self, char *name)
--- 2060,2066 ----
  	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	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/stdwinmodule.c	Fri Feb 25 05:06:33 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 *
***************
*** 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 *
***************
*** 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 *
***************
*** 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 *
diff -cr PyCVS/Modules/stropmodule.c PyMem/Modules/stropmodule.c
*** PyCVS/Modules/stropmodule.c	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/stropmodule.c	Fri Feb 25 05:17:39 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 = PyMem_NEW(char, 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_DEL(new_s);
  	}
  	return new;
  }
diff -cr PyCVS/Modules/sunaudiodev.c PyMem/Modules/sunaudiodev.c
*** PyCVS/Modules/sunaudiodev.c	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/sunaudiodev.c	Fri Feb 25 05:23:08 2000
***************
*** 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 *
***************
*** 419,425 ****
  sads_dealloc(xp)
  	sadstatusobject *xp;
  {
! 	PyMem_DEL(xp);
  }
  
  #define OFF(x) offsetof(audio_info_t,x)
--- 419,425 ----
  sads_dealloc(xp)
  	sadstatusobject *xp;
  {
! 	PyObject_DEL(xp);
  }
  
  #define OFF(x) offsetof(audio_info_t,x)
diff -cr PyCVS/Modules/svmodule.c PyMem/Modules/svmodule.c
*** PyCVS/Modules/svmodule.c	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/svmodule.c	Fri Feb 25 05:25:46 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 *
***************
*** 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 *
diff -cr PyCVS/Modules/threadmodule.c PyMem/Modules/threadmodule.c
*** PyCVS/Modules/threadmodule.c	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/threadmodule.c	Fri Feb 25 05:30:42 2000
***************
*** 63,69 ****
  		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");
  	}
--- 63,69 ----
  		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	Thu Feb 24 14:49:46 2000
--- PyMem/Modules/xxmodule.c	Fri Feb 25 05:42:09 2000
***************
*** 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	Thu Feb 24 14:49:47 2000
--- PyMem/Modules/zlibmodule.c	Fri Feb 25 05:46:11 2000
***************
*** 372,378 ****
      if (self->is_initialised)
        deflateEnd(&self->zst);
      Py_XDECREF(self->unused_data);
!     PyMem_DEL(self);
  }
  
  static void
--- 372,378 ----
      if (self->is_initialised)
        deflateEnd(&self->zst);
      Py_XDECREF(self->unused_data);
!     PyObject_DEL(self);
  }
  
  static void
***************
*** 381,387 ****
  {
      inflateEnd(&self->zst);
      Py_XDECREF(self->unused_data);
!     PyMem_DEL(self);
  }
  
  static char comp_compress__doc__[] =
--- 381,387 ----
  {
      inflateEnd(&self->zst);
      Py_XDECREF(self->unused_data);
!     PyObject_DEL(self);
  }
  
  static char comp_compress__doc__[] =