Skip to content

Commit 55cbfa5

Browse files
committed
Fix contrib/cube and contrib/seg to build with bison 3.0.
These modules used the YYPARSE_PARAM macro, which has been deprecated by the bison folk since 1.875, and which they finally removed in 3.0. Adjust the code to use the replacement facility, %parse-param, which is a much better solution anyway since it allows specification of the type of the extra parser parameter. We can thus get rid of a lot of unsightly casting. Back-patch to all active branches, since somebody might try to build a back branch with up-to-date tools.
1 parent 626092a commit 55cbfa5

File tree

6 files changed

+53
-52
lines changed

6 files changed

+53
-52
lines changed

contrib/cube/cube.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ PG_MODULE_MAGIC;
2626
#define ARRPTR(x) ( (double *) ARR_DATA_PTR(x) )
2727
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
2828

29-
extern int cube_yyparse();
30-
extern void cube_yyerror(const char *message);
29+
extern int cube_yyparse(NDBOX **result);
30+
extern void cube_yyerror(NDBOX **result, const char *message);
3131
extern void cube_scanner_init(const char *str);
3232
extern void cube_scanner_finish(void);
3333

@@ -156,12 +156,12 @@ Datum
156156
cube_in(PG_FUNCTION_ARGS)
157157
{
158158
char *str = PG_GETARG_CSTRING(0);
159-
void *result;
159+
NDBOX *result;
160160

161161
cube_scanner_init(str);
162162

163163
if (cube_yyparse(&result) != 0)
164-
cube_yyerror("bogus input");
164+
cube_yyerror(&result, "bogus input");
165165

166166
cube_scanner_finish();
167167

contrib/cube/cubeparse.y

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
%{
2+
/* contrib/cube/cubeparse.y */
3+
24
/* NdBox = [(lowerleft),(upperright)] */
35
/* [(xLL(1)...xLL(N)),(xUR(1)...xUR(n))] */
46

5-
/* contrib/cube/cubeparse.y */
6-
7-
#define YYPARSE_PARAM result /* need this to pass a pointer (void *) to yyparse */
87
#define YYSTYPE char *
98
#define YYDEBUG 1
109

@@ -28,8 +27,8 @@ extern int cube_yylex(void);
2827
static char *scanbuf;
2928
static int scanbuflen;
3029

31-
void cube_yyerror(const char *message);
32-
int cube_yyparse(void *result);
30+
extern int cube_yyparse(NDBOX **result);
31+
extern void cube_yyerror(NDBOX **result, const char *message);
3332

3433
static int delim_count(char *s, char delim);
3534
static NDBOX * write_box(unsigned int dim, char *str1, char *str2);
@@ -38,6 +37,7 @@ static NDBOX * write_point_as_box(char *s, int dim);
3837
%}
3938

4039
/* BISON Declarations */
40+
%parse-param {NDBOX **result}
4141
%expect 0
4242
%name-prefix="cube_yy"
4343

@@ -70,7 +70,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
7070
YYABORT;
7171
}
7272

73-
*((void **)result) = write_box( dim, $2, $4 );
73+
*result = write_box( dim, $2, $4 );
7474

7575
}
7676

@@ -97,7 +97,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
9797
YYABORT;
9898
}
9999

100-
*((void **)result) = write_box( dim, $1, $3 );
100+
*result = write_box( dim, $1, $3 );
101101
}
102102

103103
| paren_list
@@ -114,7 +114,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
114114
YYABORT;
115115
}
116116

117-
*((void **)result) = write_point_as_box($1, dim);
117+
*result = write_point_as_box($1, dim);
118118
}
119119

120120
| list
@@ -130,7 +130,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
130130
CUBE_MAX_DIM)));
131131
YYABORT;
132132
}
133-
*((void **)result) = write_point_as_box($1, dim);
133+
*result = write_point_as_box($1, dim);
134134
}
135135
;
136136

contrib/cube/cubescan.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ float ({integer}|{real})([eE]{integer})?
6161
%%
6262

6363
void __attribute__((noreturn))
64-
yyerror(const char *message)
64+
yyerror(NDBOX **result, const char *message)
6565
{
6666
if (*yytext == YY_END_OF_BUFFER_CHAR)
6767
{

contrib/seg/seg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
PG_MODULE_MAGIC;
2525

26-
extern int seg_yyparse();
27-
extern void seg_yyerror(const char *message);
26+
extern int seg_yyparse(SEG *result);
27+
extern void seg_yyerror(SEG *result, const char *message);
2828
extern void seg_scanner_init(const char *str);
2929
extern void seg_scanner_finish(void);
3030

@@ -126,7 +126,7 @@ seg_in(PG_FUNCTION_ARGS)
126126
seg_scanner_init(str);
127127

128128
if (seg_yyparse(result) != 0)
129-
seg_yyerror("bogus input");
129+
seg_yyerror(result, "bogus input");
130130

131131
seg_scanner_finish();
132132

contrib/seg/segparse.y

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%{
2-
#define YYPARSE_PARAM result /* need this to pass a pointer (void *) to yyparse */
2+
/* contrib/seg/segparse.y */
33

44
#include "postgres.h"
55

@@ -24,8 +24,8 @@ extern int seg_yylex(void);
2424

2525
extern int significant_digits(char *str); /* defined in seg.c */
2626

27-
void seg_yyerror(const char *message);
28-
int seg_yyparse(void *result);
27+
extern int seg_yyparse(SEG *result);
28+
extern void seg_yyerror(SEG *result, const char *message);
2929

3030
static float seg_atof(char *value);
3131

@@ -40,6 +40,7 @@ static char strbuf[25] = {
4040
%}
4141

4242
/* BISON Declarations */
43+
%parse-param {SEG *result}
4344
%expect 0
4445
%name-prefix="seg_yy"
4546

@@ -65,59 +66,59 @@ static char strbuf[25] = {
6566

6667
range: boundary PLUMIN deviation
6768
{
68-
((SEG *)result)->lower = $1.val - $3.val;
69-
((SEG *)result)->upper = $1.val + $3.val;
70-
sprintf(strbuf, "%g", ((SEG *)result)->lower);
71-
((SEG *)result)->l_sigd = Max(Min(6, significant_digits(strbuf)), Max($1.sigd, $3.sigd));
72-
sprintf(strbuf, "%g", ((SEG *)result)->upper);
73-
((SEG *)result)->u_sigd = Max(Min(6, significant_digits(strbuf)), Max($1.sigd, $3.sigd));
74-
((SEG *)result)->l_ext = '\0';
75-
((SEG *)result)->u_ext = '\0';
69+
result->lower = $1.val - $3.val;
70+
result->upper = $1.val + $3.val;
71+
sprintf(strbuf, "%g", result->lower);
72+
result->l_sigd = Max(Min(6, significant_digits(strbuf)), Max($1.sigd, $3.sigd));
73+
sprintf(strbuf, "%g", result->upper);
74+
result->u_sigd = Max(Min(6, significant_digits(strbuf)), Max($1.sigd, $3.sigd));
75+
result->l_ext = '\0';
76+
result->u_ext = '\0';
7677
}
7778

7879
| boundary RANGE boundary
7980
{
80-
((SEG *)result)->lower = $1.val;
81-
((SEG *)result)->upper = $3.val;
82-
if ( ((SEG *)result)->lower > ((SEG *)result)->upper ) {
81+
result->lower = $1.val;
82+
result->upper = $3.val;
83+
if ( result->lower > result->upper ) {
8384
ereport(ERROR,
8485
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8586
errmsg("swapped boundaries: %g is greater than %g",
86-
((SEG *)result)->lower, ((SEG *)result)->upper)));
87+
result->lower, result->upper)));
8788

8889
YYERROR;
8990
}
90-
((SEG *)result)->l_sigd = $1.sigd;
91-
((SEG *)result)->u_sigd = $3.sigd;
92-
((SEG *)result)->l_ext = ( $1.ext ? $1.ext : '\0' );
93-
((SEG *)result)->u_ext = ( $3.ext ? $3.ext : '\0' );
91+
result->l_sigd = $1.sigd;
92+
result->u_sigd = $3.sigd;
93+
result->l_ext = ( $1.ext ? $1.ext : '\0' );
94+
result->u_ext = ( $3.ext ? $3.ext : '\0' );
9495
}
9596

9697
| boundary RANGE
9798
{
98-
((SEG *)result)->lower = $1.val;
99-
((SEG *)result)->upper = HUGE_VAL;
100-
((SEG *)result)->l_sigd = $1.sigd;
101-
((SEG *)result)->u_sigd = 0;
102-
((SEG *)result)->l_ext = ( $1.ext ? $1.ext : '\0' );
103-
((SEG *)result)->u_ext = '-';
99+
result->lower = $1.val;
100+
result->upper = HUGE_VAL;
101+
result->l_sigd = $1.sigd;
102+
result->u_sigd = 0;
103+
result->l_ext = ( $1.ext ? $1.ext : '\0' );
104+
result->u_ext = '-';
104105
}
105106

106107
| RANGE boundary
107108
{
108-
((SEG *)result)->lower = -HUGE_VAL;
109-
((SEG *)result)->upper = $2.val;
110-
((SEG *)result)->l_sigd = 0;
111-
((SEG *)result)->u_sigd = $2.sigd;
112-
((SEG *)result)->l_ext = '-';
113-
((SEG *)result)->u_ext = ( $2.ext ? $2.ext : '\0' );
109+
result->lower = -HUGE_VAL;
110+
result->upper = $2.val;
111+
result->l_sigd = 0;
112+
result->u_sigd = $2.sigd;
113+
result->l_ext = '-';
114+
result->u_ext = ( $2.ext ? $2.ext : '\0' );
114115
}
115116

116117
| boundary
117118
{
118-
((SEG *)result)->lower = ((SEG *)result)->upper = $1.val;
119-
((SEG *)result)->l_sigd = ((SEG *)result)->u_sigd = $1.sigd;
120-
((SEG *)result)->l_ext = ((SEG *)result)->u_ext = ( $1.ext ? $1.ext : '\0' );
119+
result->lower = result->upper = $1.val;
120+
result->l_sigd = result->u_sigd = $1.sigd;
121+
result->l_ext = result->u_ext = ( $1.ext ? $1.ext : '\0' );
121122
}
122123
;
123124

contrib/seg/segscan.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ float ({integer}|{real})([eE]{integer})?
6060
%%
6161

6262
void __attribute__((noreturn))
63-
yyerror(const char *message)
63+
yyerror(SEG *result, const char *message)
6464
{
6565
if (*yytext == YY_END_OF_BUFFER_CHAR)
6666
{

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