From 538a96c0cc3fd4d3454be578e32a7cf9afa6b30a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 2 Dec 2024 10:35:37 +0100 Subject: [PATCH v1 03/19] cube: Simplify flex scan buffer management Instead of constructing the buffer from pieces and then using yy_scan_buffer(), we can just use yy_scan_string(), which does the same thing internally. (Actually, we use yy_scan_bytes() here because we already have the length.) The previous code was necessary because we allocated the buffer with palloc() and the rest of the state was handled by malloc(). But this is no longer the case; everything is under palloc() now. XXX We could even get rid of the yylex_destroy() call and just let the memory context cleanup handle everything. --- contrib/cube/cubescan.l | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/contrib/cube/cubescan.l b/contrib/cube/cubescan.l index b741e77d7e1..eed324d6e3b 100644 --- a/contrib/cube/cubescan.l +++ b/contrib/cube/cubescan.l @@ -25,9 +25,6 @@ fprintf_to_ereport(const char *fmt, const char *msg) { ereport(ERROR, (errmsg_internal("%s", msg))); } - -/* Handles to the buffer that the lexer uses internally */ -static char *scanbuf; // FIXME %} %option reentrant @@ -111,14 +108,8 @@ cube_scanner_init(const char *str, Size *scanbuflen, yyscan_t *yyscannerp) yyscanner = *yyscannerp; - /* - * Make a scan buffer with special termination needed by flex. - */ + yy_scan_bytes(str, slen, yyscanner); *scanbuflen = slen; - scanbuf = palloc(slen + 2); - memcpy(scanbuf, str, slen); - scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR; - yy_scan_buffer(scanbuf, slen + 2, yyscanner); } @@ -129,7 +120,6 @@ void cube_scanner_finish(yyscan_t yyscanner) { yylex_destroy(yyscanner); - pfree(scanbuf); } /* -- 2.47.1