7
7
#include " postgres.h"
8
8
9
9
#include " cubedata.h"
10
+ #include " nodes/miscnodes.h"
10
11
#include " utils/float.h"
11
12
12
13
/* All grammar constructs return strings */
21
22
#define YYFREE pfree
22
23
23
24
static int item_count (const char *s, char delim);
24
- static NDBOX *write_box (int dim, char *str1, char *str2);
25
- static NDBOX *write_point_as_box (int dim, char *str);
25
+ static bool write_box (int dim, char *str1, char *str2,
26
+ NDBOX **result, struct Node *escontext);
27
+ static bool write_point_as_box (int dim, char *str,
28
+ NDBOX **result, struct Node *escontext);
26
29
27
30
%}
28
31
29
32
/* BISON Declarations */
30
33
%parse-param {NDBOX **result}
31
34
%parse-param {Size scanbuflen}
35
+ %parse-param {struct Node *escontext}
32
36
%expect 0
33
37
%name-prefix=" cube_yy"
34
38
@@ -45,7 +49,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
45
49
dim = item_count ($2 , ' ,' );
46
50
if (item_count ($4 , ' ,' ) != dim)
47
51
{
48
- ereport (ERROR ,
52
+ errsave (escontext ,
49
53
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION),
50
54
errmsg (" invalid input syntax for cube" ),
51
55
errdetail (" Different point dimensions in (%s) and (%s)." ,
@@ -54,15 +58,16 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
54
58
}
55
59
if (dim > CUBE_MAX_DIM)
56
60
{
57
- ereport (ERROR ,
61
+ errsave (escontext ,
58
62
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION),
59
63
errmsg (" invalid input syntax for cube" ),
60
64
errdetail (" A cube cannot have more than %d dimensions." ,
61
65
CUBE_MAX_DIM)));
62
66
YYABORT;
63
67
}
64
68
65
- *result = write_box( dim, $2 , $4 );
69
+ if (!write_box (dim, $2 , $4 , result, escontext))
70
+ YYABORT;
66
71
}
67
72
68
73
| paren_list COMMA paren_list
@@ -72,7 +77,7 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
72
77
dim = item_count ($1 , ' ,' );
73
78
if (item_count ($3 , ' ,' ) != dim)
74
79
{
75
- ereport (ERROR ,
80
+ errsave (escontext ,
76
81
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION),
77
82
errmsg (" invalid input syntax for cube" ),
78
83
errdetail (" Different point dimensions in (%s) and (%s)." ,
@@ -81,15 +86,16 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
81
86
}
82
87
if (dim > CUBE_MAX_DIM)
83
88
{
84
- ereport (ERROR ,
89
+ errsave (escontext ,
85
90
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION),
86
91
errmsg (" invalid input syntax for cube" ),
87
92
errdetail (" A cube cannot have more than %d dimensions." ,
88
93
CUBE_MAX_DIM)));
89
94
YYABORT;
90
95
}
91
96
92
- *result = write_box( dim, $1 , $3 );
97
+ if (!write_box (dim, $1 , $3 , result, escontext))
98
+ YYABORT;
93
99
}
94
100
95
101
| paren_list
@@ -99,15 +105,16 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
99
105
dim = item_count ($1 , ' ,' );
100
106
if (dim > CUBE_MAX_DIM)
101
107
{
102
- ereport (ERROR ,
108
+ errsave (escontext ,
103
109
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION),
104
110
errmsg (" invalid input syntax for cube" ),
105
111
errdetail (" A cube cannot have more than %d dimensions." ,
106
112
CUBE_MAX_DIM)));
107
113
YYABORT;
108
114
}
109
115
110
- *result = write_point_as_box(dim, $1 );
116
+ if (!write_point_as_box (dim, $1 , result, escontext))
117
+ YYABORT;
111
118
}
112
119
113
120
| list
@@ -117,15 +124,16 @@ box: O_BRACKET paren_list COMMA paren_list C_BRACKET
117
124
dim = item_count ($1 , ' ,' );
118
125
if (dim > CUBE_MAX_DIM)
119
126
{
120
- ereport (ERROR ,
127
+ errsave (escontext ,
121
128
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION),
122
129
errmsg (" invalid input syntax for cube" ),
123
130
errdetail (" A cube cannot have more than %d dimensions." ,
124
131
CUBE_MAX_DIM)));
125
132
YYABORT;
126
133
}
127
134
128
- *result = write_point_as_box(dim, $1 );
135
+ if (!write_point_as_box (dim, $1 , result, escontext))
136
+ YYABORT;
129
137
}
130
138
;
131
139
@@ -173,8 +181,9 @@ item_count(const char *s, char delim)
173
181
return nitems;
174
182
}
175
183
176
- static NDBOX *
177
- write_box (int dim, char *str1, char *str2)
184
+ static bool
185
+ write_box (int dim, char *str1, char *str2,
186
+ NDBOX **result, struct Node *escontext)
178
187
{
179
188
NDBOX *bp;
180
189
char *s;
@@ -190,26 +199,36 @@ write_box(int dim, char *str1, char *str2)
190
199
s = str1;
191
200
i = 0 ;
192
201
if (dim > 0 )
193
- bp->x [i++] = float8in_internal (s, &endptr, " cube" , str1);
202
+ {
203
+ bp->x [i++] = float8in_internal (s, &endptr, " cube" , str1, escontext);
204
+ if (SOFT_ERROR_OCCURRED (escontext))
205
+ return false ;
206
+ }
194
207
while ((s = strchr (s, ' ,' )) != NULL )
195
208
{
196
209
s++;
197
- bp->x [i++] = float8in_internal (s, &endptr, " cube" , str1);
210
+ bp->x [i++] = float8in_internal (s, &endptr, " cube" , str1, escontext);
211
+ if (SOFT_ERROR_OCCURRED (escontext))
212
+ return false ;
198
213
}
199
214
Assert (i == dim);
200
215
201
216
s = str2;
202
217
if (dim > 0 )
203
218
{
204
- bp->x [i] = float8in_internal (s, &endptr, " cube" , str2);
219
+ bp->x [i] = float8in_internal (s, &endptr, " cube" , str2, escontext);
220
+ if (SOFT_ERROR_OCCURRED (escontext))
221
+ return false ;
205
222
/* code this way to do right thing with NaN */
206
223
point &= (bp->x [i] == bp->x [0 ]);
207
224
i++;
208
225
}
209
226
while ((s = strchr (s, ' ,' )) != NULL )
210
227
{
211
228
s++;
212
- bp->x [i] = float8in_internal (s, &endptr, " cube" , str2);
229
+ bp->x [i] = float8in_internal (s, &endptr, " cube" , str2, escontext);
230
+ if (SOFT_ERROR_OCCURRED (escontext))
231
+ return false ;
213
232
point &= (bp->x [i] == bp->x [i - dim]);
214
233
i++;
215
234
}
@@ -229,11 +248,13 @@ write_box(int dim, char *str1, char *str2)
229
248
SET_POINT_BIT (bp);
230
249
}
231
250
232
- return bp;
251
+ *result = bp;
252
+ return true ;
233
253
}
234
254
235
- static NDBOX *
236
- write_point_as_box (int dim, char *str)
255
+ static bool
256
+ write_point_as_box (int dim, char *str,
257
+ NDBOX **result, struct Node *escontext)
237
258
{
238
259
NDBOX *bp;
239
260
int i,
@@ -250,13 +271,20 @@ write_point_as_box(int dim, char *str)
250
271
s = str;
251
272
i = 0 ;
252
273
if (dim > 0 )
253
- bp->x [i++] = float8in_internal (s, &endptr, " cube" , str);
274
+ {
275
+ bp->x [i++] = float8in_internal (s, &endptr, " cube" , str, escontext);
276
+ if (SOFT_ERROR_OCCURRED (escontext))
277
+ return false ;
278
+ }
254
279
while ((s = strchr (s, ' ,' )) != NULL )
255
280
{
256
281
s++;
257
- bp->x [i++] = float8in_internal (s, &endptr, " cube" , str);
282
+ bp->x [i++] = float8in_internal (s, &endptr, " cube" , str, escontext);
283
+ if (SOFT_ERROR_OCCURRED (escontext))
284
+ return false ;
258
285
}
259
286
Assert (i == dim);
260
287
261
- return bp;
288
+ *result = bp;
289
+ return true ;
262
290
}
0 commit comments