Skip to content

Commit 7bc8a2b

Browse files
committed
Ensure that the regexp/regpat is cloned.
Fix crash reported when releasing MATCH filter in macros. Add corresponding regression test. Part of eng/toolchain/aws#39
1 parent 6f4e561 commit 7bc8a2b

File tree

7 files changed

+48
-0
lines changed

7 files changed

+48
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Test MATCH into a MACRO
3+
4+
5+
ONE
6+
TWO
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from test_support import *
2+
3+
run('testme', ["testme145.tmplt"])

regtests/tests/0145_regex_macro/test.yaml

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Test MATCH into a MACRO
3+
4+
@@MACRO(CHECK)@@
5+
@@IF@@ @_MATCH(.*value):VAR1_@
6+
@_$1_@
7+
@@ELSE@@
8+
FALSE
9+
@@END_IF@@
10+
@@END_MACRO@@
11+
12+
@_CHECK(ONE)_@
13+
@_CHECK(TWO)_@

src/templates_parser-data.adb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ package body Data is
642642
begin
643643
if R.Filters /= null then
644644
R.Filters := new Filter.Set'(R.Filters.all);
645+
646+
for K in R.Filters'Range loop
647+
R.Filters (K) := Filter.Clone (@);
648+
end loop;
645649
end if;
646650

647651
if R.Is_Macro then

src/templates_parser-filter.adb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,25 @@ package body Filter is
544544
return Result;
545545
end Clean_Text;
546546

547+
-----------
548+
-- Clone --
549+
-----------
550+
551+
function Clone (P : Routine) return Routine is
552+
D : Parameter_Data := P.Parameters;
553+
begin
554+
case D.Mode is
555+
when Regpat =>
556+
D.Regpat := new GNAT.Regpat.Pattern_Matcher'(D.Regpat.all);
557+
when Regexp =>
558+
D.Regexp := new GNAT.Regpat.Pattern_Matcher'(D.Regexp.all);
559+
when others =>
560+
null;
561+
end case;
562+
563+
return (P with delta Parameters => D);
564+
end Clone;
565+
547566
------------------
548567
-- Coma_2_Point --
549568
------------------

src/templates_parser.adb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ package body Templates_Parser is
365365
procedure Release (S : in out Set);
366366
-- Release all memory allocated P
367367

368+
function Clone (P : Routine) return Routine;
369+
-- Clone parameter data
370+
368371
type String_Access is access constant String;
369372

370373
type Filter_Record is record

0 commit comments

Comments
 (0)