Skip to content

Commit 3ab9def

Browse files
authored
add macros for alloc/free of string types (#38)
1 parent b5f2cbc commit 3ab9def

File tree

16 files changed

+1593
-1636
lines changed

16 files changed

+1593
-1636
lines changed

src/metamath.c

Lines changed: 128 additions & 122 deletions
Large diffs are not rendered by default.

src/mmcmdl.c

Lines changed: 97 additions & 117 deletions
Large diffs are not rendered by default.

src/mmcmds.c

Lines changed: 357 additions & 357 deletions
Large diffs are not rendered by default.

src/mmdata.c

Lines changed: 179 additions & 199 deletions
Large diffs are not rendered by default.

src/mmdata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ struct nullNmbrStruct {
208208
nmbrString nullElement; };
209209
extern struct nullNmbrStruct g_NmbrNull;
210210
#define NULL_NMBRSTRING &(g_NmbrNull.nullElement)
211+
#define nmbrString_def(x) nmbrString *x = NULL_NMBRSTRING
212+
#define free_nmbrString(x) nmbrLet(&x, NULL_NMBRSTRING)
211213

212214
/* Null pntrString -- NULL flags the end of a pntrString */
213215
struct nullPntrStruct {
@@ -217,6 +219,8 @@ struct nullPntrStruct {
217219
pntrString nullElement; };
218220
extern struct nullPntrStruct g_PntrNull;
219221
#define NULL_PNTRSTRING &(g_PntrNull.nullElement)
222+
#define pntrString_def(x) pntrString *x = NULL_PNTRSTRING
223+
#define free_pntrString(x) pntrLet(&x, NULL_PNTRSTRING)
220224

221225

222226
/* This function returns a 1 if any entry in a comma-separated list

src/mmhlpa.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/* help0 is mostly for TOOLS help */
2121
void help0(vstring helpCmd) {
2222

23-
vstring saveHelpCmd = "";
23+
vstring_def(saveHelpCmd);
2424
/* help0() may be called with a temporarily allocated argument (left(),
2525
cat(), etc.), and the let()s in the eventual print2() calls will
2626
deallocate and possibly corrupt helpCmd. So, we grab a non-temporarily
@@ -346,7 +346,7 @@ H("For your convenience, the trailing quote is optional, for example:");
346346
H(" Tools> 'ls | more");
347347
H("");
348348

349-
let(&saveHelpCmd, ""); /* Deallocate memory */
349+
free_vstring(saveHelpCmd); /* Deallocate memory */
350350

351351
return;
352352
} /* help0 */
@@ -355,7 +355,7 @@ return;
355355
/* Note: help1 should contain Metamath help */
356356
void help1(vstring helpCmd) {
357357

358-
vstring saveHelpCmd = "";
358+
vstring_def(saveHelpCmd);
359359
/* help1() may be called with a temporarily allocated argument (left(),
360360
cat(), etc.), and the let()s in the eventual print2() calls will
361361
deallocate and possibly corrupt helpCmd. So, we grab a non-temporarily
@@ -1142,7 +1142,7 @@ H("GIF format unless ALT_HTML was previously set as shown in SHOW SETTINGS.");
11421142
H("");
11431143

11441144

1145-
let(&saveHelpCmd, ""); /* Deallocate memory */
1145+
free_vstring(saveHelpCmd); /* Deallocate memory */
11461146
return;
11471147

11481148
} /* help1 */

src/mmhlpb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
void help2(vstring helpCmd)
1919
{
2020

21-
vstring saveHelpCmd = "";
21+
vstring_def(saveHelpCmd);
2222
/* help2() may be called with a temporarily allocated argument (left(),
2323
cat(), etc.), and the let()s in the eventual print2() calls will
2424
deallocate and possibly corrupt helpCmd. So, we grab a non-temporarily
@@ -348,7 +348,7 @@ H(" statements are excluded when <label-match> contains wildcard");
348348
H(" characters.");
349349
H("");
350350

351-
let(&saveHelpCmd, ""); /* Deallocate memory */
351+
free_vstring(saveHelpCmd); /* Deallocate memory */
352352

353353
return;
354354
} /* help2 */
@@ -357,7 +357,7 @@ return;
357357
/* Split up help2 into help2 and help3 so lcc optimizer wouldn't overflow */
358358
void help3(vstring helpCmd) {
359359

360-
vstring saveHelpCmd = "";
360+
vstring_def(saveHelpCmd);
361361
/* help3() may be called with a temporarily allocated argument (left(),
362362
cat(), etc.), and the let()s in the eventual print2() calls will
363363
deallocate and possibly corrupt helpCmd. So, we grab a non-temporarily
@@ -1398,6 +1398,6 @@ H("will show all statements with subset then union in them.");
13981398
H("");
13991399

14001400
if (strcmp(helpCmd, saveHelpCmd)) bug(1401); /* helpCmd got corrupted */
1401-
let(&saveHelpCmd, ""); /* Deallocate memory */
1401+
free_vstring(saveHelpCmd); /* Deallocate memory */
14021402

14031403
}

0 commit comments

Comments
 (0)