aboutsummaryrefslogtreecommitdiff
path: root/contrib/seg/segparse.y
Commit message (Collapse)AuthorAge
* seg: pure parser and reentrant scannerPeter Eisentraut2024-12-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use the flex %option reentrant and the bison option %pure-parser to make the generated scanner and parser pure, reentrant, and thread-safe. Make the generated scanner use palloc() etc. instead of malloc() etc. Previously, we only used palloc() for the buffer, but flex would still use malloc() for its internal structures. As a result, there could be some small memory leaks in case of uncaught errors. (We do catch normal syntax errors as soft errors.) Now, all the memory is under palloc() control, so there are no more such issues. 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. 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. (We could even get rid of the yylex_destroy() call and just let the memory context cleanup handle everything. But for now, we preserve the existing behavior.) Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Andreas Karlsson <andreas@proxel.se> Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
* Include bison header files into implementation filesPeter Eisentraut2024-08-02
| | | | | | | | | | | | | | | | | | | | Before Bison 3.4, the generated parser implementation files run afoul of -Wmissing-variable-declarations (in spite of commit ab61c40bfa2) because declarations for yylval and possibly yylloc are missing. The generated header files contain an extern declaration, but the implementation files don't include the header files. Since Bison 3.4, the generated implementation files automatically include the generated header files, so then it works. To make this work with older Bison versions as well, include the generated header file from the .y file. (With older Bison versions, the generated implementation file contains effectively a copy of the header file pasted in, so including the header file is redundant. But we know this works anyway because the core grammar uses this arrangement already.) Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org
* Replace static buf with a stack-allocated one in 'seg' extensionHeikki Linnakangas2024-07-30
| | | | | | | | | | | | | | The buffer is used only locally within the function. Also, the initialization to '0' characters was unnecessary, the initial content were always overwritten with sprintf(). I don't understand why it was done that way, but it's been like that since forever. In the passing, change from sprintf() to snprintf(). The buffer was long enough so sprintf() was fine, but this makes it more obvious that there's no risk of a buffer overflow. Reviewed-by: Robert Haas Discussion: https://www.postgresql.org/message-id/7f86e06a-98c5-4ce3-8ec9-3885c8de0358@iki.fi
* Add extern declarations for Bison global variablesPeter Eisentraut2024-07-25
| | | | | | | | | | | | | | | This adds extern declarations for some global variables produced by Bison that are not already declared in its generated header file. This is a workaround to be able to add -Wmissing-variable-declarations to the global set of warning options in the near future. Another longer-term solution would be to convert these grammars to "pure" parsers in Bison, to avoid global variables altogether. Note that the core grammar is already pure, so this patch did not need to touch it. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org
* Convert contrib/seg's input function to report errors softlyAndrew Dunstan2022-12-23
| | | | | | Reviewed by Tom Lane Discussion: https://postgr.es/m/a8dc5700-c341-3ba8-0507-cc09881e6200@dunslane.net
* Fix contrib/seg to be more wary of long input numbers.Tom Lane2022-12-21
| | | | | | | | | | | | | | | | | | | | | seg stores the number of significant digits in an input number in a "char" field. If char is signed, and the input is more than 127 digits long, the count can read out as negative causing seg_out() to print garbage (or, if you're really unlucky, even crash). To fix, clamp the digit count to be not more than FLT_DIG. (In theory this loses some information about what the original input was, but it doesn't seem like useful information; it would not survive dump/restore in any case.) Also, in case there are stored values of the seg type containing bad data, add a clamp in seg_out's restore() subroutine. Per bug #17725 from Robins Tharakan. It's been like this forever, so back-patch to all supported branches. Discussion: https://postgr.es/m/17725-0a09313b67fbe86e@postgresql.org
* Bump minimum version of Bison to 2.3John Naylor2022-09-09
| | | | | | | | | | | | Since the retirement of some older buildfarm members, the oldest Bison that gets regular testing is 2.3. MacOS ships that version, and will continue doing so for the forseeable future because of Apple's policy regarding GPLv3. While Mac users could use a package manager to install a newer version, there is no compelling reason to force them do so at this time. Reviewed by Andres Freund Discussion: https://www.postgresql.org/message-id/1097762.1662145681@sss.pgh.pa.us
* Build all Flex files standaloneJohn Naylor2022-09-04
| | | | | | | | | | | | | The proposed Meson build system will need a way to ignore certain generated files in order to coexist with the autoconf build system, and C files generated by Flex which are #include'd into .y files make this more difficult. In similar vein to 72b1e3a21, arrange for all Flex C files to compile to their own .o targets. Reviewed by Andres Freund Discussion: https://www.postgresql.org/message-id/20220810171935.7k5zgnjwqzalzmtm%40awork3.anarazel.de Discussion: https://www.postgresql.org/message-id/CAFBsxsF8Gc2StS3haXofshHCzqNMRXiSxvQEYGwnFsTmsdwNeg@mail.gmail.com
* Indent C code in flex and bison filesPeter Eisentraut2022-05-13
| | | | | | In the style of pgindent, done semi-manually. Discussion: https://www.postgresql.org/message-id/flat/7d062ecc-7444-23ec-a159-acd8adf9b586%40enterprisedb.com
* Add some const decorations to prototypesPeter Eisentraut2017-11-10
| | | | Reviewed-by: Fabien COELHO <coelho@cri.ensmp.fr>
* Tweak __attribute__-wrapping macros for better pgindent results.Tom Lane2015-03-26
| | | | | | | | | | | | | | | | | | | | | This improves on commit bbfd7edae5aa5ad5553d3c7e102f2e450d4380d4 by making two simple changes: * pg_attribute_noreturn now takes parentheses, ie pg_attribute_noreturn(). Likewise pg_attribute_unused(), pg_attribute_packed(). This reduces pgindent's tendency to misformat declarations involving them. * attributes are now always attached to function declarations, not definitions. Previously some places were taking creative shortcuts, which were not merely candidates for bad misformatting by pgindent but often were outright wrong anyway. (It does little good to put a noreturn annotation where callers can't see it.) In any case, if we would like to believe that these macros can be used with non-gcc compilers, we should avoid gratuitous variance in usage patterns. I also went through and manually improved the formatting of a lot of declarations, and got rid of excessively repetitive (and now obsolete anyway) comments informing the reader what pg_attribute_printf is for.
* Revert "Fix bogus %name-prefix option syntax in all our Bison files."Tom Lane2014-05-28
| | | | | | | | | | | | This reverts commit 45b7abe59e9485657ac9380f35d2d917dd0da25b. It turns out that the %name-prefix syntax without "=" does not work at all in pre-2.4 Bison. We are not prepared to make such a large jump in minimum required Bison version just to suppress a warning message in a version hardly any developers are using yet. When 3.0 gets more popular, we'll figure out a way to deal with this. In the meantime, BISONFLAGS=-Wno-deprecated is recommendable for anyone using 3.0 who doesn't want to see the warning.
* Fix bogus %name-prefix option syntax in all our Bison files.Tom Lane2014-05-28
| | | | | | | | | | | | %name-prefix doesn't use an "=" sign according to the Bison docs, but it silently accepted one anyway, until Bison 3.0. This was originally a typo of mine in commit 012abebab1bc72043f3f670bf32e91ae4ee04bd2, and we seem to have slavishly copied the error into all the other grammar files. Per report from Vik Fearing; analysis by Peter Eisentraut. Back-patch to all active branches, since somebody might try to build a back branch with up-to-date tools.
* Fix contrib/cube and contrib/seg to build with bison 3.0.Tom Lane2013-07-29
| | | | | | | | | | | | 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.
* Clean up whitespace and indentation in parser and scanner filesPeter Eisentraut2011-11-01
| | | | These are not touched by pgindent, so clean them up a bit manually.
* Remove useless whitespace at end of linesPeter Eisentraut2010-11-23
|
* Add %expect 0 to all parser input files to prevent conflicts slipping by.Peter Eisentraut2008-11-26
|
* Prevent memory leaks in our various bison parsers when an error occursTom Lane2008-09-02
| | | | | | | during parsing. Formerly the parser's stack was allocated with malloc and so wouldn't be reclaimed; this patch makes it use palloc instead, so that flushing the current context will reclaim the memory. Per Marko Kreen.
* Got tired of waiting for spoonbill's compiler to get fixed. Let'sTom Lane2006-06-01
| | | | see if using an intermediate variable avoids the gcc bug.
* Make all our flex and bison files use %option prefix or %name-prefixTom Lane2006-03-07
| | | | | | (respectively) to rename yylex and related symbols. Some were doing it this way already, while others used not-too-reliable sed hacks in the Makefiles. It's all nice and consistent now.
* Replace ad-hoc atof() code with call to float4in, per Andrew Dunstan.Tom Lane2004-10-24
|
* Fix contrib/cube and contrib/seg to compile on Windows.Tom Lane2004-09-14
| | | | Andreas Pflug
* Fix two typos in comments.Neil Conway2004-09-10
|
* Fix ancient declaration inconsistency in cube & seg ... came across aTom Lane2004-09-02
| | | | compiler that warns about it.
* Localize our dependencies on the way to create NAN or INFINITY.Tom Lane2004-03-15
| | | | Per recent proposal to pghackers.
* Make contrib/seg work with flex 2.5.31. Fix it up to have a realTom Lane2003-09-14
| | | | btree operator class, too, since in PG 7.4 you can't GROUP without one.
* Error message editing in contrib (mostly by Joe Conway --- thanks Joe!)Tom Lane2003-07-24
|
* Fix a dozen or so places that were passing unpredictable data stringsTom Lane2002-11-22
| | | | | as elog format strings. Hai-Chen Tu pointed out the problem in contrib/dbmirror, but it wasn't the only such error.
* Arrange to compile flex output files as inclusions into other filesTom Lane2002-11-01
| | | | | | | | (usually bison output files), not as standalone files. This hack works around flex's insistence on including <stdio.h> before we are able to include postgres.h; postgres.h will already be read before the compiler starts to read the flex output file. Needed for largefile support on some platforms.
* Remove extraneous | ... while bison 1.28 doesn't object, newer versionsTom Lane2002-09-22
| | | | do.
* I haven't seen any objections, so here is a patch. It removes "#defineTom Lane2002-09-22
| | | | | | | | YYERROR_VERBOSE" from contrib/cube and contrib/seg, and adjusts the expected output accordingly. Hopefully this will consistently pass across multiple bison versions. Joe Conway
* I checked all the previous string handling errors and most of them wereBruce Momjian2002-09-02
| | | | | | | | | | | | | | | already fixed by You. However there were a few left and attached patch should fix the rest of them. I used StringInfo only in 2 places and both of them are inside debug ifdefs. Only performance penalty will come from using strlen() like all the other code does. I also modified some of the already patched parts by changing snprintf(buf, 2 * BUFSIZE, ... style lines to snprintf(buf, sizeof(buf), ... where buf is an array. Jukka Holappa
* Use Max/Min macros, not MAX/MIN, to eliminate portability issues.Tom Lane2002-07-30
|
* The attached patch enables the contrib subtree to build cleanly underBruce Momjian2001-06-18
| | | | | | | | | | | | | | | | | | | | | Cygwin with the possible exception of mSQL-interface. Since I don't have mSQL installed, I skipped this tool. Except for dealing with a missing getopt.h (oid2name) and HUGE (seg), the bulk of the patch uses the standard PostgreSQL approach to deal with Windows DLL issues. I tested the build aspect of this patch under Cygwin and Linux without any ill affects. Note that I did not actually attempt to test the code for functionality. The procedure to apply the patch is as follows: $ # save the attachment as /tmp/contrib.patch $ # change directory to the top of the PostgreSQL source tree $ patch -p0 </tmp/contrib.patch Jason
* Gene Selkov's SEG datatype (GiST example code)Tom Lane2000-12-11