dlangBugzillaToGithub / migration_test

0 stars 0 forks source link

regex purity issues #1058

Open dlangBugzillaToGithub opened 7 years ago

dlangBugzillaToGithub commented 7 years ago

braddr (braddr) reported this on 2017-05-27T07:30:09Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=17442

CC List

Description

At least two of the functions in std.regex that ought to be usable in a pure context aren't.  I suspect there's a broader issue with that subsystem, but haven't investigated.

---------
module bugregex;

string unifyNewLine(string str) pure
{
    import std.regex;

    return std.regex.replace(str, regex(`\r
|\r|
`, "g"), "
");
}
---------

$ dmd -c -ofbugregex.o bugregex.d
bugregex.d(7): Error: pure function 'bugregex.unifyNewLine' cannot call impure function 'std.regex.regex!string.regex'
bugregex.d(7): Error: pure function 'bugregex.unifyNewLine' cannot call impure function 'std.regex.replace!(match, string, char, Regex!char).replace'
dlangBugzillaToGithub commented 7 years ago

uplink.coder commented on 2017-05-29T02:06:34Z

The reason for this is that regex calls malloc
dlangBugzillaToGithub commented 7 years ago

braddr commented on 2017-05-29T02:25:15Z

That's a tiny tip of a much larger iceberg.