Merge ~info-martin-konrad/epics-base:fix-substitution-file-expansion into ~epics-core/epics-base/+git/epics-base:3.15
- Git
- lp:~info-martin-konrad/epics-base
- fix-substitution-file-expansion
- Merge into 3.15
Status: | Merged |
---|---|
Merged at revision: | 59cb5ba6a0f66461e1b0efea28699046d44a7a8b |
Proposed branch: | ~info-martin-konrad/epics-base:fix-substitution-file-expansion |
Merge into: | ~epics-core/epics-base/+git/epics-base:3.15 |
Diff against target: |
531 lines (+109/-92) 9 files modified
src/ioc/dbtemplate/Makefile (+1/-1) src/ioc/dbtemplate/msi.cpp (+71/-90) src/ioc/dbtemplate/test/msi.plt (+7/-1) src/ioc/dbtemplate/test/t10-result.txt (+4/-0) src/ioc/dbtemplate/test/t10-substitute.txt (+8/-0) src/ioc/dbtemplate/test/t10-template.txt (+2/-0) src/ioc/dbtemplate/test/t11-result.txt (+4/-0) src/ioc/dbtemplate/test/t11-substitute.txt (+10/-0) src/ioc/dbtemplate/test/t11-template.txt (+2/-0) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andrew Johnson | Pending | ||
Review via email: mp+361500@code.launchpad.net |
Commit message
Description of the change
Fix https:/
It's way too easy to goof these kind of things up when doing manual memory management. By converting MSI to C++ I'm trying to start some improvements with regards to this. I have a bunch of other clean up changes we can look at once this issue is fixed (see https:/
mdavidsaver (mdavidsaver) wrote : | # |
Martin Konrad (info-martin-konrad) wrote : | # |
I have created a MP for my clean-up-msi branch: https:/
Andrew Johnson (anj) wrote : | # |
Martin, please clarify which of your two MRs should be merged, we think we're okay with fixing these bugs.
Martin Konrad (info-martin-konrad) wrote : | # |
This one only fixes the immediate problem I ran into. https:/
Preview Diff
1 | diff --git a/src/ioc/dbtemplate/Makefile b/src/ioc/dbtemplate/Makefile | |||
2 | index 2aa5a0c..13b4f11 100644 | |||
3 | --- a/src/ioc/dbtemplate/Makefile | |||
4 | +++ b/src/ioc/dbtemplate/Makefile | |||
5 | @@ -13,7 +13,7 @@ SRC_DIRS += $(IOCDIR)/dbtemplate | |||
6 | 13 | 13 | ||
7 | 14 | PROD_HOST += msi | 14 | PROD_HOST += msi |
8 | 15 | 15 | ||
10 | 16 | msi_SRCS = msi.c | 16 | msi_SRCS = msi.cpp |
11 | 17 | msi_LIBS += Com | 17 | msi_LIBS += Com |
12 | 18 | HTMLS += msi.html | 18 | HTMLS += msi.html |
13 | 19 | 19 | ||
14 | diff --git a/src/ioc/dbtemplate/msi.c b/src/ioc/dbtemplate/msi.cpp | |||
15 | 20 | similarity index 80% | 20 | similarity index 80% |
16 | 21 | rename from src/ioc/dbtemplate/msi.c | 21 | rename from src/ioc/dbtemplate/msi.c |
17 | 22 | rename to src/ioc/dbtemplate/msi.cpp | 22 | rename to src/ioc/dbtemplate/msi.cpp |
18 | index 69680e1..9a370e8 100644 | |||
19 | --- a/src/ioc/dbtemplate/msi.c | |||
20 | +++ b/src/ioc/dbtemplate/msi.cpp | |||
21 | @@ -9,6 +9,8 @@ | |||
22 | 9 | 9 | ||
23 | 10 | /* msi - macro substitutions and include */ | 10 | /* msi - macro substitutions and include */ |
24 | 11 | 11 | ||
25 | 12 | #include <string> | ||
26 | 13 | |||
27 | 12 | #include <stdlib.h> | 14 | #include <stdlib.h> |
28 | 13 | #include <stddef.h> | 15 | #include <stddef.h> |
29 | 14 | #include <stdio.h> | 16 | #include <stdio.h> |
30 | @@ -56,28 +58,31 @@ int din = 0; | |||
31 | 56 | typedef struct inputData inputData; | 58 | typedef struct inputData inputData; |
32 | 57 | 59 | ||
33 | 58 | static void inputConstruct(inputData **ppvt); | 60 | static void inputConstruct(inputData **ppvt); |
40 | 59 | static void inputDestruct(inputData *pvt); | 61 | static void inputDestruct(inputData * const pvt); |
41 | 60 | static void inputAddPath(inputData *pvt, char *pval); | 62 | static void inputAddPath(inputData * const pvt, const char * const pval); |
42 | 61 | static void inputBegin(inputData *pvt, char *fileName); | 63 | static void inputBegin(inputData * const pvt, const char * const fileName); |
43 | 62 | static char *inputNextLine(inputData *pvt); | 64 | static char *inputNextLine(inputData * const pvt); |
44 | 63 | static void inputNewIncludeFile(inputData *pvt, char *name); | 65 | static void inputNewIncludeFile(inputData * const pvt, const char * const name); |
45 | 64 | static void inputErrPrint(inputData *pvt); | 66 | static void inputErrPrint(const inputData * const pvt); |
46 | 65 | 67 | ||
47 | 66 | /* Module to read the substitution file */ | 68 | /* Module to read the substitution file */ |
48 | 67 | typedef struct subInfo subInfo; | 69 | typedef struct subInfo subInfo; |
49 | 68 | 70 | ||
56 | 69 | static void substituteOpen(subInfo **ppvt, char *substitutionName); | 71 | static void substituteOpen(subInfo **ppvt, char * const substitutionName); |
57 | 70 | static void substituteDestruct(subInfo *pvt); | 72 | static void substituteDestruct(subInfo * const pvt); |
58 | 71 | static int substituteGetNextSet(subInfo *pvt, char **filename); | 73 | static int substituteGetNextSet(subInfo * const pvt, char **filename); |
59 | 72 | static int substituteGetGlobalSet(subInfo *pvt); | 74 | static int substituteGetGlobalSet(subInfo * const pvt); |
60 | 73 | static char *substituteGetReplacements(subInfo *pvt); | 75 | static const char *substituteGetReplacements(subInfo * const pvt); |
61 | 74 | static char *substituteGetGlobalReplacements(subInfo *pvt); | 76 | static const char *substituteGetGlobalReplacements(subInfo * const pvt); |
62 | 75 | 77 | ||
63 | 76 | /* Forward references to local routines */ | 78 | /* Forward references to local routines */ |
68 | 77 | static void usageExit(int status); | 79 | static void usageExit(const int status); |
69 | 78 | static void abortExit(int status); | 80 | static void abortExit(const int status); |
70 | 79 | static void addMacroReplacements(MAC_HANDLE *macPvt, char *pval); | 81 | static void addMacroReplacements(MAC_HANDLE * const macPvt, |
71 | 80 | static void makeSubstitutions(inputData *inputPvt, MAC_HANDLE *macPvt, char *templateName); | 82 | const char * const pval); |
72 | 83 | static void makeSubstitutions(inputData * const inputPvt, | ||
73 | 84 | MAC_HANDLE * const macPvt, | ||
74 | 85 | const char * const templateName); | ||
75 | 81 | 86 | ||
76 | 82 | /*Global variables */ | 87 | /*Global variables */ |
77 | 83 | static int opt_V = 0; | 88 | static int opt_V = 0; |
78 | @@ -180,9 +185,9 @@ int main(int argc,char **argv) | |||
79 | 180 | isGlobal = substituteGetGlobalSet(substitutePvt); | 185 | isGlobal = substituteGetGlobalSet(substitutePvt); |
80 | 181 | if (isGlobal) { | 186 | if (isGlobal) { |
81 | 182 | STEP("Handling global macros"); | 187 | STEP("Handling global macros"); |
85 | 183 | pval = substituteGetGlobalReplacements(substitutePvt); | 188 | const char *macStr = substituteGetGlobalReplacements(substitutePvt); |
86 | 184 | if (pval) | 189 | if (macStr) |
87 | 185 | addMacroReplacements(macPvt, pval); | 190 | addMacroReplacements(macPvt, macStr); |
88 | 186 | } | 191 | } |
89 | 187 | else if ((isFile = substituteGetNextSet(substitutePvt, &filename))) { | 192 | else if ((isFile = substituteGetNextSet(substitutePvt, &filename))) { |
90 | 188 | if (templateName) | 193 | if (templateName) |
91 | @@ -193,11 +198,12 @@ int main(int argc,char **argv) | |||
92 | 193 | } | 198 | } |
93 | 194 | 199 | ||
94 | 195 | STEPS("Handling template file", filename); | 200 | STEPS("Handling template file", filename); |
96 | 196 | while ((pval = substituteGetReplacements(substitutePvt))) { | 201 | const char *macStr; |
97 | 202 | while ((macStr = substituteGetReplacements(substitutePvt))) { | ||
98 | 197 | if (localScope) | 203 | if (localScope) |
99 | 198 | macPushScope(macPvt); | 204 | macPushScope(macPvt); |
100 | 199 | 205 | ||
102 | 200 | addMacroReplacements(macPvt, pval); | 206 | addMacroReplacements(macPvt, macStr); |
103 | 201 | makeSubstitutions(inputPvt, macPvt, filename); | 207 | makeSubstitutions(inputPvt, macPvt, filename); |
104 | 202 | 208 | ||
105 | 203 | if (localScope) | 209 | if (localScope) |
106 | @@ -218,7 +224,7 @@ int main(int argc,char **argv) | |||
107 | 218 | return opt_V & 2; | 224 | return opt_V & 2; |
108 | 219 | } | 225 | } |
109 | 220 | 226 | ||
110 | 221 | 227 | ||
112 | 222 | void usageExit(int status) | 228 | void usageExit(const int status) |
113 | 223 | { | 229 | { |
114 | 224 | fprintf(stderr, | 230 | fprintf(stderr, |
115 | 225 | "Usage: msi [options] [template]\n" | 231 | "Usage: msi [options] [template]\n" |
116 | @@ -236,7 +242,7 @@ void usageExit(int status) | |||
117 | 236 | exit(status); | 242 | exit(status); |
118 | 237 | } | 243 | } |
119 | 238 | 244 | ||
121 | 239 | void abortExit(int status) | 245 | void abortExit(const int status) |
122 | 240 | { | 246 | { |
123 | 241 | if (outFile) { | 247 | if (outFile) { |
124 | 242 | fclose(stdout); | 248 | fclose(stdout); |
125 | @@ -245,7 +251,8 @@ void abortExit(int status) | |||
126 | 245 | exit(status); | 251 | exit(status); |
127 | 246 | } | 252 | } |
128 | 247 | 253 | ||
130 | 248 | static void addMacroReplacements(MAC_HANDLE *macPvt, char *pval) | 254 | static void addMacroReplacements(MAC_HANDLE * const macPvt, |
131 | 255 | const char * const pval) | ||
132 | 249 | { | 256 | { |
133 | 250 | char **pairs; | 257 | char **pairs; |
134 | 251 | long status; | 258 | long status; |
135 | @@ -268,7 +275,9 @@ static void addMacroReplacements(MAC_HANDLE *macPvt, char *pval) | |||
136 | 268 | typedef enum {cmdInclude,cmdSubstitute} cmdType; | 275 | typedef enum {cmdInclude,cmdSubstitute} cmdType; |
137 | 269 | static const char *cmdNames[] = {"include","substitute"}; | 276 | static const char *cmdNames[] = {"include","substitute"}; |
138 | 270 | 277 | ||
140 | 271 | static void makeSubstitutions(inputData *inputPvt, MAC_HANDLE *macPvt, char *templateName) | 278 | static void makeSubstitutions(inputData * const inputPvt, |
141 | 279 | MAC_HANDLE * const macPvt, | ||
142 | 280 | const char * const templateName) | ||
143 | 272 | { | 281 | { |
144 | 273 | char *input; | 282 | char *input; |
145 | 274 | static char buffer[MAX_BUFFER_SIZE]; | 283 | static char buffer[MAX_BUFFER_SIZE]; |
146 | @@ -325,7 +334,7 @@ static void makeSubstitutions(inputData *inputPvt, MAC_HANDLE *macPvt, char *tem | |||
147 | 325 | /*skip quote and any trailing blanks*/ | 334 | /*skip quote and any trailing blanks*/ |
148 | 326 | while (*++p == ' ') ; | 335 | while (*++p == ' ') ; |
149 | 327 | if (*p != '\n' && *p != 0) goto endcmd; | 336 | if (*p != '\n' && *p != 0) goto endcmd; |
151 | 328 | copy = calloc(pend-pstart + 1, sizeof(char)); | 337 | copy = static_cast<char *>(calloc(pend-pstart + 1, sizeof(char))); |
152 | 329 | strncpy(copy, pstart, pend-pstart); | 338 | strncpy(copy, pstart, pend-pstart); |
153 | 330 | 339 | ||
154 | 331 | switch(cmdind) { | 340 | switch(cmdind) { |
155 | @@ -378,7 +387,7 @@ struct inputData { | |||
156 | 378 | char inputBuffer[MAX_BUFFER_SIZE]; | 387 | char inputBuffer[MAX_BUFFER_SIZE]; |
157 | 379 | }; | 388 | }; |
158 | 380 | 389 | ||
160 | 381 | static void inputOpenFile(inputData *pinputData, char *filename); | 390 | static void inputOpenFile(inputData *pinputData, const char * const filename); |
161 | 382 | static void inputCloseFile(inputData *pinputData); | 391 | static void inputCloseFile(inputData *pinputData); |
162 | 383 | static void inputCloseAllFiles(inputData *pinputData); | 392 | static void inputCloseAllFiles(inputData *pinputData); |
163 | 384 | 393 | ||
164 | @@ -386,13 +395,13 @@ static void inputConstruct(inputData **ppvt) | |||
165 | 386 | { | 395 | { |
166 | 387 | inputData *pinputData; | 396 | inputData *pinputData; |
167 | 388 | 397 | ||
169 | 389 | pinputData = calloc(1, sizeof(inputData)); | 398 | pinputData = static_cast<inputData *>(calloc(1, sizeof(inputData))); |
170 | 390 | ellInit(&pinputData->inputFileList); | 399 | ellInit(&pinputData->inputFileList); |
171 | 391 | ellInit(&pinputData->pathList); | 400 | ellInit(&pinputData->pathList); |
172 | 392 | *ppvt = pinputData; | 401 | *ppvt = pinputData; |
173 | 393 | } | 402 | } |
174 | 394 | 403 | ||
176 | 395 | static void inputDestruct(inputData *pinputData) | 404 | static void inputDestruct(inputData * const pinputData) |
177 | 396 | { | 405 | { |
178 | 397 | pathNode *ppathNode; | 406 | pathNode *ppathNode; |
179 | 398 | 407 | ||
180 | @@ -405,7 +414,7 @@ static void inputDestruct(inputData *pinputData) | |||
181 | 405 | free(pinputData); | 414 | free(pinputData); |
182 | 406 | } | 415 | } |
183 | 407 | 416 | ||
184 | 408 | 417 | ||
186 | 409 | static void inputAddPath(inputData *pinputData, char *path) | 418 | static void inputAddPath(inputData * const pinputData, const char * const path) |
187 | 410 | { | 419 | { |
188 | 411 | ELLLIST *ppathList = &pinputData->pathList; | 420 | ELLLIST *ppathList = &pinputData->pathList; |
189 | 412 | pathNode *ppathNode; | 421 | pathNode *ppathNode; |
190 | @@ -448,7 +457,7 @@ static void inputAddPath(inputData *pinputData, char *path) | |||
191 | 448 | EXIT; | 457 | EXIT; |
192 | 449 | } | 458 | } |
193 | 450 | 459 | ||
194 | 451 | 460 | ||
196 | 452 | static void inputBegin(inputData *pinputData, char *fileName) | 461 | static void inputBegin(inputData * const pinputData, const char * const fileName) |
197 | 453 | { | 462 | { |
198 | 454 | ENTER; | 463 | ENTER; |
199 | 455 | inputCloseAllFiles(pinputData); | 464 | inputCloseAllFiles(pinputData); |
200 | @@ -456,7 +465,7 @@ static void inputBegin(inputData *pinputData, char *fileName) | |||
201 | 456 | EXIT; | 465 | EXIT; |
202 | 457 | } | 466 | } |
203 | 458 | 467 | ||
205 | 459 | static char *inputNextLine(inputData *pinputData) | 468 | static char *inputNextLine(inputData * const pinputData) |
206 | 460 | { | 469 | { |
207 | 461 | inputFile *pinputFile; | 470 | inputFile *pinputFile; |
208 | 462 | char *pline; | 471 | char *pline; |
209 | @@ -475,14 +484,15 @@ static char *inputNextLine(inputData *pinputData) | |||
210 | 475 | return 0; | 484 | return 0; |
211 | 476 | } | 485 | } |
212 | 477 | 486 | ||
214 | 478 | static void inputNewIncludeFile(inputData *pinputData, char *name) | 487 | static void inputNewIncludeFile(inputData * const pinputData, |
215 | 488 | const char * const name) | ||
216 | 479 | { | 489 | { |
217 | 480 | ENTER; | 490 | ENTER; |
218 | 481 | inputOpenFile(pinputData,name); | 491 | inputOpenFile(pinputData,name); |
219 | 482 | EXIT; | 492 | EXIT; |
220 | 483 | } | 493 | } |
221 | 484 | 494 | ||
223 | 485 | static void inputErrPrint(inputData *pinputData) | 495 | static void inputErrPrint(const inputData *const pinputData) |
224 | 486 | { | 496 | { |
225 | 487 | inputFile *pinputFile; | 497 | inputFile *pinputFile; |
226 | 488 | 498 | ||
227 | @@ -511,7 +521,7 @@ static void inputErrPrint(inputData *pinputData) | |||
228 | 511 | EXIT; | 521 | EXIT; |
229 | 512 | } | 522 | } |
230 | 513 | 523 | ||
231 | 514 | 524 | ||
233 | 515 | static void inputOpenFile(inputData *pinputData,char *filename) | 525 | static void inputOpenFile(inputData *pinputData, const char * const filename) |
234 | 516 | { | 526 | { |
235 | 517 | ELLLIST *ppathList = &pinputData->pathList; | 527 | ELLLIST *ppathList = &pinputData->pathList; |
236 | 518 | pathNode *ppathNode = 0; | 528 | pathNode *ppathNode = 0; |
237 | @@ -531,8 +541,8 @@ static void inputOpenFile(inputData *pinputData,char *filename) | |||
238 | 531 | else { | 541 | else { |
239 | 532 | ppathNode = (pathNode *) ellFirst(ppathList); | 542 | ppathNode = (pathNode *) ellFirst(ppathList); |
240 | 533 | while (ppathNode) { | 543 | while (ppathNode) { |
243 | 534 | fullname = calloc(strlen(filename) + strlen(ppathNode->directory) + 2, | 544 | fullname = static_cast<char *>(calloc(strlen(filename) + strlen(ppathNode->directory) + 2, |
244 | 535 | sizeof(char)); | 545 | sizeof(char))); |
245 | 536 | strcpy(fullname, ppathNode->directory); | 546 | strcpy(fullname, ppathNode->directory); |
246 | 537 | strcat(fullname, "/"); | 547 | strcat(fullname, "/"); |
247 | 538 | strcat(fullname, filename); | 548 | strcat(fullname, filename); |
248 | @@ -552,7 +562,7 @@ static void inputOpenFile(inputData *pinputData,char *filename) | |||
249 | 552 | } | 562 | } |
250 | 553 | 563 | ||
251 | 554 | STEP("File opened"); | 564 | STEP("File opened"); |
253 | 555 | pinputFile = calloc(1, sizeof(inputFile)); | 565 | pinputFile = static_cast<inputFile *>(calloc(1, sizeof(inputFile))); |
254 | 556 | 566 | ||
255 | 557 | if (ppathNode) { | 567 | if (ppathNode) { |
256 | 558 | pinputFile->filename = fullname; | 568 | pinputFile->filename = fullname; |
257 | @@ -647,14 +657,13 @@ struct subInfo { | |||
258 | 647 | char *filename; | 657 | char *filename; |
259 | 648 | int isPattern; | 658 | int isPattern; |
260 | 649 | ELLLIST patternList; | 659 | ELLLIST patternList; |
264 | 650 | size_t size; | 660 | std::string macroReplacements; |
265 | 651 | size_t curLength; | 661 | subInfo() : psubFile(NULL), isFile(0), filename(NULL), isPattern(0) {}; |
263 | 652 | char *macroReplacements; | ||
266 | 653 | }; | 662 | }; |
267 | 654 | 663 | ||
268 | 655 | static char *subGetNextLine(subFile *psubFile); | 664 | static char *subGetNextLine(subFile *psubFile); |
269 | 656 | static tokenType subGetNextToken(subFile *psubFile); | 665 | static tokenType subGetNextToken(subFile *psubFile); |
271 | 657 | static void subFileErrPrint(subFile *psubFile,char * message); | 666 | static void subFileErrPrint(subFile *psubFile, const char * message); |
272 | 658 | static void freeSubFile(subInfo *psubInfo); | 667 | static void freeSubFile(subInfo *psubInfo); |
273 | 659 | static void freePattern(subInfo *psubInfo); | 668 | static void freePattern(subInfo *psubInfo); |
274 | 660 | static void catMacroReplacements(subInfo *psubInfo,const char *value); | 669 | static void catMacroReplacements(subInfo *psubInfo,const char *value); |
275 | @@ -688,25 +697,25 @@ void freePattern(subInfo *psubInfo) | |||
276 | 688 | EXIT; | 697 | EXIT; |
277 | 689 | } | 698 | } |
278 | 690 | 699 | ||
279 | 691 | 700 | ||
281 | 692 | static void substituteDestruct(subInfo *psubInfo) | 701 | static void substituteDestruct(subInfo * const psubInfo) |
282 | 693 | { | 702 | { |
283 | 694 | ENTER; | 703 | ENTER; |
284 | 695 | freeSubFile(psubInfo); | 704 | freeSubFile(psubInfo); |
285 | 696 | freePattern(psubInfo); | 705 | freePattern(psubInfo); |
287 | 697 | free(psubInfo); | 706 | delete(psubInfo); |
288 | 698 | EXIT; | 707 | EXIT; |
289 | 699 | } | 708 | } |
290 | 700 | 709 | ||
292 | 701 | static void substituteOpen(subInfo **ppvt, char *substitutionName) | 710 | static void substituteOpen(subInfo **ppvt, char * const substitutionName) |
293 | 702 | { | 711 | { |
294 | 703 | subInfo *psubInfo; | 712 | subInfo *psubInfo; |
295 | 704 | subFile *psubFile; | 713 | subFile *psubFile; |
296 | 705 | FILE *fp; | 714 | FILE *fp; |
297 | 706 | 715 | ||
298 | 707 | ENTER; | 716 | ENTER; |
300 | 708 | psubInfo = calloc(1, sizeof(subInfo)); | 717 | psubInfo = new subInfo; |
301 | 709 | *ppvt = psubInfo; | 718 | *ppvt = psubInfo; |
303 | 710 | psubFile = calloc(1, sizeof(subFile)); | 719 | psubFile = static_cast<subFile *>(calloc(1, sizeof(subFile))); |
304 | 711 | psubInfo->psubFile = psubFile; | 720 | psubInfo->psubFile = psubFile; |
305 | 712 | ellInit(&psubInfo->patternList); | 721 | ellInit(&psubInfo->patternList); |
306 | 713 | 722 | ||
307 | @@ -725,7 +734,7 @@ static void substituteOpen(subInfo **ppvt, char *substitutionName) | |||
308 | 725 | EXIT; | 734 | EXIT; |
309 | 726 | } | 735 | } |
310 | 727 | 736 | ||
312 | 728 | static int substituteGetGlobalSet(subInfo *psubInfo) | 737 | static int substituteGetGlobalSet(subInfo * const psubInfo) |
313 | 729 | { | 738 | { |
314 | 730 | subFile *psubFile = psubInfo->psubFile; | 739 | subFile *psubFile = psubInfo->psubFile; |
315 | 731 | 740 | ||
316 | @@ -744,7 +753,7 @@ static int substituteGetGlobalSet(subInfo *psubInfo) | |||
317 | 744 | return 0; | 753 | return 0; |
318 | 745 | } | 754 | } |
319 | 746 | 755 | ||
321 | 747 | static int substituteGetNextSet(subInfo *psubInfo,char **filename) | 756 | static int substituteGetNextSet(subInfo * const psubInfo,char **filename) |
322 | 748 | { | 757 | { |
323 | 749 | subFile *psubFile = psubInfo->psubFile; | 758 | subFile *psubFile = psubInfo->psubFile; |
324 | 750 | patternNode *ppatternNode; | 759 | patternNode *ppatternNode; |
325 | @@ -831,7 +840,7 @@ static int substituteGetNextSet(subInfo *psubInfo,char **filename) | |||
326 | 831 | if (psubFile->token != tokenString) | 840 | if (psubFile->token != tokenString) |
327 | 832 | break; | 841 | break; |
328 | 833 | 842 | ||
330 | 834 | ppatternNode = calloc(1, sizeof(patternNode)); | 843 | ppatternNode = static_cast<patternNode *>(calloc(1, sizeof(patternNode))); |
331 | 835 | ellAdd(&psubInfo->patternList, &ppatternNode->node); | 844 | ellAdd(&psubInfo->patternList, &ppatternNode->node); |
332 | 836 | ppatternNode->var = epicsStrDup(psubFile->string); | 845 | ppatternNode->var = epicsStrDup(psubFile->string); |
333 | 837 | } | 846 | } |
334 | @@ -846,14 +855,12 @@ static int substituteGetNextSet(subInfo *psubInfo,char **filename) | |||
335 | 846 | return 1; | 855 | return 1; |
336 | 847 | } | 856 | } |
337 | 848 | 857 | ||
338 | 849 | 858 | ||
340 | 850 | static char *substituteGetGlobalReplacements(subInfo *psubInfo) | 859 | static const char *substituteGetGlobalReplacements(subInfo * const psubInfo) |
341 | 851 | { | 860 | { |
342 | 852 | subFile *psubFile = psubInfo->psubFile; | 861 | subFile *psubFile = psubInfo->psubFile; |
343 | 853 | 862 | ||
344 | 854 | ENTER; | 863 | ENTER; |
348 | 855 | if (psubInfo->macroReplacements) | 864 | psubInfo->macroReplacements.clear(); |
346 | 856 | psubInfo->macroReplacements[0] = 0; | ||
347 | 857 | psubInfo->curLength = 0; | ||
349 | 858 | 865 | ||
350 | 859 | while (psubFile->token == tokenSeparator) | 866 | while (psubFile->token == tokenSeparator) |
351 | 860 | subGetNextToken(psubFile); | 867 | subGetNextToken(psubFile); |
352 | @@ -881,8 +888,8 @@ static char *substituteGetGlobalReplacements(subInfo *psubInfo) | |||
353 | 881 | switch(subGetNextToken(psubFile)) { | 888 | switch(subGetNextToken(psubFile)) { |
354 | 882 | case tokenRBrace: | 889 | case tokenRBrace: |
355 | 883 | subGetNextToken(psubFile); | 890 | subGetNextToken(psubFile); |
358 | 884 | EXITS(psubInfo->macroReplacements); | 891 | EXITS(psubInfo->macroReplacements.c_str()); |
359 | 885 | return psubInfo->macroReplacements; | 892 | return psubInfo->macroReplacements.c_str(); |
360 | 886 | 893 | ||
361 | 887 | case tokenSeparator: | 894 | case tokenSeparator: |
362 | 888 | catMacroReplacements(psubInfo, ","); | 895 | catMacroReplacements(psubInfo, ","); |
363 | @@ -902,15 +909,13 @@ static char *substituteGetGlobalReplacements(subInfo *psubInfo) | |||
364 | 902 | } | 909 | } |
365 | 903 | } | 910 | } |
366 | 904 | 911 | ||
368 | 905 | static char *substituteGetReplacements(subInfo *psubInfo) | 912 | static const char *substituteGetReplacements(subInfo * const psubInfo) |
369 | 906 | { | 913 | { |
370 | 907 | subFile *psubFile = psubInfo->psubFile; | 914 | subFile *psubFile = psubInfo->psubFile; |
371 | 908 | patternNode *ppatternNode; | 915 | patternNode *ppatternNode; |
372 | 909 | 916 | ||
373 | 910 | ENTER; | 917 | ENTER; |
377 | 911 | if (psubInfo->macroReplacements) | 918 | psubInfo->macroReplacements.clear(); |
375 | 912 | psubInfo->macroReplacements[0] = 0; | ||
376 | 913 | psubInfo->curLength = 0; | ||
378 | 914 | 919 | ||
379 | 915 | while (psubFile->token == tokenSeparator) | 920 | while (psubFile->token == tokenSeparator) |
380 | 916 | subGetNextToken(psubFile); | 921 | subGetNextToken(psubFile); |
381 | @@ -943,8 +948,8 @@ static char *substituteGetReplacements(subInfo *psubInfo) | |||
382 | 943 | while (1) { | 948 | while (1) { |
383 | 944 | if (psubFile->token == tokenRBrace) { | 949 | if (psubFile->token == tokenRBrace) { |
384 | 945 | subGetNextToken(psubFile); | 950 | subGetNextToken(psubFile); |
387 | 946 | EXITS(psubInfo->macroReplacements); | 951 | EXITS(psubInfo->macroReplacements.c_str()); |
388 | 947 | return psubInfo->macroReplacements; | 952 | return psubInfo->macroReplacements.c_str(); |
389 | 948 | } | 953 | } |
390 | 949 | 954 | ||
391 | 950 | if (psubFile->token != tokenString) { | 955 | if (psubFile->token != tokenString) { |
392 | @@ -973,8 +978,8 @@ static char *substituteGetReplacements(subInfo *psubInfo) | |||
393 | 973 | switch(subGetNextToken(psubFile)) { | 978 | switch(subGetNextToken(psubFile)) { |
394 | 974 | case tokenRBrace: | 979 | case tokenRBrace: |
395 | 975 | subGetNextToken(psubFile); | 980 | subGetNextToken(psubFile); |
398 | 976 | EXITS(psubInfo->macroReplacements); | 981 | EXITS(psubInfo->macroReplacements.c_str()); |
399 | 977 | return psubInfo->macroReplacements; | 982 | return psubInfo->macroReplacements.c_str(); |
400 | 978 | 983 | ||
401 | 979 | case tokenSeparator: | 984 | case tokenSeparator: |
402 | 980 | catMacroReplacements(psubInfo, ","); | 985 | catMacroReplacements(psubInfo, ","); |
403 | @@ -1017,7 +1022,7 @@ static char *subGetNextLine(subFile *psubFile) | |||
404 | 1017 | return &psubFile->inputBuffer[0]; | 1022 | return &psubFile->inputBuffer[0]; |
405 | 1018 | } | 1023 | } |
406 | 1019 | 1024 | ||
408 | 1020 | static void subFileErrPrint(subFile *psubFile,char * message) | 1025 | static void subFileErrPrint(subFile *psubFile, const char * message) |
409 | 1021 | { | 1026 | { |
410 | 1022 | fprintf(stderr, "msi: %s\n",message); | 1027 | fprintf(stderr, "msi: %s\n",message); |
411 | 1023 | fprintf(stderr, " in substitution file '%s' at line %d:\n %s", | 1028 | fprintf(stderr, " in substitution file '%s' at line %d:\n %s", |
412 | @@ -1107,32 +1112,8 @@ done: | |||
413 | 1107 | 1112 | ||
414 | 1108 | static void catMacroReplacements(subInfo *psubInfo, const char *value) | 1113 | static void catMacroReplacements(subInfo *psubInfo, const char *value) |
415 | 1109 | { | 1114 | { |
416 | 1110 | size_t len = strlen(value); | ||
417 | 1111 | |||
418 | 1112 | ENTER; | 1115 | ENTER; |
419 | 1113 | if (psubInfo->size <= (psubInfo->curLength + len)) { | ||
420 | 1114 | size_t newsize = psubInfo->size + MAX_BUFFER_SIZE; | ||
421 | 1115 | char *newbuf; | ||
422 | 1116 | |||
423 | 1117 | STEP("Enlarging buffer"); | ||
424 | 1118 | if (newsize <= psubInfo->curLength + len) | ||
425 | 1119 | newsize = psubInfo->curLength + len + 1; | ||
426 | 1120 | newbuf = calloc(1, newsize); | ||
427 | 1121 | if (!newbuf) { | ||
428 | 1122 | fprintf(stderr, "calloc failed for size %lu\n", | ||
429 | 1123 | (unsigned long) newsize); | ||
430 | 1124 | abortExit(1); | ||
431 | 1125 | } | ||
432 | 1126 | if (psubInfo->macroReplacements) { | ||
433 | 1127 | memcpy(newbuf, psubInfo->macroReplacements, psubInfo->curLength); | ||
434 | 1128 | free(psubInfo->macroReplacements); | ||
435 | 1129 | } | ||
436 | 1130 | psubInfo->size = newsize; | ||
437 | 1131 | psubInfo->macroReplacements = newbuf; | ||
438 | 1132 | } | ||
439 | 1133 | |||
440 | 1134 | STEPS("Appending", value); | 1116 | STEPS("Appending", value); |
443 | 1135 | strcat(psubInfo->macroReplacements, value); | 1117 | psubInfo->macroReplacements += value; |
442 | 1136 | psubInfo->curLength += len; | ||
444 | 1137 | EXIT; | 1118 | EXIT; |
445 | 1138 | } | 1119 | } |
446 | diff --git a/src/ioc/dbtemplate/test/msi.plt b/src/ioc/dbtemplate/test/msi.plt | |||
447 | index 4149125..332defb 100644 | |||
448 | --- a/src/ioc/dbtemplate/test/msi.plt | |||
449 | +++ b/src/ioc/dbtemplate/test/msi.plt | |||
450 | @@ -11,7 +11,7 @@ | |||
451 | 11 | use strict; | 11 | use strict; |
452 | 12 | use Test; | 12 | use Test; |
453 | 13 | 13 | ||
455 | 14 | BEGIN {plan tests => 9} | 14 | BEGIN {plan tests => 11} |
456 | 15 | 15 | ||
457 | 16 | # Check include/substitute command model | 16 | # Check include/substitute command model |
458 | 17 | ok(msi('-I .. ../t1-template.txt'), slurp('../t1-result.txt')); | 17 | ok(msi('-I .. ../t1-template.txt'), slurp('../t1-result.txt')); |
459 | @@ -50,6 +50,12 @@ ok(msi('-I.. -D -o t8.txt ../t1-template.txt'), slurp('../t8-result.txt')); | |||
460 | 50 | # Dependency generation, dbLoadTemplate format | 50 | # Dependency generation, dbLoadTemplate format |
461 | 51 | ok(msi('-I.. -D -ot9.txt -S ../t2-substitution.txt'), slurp('../t9-result.txt')); | 51 | ok(msi('-I.. -D -ot9.txt -S ../t2-substitution.txt'), slurp('../t9-result.txt')); |
462 | 52 | 52 | ||
463 | 53 | # Substitution file, variable format, with 0 variable definitions | ||
464 | 54 | ok(msi('-I. -I.. -S ../t10-substitute.txt'), slurp('../t10-result.txt')); | ||
465 | 55 | |||
466 | 56 | # Substitution file, pattern format, with 0 pattern definitions | ||
467 | 57 | ok(msi('-I. -I.. -S ../t11-substitute.txt'), slurp('../t11-result.txt')); | ||
468 | 58 | |||
469 | 53 | 59 | ||
470 | 54 | # Test support routines | 60 | # Test support routines |
471 | 55 | 61 | ||
472 | diff --git a/src/ioc/dbtemplate/test/t10-result.txt b/src/ioc/dbtemplate/test/t10-result.txt | |||
473 | 56 | new file mode 100644 | 62 | new file mode 100644 |
474 | index 0000000..47b594e | |||
475 | --- /dev/null | |||
476 | +++ b/src/ioc/dbtemplate/test/t10-result.txt | |||
477 | @@ -0,0 +1,4 @@ | |||
478 | 1 | # comment line | ||
479 | 2 | a=$(a) | ||
480 | 3 | # comment line | ||
481 | 4 | a=gbl | ||
482 | diff --git a/src/ioc/dbtemplate/test/t10-substitute.txt b/src/ioc/dbtemplate/test/t10-substitute.txt | |||
483 | 0 | new file mode 100644 | 5 | new file mode 100644 |
484 | index 0000000..aec88bb | |||
485 | --- /dev/null | |||
486 | +++ b/src/ioc/dbtemplate/test/t10-substitute.txt | |||
487 | @@ -0,0 +1,8 @@ | |||
488 | 1 | file t10-template.txt { | ||
489 | 2 | {} | ||
490 | 3 | } | ||
491 | 4 | |||
492 | 5 | global { a=gbl } | ||
493 | 6 | file t10-template.txt { | ||
494 | 7 | {} | ||
495 | 8 | } | ||
496 | diff --git a/src/ioc/dbtemplate/test/t10-template.txt b/src/ioc/dbtemplate/test/t10-template.txt | |||
497 | 0 | new file mode 100644 | 9 | new file mode 100644 |
498 | index 0000000..7958885 | |||
499 | --- /dev/null | |||
500 | +++ b/src/ioc/dbtemplate/test/t10-template.txt | |||
501 | @@ -0,0 +1,2 @@ | |||
502 | 1 | # comment line | ||
503 | 2 | a=$(a) | ||
504 | diff --git a/src/ioc/dbtemplate/test/t11-result.txt b/src/ioc/dbtemplate/test/t11-result.txt | |||
505 | 0 | new file mode 100644 | 3 | new file mode 100644 |
506 | index 0000000..47b594e | |||
507 | --- /dev/null | |||
508 | +++ b/src/ioc/dbtemplate/test/t11-result.txt | |||
509 | @@ -0,0 +1,4 @@ | |||
510 | 1 | # comment line | ||
511 | 2 | a=$(a) | ||
512 | 3 | # comment line | ||
513 | 4 | a=gbl | ||
514 | diff --git a/src/ioc/dbtemplate/test/t11-substitute.txt b/src/ioc/dbtemplate/test/t11-substitute.txt | |||
515 | 0 | new file mode 100644 | 5 | new file mode 100644 |
516 | index 0000000..94dcdbc | |||
517 | --- /dev/null | |||
518 | +++ b/src/ioc/dbtemplate/test/t11-substitute.txt | |||
519 | @@ -0,0 +1,10 @@ | |||
520 | 1 | file t11-template.txt { | ||
521 | 2 | pattern {} | ||
522 | 3 | {} | ||
523 | 4 | } | ||
524 | 5 | |||
525 | 6 | global { a=gbl } | ||
526 | 7 | file t11-template.txt { | ||
527 | 8 | pattern {} | ||
528 | 9 | {} | ||
529 | 10 | } | ||
530 | diff --git a/src/ioc/dbtemplate/test/t11-template.txt b/src/ioc/dbtemplate/test/t11-template.txt | |||
531 | 0 | new file mode 100644 | 11 | new file mode 100644 |
532 | index 0000000..7958885 | |||
533 | --- /dev/null | |||
534 | +++ b/src/ioc/dbtemplate/test/t11-template.txt | |||
535 | @@ -0,0 +1,2 @@ | |||
536 | 1 | # comment line | ||
537 | 2 | a=$(a) |
Looking at the change in this MR I see a good start with a lot of work remaining. Looking at your clean-up-msi branch, I see that a lot of the remaining work is done there. If you don't want to fix the leak in the C code first, then I'd rather review all of the c++ conversion at once. The main points which make this c++ code (eg. ellLib -> std::list) are on the clean-up-msi branch.