[Python-checkins] r45257 - python/trunk/Parser/bitset.c python/trunk/Parser/firstsets.c python/trunk/Parser/grammar.c python/trunk/Parser/myreadline.c python/trunk/Parser/parser.c python/trunk/Parser/pgen.c python/trunk/Parser/tokenizer.c

anthony.baxter python-checkins at python.org
Tue Apr 11 07:39:16 CEST 2006


Author: anthony.baxter
Date: Tue Apr 11 07:39:14 2006
New Revision: 45257

Modified:
   python/trunk/Parser/bitset.c
   python/trunk/Parser/firstsets.c
   python/trunk/Parser/grammar.c
   python/trunk/Parser/myreadline.c
   python/trunk/Parser/parser.c
   python/trunk/Parser/pgen.c
   python/trunk/Parser/tokenizer.c
Log:
Fix the code in Parser/ to also compile with C++. This was mostly casts for
malloc/realloc type functions, as well as renaming one variable called 'new'
in tokensizer.c. Still lots more to be done, going to be checking in one
chunk at a time or the patch will be massively huge. Still compiles ok with
gcc.


Modified: python/trunk/Parser/bitset.c
==============================================================================
--- python/trunk/Parser/bitset.c	(original)
+++ python/trunk/Parser/bitset.c	Tue Apr 11 07:39:14 2006
@@ -8,7 +8,7 @@
 newbitset(int nbits)
 {
 	int nbytes = NBYTES(nbits);
-	bitset ss = PyObject_MALLOC(sizeof(BYTE) *  nbytes);
+	bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) *  nbytes);
 	
 	if (ss == NULL)
 		Py_FatalError("no mem for bitset");

Modified: python/trunk/Parser/firstsets.c
==============================================================================
--- python/trunk/Parser/firstsets.c	(original)
+++ python/trunk/Parser/firstsets.c	Tue Apr 11 07:39:14 2006
@@ -59,7 +59,7 @@
 	nbits = g->g_ll.ll_nlabels;
 	result = newbitset(nbits);
 	
-	sym = PyObject_MALLOC(sizeof(int));
+	sym = (int *)PyObject_MALLOC(sizeof(int));
 	if (sym == NULL)
 		Py_FatalError("no mem for new sym in calcfirstset");
 	nsyms = 1;
@@ -73,7 +73,8 @@
 				break;
 		}
 		if (j >= nsyms) { /* New label */
-			sym = PyObject_REALLOC(sym, sizeof(int) * (nsyms + 1));
+			sym = (int *)PyObject_REALLOC(sym, 
+                                                sizeof(int) * (nsyms + 1));
 			if (sym == NULL)
 				Py_FatalError(
 				    "no mem to resize sym in calcfirstset");

Modified: python/trunk/Parser/grammar.c
==============================================================================
--- python/trunk/Parser/grammar.c	(original)
+++ python/trunk/Parser/grammar.c	Tue Apr 11 07:39:14 2006
@@ -20,7 +20,7 @@
 {
 	grammar *g;
 	
-	g = PyObject_MALLOC(sizeof(grammar));
+	g = (grammar *)PyObject_MALLOC(sizeof(grammar));
 	if (g == NULL)
 		Py_FatalError("no mem for new grammar");
 	g->g_ndfas = 0;
@@ -37,7 +37,8 @@
 {
 	dfa *d;
 	
-	g->g_dfa = PyObject_REALLOC(g->g_dfa, sizeof(dfa) * (g->g_ndfas + 1));
+	g->g_dfa = (dfa *)PyObject_REALLOC(g->g_dfa, 
+                                            sizeof(dfa) * (g->g_ndfas + 1));
 	if (g->g_dfa == NULL)
 		Py_FatalError("no mem to resize dfa in adddfa");
 	d = &g->g_dfa[g->g_ndfas++];
@@ -55,7 +56,7 @@
 {
 	state *s;
 	
-	d->d_state = PyObject_REALLOC(d->d_state,
+	d->d_state = (state *)PyObject_REALLOC(d->d_state,
 				      sizeof(state) * (d->d_nstates + 1));
 	if (d->d_state == NULL)
 		Py_FatalError("no mem to resize state in addstate");
@@ -79,7 +80,7 @@
 	assert(0 <= to && to < d->d_nstates);
 	
 	s = &d->d_state[from];
-	s->s_arc = PyObject_REALLOC(s->s_arc, sizeof(arc) * (s->s_narcs + 1));
+	s->s_arc = (arc *)PyObject_REALLOC(s->s_arc, sizeof(arc) * (s->s_narcs + 1));
 	if (s->s_arc == NULL)
 		Py_FatalError("no mem to resize arc list in addarc");
 	a = &s->s_arc[s->s_narcs++];
@@ -98,7 +99,7 @@
 			strcmp(ll->ll_label[i].lb_str, str) == 0)
 			return i;
 	}
-	ll->ll_label = PyObject_REALLOC(ll->ll_label,
+	ll->ll_label = (label *)PyObject_REALLOC(ll->ll_label,
 					sizeof(label) * (ll->ll_nlabels + 1));
 	if (ll->ll_label == NULL)
 		Py_FatalError("no mem to resize labellist in addlabel");
@@ -197,7 +198,7 @@
 				name_len = p - src;
 			else
 				name_len = strlen(src);
-			dest = malloc(name_len + 1);
+			dest = (char *)malloc(name_len + 1);
 			strncpy(dest, src, name_len);
 			dest[name_len] = '\0';
 			free(lb->lb_str);

Modified: python/trunk/Parser/myreadline.c
==============================================================================
--- python/trunk/Parser/myreadline.c	(original)
+++ python/trunk/Parser/myreadline.c	Tue Apr 11 07:39:14 2006
@@ -111,7 +111,7 @@
 	size_t n;
 	char *p;
 	n = 100;
-	if ((p = PyObject_MALLOC(n)) == NULL)
+	if ((p = (char *)PyObject_MALLOC(n)) == NULL)
 		return NULL;
 	fflush(sys_stdout);
 #ifndef RISCOS
@@ -141,7 +141,7 @@
 	n = strlen(p);
 	while (n > 0 && p[n-1] != '\n') {
 		size_t incr = n+2;
-		p = PyObject_REALLOC(p, n + incr);
+		p = (char *)PyObject_REALLOC(p, n + incr);
 		if (p == NULL)
 			return NULL;
 		if (incr > INT_MAX) {
@@ -151,7 +151,7 @@
 			break;
 		n += strlen(p+n);
 	}
-	return PyObject_REALLOC(p, n+1);
+	return (char *)PyObject_REALLOC(p, n+1);
 }
 
 

Modified: python/trunk/Parser/parser.c
==============================================================================
--- python/trunk/Parser/parser.c	(original)
+++ python/trunk/Parser/parser.c	Tue Apr 11 07:39:14 2006
@@ -75,7 +75,7 @@
 	
 	if (!g->g_accel)
 		PyGrammar_AddAccelerators(g);
-	ps = PyMem_MALLOC(sizeof(parser_state));
+	ps = (parser_state *)PyMem_MALLOC(sizeof(parser_state));
 	if (ps == NULL)
 		return NULL;
 	ps->p_grammar = g;

Modified: python/trunk/Parser/pgen.c
==============================================================================
--- python/trunk/Parser/pgen.c	(original)
+++ python/trunk/Parser/pgen.c	Tue Apr 11 07:39:14 2006
@@ -49,8 +49,8 @@
 {
 	nfastate *st;
 	
-	nf->nf_state = PyObject_REALLOC(nf->nf_state, sizeof(nfastate) *
-							(nf->nf_nstates + 1));
+	nf->nf_state = (nfastate *)PyObject_REALLOC(nf->nf_state, 
+                                    sizeof(nfastate) * (nf->nf_nstates + 1));
 	if (nf->nf_state == NULL)
 		Py_FatalError("out of mem");
 	st = &nf->nf_state[nf->nf_nstates++];
@@ -66,7 +66,7 @@
 	nfaarc *ar;
 	
 	st = &nf->nf_state[from];
-	st->st_arc = PyObject_REALLOC(st->st_arc,
+	st->st_arc = (nfaarc *)PyObject_REALLOC(st->st_arc,
 				      sizeof(nfaarc) * (st->st_narcs + 1));
 	if (st->st_arc == NULL)
 		Py_FatalError("out of mem");
@@ -81,7 +81,7 @@
 	nfa *nf;
 	static int type = NT_OFFSET; /* All types will be disjunct */
 	
-	nf = PyObject_MALLOC(sizeof(nfa));
+	nf = (nfa *)PyObject_MALLOC(sizeof(nfa));
 	if (nf == NULL)
 		Py_FatalError("no mem for new nfa");
 	nf->nf_type = type++;
@@ -106,7 +106,7 @@
 {
 	nfagrammar *gr;
 	
-	gr = PyObject_MALLOC(sizeof(nfagrammar));
+	gr = (nfagrammar *)PyObject_MALLOC(sizeof(nfagrammar));
 	if (gr == NULL)
 		Py_FatalError("no mem for new nfa grammar");
 	gr->gr_nnfas = 0;
@@ -123,7 +123,7 @@
 	nfa *nf;
 	
 	nf = newnfa(name);
-	gr->gr_nfa = PyObject_REALLOC(gr->gr_nfa,
+	gr->gr_nfa = (nfa **)PyObject_REALLOC(gr->gr_nfa,
 				      sizeof(nfa) * (gr->gr_nnfas + 1));
 	if (gr->gr_nfa == NULL)
 		Py_FatalError("out of mem");
@@ -364,7 +364,7 @@
 typedef struct _ss_state {
 	bitset	ss_ss;
 	int	ss_narcs;
-	ss_arc	*ss_arc;
+	struct _ss_arc	*ss_arc;
 	int	ss_deleted;
 	int	ss_finish;
 	int	ss_rename;
@@ -395,7 +395,7 @@
 	
 	ss = newbitset(nbits);
 	addclosure(ss, nf, nf->nf_start);
-	xx_state = PyObject_MALLOC(sizeof(ss_state));
+	xx_state = (ss_state *)PyObject_MALLOC(sizeof(ss_state));
 	if (xx_state == NULL)
 		Py_FatalError("no mem for xx_state in makedfa");
 	xx_nstates = 1;
@@ -435,8 +435,8 @@
 				}
 				/* Add new arc for this state */
 				size = sizeof(ss_arc) * (yy->ss_narcs + 1);
-				yy->ss_arc = PyObject_REALLOC(yy->ss_arc,
-							      size);
+				yy->ss_arc = (ss_arc *)PyObject_REALLOC(
+                                                            yy->ss_arc, size);
 				if (yy->ss_arc == NULL)
 					Py_FatalError("out of mem");
 				zz = &yy->ss_arc[yy->ss_narcs++];
@@ -459,7 +459,8 @@
 				}
 			}
 			size = sizeof(ss_state) * (xx_nstates + 1);
-			xx_state = PyObject_REALLOC(xx_state, size);
+			xx_state = (ss_state *)PyObject_REALLOC(xx_state, 
+                                                                    size);
 			if (xx_state == NULL)
 				Py_FatalError("out of mem");
 			zz->sa_arrow = xx_nstates;

Modified: python/trunk/Parser/tokenizer.c
==============================================================================
--- python/trunk/Parser/tokenizer.c	(original)
+++ python/trunk/Parser/tokenizer.c	Tue Apr 11 07:39:14 2006
@@ -105,7 +105,8 @@
 static struct tok_state *
 tok_new(void)
 {
-	struct tok_state *tok = PyMem_MALLOC(sizeof(struct tok_state));
+	struct tok_state *tok = (struct tok_state *)PyMem_MALLOC(
+                                                sizeof(struct tok_state));
 	if (tok == NULL)
 		return NULL;
 	tok->buf = tok->cur = tok->end = tok->inp = tok->start = NULL;
@@ -775,38 +776,38 @@
 			return Py_CHARMASK(*tok->cur++);
 		}
 		if (tok->prompt != NULL) {
-			char *new = PyOS_Readline(stdin, stdout, tok->prompt);
+			char *newtok = PyOS_Readline(stdin, stdout, tok->prompt);
 			if (tok->nextprompt != NULL)
 				tok->prompt = tok->nextprompt;
-			if (new == NULL)
+			if (newtok == NULL)
 				tok->done = E_INTR;
-			else if (*new == '\0') {
-				PyObject_FREE(new);
+			else if (*newtok == '\0') {
+				PyObject_FREE(newtok);
 				tok->done = E_EOF;
 			}
 #if !defined(PGEN) && defined(Py_USING_UNICODE)
-			else if (tok_stdin_decode(tok, &new) != 0)
-				PyObject_FREE(new);
+			else if (tok_stdin_decode(tok, &newtok) != 0)
+				PyObject_FREE(newtok);
 #endif
 			else if (tok->start != NULL) {
 				size_t start = tok->start - tok->buf;
 				size_t oldlen = tok->cur - tok->buf;
-				size_t newlen = oldlen + strlen(new);
+				size_t newlen = oldlen + strlen(newtok);
 				char *buf = tok->buf;
 				buf = (char *)PyObject_REALLOC(buf, newlen+1);
 				tok->lineno++;
 				if (buf == NULL) {
 					PyObject_FREE(tok->buf);
 					tok->buf = NULL;
-					PyObject_FREE(new);
+					PyObject_FREE(newtok);
 					tok->done = E_NOMEM;
 					return EOF;
 				}
 				tok->buf = buf;
 				tok->cur = tok->buf + oldlen;
 				tok->line_start = tok->cur;
-				strcpy(tok->buf + oldlen, new);
-				PyObject_FREE(new);
+				strcpy(tok->buf + oldlen, newtok);
+				PyObject_FREE(newtok);
 				tok->inp = tok->buf + newlen;
 				tok->end = tok->inp + 1;
 				tok->start = tok->buf + start;
@@ -815,7 +816,7 @@
 				tok->lineno++;
 				if (tok->buf != NULL)
 					PyObject_FREE(tok->buf);
-				tok->buf = new;
+				tok->buf = newtok;
 				tok->line_start = tok->buf;
 				tok->cur = tok->buf;
 				tok->line_start = tok->buf;


More information about the Python-checkins mailing list