[Patches] PyMem [6/8] - Python/*

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


- Cleanup w.r.t. various mallocs

- Bits of Greg's import.c are slightly rewritten for simplicity and beauty

- What's left out of scope:

     a) The dynload_<plat>.c files
     b) The locks in thread_<type>.h

     These can rest in piece; besides, to be on the safe side, it's probably
     better to use libc malloc when we deal with system locks, etc.

-- 
       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 ]---------------------------  
diff -cr PyCVS/Python/bltinmodule.c PyMem/Python/bltinmodule.c
*** PyCVS/Python/bltinmodule.c	Thu Feb 24 14:49:50 2000
--- PyMem/Python/bltinmodule.c	Thu Feb 24 19:10:20 2000
***************
*** 32,37 ****
--- 32,38 ----
  /* Built-in functions */
  
  #include "Python.h"
+ #include "pycore.h"
  
  #include "node.h"
  #include "compile.h"
***************
*** 1753,1759 ****
  		else { /* strip trailing '\n' */
  			result = PyString_FromStringAndSize(s, strlen(s)-1);
  		}
! 		free(s);
  		return result;
  	}
  	if (v != NULL) {
--- 1754,1760 ----
  		else { /* strip trailing '\n' */
  			result = PyString_FromStringAndSize(s, strlen(s)-1);
  		}
! 		PyMem_FREE(s);
  		return result;
  	}
  	if (v != NULL) {
diff -cr PyCVS/Python/ceval.c PyMem/Python/ceval.c
*** PyCVS/Python/ceval.c	Thu Feb 24 14:49:50 2000
--- PyMem/Python/ceval.c	Thu Feb 24 19:32:23 2000
***************
*** 38,43 ****
--- 38,44 ----
     */
  
  #include "Python.h"
+ #include "pycore.h"
  
  #include "compile.h"
  #include "frameobject.h"
***************
*** 2501,2507 ****
  		class);
  	
  	Py_DECREF(arg);
! 	PyMem_XDEL(k);
  	
  	return result;
  }
--- 2502,2509 ----
  		class);
  	
  	Py_DECREF(arg);
! 	if (k != NULL)
! 		PyMem_DEL(k);
  	
  	return result;
  }
diff -cr PyCVS/Python/compile.c PyMem/Python/compile.c
*** PyCVS/Python/compile.c	Thu Feb 24 14:49:50 2000
--- PyMem/Python/compile.c	Thu Feb 24 19:30:44 2000
***************
*** 45,50 ****
--- 45,51 ----
  #endif
  
  #include "Python.h"
+ #include "pycore.h"
  
  #include "node.h"
  #include "token.h"
***************
*** 112,118 ****
  	Py_XDECREF(co->co_filename);
  	Py_XDECREF(co->co_name);
  	Py_XDECREF(co->co_lnotab);
! 	PyMem_DEL(co);
  }
  
  static PyObject *
--- 113,119 ----
  	Py_XDECREF(co->co_filename);
  	Py_XDECREF(co->co_name);
  	Py_XDECREF(co->co_lnotab);
! 	PyObject_DEL(co);
  }
  
  static PyObject *
diff -cr PyCVS/Python/import.c PyMem/Python/import.c
*** PyCVS/Python/import.c	Thu Feb 24 14:49:50 2000
--- PyMem/Python/import.c	Thu Feb 24 19:13:54 2000
***************
*** 32,37 ****
--- 32,38 ----
  /* Module definition and import implementation */
  
  #include "Python.h"
+ #include "pycore.h"
  
  #include "node.h"
  #include "token.h"
***************
*** 119,125 ****
  		++countD;
  	for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan)
  		++countS;
! 	filetab = malloc((countD + countS + 1) * sizeof(struct filedescr));
  	memcpy(filetab, _PyImport_DynLoadFiletab,
  	       countD * sizeof(struct filedescr));
  	memcpy(filetab + countD, _PyImport_StandardFiletab,
--- 120,126 ----
  		++countD;
  	for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan)
  		++countS;
! 	filetab = PyMem_NEW(struct filedescr, countD + countS + 1);
  	memcpy(filetab, _PyImport_DynLoadFiletab,
  	       countD * sizeof(struct filedescr));
  	memcpy(filetab + countD, _PyImport_StandardFiletab,
***************
*** 2410,2419 ****
  		;
  
  	/* Allocate new memory for the combined table */
! 	if (our_copy == NULL)
! 		p = malloc((i+n+1) * sizeof(struct _inittab));
! 	else
! 		p = realloc(our_copy, (i+n+1) * sizeof(struct _inittab));
  	if (p == NULL)
  		return -1;
  
--- 2411,2418 ----
  		;
  
  	/* Allocate new memory for the combined table */
! 	p = our_copy;
! 	PyMem_RESIZE(p, struct _inittab, i+n+1);
  	if (p == NULL)
  		return -1;
  
diff -cr PyCVS/Python/pystate.c PyMem/Python/pystate.c
*** PyCVS/Python/pystate.c	Thu Feb 24 14:49:50 2000
--- PyMem/Python/pystate.c	Thu Feb 24 19:24:57 2000
***************
*** 32,37 ****
--- 32,38 ----
  /* Thread and interpreter state structures and their interfaces */
  
  #include "Python.h"
+ #include "pycore.h"
  
  #define ZAP(x) { \
  	PyObject *tmp = (PyObject *)(x); \
diff -cr PyCVS/Python/pythonrun.c PyMem/Python/pythonrun.c
*** PyCVS/Python/pythonrun.c	Thu Feb 24 14:49:50 2000
--- PyMem/Python/pythonrun.c	Fri Feb 25 07:42:21 2000
***************
*** 32,37 ****
--- 32,38 ----
  /* Python interpreter top-level routines, including init/exit */
  
  #include "Python.h"
+ #include "pycore.h"
  
  #include "grammar.h"
  #include "node.h"
***************
*** 518,524 ****
  	if (n == NULL) {
  		if (err.error == E_EOF) {
  			if (err.text)
! 				free(err.text);
  			return E_EOF;
  		}
  		err_input(&err);
--- 519,525 ----
  	if (n == NULL) {
  		if (err.error == E_EOF) {
  			if (err.text)
! 				PyMem_DEL(err.text);
  			return E_EOF;
  		}
  		err_input(&err);
***************
*** 984,990 ****
  	v = Py_BuildValue("(ziiz)", err->filename,
  			    err->lineno, err->offset, err->text);
  	if (err->text != NULL) {
! 		free(err->text);
  		err->text = NULL;
  	}
  	switch (err->error) {
--- 985,991 ----
  	v = Py_BuildValue("(ziiz)", err->filename,
  			    err->lineno, err->offset, err->text);
  	if (err->text != NULL) {
! 		PyMem_DEL(err->text);
  		err->text = NULL;
  	}
  	switch (err->error) {
diff -cr PyCVS/Python/traceback.c PyMem/Python/traceback.c
*** PyCVS/Python/traceback.c	Thu Feb 24 14:49:50 2000
--- PyMem/Python/traceback.c	Thu Feb 24 19:28:23 2000
***************
*** 32,37 ****
--- 32,38 ----
  /* Traceback implementation */
  
  #include "Python.h"
+ #include "pycore.h"
  
  #include "compile.h"
  #include "frameobject.h"
***************
*** 70,76 ****
  {
  	Py_XDECREF(tb->tb_next);
  	Py_XDECREF(tb->tb_frame);
! 	PyMem_DEL(tb);
  }
  
  #define Tracebacktype PyTraceBack_Type
--- 71,77 ----
  {
  	Py_XDECREF(tb->tb_next);
  	Py_XDECREF(tb->tb_frame);
! 	PyObject_DEL(tb);
  }
  
  #define Tracebacktype PyTraceBack_Type