Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1acd0f5

Browse files
committed
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
1 parent f18231e commit 1acd0f5

File tree

12 files changed

+599
-529
lines changed

12 files changed

+599
-529
lines changed

src/interfaces/ecpg/preproc/descriptor.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
static struct assignment *assignments;
1919

2020
void
21-
push_assignment(char *var, enum ECPGdtype value)
21+
push_assignment(const char *var, enum ECPGdtype value)
2222
{
2323
struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));
2424

2525
new->next = assignments;
26-
new->variable = mm_alloc(strlen(var) + 1);
27-
strcpy(new->variable, var);
26+
new->variable = mm_strdup(var);
2827
new->value = value;
2928
assignments = new;
3029
}
@@ -73,7 +72,7 @@ ECPGnumeric_lvalue(char *name)
7372
static struct descriptor *descriptors;
7473

7574
void
76-
add_descriptor(char *name, char *connection)
75+
add_descriptor(const char *name, const char *connection)
7776
{
7877
struct descriptor *new;
7978

@@ -83,20 +82,16 @@ add_descriptor(char *name, char *connection)
8382
new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
8483

8584
new->next = descriptors;
86-
new->name = mm_alloc(strlen(name) + 1);
87-
strcpy(new->name, name);
85+
new->name = mm_strdup(name);
8886
if (connection)
89-
{
90-
new->connection = mm_alloc(strlen(connection) + 1);
91-
strcpy(new->connection, connection);
92-
}
87+
new->connection = mm_strdup(connection);
9388
else
94-
new->connection = connection;
89+
new->connection = NULL;
9590
descriptors = new;
9691
}
9792

9893
void
99-
drop_descriptor(char *name, char *connection)
94+
drop_descriptor(const char *name, const char *connection)
10095
{
10196
struct descriptor *i;
10297
struct descriptor **lastptr = &descriptors;
@@ -126,9 +121,8 @@ drop_descriptor(char *name, char *connection)
126121
mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
127122
}
128123

129-
struct descriptor
130-
*
131-
lookup_descriptor(char *name, char *connection)
124+
struct descriptor *
125+
lookup_descriptor(const char *name, const char *connection)
132126
{
133127
struct descriptor *i;
134128

@@ -159,7 +153,7 @@ lookup_descriptor(char *name, char *connection)
159153
}
160154

161155
void
162-
output_get_descr_header(char *desc_name)
156+
output_get_descr_header(const char *desc_name)
163157
{
164158
struct assignment *results;
165159

@@ -178,7 +172,7 @@ output_get_descr_header(char *desc_name)
178172
}
179173

180174
void
181-
output_get_descr(char *desc_name, char *index)
175+
output_get_descr(const char *desc_name, const char *index)
182176
{
183177
struct assignment *results;
184178

@@ -211,7 +205,7 @@ output_get_descr(char *desc_name, char *index)
211205
}
212206

213207
void
214-
output_set_descr_header(char *desc_name)
208+
output_set_descr_header(const char *desc_name)
215209
{
216210
struct assignment *results;
217211

@@ -272,7 +266,7 @@ descriptor_item_name(enum ECPGdtype itemcode)
272266
}
273267

274268
void
275-
output_set_descr(char *desc_name, char *index)
269+
output_set_descr(const char *desc_name, const char *index)
276270
{
277271
struct assignment *results;
278272

0 commit comments

Comments
 (0)