From 6f0cef9353fcef50e74c31bb06c96c40207fd535 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 16 Apr 2024 12:31:32 -0400 Subject: Fix assorted bugs in ecpg's macro mechanism. The code associated with EXEC SQL DEFINE was unreadable and full of bugs, notably: * It'd attempt to free a non-malloced string if the ecpg program tries to redefine a macro that was defined on the command line. * Possible memory stomp if user writes "-D=foo". * Undef'ing or redefining a macro defined on the command line would change the state visible to the next file, when multiple files are specified on the command line. (While possibly that could have been an intentional choice, the code clearly intends to revert to the original macro state; it's just failing to consider this interaction.) * Missing "break" in defining a new macro meant that redefinition of an existing name would cause an extra entry to be added to the definition list. While not immediately harmful, a subsequent undef would result in the prior entry becoming visible again. * The interactions with input buffering are subtle and were entirely undocumented. It's not that surprising that we hadn't noticed these bugs, because there was no test coverage at all of either the -D command line switch or multiple input files. This patch adds such coverage (in a rather hacky way I guess). In addition to the code bugs, the user documentation was confused about whether the -D switch defines a C macro or an ecpg one, and it failed to mention that you can write "-Dsymbol=value". These problems are old, so back-patch to all supported branches. Discussion: https://postgr.es/m/998011.1713217712@sss.pgh.pa.us --- doc/src/sgml/ecpg.sgml | 8 ++++++++ doc/src/sgml/ref/ecpg-ref.sgml | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml index b332aa435df..e7a53f3c9d0 100644 --- a/doc/src/sgml/ecpg.sgml +++ b/doc/src/sgml/ecpg.sgml @@ -5793,6 +5793,14 @@ EXEC SQL UPDATE Tbl SET col = MYNUMBER; embedded SQL query because in this case the embedded SQL precompiler is not able to see this declaration. + + + If multiple input files are named on the ecpg + preprocessor's command line, the effects of EXEC SQL + DEFINE and EXEC SQL UNDEF do not carry + across files: each file starts with only the symbols defined + by switches on the command line. + diff --git a/doc/src/sgml/ref/ecpg-ref.sgml b/doc/src/sgml/ref/ecpg-ref.sgml index f3b6034f42a..43f2d8bdaa7 100644 --- a/doc/src/sgml/ref/ecpg-ref.sgml +++ b/doc/src/sgml/ref/ecpg-ref.sgml @@ -93,10 +93,12 @@ PostgreSQL documentation - + - Define a C preprocessor symbol. + Define a preprocessor symbol, equivalently to the EXEC SQL + DEFINE directive. If no value is + specified, the symbol is defined with the value 1. -- cgit v1.2.3