Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb21de4e

Browse files
committed
ecpg: Split off mmfatal() from mmerror()
This allows decorating mmfatal() with noreturn compiler hints, leadingto better diagnostics.
1 parent22967d8 commitb21de4e

File tree

9 files changed

+85
-72
lines changed

9 files changed

+85
-72
lines changed

‎src/interfaces/ecpg/preproc/descriptor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ output_set_descr(char *desc_name, char *index)
274274
caseECPGd_di_precision:
275275
caseECPGd_precision:
276276
caseECPGd_scale:
277-
mmerror(PARSE_ERROR,ET_FATAL,"descriptor item \"%s\" is not implemented",
277+
mmfatal(PARSE_ERROR,"descriptor item \"%s\" is not implemented",
278278
descriptor_item_name(results->value));
279279
break;
280280

@@ -284,7 +284,7 @@ output_set_descr(char *desc_name, char *index)
284284
caseECPGd_octet:
285285
caseECPGd_ret_length:
286286
caseECPGd_ret_octet:
287-
mmerror(PARSE_ERROR,ET_FATAL,"descriptor item \"%s\" cannot be set",
287+
mmfatal(PARSE_ERROR,"descriptor item \"%s\" cannot be set",
288288
descriptor_item_name(results->value));
289289
break;
290290

‎src/interfaces/ecpg/preproc/ecpg.header

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ struct ECPGtype ecpg_query = {ECPGt_char_variable, NULL, NULL, NULL, {NULL}, 0};
6464
/*
6565
* Handle parsing errors and warnings
6666
*/
67-
void
68-
mmerror(int error_code, enum errortype type, const char *error,...)
67+
staticvoid __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)))
68+
vmmerror(int error_code, enum errortype type, const char *error,va_list ap)
6969
{
70-
va_list ap;
71-
7270
/* internationalize the error message string */
7371
error = _(error);
7472

@@ -80,14 +78,11 @@ mmerror(int error_code, enum errortype type, const char *error, ...)
8078
fprintf(stderr, _("WARNING: "));
8179
break;
8280
case ET_ERROR:
83-
case ET_FATAL:
8481
fprintf(stderr, _("ERROR: "));
8582
break;
8683
}
8784

88-
va_start(ap, error);
8985
vfprintf(stderr, error, ap);
90-
va_end(ap);
9186

9287
fprintf(stderr, "\n");
9388

@@ -98,18 +93,38 @@ mmerror(int error_code, enum errortype type, const char *error, ...)
9893
case ET_ERROR:
9994
ret_value = error_code;
10095
break;
101-
case ET_FATAL:
102-
if (yyin)
103-
fclose(yyin);
104-
if (yyout)
105-
fclose(yyout);
106-
107-
if (strcmp(output_filename, "-") != 0 && unlink(output_filename) != 0)
108-
fprintf(stderr, _("could not remove output file \"%s\"\n"), output_filename);
109-
exit(error_code);
11096
}
11197
}
11298

99+
void
100+
mmerror(int error_code, enum errortype type, const char *error, ...)
101+
{
102+
va_listap;
103+
104+
va_start(ap, error);
105+
vmmerror(error_code, type, error, ap);
106+
va_end(ap);
107+
}
108+
109+
void
110+
mmfatal(int error_code, const char *error, ...)
111+
{
112+
va_listap;
113+
114+
va_start(ap, error);
115+
vmmerror(error_code, ET_ERROR, error, ap);
116+
va_end(ap);
117+
118+
if (yyin)
119+
fclose(yyin);
120+
if (yyout)
121+
fclose(yyout);
122+
123+
if (strcmp(output_filename, "-") != 0 && unlink(output_filename) != 0)
124+
fprintf(stderr, _("could not remove output file \"%s\"\n"), output_filename);
125+
exit(error_code);
126+
}
127+
113128
/*
114129
* string concatenation
115130
*/

‎src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ cvariable:CVARIABLE
16871687
{
16881688
case '[':
16891689
if (brace)
1690-
mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays for simple data types are not supported");
1690+
mmfatal(PARSE_ERROR, "multidimensional arrays for simple data types are not supported");
16911691
brace_open++;
16921692
break;
16931693
case ']':

‎src/interfaces/ecpg/preproc/extern.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ extern intbase_yylex(void);
7373
externvoidbase_yyerror(constchar*);
7474
externvoid*mm_alloc(size_t),*mm_realloc(void*,size_t);
7575
externchar*mm_strdup(constchar*);
76-
externvoid
77-
mmerror(int,enumerrortype,constchar*,...)
78-
/* This extension allows gcc to check the format string */
79-
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
76+
externvoidmmerror(interrorcode,enumerrortypetype,constchar*error, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
77+
externvoidmmfatal(interrorcode,constchar*error, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE,2,3),noreturn));
8078
externvoidoutput_get_descr_header(char*);
8179
externvoidoutput_get_descr(char*,char*);
8280
externvoidoutput_set_descr_header(char*);

‎src/interfaces/ecpg/preproc/nls.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
CATALOG_NAME = ecpg
33
AVAIL_LANGUAGES = cs de es fr it ja ko pl pt_BR ru tr zh_CN zh_TW
44
GETTEXT_FILES = descriptor.c ecpg.c pgc.c preproc.c type.c variable.c
5-
GETTEXT_TRIGGERS = mmerror:3
6-
GETTEXT_FLAGS = mmerror:3:c-format
5+
GETTEXT_TRIGGERS = mmerror:3 mmfatal:2
6+
GETTEXT_FLAGS = mmerror:3:c-format mmfatal:2:c-format

‎src/interfaces/ecpg/preproc/pgc.l

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
400400
<xc>{op_chars}{ ECHO; }
401401
<xc>\*+{ ECHO; }
402402

403-
<xc><<EOF>>{mmerror(PARSE_ERROR, ET_FATAL,"unterminated /* comment"); }
403+
<xc><<EOF>>{mmfatal(PARSE_ERROR,"unterminated /* comment"); }
404404

405405
<SQL>{xbstart}{
406406
token_start = yytext;
@@ -422,7 +422,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
422422
<xb>{xbinside}{addlit(yytext, yyleng); }
423423
<xh>{quotecontinue}|
424424
<xb>{quotecontinue}{/* ignore */ }
425-
<xb><<EOF>>{mmerror(PARSE_ERROR, ET_FATAL,"unterminated bit string literal"); }
425+
<xb><<EOF>>{mmfatal(PARSE_ERROR,"unterminated bit string literal"); }
426426

427427
<SQL>{xhstart}{
428428
token_start = yytext;
@@ -438,7 +438,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
438438
return XCONST;
439439
}
440440

441-
<xh><<EOF>>{mmerror(PARSE_ERROR, ET_FATAL,"unterminated hexadecimal string literal"); }
441+
<xh><<EOF>>{mmfatal(PARSE_ERROR,"unterminated hexadecimal string literal"); }
442442
<SQL>{xnstart} {
443443
/* National character.
444444
* Transfer it as-is to the backend.
@@ -516,7 +516,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
516516
/* This is only needed for \ just before EOF */
517517
addlitchar(yytext[0]);
518518
}
519-
<xq,xqc,xe,xn,xus><<EOF>>{mmerror(PARSE_ERROR, ET_FATAL,"unterminated quoted string"); }
519+
<xq,xqc,xe,xn,xus><<EOF>>{mmfatal(PARSE_ERROR,"unterminated quoted string"); }
520520
<SQL>{dolqfailed}{
521521
/* throw back all but the initial "$" */
522522
yyless(1);
@@ -592,7 +592,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
592592
}
593593
<xd,xui>{xddouble}{addlitchar('"'); }
594594
<xd,xui>{xdinside}{addlit(yytext, yyleng); }
595-
<xd,xdc,xui><<EOF>>{mmerror(PARSE_ERROR, ET_FATAL,"unterminated quoted identifier"); }
595+
<xd,xdc,xui><<EOF>>{mmfatal(PARSE_ERROR,"unterminated quoted identifier"); }
596596
<C,SQL>{xdstart}{
597597
state_before = YYSTATE;
598598
BEGIN(xdc);
@@ -938,7 +938,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
938938
BEGIN(C);
939939
}
940940
<undef>{other}|\n {
941-
mmerror(PARSE_ERROR, ET_FATAL,"missing identifier in EXEC SQL UNDEF command");
941+
mmfatal(PARSE_ERROR,"missing identifier in EXEC SQL UNDEF command");
942942
yyterminate();
943943
}
944944
<C>{exec_sql}{include}{space}*{BEGIN(incl); }
@@ -984,10 +984,10 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
984984
}
985985
<C,xskip>{exec_sql}{elif}{space}*{/* pop stack */
986986
if ( preproc_tos ==0 ) {
987-
mmerror(PARSE_ERROR, ET_FATAL,"missing matching\"EXEC SQL IFDEF\" /\"EXEC SQL IFNDEF\"");
987+
mmfatal(PARSE_ERROR,"missing matching\"EXEC SQL IFDEF\" /\"EXEC SQL IFNDEF\"");
988988
}
989989
elseif ( stacked_if_value[preproc_tos].else_branch )
990-
mmerror(PARSE_ERROR, ET_FATAL,"missing\"EXEC SQL ENDIF;\"");
990+
mmfatal(PARSE_ERROR,"missing\"EXEC SQL ENDIF;\"");
991991
else
992992
preproc_tos--;
993993

@@ -998,9 +998,9 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
998998
if (INFORMIX_MODE)
999999
{
10001000
if (preproc_tos ==0)
1001-
mmerror(PARSE_ERROR, ET_FATAL,"missing matching\"EXEC SQL IFDEF\" /\"EXEC SQL IFNDEF\"");
1001+
mmfatal(PARSE_ERROR,"missing matching\"EXEC SQL IFDEF\" /\"EXEC SQL IFNDEF\"");
10021002
elseif (stacked_if_value[preproc_tos].else_branch)
1003-
mmerror(PARSE_ERROR, ET_FATAL,"missing\"EXEC SQL ENDIF;\"");
1003+
mmfatal(PARSE_ERROR,"missing\"EXEC SQL ENDIF;\"");
10041004
else
10051005
preproc_tos--;
10061006

@@ -1016,7 +1016,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
10161016

10171017
<C,xskip>{exec_sql}{else}{space}*";" {/* only exec sql endif pops the stack, so take care of duplicated 'else' */
10181018
if (stacked_if_value[preproc_tos].else_branch)
1019-
mmerror(PARSE_ERROR, ET_FATAL,"more than one EXEC SQL ELSE");
1019+
mmfatal(PARSE_ERROR,"more than one EXEC SQL ELSE");
10201020
else
10211021
{
10221022
stacked_if_value[preproc_tos].else_branch =TRUE;
@@ -1035,7 +1035,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
10351035
if (INFORMIX_MODE)
10361036
{
10371037
if (stacked_if_value[preproc_tos].else_branch)
1038-
mmerror(PARSE_ERROR, ET_FATAL,"more than one EXEC SQL ELSE");
1038+
mmfatal(PARSE_ERROR,"more than one EXEC SQL ELSE");
10391039
else
10401040
{
10411041
stacked_if_value[preproc_tos].else_branch =TRUE;
@@ -1057,7 +1057,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
10571057
}
10581058
<C,xskip>{exec_sql}{endif}{space}*";" {
10591059
if (preproc_tos ==0)
1060-
mmerror(PARSE_ERROR, ET_FATAL,"unmatched EXEC SQL ENDIF");
1060+
mmfatal(PARSE_ERROR,"unmatched EXEC SQL ENDIF");
10611061
else
10621062
preproc_tos--;
10631063

@@ -1071,7 +1071,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
10711071
if (INFORMIX_MODE)
10721072
{
10731073
if (preproc_tos ==0)
1074-
mmerror(PARSE_ERROR, ET_FATAL,"unmatched EXEC SQL ENDIF");
1074+
mmfatal(PARSE_ERROR,"unmatched EXEC SQL ENDIF");
10751075
else
10761076
preproc_tos--;
10771077

@@ -1091,7 +1091,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
10911091

10921092
<xcond>{identifier}{space}*";" {
10931093
if (preproc_tos >= MAX_NESTED_IF-1)
1094-
mmerror(PARSE_ERROR, ET_FATAL,"too many nested EXEC SQL IFDEF conditions");
1094+
mmfatal(PARSE_ERROR,"too many nested EXEC SQL IFDEF conditions");
10951095
else
10961096
{
10971097
struct_defines *defptr;
@@ -1124,7 +1124,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
11241124
}
11251125

11261126
<xcond>{other}|\n{
1127-
mmerror(PARSE_ERROR, ET_FATAL,"missing identifier in EXEC SQL IFDEF command");
1127+
mmfatal(PARSE_ERROR,"missing identifier in EXEC SQL IFDEF command");
11281128
yyterminate();
11291129
}
11301130
<def_ident>{identifier} {
@@ -1133,7 +1133,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
11331133
startlit();
11341134
}
11351135
<def_ident>{other}|\n{
1136-
mmerror(PARSE_ERROR, ET_FATAL,"missing identifier in EXEC SQL DEFINE command");
1136+
mmfatal(PARSE_ERROR,"missing identifier in EXEC SQL DEFINE command");
11371137
yyterminate();
11381138
}
11391139
<def>{space}*";"{
@@ -1166,7 +1166,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
11661166
<incl>{dquote}{xdinside}{dquote}{space}*";"?{parse_include(); }
11671167
<incl>[^;\<\>\"]+";"{parse_include(); }
11681168
<incl>{other}|\n{
1169-
mmerror(PARSE_ERROR, ET_FATAL,"syntax error in EXEC SQL INCLUDE command");
1169+
mmfatal(PARSE_ERROR,"syntax error in EXEC SQL INCLUDE command");
11701170
yyterminate();
11711171
}
11721172

@@ -1176,7 +1176,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
11761176
if ( preproc_tos >0 )
11771177
{
11781178
preproc_tos =0;
1179-
mmerror(PARSE_ERROR, ET_FATAL,"missing\"EXEC SQL ENDIF;\"");
1179+
mmfatal(PARSE_ERROR,"missing\"EXEC SQL ENDIF;\"");
11801180
}
11811181
yyterminate();
11821182
}
@@ -1215,7 +1215,7 @@ cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.
12151215

12161216
}
12171217
}
1218-
<INITIAL>{other}|\n{mmerror(PARSE_ERROR, ET_FATAL,"internal error: unreachable state; please report this to <pgsql-bugs@postgresql.org>"); }
1218+
<INITIAL>{other}|\n{mmfatal(PARSE_ERROR,"internal error: unreachable state; please report this to <pgsql-bugs@postgresql.org>"); }
12191219
%%
12201220
void
12211221
lex_init(void)
@@ -1362,7 +1362,7 @@ parse_include(void)
13621362
}
13631363
}
13641364
if (!yyin)
1365-
mmerror(NO_INCLUDE_FILE, ET_FATAL,"could not open include file\"%s\" on line %d", yytext, yylineno);
1365+
mmfatal(NO_INCLUDE_FILE,"could not open include file\"%s\" on line %d", yytext, yylineno);
13661366

13671367
input_filename =mm_strdup(inc_file);
13681368
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE ));

‎src/interfaces/ecpg/preproc/type.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mm_alloc(size_t size)
1515
void*ptr=malloc(size);
1616

1717
if (ptr==NULL)
18-
mmerror(OUT_OF_MEMORY,ET_FATAL,"out of memory");
18+
mmfatal(OUT_OF_MEMORY,"out of memory");
1919

2020
returnptr;
2121
}
@@ -27,7 +27,7 @@ mm_strdup(const char *string)
2727
char*new=strdup(string);
2828

2929
if (new==NULL)
30-
mmerror(OUT_OF_MEMORY,ET_FATAL,"out of memory");
30+
mmfatal(OUT_OF_MEMORY,"out of memory");
3131

3232
returnnew;
3333
}
@@ -282,7 +282,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const int bra
282282
{
283283
caseECPGt_array:
284284
if (indicator_set&&ind_type->type!=ECPGt_array)
285-
mmerror(INDICATOR_NOT_ARRAY,ET_FATAL,"indicator for array/pointer has to be array/pointer");
285+
mmfatal(INDICATOR_NOT_ARRAY,"indicator for array/pointer has to be array/pointer");
286286
switch (type->u.element->type)
287287
{
288288
caseECPGt_array:
@@ -319,7 +319,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const int bra
319319
break;
320320
caseECPGt_struct:
321321
if (indicator_set&&ind_type->type!=ECPGt_struct)
322-
mmerror(INDICATOR_NOT_STRUCT,ET_FATAL,"indicator for struct has to be a struct");
322+
mmfatal(INDICATOR_NOT_STRUCT,"indicator for struct has to be a struct");
323323

324324
ECPGdump_a_struct(o,name,ind_name,mm_strdup("1"),type,ind_type,prefix,ind_prefix);
325325
break;
@@ -328,23 +328,23 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const int bra
328328
break;
329329
caseECPGt_char_variable:
330330
if (indicator_set&& (ind_type->type==ECPGt_struct||ind_type->type==ECPGt_array))
331-
mmerror(INDICATOR_NOT_SIMPLE,ET_FATAL,"indicator for simple data type has to be simple");
331+
mmfatal(INDICATOR_NOT_SIMPLE,"indicator for simple data type has to be simple");
332332

333333
ECPGdump_a_simple(o,name,type->type,mm_strdup("1"), (arr_str_siz&&strcmp(arr_str_siz,"0")!=0) ?arr_str_siz :mm_strdup("1"),struct_sizeof,prefix,0);
334334
if (ind_type!=NULL)
335335
ECPGdump_a_simple(o,ind_name,ind_type->type,ind_type->size, (arr_str_siz&&strcmp(arr_str_siz,"0")!=0) ?arr_str_siz :mm_strdup("-1"),ind_struct_sizeof,ind_prefix,0);
336336
break;
337337
caseECPGt_descriptor:
338338
if (indicator_set&& (ind_type->type==ECPGt_struct||ind_type->type==ECPGt_array))
339-
mmerror(INDICATOR_NOT_SIMPLE,ET_FATAL,"indicator for simple data type has to be simple");
339+
mmfatal(INDICATOR_NOT_SIMPLE,"indicator for simple data type has to be simple");
340340

341341
ECPGdump_a_simple(o,name,type->type,NULL,mm_strdup("-1"),NULL,prefix,0);
342342
if (ind_type!=NULL)
343343
ECPGdump_a_simple(o,ind_name,ind_type->type,ind_type->size,mm_strdup("-1"),NULL,ind_prefix,0);
344344
break;
345345
default:
346346
if (indicator_set&& (ind_type->type==ECPGt_struct||ind_type->type==ECPGt_array))
347-
mmerror(INDICATOR_NOT_SIMPLE,ET_FATAL,"indicator for simple data type has to be simple");
347+
mmfatal(INDICATOR_NOT_SIMPLE,"indicator for simple data type has to be simple");
348348

349349
ECPGdump_a_simple(o,name,type->type,type->size, (arr_str_siz&&strcmp(arr_str_siz,"0")!=0) ?arr_str_siz :mm_strdup("-1"),struct_sizeof,prefix,type->counter);
350350
if (ind_type!=NULL)

‎src/interfaces/ecpg/preproc/type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ struct assignment
186186

187187
enumerrortype
188188
{
189-
ET_WARNING,ET_ERROR,ET_FATAL
189+
ET_WARNING,ET_ERROR
190190
};
191191

192192
structfetch_desc

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp