@@ -38,30 +38,36 @@ fprintf_to_ereport(const char *fmt, const char *msg)
38
38
ereport (ERROR, (errmsg_internal (" %s" , msg)));
39
39
}
40
40
41
- /* Handle to the buffer that the lexer uses internally */
42
- static YY_BUFFER_STATE scanbufhandle;
43
-
44
- /* Pushed-back token (we only handle one) */
45
- static int repl_pushed_back_token;
41
+ struct replication_yy_extra_type
42
+ {
43
+ /* Pushed-back token (we only handle one) */
44
+ int repl_pushed_back_token;
46
45
47
- /* Work area for collecting literals */
48
- static StringInfoData litbuf;
46
+ /* Work area for collecting literals */
47
+ StringInfoData litbuf;
48
+ };
49
+ #define YY_EXTRA_TYPE struct replication_yy_extra_type *
49
50
50
- static void startlit (void );
51
- static char *litbufdup (void );
52
- static void addlit (char *ytext, int yleng);
53
- static void addlitchar (unsigned char ychar);
51
+ static void startlit (yyscan_t yyscanner );
52
+ static char *litbufdup (yyscan_t yyscanner );
53
+ static void addlit (char *ytext, int yleng, yyscan_t yyscanner );
54
+ static void addlitchar (unsigned char ychar, yyscan_t yyscanner );
54
55
55
56
/* LCOV_EXCL_START */
56
57
57
58
%}
58
59
60
+ %option reentrant
61
+ %option bison-bridge
59
62
%option 8bit
60
63
%option never-interactive
61
64
%option nodefault
62
65
%option noinput
63
66
%option nounput
64
67
%option noyywrap
68
+ %option noyyalloc
69
+ %option noyyrealloc
70
+ %option noyyfree
65
71
%option warn
66
72
%option prefix=" replication_yy"
67
73
@@ -108,11 +114,11 @@ identifier {ident_start}{ident_cont}*
108
114
/* This code is inserted at the start of replication_yylex() */
109
115
110
116
/* If we have a pushed-back token, return that. */
111
- if (repl_pushed_back_token)
117
+ if (yyextra-> repl_pushed_back_token )
112
118
{
113
- int result = repl_pushed_back_token;
119
+ int result = yyextra-> repl_pushed_back_token ;
114
120
115
- repl_pushed_back_token = 0 ;
121
+ yyextra-> repl_pushed_back_token = 0 ;
116
122
return result;
117
123
}
118
124
%}
@@ -142,63 +148,63 @@ UPLOAD_MANIFEST { return K_UPLOAD_MANIFEST; }
142
148
{space}+ { /* do nothing */ }
143
149
144
150
{digit}+ {
145
- replication_yylval. uintval = strtoul (yytext, NULL , 10 );
151
+ yylval-> uintval = strtoul (yytext, NULL , 10 );
146
152
return UCONST;
147
153
}
148
154
149
155
{hexdigit}+\/{hexdigit}+ {
150
156
uint32 hi,
151
157
lo;
152
158
if (sscanf (yytext, " %X/%X" , &hi, &lo) != 2 )
153
- replication_yyerror (" invalid streaming start location" );
154
- replication_yylval. recptr = ((uint64) hi) << 32 | lo;
159
+ replication_yyerror (yyscanner, " invalid streaming start location" );
160
+ yylval-> recptr = ((uint64) hi) << 32 | lo;
155
161
return RECPTR;
156
162
}
157
163
158
164
{xqstart} {
159
165
BEGIN (xq);
160
- startlit ();
166
+ startlit (yyscanner );
161
167
}
162
168
163
169
<xq>{quotestop} {
164
170
yyless (1 );
165
171
BEGIN (INITIAL);
166
- replication_yylval. str = litbufdup ();
172
+ yylval-> str = litbufdup (yyscanner );
167
173
return SCONST;
168
174
}
169
175
170
176
<xq>{xqdouble} {
171
- addlitchar (' \' ' );
177
+ addlitchar (' \' ' , yyscanner );
172
178
}
173
179
174
180
<xq>{xqinside} {
175
- addlit (yytext, yyleng);
181
+ addlit (yytext, yyleng, yyscanner );
176
182
}
177
183
178
184
{xdstart} {
179
185
BEGIN (xd);
180
- startlit ();
186
+ startlit (yyscanner );
181
187
}
182
188
183
189
<xd>{xdstop} {
184
190
int len;
185
191
186
192
yyless (1 );
187
193
BEGIN (INITIAL);
188
- replication_yylval. str = litbufdup ();
189
- len = strlen (replication_yylval. str );
190
- truncate_identifier (replication_yylval. str , len, true );
194
+ yylval-> str = litbufdup (yyscanner );
195
+ len = strlen (yylval-> str );
196
+ truncate_identifier (yylval-> str , len, true );
191
197
return IDENT;
192
198
}
193
199
194
200
<xd>{xdinside} {
195
- addlit (yytext, yyleng);
201
+ addlit (yytext, yyleng, yyscanner );
196
202
}
197
203
198
204
{identifier} {
199
205
int len = strlen (yytext);
200
206
201
- replication_yylval. str = downcase_truncate_identifier (yytext, len, true );
207
+ yylval-> str = downcase_truncate_identifier (yytext, len, true );
202
208
return IDENT;
203
209
}
204
210
@@ -207,7 +213,7 @@ UPLOAD_MANIFEST { return K_UPLOAD_MANIFEST; }
207
213
return yytext[0 ];
208
214
}
209
215
210
- <xq ,xd ><<EOF>> { replication_yyerror (" unterminated quoted string" ); }
216
+ <xq,xd><<EOF>> { replication_yyerror (yyscanner, " unterminated quoted string" ); }
211
217
212
218
213
219
<<EOF>> {
@@ -218,68 +224,63 @@ UPLOAD_MANIFEST { return K_UPLOAD_MANIFEST; }
218
224
219
225
/* LCOV_EXCL_STOP */
220
226
227
+ /* see scan.l */
228
+ #undef yyextra
229
+ #define yyextra (((struct yyguts_t *) yyscanner)->yyextra_r)
230
+
221
231
static void
222
- startlit (void )
232
+ startlit (yyscan_t yyscanner )
223
233
{
224
- initStringInfo (&litbuf);
234
+ initStringInfo (&yyextra-> litbuf );
225
235
}
226
236
227
237
static char *
228
- litbufdup (void )
238
+ litbufdup (yyscan_t yyscanner )
229
239
{
230
- return litbuf.data ;
240
+ return yyextra-> litbuf .data ;
231
241
}
232
242
233
243
static void
234
- addlit (char *ytext, int yleng)
244
+ addlit (char *ytext, int yleng, yyscan_t yyscanner )
235
245
{
236
- appendBinaryStringInfo (&litbuf, ytext, yleng);
246
+ appendBinaryStringInfo (&yyextra-> litbuf , ytext, yleng);
237
247
}
238
248
239
249
static void
240
- addlitchar (unsigned char ychar)
250
+ addlitchar (unsigned char ychar, yyscan_t yyscanner )
241
251
{
242
- appendStringInfoChar (&litbuf, ychar);
252
+ appendStringInfoChar (&yyextra-> litbuf , ychar);
243
253
}
244
254
245
255
void
246
- replication_yyerror (const char *message)
256
+ replication_yyerror (yyscan_t yyscanner, const char *message)
247
257
{
248
258
ereport (ERROR,
249
259
(errcode (ERRCODE_SYNTAX_ERROR),
250
260
errmsg_internal (" %s" , message)));
251
261
}
252
262
253
263
void
254
- replication_scanner_init (const char *str)
264
+ replication_scanner_init (const char *str, yyscan_t *yyscannerp )
255
265
{
256
- Size slen = strlen (str);
257
- char *scanbuf;
258
-
259
- /*
260
- * Might be left over after ereport()
261
- */
262
- if (YY_CURRENT_BUFFER)
263
- yy_delete_buffer (YY_CURRENT_BUFFER);
264
-
265
- /*
266
- * Make a scan buffer with special termination needed by flex.
267
- */
268
- scanbuf = (char *) palloc (slen + 2 );
269
- memcpy (scanbuf, str, slen);
270
- scanbuf[slen] = scanbuf[slen + 1 ] = YY_END_OF_BUFFER_CHAR;
271
- scanbufhandle = yy_scan_buffer (scanbuf, slen + 2 );
272
-
273
- /* Make sure we start in proper state */
274
- BEGIN (INITIAL);
275
- repl_pushed_back_token = 0 ;
266
+ yyscan_t yyscanner;
267
+ struct replication_yy_extra_type *yyext = palloc0_object (struct replication_yy_extra_type );
268
+
269
+ if (yylex_init (yyscannerp) != 0 )
270
+ elog (ERROR, " yylex_init() failed: %m" );
271
+
272
+ yyscanner = *yyscannerp;
273
+
274
+ yyset_extra (yyext, yyscanner);
275
+
276
+ yy_scan_string (str, yyscanner);
276
277
}
277
278
278
279
void
279
- replication_scanner_finish (void )
280
+ replication_scanner_finish (yyscan_t yyscanner )
280
281
{
281
- yy_delete_buffer (scanbufhandle );
282
- scanbufhandle = NULL ;
282
+ pfree (yyextra );
283
+ yylex_destroy (yyscanner) ;
283
284
}
284
285
285
286
/*
@@ -291,9 +292,10 @@ replication_scanner_finish(void)
291
292
* IDENT token here, although some other cases are possible.
292
293
*/
293
294
bool
294
- replication_scanner_is_replication_command (void )
295
+ replication_scanner_is_replication_command (yyscan_t yyscanner )
295
296
{
296
- int first_token = replication_yylex ();
297
+ YYSTYPE dummy;
298
+ int first_token = replication_yylex (&dummy, yyscanner);
297
299
298
300
switch (first_token)
299
301
{
@@ -308,10 +310,37 @@ replication_scanner_is_replication_command(void)
308
310
case K_UPLOAD_MANIFEST:
309
311
case K_SHOW:
310
312
/* Yes; push back the first token so we can parse later. */
311
- repl_pushed_back_token = first_token;
313
+ yyextra-> repl_pushed_back_token = first_token;
312
314
return true ;
313
315
default :
314
316
/* Nope; we don't bother to push back the token. */
315
317
return false ;
316
318
}
317
319
}
320
+
321
+ /*
322
+ * Interface functions to make flex use palloc() instead of malloc().
323
+ * It'd be better to make these static, but flex insists otherwise.
324
+ */
325
+
326
+ void *
327
+ yyalloc (yy_size_t size, yyscan_t yyscanner)
328
+ {
329
+ return palloc (size);
330
+ }
331
+
332
+ void *
333
+ yyrealloc (void *ptr, yy_size_t size, yyscan_t yyscanner)
334
+ {
335
+ if (ptr)
336
+ return repalloc (ptr, size);
337
+ else
338
+ return palloc (size);
339
+ }
340
+
341
+ void
342
+ yyfree (void *ptr, yyscan_t yyscanner)
343
+ {
344
+ if (ptr)
345
+ pfree (ptr);
346
+ }
0 commit comments