[7/9] wpp: Remove the assumption pp_internal_error calls exit() [try 2]

Matteo Bruni matteo.mystral at gmail.com
Thu Oct 1 07:21:36 CDT 2009


-------------- next part --------------
From 79aebdb612334b9816375abce58c65b90130732a Mon Sep 17 00:00:00 2001
From: Matteo Bruni <matteo.mystral at gmail.com>
Date: Tue, 29 Sep 2009 12:10:24 +0200
Subject: wpp: Remove the assumption pp_internal_error calls exit()

---
 libs/wpp/ppl.l     |   32 +++++++++++++++++++++++++++-----
 libs/wpp/preproc.c |    4 ++++
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/libs/wpp/ppl.l b/libs/wpp/ppl.l
index 2a0c357..d3ab50e 100644
--- a/libs/wpp/ppl.l
+++ b/libs/wpp/ppl.l
@@ -497,10 +497,13 @@ includelogicentry_t *pp_includelogiclist = NULL;
 <pp_macign>{ws}*\\\r?\n	newline(0);
 <pp_macign>{ws}+|{ws}*\\\r?|.	{
 		macexpstackentry_t *mac = pop_macro();
-		yy_pop_state();
-		put_buffer(mac->ppp->ident, strlen(mac->ppp->ident));
-		put_buffer(ppy_text, ppy_leng);
-		free_macro(mac);
+		if(mac)
+		{
+			yy_pop_state();
+			put_buffer(mac->ppp->ident, strlen(mac->ppp->ident));
+			put_buffer(ppy_text, ppy_leng);
+			free_macro(mac);
+		}
 	}
 
 	/*
@@ -727,7 +730,8 @@ includelogicentry_t *pp_includelogiclist = NULL;
 		{
 			macexpstackentry_t *mac;
 			mac = pop_macro();
-			expand_macro(mac);
+			if(mac)
+				expand_macro(mac);
 		}
 		ppy__delete_buffer(b);
 	}
@@ -934,7 +938,10 @@ static void expand_special(pp_entry_t *ppp)
 		sprintf(buf, "\"%s\"", pp_status.input);
 	}
 	else
+	{
 		pp_internal_error(__FILE__, __LINE__, "Special macro '%s' not found...\n", ppp->ident);
+		return;
+	}
 
 	if(pp_flex_debug)
 		fprintf(stderr, "expand_special(%d): %s:%d: '%s' -> '%s'\n",
@@ -1242,7 +1249,10 @@ static void push_buffer(pp_entry_t *ppp, char *filename, char *incname, int pop)
 	if(ppy_debug)
 		printf("push_buffer(%d): %p %p %p %d\n", bufferstackidx, ppp, filename, incname, pop);
 	if(bufferstackidx >= MAXBUFFERSTACK)
+	{
 		pp_internal_error(__FILE__, __LINE__, "Buffer stack overflow");
+		return;
+	}
 
 	memset(&bufferstack[bufferstackidx], 0, sizeof(bufferstack[0]));
 	bufferstack[bufferstackidx].bufferstate	= YY_CURRENT_BUFFER;
@@ -1267,14 +1277,20 @@ static void push_buffer(pp_entry_t *ppp, char *filename, char *incname, int pop)
 		ncontinuations = 0;
 	}
 	else if(!pop)
+	{
 		pp_internal_error(__FILE__, __LINE__, "Pushing buffer without knowing where to go to");
+		return;
+	}
 	bufferstackidx++;
 }
 
 static bufferstackentry_t *pop_buffer(void)
 {
 	if(bufferstackidx < 0)
+	{
 		pp_internal_error(__FILE__, __LINE__, "Bufferstack underflow?");
+		return NULL;
+	}
 
 	if(bufferstackidx == 0)
 		return NULL;
@@ -1342,7 +1358,10 @@ static bufferstackentry_t *pop_buffer(void)
 		if(yy_current_state() == pp_macexp)
 			macro_add_expansion();
 		else
+		{
 			pp_internal_error(__FILE__, __LINE__, "Pop buffer and state without macro expansion state");
+			return &bufferstack[bufferstackidx];
+		}
 		yy_pop_state();
 	}
 
@@ -1379,7 +1398,10 @@ static macexpstackentry_t *top_macro(void)
 static macexpstackentry_t *pop_macro(void)
 {
 	if(macexpstackidx <= 0)
+	{
 		pp_internal_error(__FILE__, __LINE__, "Macro expansion stack underflow\n");
+		return NULL;
+	}
 	return macexpstack[--macexpstackidx];
 }
 
diff --git a/libs/wpp/preproc.c b/libs/wpp/preproc.c
index 0293bdf..885e9a6 100644
--- a/libs/wpp/preproc.c
+++ b/libs/wpp/preproc.c
@@ -552,7 +552,10 @@ static const char * const pp_if_state_str[] = {
 void pp_push_if(pp_if_state_t s)
 {
 	if(if_stack_idx >= MAXIFSTACK)
+	{
 		pp_internal_error(__FILE__, __LINE__, "#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)", MAXIFSTACK);
+		return;
+	}
 
 	if(pp_flex_debug)
 		fprintf(stderr, "Push if %s:%d: %s(%d) -> %s(%d)\n", pp_status.input, pp_status.line_number, pp_if_state_str[pp_if_state()], if_stack_idx, pp_if_state_str[s], if_stack_idx+1);
@@ -596,6 +599,7 @@ pp_if_state_t pp_pop_if(void)
 		break;
 	default:
 		pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
+		return if_error;
 	}
 
 	if(pp_flex_debug)
-- 
1.6.3.3


More information about the wine-patches mailing list