ecpg: improve preprocessor's memory management.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 14 Oct 2024 17:55:08 +0000 (13:55 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 14 Oct 2024 17:55:08 +0000 (13:55 -0400)
commit1acd0f55274fab8c936779a0f2b738f6005cc48f
treecfcd82b581fa2cfc0ce25608f0d0adaf38811159
parentf18231e817599246fc99a798c9bf57ab785db91f
ecpg: improve preprocessor's memory management.

Invent a notion of "local" storage that will automatically be
reclaimed at the end of each statement.  Use this for location
strings as well as other visibly short-lived data within the parser.

Also, make cat_str and make_str return local storage and not free
their inputs, which allows dispensing with a whole lot of retail
mm_strdup calls.  We do have to add some new ones in places where
a local-lifetime string needs to be added to a longer-lived data
structure, but on balance there are a lot less mm_strdup calls than
before.

In hopes of flushing out places where changes were necessary,
I changed YYLTYPE from "char *" to "const char *", which forced
const-ification of various function arguments that probably
should've been like that all along.

This still leaks somewhat more memory than v17, but that will be
cleaned up in future commits.

Discussion: https://postgr.es/m/2011420.1713493114@sss.pgh.pa.us
12 files changed:
src/interfaces/ecpg/preproc/descriptor.c
src/interfaces/ecpg/preproc/ecpg.addons
src/interfaces/ecpg/preproc/ecpg.header
src/interfaces/ecpg/preproc/ecpg.trailer
src/interfaces/ecpg/preproc/output.c
src/interfaces/ecpg/preproc/parser.c
src/interfaces/ecpg/preproc/preproc_extern.h
src/interfaces/ecpg/preproc/type.c
src/interfaces/ecpg/preproc/type.h
src/interfaces/ecpg/preproc/util.c
src/interfaces/ecpg/preproc/variable.c
src/tools/pgindent/typedefs.list