[Python-checkins] CVS: python/dist/src/Parser node.c,2.7,2.8 parser.c,2.10,2.11

Jeremy Hylton python-dev@python.org
Tue, 20 Jun 2000 12:10:47 -0700


Update of /cvsroot/python/python/dist/src/Parser
In directory slayer.i.sourceforge.net:/tmp/cvs-serv509/Parser

Modified Files:
	node.c parser.c 
Log Message:
Add new parser error code, E_OVERFLOW.  This error is returned when
the number of children of a node exceeds the max possible value for
the short that is used to count them.  The Python runtime converts
this parser error into the SyntaxError "expression too long."



Index: node.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/node.c,v
retrieving revision 2.7
retrieving revision 2.8
diff -C2 -r2.7 -r2.8
*** node.c	1997/04/29 21:02:42	2.7
--- node.c	2000/06/20 19:10:44	2.8
***************
*** 30,37 ****
--- 30,40 ----
  ******************************************************************/
  
+ #include <limits.h>
+ 
  /* Parse tree node implementation */
  
  #include "pgenheaders.h"
  #include "node.h"
+ #include "errcode.h"
  
  node *
***************
*** 53,57 ****
  #define XXXROUNDUP(n) ((n) == 1 ? 1 : ((n) + XXX - 1) / XXX * XXX)
  
! node *
  PyNode_AddChild(n1, type, str, lineno)
  	register node *n1;
--- 56,60 ----
  #define XXXROUNDUP(n) ((n) == 1 ? 1 : ((n) + XXX - 1) / XXX * XXX)
  
! int
  PyNode_AddChild(n1, type, str, lineno)
  	register node *n1;
***************
*** 63,66 ****
--- 66,71 ----
  	register int nch1 = nch+1;
  	register node *n;
+ 	if (nch == SHRT_MAX || nch < 0)
+ 		return E_OVERFLOW;
  	if (XXXROUNDUP(nch) < nch1) {
  		n = n1->n_child;
***************
*** 68,72 ****
  		PyMem_RESIZE(n, node, nch1);
  		if (n == NULL)
! 			return NULL;
  		n1->n_child = n;
  	}
--- 73,77 ----
  		PyMem_RESIZE(n, node, nch1);
  		if (n == NULL)
! 			return E_NOMEM;
  		n1->n_child = n;
  	}
***************
*** 77,81 ****
  	n->n_nchildren = 0;
  	n->n_child = NULL;
! 	return n;
  }
  
--- 82,86 ----
  	n->n_nchildren = 0;
  	n->n_child = NULL;
! 	return 0;
  }
  

Index: parser.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/parser.c,v
retrieving revision 2.10
retrieving revision 2.11
diff -C2 -r2.10 -r2.11
*** parser.c	1997/04/29 21:02:45	2.10
--- parser.c	2000/06/20 19:10:44	2.11
***************
*** 154,162 ****
  	int lineno;
  {
  	assert(!s_empty(s));
! 	if (PyNode_AddChild(s->s_top->s_parent, type, str, lineno) == NULL) {
! 		fprintf(stderr, "shift: no mem in addchild\n");
! 		return -1;
! 	}
  	s->s_top->s_state = newstate;
  	return 0;
--- 154,162 ----
  	int lineno;
  {
+ 	int err;
  	assert(!s_empty(s));
! 	err = PyNode_AddChild(s->s_top->s_parent, type, str, lineno);
! 	if (err)
! 		return err;
  	s->s_top->s_state = newstate;
  	return 0;
***************
*** 173,183 ****
  	int lineno;
  {
  	register node *n;
  	n = s->s_top->s_parent;
  	assert(!s_empty(s));
! 	if (PyNode_AddChild(n, type, (char *)NULL, lineno) == NULL) {
! 		fprintf(stderr, "push: no mem in addchild\n");
! 		return -1;
! 	}
  	s->s_top->s_state = newstate;
  	return s_push(s, d, CHILD(n, NCH(n)-1));
--- 173,183 ----
  	int lineno;
  {
+ 	int err;
  	register node *n;
  	n = s->s_top->s_parent;
  	assert(!s_empty(s));
! 	err = PyNode_AddChild(n, type, (char *)NULL, lineno);
! 	if (err)
! 		return err;
  	s->s_top->s_state = newstate;
  	return s_push(s, d, CHILD(n, NCH(n)-1));
***************
*** 234,237 ****
--- 234,238 ----
  {
  	register int ilabel;
+ 	int err;
  	
  	D(printf("Token %s/'%s' ... ", _PyParser_TokenNames[type], str));
***************
*** 261,268 ****
  					dfa *d1 = PyGrammar_FindDFA(
  						ps->p_grammar, nt);
! 					if (push(&ps->p_stack, nt, d1,
! 						arrow, lineno) < 0) {
  						D(printf(" MemError: push\n"));
! 						return E_NOMEM;
  					}
  					D(printf(" Push ...\n"));
--- 262,269 ----
  					dfa *d1 = PyGrammar_FindDFA(
  						ps->p_grammar, nt);
! 					if ((err = push(&ps->p_stack, nt, d1,
! 						arrow, lineno)) > 0) {
  						D(printf(" MemError: push\n"));
! 						return err;
  					}
  					D(printf(" Push ...\n"));
***************
*** 271,278 ****
  				
  				/* Shift the token */
! 				if (shift(&ps->p_stack, type, str,
! 						x, lineno) < 0) {
  					D(printf(" MemError: shift.\n"));
! 					return E_NOMEM;
  				}
  				D(printf(" Shift.\n"));
--- 272,279 ----
  				
  				/* Shift the token */
! 				if ((err = shift(&ps->p_stack, type, str,
! 						x, lineno)) > 0) {
  					D(printf(" MemError: shift.\n"));
! 					return err;
  				}
  				D(printf(" Shift.\n"));