diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-10-14 13:55:08 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-10-14 13:55:08 -0400 |
commit | 1acd0f55274fab8c936779a0f2b738f6005cc48f (patch) | |
tree | cfcd82b581fa2cfc0ce25608f0d0adaf38811159 /src/interfaces/ecpg/preproc/parser.c | |
parent | f18231e817599246fc99a798c9bf57ab785db91f (diff) | |
download | postgresql-1acd0f55274fab8c936779a0f2b738f6005cc48f.tar.gz postgresql-1acd0f55274fab8c936779a0f2b738f6005cc48f.zip |
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
Diffstat (limited to 'src/interfaces/ecpg/preproc/parser.c')
-rw-r--r-- | src/interfaces/ecpg/preproc/parser.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/interfaces/ecpg/preproc/parser.c b/src/interfaces/ecpg/preproc/parser.c index ca0dead26d0..373c93fc04a 100644 --- a/src/interfaces/ecpg/preproc/parser.c +++ b/src/interfaces/ecpg/preproc/parser.c @@ -204,7 +204,7 @@ filtered_base_yylex(void) /* Combine 3 tokens into 1 */ base_yylval.str = psprintf("%s UESCAPE %s", base_yylval.str, escstr); - base_yylloc = mm_strdup(base_yylval.str); + base_yylloc = loc_strdup(base_yylval.str); /* Clear have_lookahead, thereby consuming all three tokens */ have_lookahead = false; @@ -254,11 +254,11 @@ base_yylex_location(void) case UIDENT: case IP: /* Duplicate the <str> value */ - base_yylloc = mm_strdup(base_yylval.str); + base_yylloc = loc_strdup(base_yylval.str); break; default: /* Else just use the input, i.e., yytext */ - base_yylloc = mm_strdup(base_yytext); + base_yylloc = loc_strdup(base_yytext); /* Apply an ASCII-only downcasing */ for (unsigned char *ptr = (unsigned char *) base_yylloc; *ptr; ptr++) { |