Skip to content

Commit 1d66a1c

Browse files
author
Michael Meskes
committed
ECPG only copied #include statements instead of processing them according to
commandline option "-i". This change fixes this and adds a test case. It also honors #include_next, although this is probably never used for embedded SQL.
1 parent 6ad4249 commit 1d66a1c

File tree

10 files changed

+72
-43
lines changed

10 files changed

+72
-43
lines changed

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.172 2010/01/26 09:07:31 meskes Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.173 2010/03/21 10:49:51 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -44,6 +44,9 @@ static int literalalloc; /* current allocated buffer size */
4444
/* Used for detecting global state together with braces_open */
4545
static int parenths_open;
4646

47+
/* Used to tell parse_include() whether the command was #include or #include_next */
48+
static bool include_next;
49+
4750
#define startlit() (literalbuf[0] = '\0', literallen = 0)
4851
static void addlit(char *ytext, int yleng);
4952
static void addlitchar (unsigned char);
@@ -310,11 +313,14 @@ other .
310313

311314
/* some stuff needed for ecpg */
312315
exec [eE][xX][eE][cC]
313-
sql [sS][qQ][lL]
316+
sql [sS][qQ][lL]
314317
define [dD][eE][fF][iI][nN][eE]
315318
include [iI][nN][cC][lL][uU][dD][eE]
319+
include_next [iI][nN][cC][lL][uU][dD][eE]_[nN][eE][xX][tT]
320+
import [iI][mM][pP][oO][rR][tT]
316321
undef [uU][nN][dD][eE][fF]
317322

323+
if [iI][fF]
318324
ifdef [iI][fF][dD][eE][fF]
319325
ifndef [iI][fF][nN][dD][eE][fF]
320326
else [eE][lL][sS][eE]
@@ -325,13 +331,17 @@ struct [sS][tT][rR][uU][cC][tT]
325331

326332
exec_sql {exec}{space}*{sql}{space}*
327333
ipdigit ({digit}|{digit}{digit}|{digit}{digit}{digit})
328-
ip {ipdigit}\.{ipdigit}\.{ipdigit}\.{ipdigit}
334+
ip {ipdigit}\.{ipdigit}\.{ipdigit}\.{ipdigit}
329335

330336
/* we might want to parse all cpp include files */
331337
cppinclude {space}*#{include}{space}*
338+
cppinclude_next {space}*#{include_next}{space}*
332339

333-
/* Take care of cpp lines, they may also be continuated */
334-
cppline {space}*#(.*\\{space})*.*{newline}
340+
/* take care of cpp lines, they may also be continuated */
341+
/* first a general line for all commands not starting with "i" */
342+
/* and then the other commands starting with "i", we have to add these
343+
* seperately because the cppline production would match on "include" too */
344+
cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.*{newline}
335345

336346
/*
337347
* Dollar quoted strings are totally opaque, and no escaping is done on them.
@@ -777,6 +787,19 @@ cppline {space}*#(.*\\{space})*.*{newline}
777787
<C>{cppinclude} {
778788
if (system_includes)
779789
{
790+
include_next = false;
791+
BEGIN(incl);
792+
}
793+
else
794+
{
795+
yylval.str = mm_strdup(yytext);
796+
return(CPP_LINE);
797+
}
798+
}
799+
<C>{cppinclude_next} {
800+
if (system_includes)
801+
{
802+
include_next = true;
780803
BEGIN(incl);
781804
}
782805
else
@@ -1322,6 +1345,12 @@ parse_include(void)
13221345
yyin = fopen( inc_file, "r" );
13231346
}
13241347
}
1348+
/* if the command was "include_next" we have to disregard the first hit */
1349+
if (yyin && include_next)
1350+
{
1351+
yyin = NULL;
1352+
include_next = false;
1353+
}
13251354
}
13261355
}
13271356
if (!yyin)

src/interfaces/ecpg/test/compat_informix/rnull.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "sqltypes.h"
22
#include <stdlib.h>
3-
#
3+
44
$include ../regression;
55
$define NUMBER 12;
66

src/interfaces/ecpg/test/compat_informix/test_informix.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "sqltypes.h"
22
#include <stdlib.h>
3-
#
3+
44
$include ../regression;
55
$define NUMBER 12;
66

src/interfaces/ecpg/test/expected/compat_informix-rnull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#line 1 "rnull.pgc"
1212
#include "sqltypes.h"
1313
#include <stdlib.h>
14-
#
14+
1515

1616
#line 1 "regression.h"
1717

src/interfaces/ecpg/test/expected/compat_informix-test_informix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#line 1 "test_informix.pgc"
1212
#include "sqltypes.h"
1313
#include <stdlib.h>
14-
#
14+
1515

1616
#line 1 "regression.h"
1717

src/interfaces/ecpg/test/expected/preproc-strings.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
88

99
#line 1 "strings.pgc"
10-
#include <stdlib.h>
11-
1210

1311
#line 1 "regression.h"
1412

@@ -18,27 +16,28 @@
1816

1917

2018
#line 3 "strings.pgc"
21-
22-
2319
/* exec sql begin declare section */
20+
#line 1 "strings.h"
2421

2522

26-
#line 6 "strings.pgc"
23+
#line 5 "strings.pgc"
24+
25+
#line 1 "strings.h"
2726
char * s1 , * s2 , * s3 , * s4 , * s5 , * s6 ;
2827
/* exec sql end declare section */
29-
#line 7 "strings.pgc"
28+
#line 5 "strings.pgc"
3029

3130

3231
int main(void)
3332
{
3433
ECPGdebug(1, stderr);
3534

3635
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
37-
#line 13 "strings.pgc"
36+
#line 11 "strings.pgc"
3837

3938

4039
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set standard_conforming_strings to on", ECPGt_EOIT, ECPGt_EORT);}
41-
#line 15 "strings.pgc"
40+
#line 13 "strings.pgc"
4241

4342

4443
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select 'abcdef' , N'abcdef' as foo , E'abc\\bdef' as \"foo\" , U&'d\\0061t\\0061' as U&\"foo\" , U&'d!+000061t!+000061' uescape '!' , $foo$abc$def$foo$", ECPGt_EOIT,
@@ -54,13 +53,13 @@ int main(void)
5453
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
5554
ECPGt_char,&(s6),(long)0,(long)1,(1)*sizeof(char),
5655
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
57-
#line 23 "strings.pgc"
56+
#line 21 "strings.pgc"
5857

5958

6059
printf("%s %s %s %s %s %s\n", s1, s2, s3, s4, s5, s6);
6160

6261
{ ECPGdisconnect(__LINE__, "CURRENT");}
63-
#line 27 "strings.pgc"
62+
#line 25 "strings.pgc"
6463

65-
exit (0);
64+
return (0);
6665
}

src/interfaces/ecpg/test/expected/preproc-strings.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
[NO_PID]: sqlca: code: 0, state: 00000
33
[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT>
44
[NO_PID]: sqlca: code: 0, state: 00000
5-
[NO_PID]: ecpg_execute on line 15: query: set standard_conforming_strings to on; with 0 parameter(s) on connection regress1
5+
[NO_PID]: ecpg_execute on line 13: query: set standard_conforming_strings to on; with 0 parameter(s) on connection regress1
66
[NO_PID]: sqlca: code: 0, state: 00000
7-
[NO_PID]: ecpg_execute on line 15: using PQexec
7+
[NO_PID]: ecpg_execute on line 13: using PQexec
88
[NO_PID]: sqlca: code: 0, state: 00000
9-
[NO_PID]: ecpg_execute on line 15: OK: SET
9+
[NO_PID]: ecpg_execute on line 13: OK: SET
1010
[NO_PID]: sqlca: code: 0, state: 00000
11-
[NO_PID]: ecpg_execute on line 17: query: select 'abcdef' , N'abcdef' as foo , E'abc\bdef' as "foo" , U&'d\0061t\0061' as U&"foo" , U&'d!+000061t!+000061' uescape '!' , $foo$abc$def$foo$; with 0 parameter(s) on connection regress1
11+
[NO_PID]: ecpg_execute on line 15: query: select 'abcdef' , N'abcdef' as foo , E'abc\bdef' as "foo" , U&'d\0061t\0061' as U&"foo" , U&'d!+000061t!+000061' uescape '!' , $foo$abc$def$foo$; with 0 parameter(s) on connection regress1
1212
[NO_PID]: sqlca: code: 0, state: 00000
13-
[NO_PID]: ecpg_execute on line 17: using PQexec
13+
[NO_PID]: ecpg_execute on line 15: using PQexec
1414
[NO_PID]: sqlca: code: 0, state: 00000
15-
[NO_PID]: ecpg_execute on line 17: correctly got 1 tuples with 6 fields
15+
[NO_PID]: ecpg_execute on line 15: correctly got 1 tuples with 6 fields
1616
[NO_PID]: sqlca: code: 0, state: 00000
17-
[NO_PID]: ecpg_store_result on line 17: allocating memory for 1 tuples
17+
[NO_PID]: ecpg_store_result on line 15: allocating memory for 1 tuples
1818
[NO_PID]: sqlca: code: 0, state: 00000
19-
[NO_PID]: ecpg_get_data on line 17: RESULT: abcdef offset: -1; array: no
19+
[NO_PID]: ecpg_get_data on line 15: RESULT: abcdef offset: -1; array: no
2020
[NO_PID]: sqlca: code: 0, state: 00000
21-
[NO_PID]: ecpg_store_result on line 17: allocating memory for 1 tuples
21+
[NO_PID]: ecpg_store_result on line 15: allocating memory for 1 tuples
2222
[NO_PID]: sqlca: code: 0, state: 00000
23-
[NO_PID]: ecpg_get_data on line 17: RESULT: abcdef offset: -1; array: no
23+
[NO_PID]: ecpg_get_data on line 15: RESULT: abcdef offset: -1; array: no
2424
[NO_PID]: sqlca: code: 0, state: 00000
25-
[NO_PID]: ecpg_store_result on line 17: allocating memory for 1 tuples
25+
[NO_PID]: ecpg_store_result on line 15: allocating memory for 1 tuples
2626
[NO_PID]: sqlca: code: 0, state: 00000
27-
[NO_PID]: ecpg_get_data on line 17: RESULT: abcdef offset: -1; array: no
27+
[NO_PID]: ecpg_get_data on line 15: RESULT: abcdef offset: -1; array: no
2828
[NO_PID]: sqlca: code: 0, state: 00000
29-
[NO_PID]: ecpg_store_result on line 17: allocating memory for 1 tuples
29+
[NO_PID]: ecpg_store_result on line 15: allocating memory for 1 tuples
3030
[NO_PID]: sqlca: code: 0, state: 00000
31-
[NO_PID]: ecpg_get_data on line 17: RESULT: data offset: -1; array: no
31+
[NO_PID]: ecpg_get_data on line 15: RESULT: data offset: -1; array: no
3232
[NO_PID]: sqlca: code: 0, state: 00000
33-
[NO_PID]: ecpg_store_result on line 17: allocating memory for 1 tuples
33+
[NO_PID]: ecpg_store_result on line 15: allocating memory for 1 tuples
3434
[NO_PID]: sqlca: code: 0, state: 00000
35-
[NO_PID]: ecpg_get_data on line 17: RESULT: data offset: -1; array: no
35+
[NO_PID]: ecpg_get_data on line 15: RESULT: data offset: -1; array: no
3636
[NO_PID]: sqlca: code: 0, state: 00000
37-
[NO_PID]: ecpg_store_result on line 17: allocating memory for 1 tuples
37+
[NO_PID]: ecpg_store_result on line 15: allocating memory for 1 tuples
3838
[NO_PID]: sqlca: code: 0, state: 00000
39-
[NO_PID]: ecpg_get_data on line 17: RESULT: abc$def offset: -1; array: no
39+
[NO_PID]: ecpg_get_data on line 15: RESULT: abc$def offset: -1; array: no
4040
[NO_PID]: sqlca: code: 0, state: 00000
4141
[NO_PID]: ecpg_finish: connection regress1 closed
4242
[NO_PID]: sqlca: code: 0, state: 00000

src/interfaces/ecpg/test/preproc/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ array_of_struct.c: array_of_struct.pgc ../regression.h
2424
autoprep.c: autoprep.pgc ../regression.h
2525
$(ECPG) -r prepare -o $@ -I$(srcdir) $<
2626

27+
strings.c: strings.pgc strings.h ../regression.h
28+
$(ECPG) -i -o $@ -I$(srcdir) $<
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
char *s1, *s2, *s3, *s4, *s5, *s6;

src/interfaces/ecpg/test/preproc/strings.pgc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#include <stdlib.h>
2-
3-
exec sql include ../regression;
1+
#include "../regression.h"
42

53
exec sql begin declare section;
6-
char *s1, *s2, *s3, *s4, *s5, *s6;
4+
#include "strings.h"
75
exec sql end declare section;
86

97
int main(void)
@@ -25,5 +23,5 @@ int main(void)
2523
printf("%s %s %s %s %s %s\n", s1, s2, s3, s4, s5, s6);
2624

2725
exec sql disconnect;
28-
exit (0);
26+
return (0);
2927
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy