Matteo Bruni : wpp: Remove the assumption ppy_error calls exit().

Alexandre Julliard julliard at winehq.org
Fri Oct 2 11:02:21 CDT 2009


Module: wine
Branch: master
Commit: 026ca4cd00d49bdce5c84ff5165d8471c0a3993f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=026ca4cd00d49bdce5c84ff5165d8471c0a3993f

Author: Matteo Bruni <matteo.mystral at gmail.com>
Date:   Mon Sep 28 14:21:00 2009 +0200

wpp: Remove the assumption ppy_error calls exit().

---

 libs/wpp/ppl.l         |   17 ++++++++++++++++-
 libs/wpp/ppy.y         |   33 +++++++++++++++++++++------------
 libs/wpp/preproc.c     |    7 +++++++
 libs/wpp/wpp.c         |   15 +++++++++------
 libs/wpp/wpp_private.h |    4 +++-
 5 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/libs/wpp/ppl.l b/libs/wpp/ppl.l
index e71bf6e..1c83547 100644
--- a/libs/wpp/ppl.l
+++ b/libs/wpp/ppl.l
@@ -639,7 +639,7 @@ includelogicentry_t *pp_includelogiclist = NULL;
 			if(yy_current_state() == pp_inc)
 				ppy_error("Expected include filename");
 
-			if(yy_current_state() == pp_if)
+			else if(yy_current_state() == pp_if)
 			{
 				ppy_lval.cptr = pp_xstrdup(ppy_text);
 				return tIDENT;
@@ -808,7 +808,10 @@ static int make_number(int radix, YYSTYPE *val, const char *str, int len)
 	ext[0] = len > 2 ? toupper(str[len-3]) : ' ';
 
 	if(!strcmp(ext, "LUL"))
+	{
 		ppy_error("Invalid constant suffix");
+		return 0;
+	}
 	else if(!strcmp(ext, "LLU") || !strcmp(ext, "ULL"))
 	{
 		is_ll++;
@@ -1085,7 +1088,10 @@ static void expand_macro(macexpstackentry_t *mep)
 	assert(ppp->expanding == 0);
 
 	if((ppp->nargs >= 0 && nargs != ppp->nargs) || (ppp->nargs < 0 && nargs < -ppp->nargs))
+	{
 		ppy_error("Too %s macro arguments (%d)", nargs < abs(ppp->nargs) ? "few" : "many", nargs);
+		return;
+	}
 
 	for(n = 0; n < nargs; n++)
 		nnl += mep->nnls[n];
@@ -1323,7 +1329,10 @@ static bufferstackentry_t *pop_buffer(void)
 static void push_macro(pp_entry_t *ppp)
 {
 	if(macexpstackidx >= MAXMACEXPSTACK)
+	{
 		ppy_error("Too many nested macros");
+		return;
+	}
 
 	macexpstack[macexpstackidx] = pp_xmalloc(sizeof(macexpstack[0][0]));
         memset( macexpstack[macexpstackidx], 0, sizeof(macexpstack[0][0]));
@@ -1472,13 +1481,19 @@ void pp_do_include(char *fname, int type)
 	n = strlen(fname);
 
 	if(n <= 2)
+	{
 		ppy_error("Empty include filename");
+		return;
+	}
 
 	/* Undo the effect of the quotation */
 	fname[n-1] = '\0';
 
 	if((ppy_in = pp_open_include(fname+1, type ? pp_status.input : NULL, &newpath)) == NULL)
+	{
 		ppy_error("Unable to open include file %s", fname+1);
+		return;
+	}
 
 	fname[n-1] = *fname;	/* Redo the quotes */
 	push_buffer(NULL, newpath, fname, 0);
diff --git a/libs/wpp/ppy.y b/libs/wpp/ppy.y
index fc94bb5..2098ca3 100644
--- a/libs/wpp/ppy.y
+++ b/libs/wpp/ppy.y
@@ -224,6 +224,9 @@ preprocessor
 		case if_elsetrue:
 		case if_elsefalse:
 			ppy_error("#elif cannot follow #else");
+			break;
+		case if_error:
+			break;
 		default:
 			pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #elif directive", s);
 		}
@@ -247,24 +250,29 @@ preprocessor
 		case if_elsetrue:
 		case if_elsefalse:
 			ppy_error("#else clause already defined");
+			break;
+		case if_error:
+			break;
 		default:
 			pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #else directive", s);
 		}
 		}
 	| tENDIF tNL		{
-		pp_pop_if();
-		if(pp_incl_state.ifdepth == pp_get_if_depth() && pp_incl_state.state == 1)
+		if(pp_pop_if() != if_error)
 		{
-			pp_incl_state.state = 2;
-			pp_incl_state.seen_junk = 0;
+			if(pp_incl_state.ifdepth == pp_get_if_depth() && pp_incl_state.state == 1)
+			{
+				pp_incl_state.state = 2;
+				pp_incl_state.seen_junk = 0;
+			}
+			else if(pp_incl_state.state != 1)
+			{
+				pp_incl_state.state = -1;
+			}
+			if(pp_status.debug)
+				fprintf(stderr, "tENDIF: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n",
+					pp_status.input, pp_status.line_number, pp_incl_state.state, pp_incl_state.ppp, pp_incl_state.ifdepth);
 		}
-		else if(pp_incl_state.state != 1)
-		{
-			pp_incl_state.state = -1;
-		}
-		if(pp_status.debug)
-			fprintf(stderr, "tENDIF: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n",
-                                pp_status.input, pp_status.line_number, pp_incl_state.state, pp_incl_state.ppp, pp_incl_state.ifdepth);
 		}
 	| tUNDEF tIDENT tNL	{ pp_del_define($2); free($2); }
 	| tDEFINE opt_text tNL	{ pp_add_define($1, $2); }
@@ -346,7 +354,8 @@ mtext	: tLITERAL	{ $$ = new_mtext($1, 0, exp_text); }
 		int mat = marg_index($2);
 		if(mat < 0)
 			ppy_error("Stringification identifier must be an argument parameter");
-		$$ = new_mtext(NULL, mat, exp_stringize);
+		else
+			$$ = new_mtext(NULL, mat, exp_stringize);
 		}
 	| tIDENT	{
 		int mat = marg_index($1);
diff --git a/libs/wpp/preproc.c b/libs/wpp/preproc.c
index 63455ce..2ebec83 100644
--- a/libs/wpp/preproc.c
+++ b/libs/wpp/preproc.c
@@ -519,13 +519,18 @@ void pp_push_if(pp_if_state_t s)
 	case if_ignore:
 		pp_push_ignore_state();
 		break;
+	default:
+		pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
 	}
 }
 
 pp_if_state_t pp_pop_if(void)
 {
 	if(if_stack_idx <= 0)
+	{
 		ppy_error("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
+		return if_error;
+	}
 
 	switch(pp_if_state())
 	{
@@ -538,6 +543,8 @@ pp_if_state_t pp_pop_if(void)
 	case if_ignore:
 		pp_pop_ignore_state();
 		break;
+	default:
+		pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
 	}
 
 	if(pp_flex_debug)
diff --git a/libs/wpp/wpp.c b/libs/wpp/wpp.c
index d149591..a7597ec 100644
--- a/libs/wpp/wpp.c
+++ b/libs/wpp/wpp.c
@@ -144,6 +144,7 @@ int wpp_parse( const char *input, FILE *output )
     int ret;
 
     pp_status.input = NULL;
+    pp_status.state = 0;
 
     pp_push_define_state();
     add_cmdline_defines();
@@ -152,8 +153,8 @@ int wpp_parse( const char *input, FILE *output )
     if (!input) ppy_in = stdin;
     else if (!(ppy_in = fopen(input, "rt")))
     {
-        fprintf(stderr,"Could not open %s\n", input);
-        exit(2);
+        ppy_error("Could not open %s\n", input);
+        return 2;
     }
 
     pp_status.input = input;
@@ -162,6 +163,8 @@ int wpp_parse( const char *input, FILE *output )
     fprintf(ppy_out, "# 1 \"%s\" 1\n", input ? input : "");
 
     ret = ppy_parse();
+    /* If there were errors during processing, return an error code */
+    if(!ret && pp_status.state) ret = pp_status.state;
 
     if (input) fclose(ppy_in);
     pp_pop_define_state();
@@ -184,14 +187,14 @@ int wpp_parse_temp( const char *input, const char *output_base, char **output_na
 
     if((fd = mkstemps( temp_name, 0 )) == -1)
     {
-        fprintf(stderr, "Could not generate a temp name from %s\n", temp_name);
-        exit(2);
+        ppy_error("Could not generate a temp name from %s\n", temp_name);
+        return 2;
     }
 
     if (!(output = fdopen(fd, "wt")))
     {
-        fprintf(stderr,"Could not open fd %s for writing\n", temp_name);
-        exit(2);
+        ppy_error("Could not open fd %s for writing\n", temp_name);
+        return 2;
     }
 
     *output_name = temp_name;
diff --git a/libs/wpp/wpp_private.h b/libs/wpp/wpp_private.h
index 24ed6b8..b485d70 100644
--- a/libs/wpp/wpp_private.h
+++ b/libs/wpp/wpp_private.h
@@ -113,7 +113,8 @@ typedef enum {
 	if_elif,
 	if_elsefalse,
 	if_elsetrue,
-	if_ignore
+	if_ignore,
+	if_error
 } pp_if_state_t;
 
 
@@ -228,6 +229,7 @@ struct pp_status
     const char *input;  /* current input file name */
     int line_number;    /* current line number */
     int char_number;    /* current char number in line */
+    int state;          /* current error state */
     int pedantic;       /* pedantic option */
     int debug;          /* debug messages flag */
 };




More information about the wine-cvs mailing list