[Python-checkins] CVS: python/dist/src/Parser myreadline.c,2.16,2.17 parsetok.c,2.15,2.16 pgenmain.c,2.15,2.16 tokenizer.c,2.40,2.41

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


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

Modified Files:
	myreadline.c parsetok.c pgenmain.c tokenizer.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: myreadline.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Parser/myreadline.c,v
retrieving revision 2.16
retrieving revision 2.17
diff -C2 -r2.16 -r2.17
*** myreadline.c	1998/08/29 16:03:27	2.16
--- myreadline.c	2000/05/03 23:44:37	2.17
***************
*** 90,94 ****
  	char *p;
  	n = 100;
! 	if ((p = malloc(n)) == NULL)
  		return NULL;
  	fflush(stdout);
--- 90,94 ----
  	char *p;
  	n = 100;
! 	if ((p = PyMem_MALLOC(n)) == NULL)
  		return NULL;
  	fflush(stdout);
***************
*** 100,104 ****
  		break;
  	case 1: /* Interrupt */
! 		free(p);
  		return NULL;
  	case -1: /* EOF */
--- 100,104 ----
  		break;
  	case 1: /* Interrupt */
! 		PyMem_FREE(p);
  		return NULL;
  	case -1: /* EOF */
***************
*** 118,122 ****
  	while (n > 0 && p[n-1] != '\n') {
  		int incr = n+2;
! 		p = realloc(p, n + incr);
  		if (p == NULL)
  			return NULL;
--- 118,122 ----
  	while (n > 0 && p[n-1] != '\n') {
  		int incr = n+2;
! 		p = PyMem_REALLOC(p, n + incr);
  		if (p == NULL)
  			return NULL;
***************
*** 125,134 ****
  		n += strlen(p+n);
  	}
! 	return realloc(p, n+1);
  }
  
  
  /* By initializing this function pointer, systems embedding Python can
!    override the readline function. */
  
  char *(*PyOS_ReadlineFunctionPointer) Py_PROTO((char *));
--- 125,136 ----
  		n += strlen(p+n);
  	}
! 	return PyMem_REALLOC(p, n+1);
  }
  
  
  /* By initializing this function pointer, systems embedding Python can
!    override the readline function.
! 
!    Note: Python expects in return a buffer allocated with PyMem_Malloc. */
  
  char *(*PyOS_ReadlineFunctionPointer) Py_PROTO((char *));

Index: parsetok.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Parser/parsetok.c,v
retrieving revision 2.15
retrieving revision 2.16
diff -C2 -r2.15 -r2.16
*** parsetok.c	1998/12/21 18:32:40	2.15
--- parsetok.c	2000/05/03 23:44:37	2.16
***************
*** 193,197 ****
  		if (tok->buf != NULL) {
  			int len = tok->inp - tok->buf;
! 			err_ret->text = malloc(len + 1);
  			if (err_ret->text != NULL) {
  				if (len > 0)
--- 193,197 ----
  		if (tok->buf != NULL) {
  			int len = tok->inp - tok->buf;
! 			err_ret->text = PyMem_NEW(char, len + 1);
  			if (err_ret->text != NULL) {
  				if (len > 0)

Index: pgenmain.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Parser/pgenmain.c,v
retrieving revision 2.15
retrieving revision 2.16
diff -C2 -r2.15 -r2.16
*** pgenmain.c	1998/08/25 18:12:36	2.15
--- pgenmain.c	2000/05/03 23:44:37	2.16
***************
*** 140,144 ****
  			}
  			fprintf(stderr, "^\n");
! 			free(err.text);
  		}
  		Py_Exit(1);
--- 140,144 ----
  			}
  			fprintf(stderr, "^\n");
! 			PyMem_DEL(err.text);
  		}
  		Py_Exit(1);
***************
*** 197,201 ****
  {
  	int n = 1000;
! 	char *p = malloc(n);
  	char *q;
  	if (p == NULL)
--- 197,201 ----
  {
  	int n = 1000;
! 	char *p = PyMem_MALLOC(n);
  	char *q;
  	if (p == NULL)
***************
*** 210,214 ****
  	if (n > 0 && p[n-1] != '\n')
  		p[n-1] = '\n';
! 	return realloc(p, n+1);
  }
  
--- 210,214 ----
  	if (n > 0 && p[n-1] != '\n')
  		p[n-1] = '\n';
! 	return PyMem_REALLOC(p, n+1);
  }
  

Index: tokenizer.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Parser/tokenizer.c,v
retrieving revision 2.40
retrieving revision 2.41
diff -C2 -r2.40 -r2.41
*** tokenizer.c	2000/04/03 23:02:17	2.40
--- tokenizer.c	2000/05/03 23:44:37	2.41
***************
*** 220,224 ****
  				tok->done = E_INTR;
  			else if (*new == '\0') {
! 				free(new);
  				tok->done = E_EOF;
  			}
--- 220,224 ----
  				tok->done = E_INTR;
  			else if (*new == '\0') {
! 				PyMem_FREE(new);
  				tok->done = E_EOF;
  			}
***************
*** 227,236 ****
  				int oldlen = tok->cur - tok->buf;
  				int newlen = oldlen + strlen(new);
! 				char *buf = realloc(tok->buf, newlen+1);
  				tok->lineno++;
  				if (buf == NULL) {
! 					free(tok->buf);
  					tok->buf = NULL;
! 					free(new);
  					tok->done = E_NOMEM;
  					return EOF;
--- 227,237 ----
  				int oldlen = tok->cur - tok->buf;
  				int newlen = oldlen + strlen(new);
! 				char *buf = tok->buf;
! 				PyMem_RESIZE(buf, char, newlen+1);
  				tok->lineno++;
  				if (buf == NULL) {
! 					PyMem_DEL(tok->buf);
  					tok->buf = NULL;
! 					PyMem_FREE(new);
  					tok->done = E_NOMEM;
  					return EOF;
***************
*** 239,243 ****
  				tok->cur = tok->buf + oldlen;
  				strcpy(tok->buf + oldlen, new);
! 				free(new);
  				tok->inp = tok->buf + newlen;
  				tok->end = tok->inp + 1;
--- 240,244 ----
  				tok->cur = tok->buf + oldlen;
  				strcpy(tok->buf + oldlen, new);
! 				PyMem_FREE(new);
  				tok->inp = tok->buf + newlen;
  				tok->end = tok->inp + 1;
***************
*** 247,251 ****
  				tok->lineno++;
  				if (tok->buf != NULL)
! 					free(tok->buf);
  				tok->buf = new;
  				tok->cur = tok->buf;
--- 248,252 ----
  				tok->lineno++;
  				if (tok->buf != NULL)
! 					PyMem_DEL(tok->buf);
  				tok->buf = new;
  				tok->cur = tok->buf;