"No more memory" when using PCRE2CompilerMBS

I’m getting an exception

for the following code on Monterey:

RegexCompiler = new PCRE2CompilerMBS
RegexCompiler.Pattern = "(\r|\n)+\s+"
RegexCompiler.Dotall = True
RegexCompiler.Greedy = True
RegexCompiler.NewLine = RegexCompiler.kNewLineAny

RegexCode = RegexCompiler.Compile
RegexCode.SubstituteGlobal = True
RegexCode.JITCompile(RegexCode.kJITComplete)

RegexMatch = new PCRE2MatchDataMBS(RegexCode)

How do I give the PCRE more memory?

Latest plugin?

Works fine here and I just added the dim lines:

Dim RegexCompiler As PCRE2CompilerMBS
Dim RegexCode As PCRE2CodeMBS
Dim RegexMatch As PCRE2MatchDataMBS

RegexCompiler = New PCRE2CompilerMBS
RegexCompiler.Pattern = "(\r|\n)+\s+"
RegexCompiler.Dotall = True
RegexCompiler.Greedy = True
RegexCompiler.NewLine = RegexCompiler.kNewLineAny

RegexCode = RegexCompiler.Compile
RegexCode.SubstituteGlobal = True
RegexCode.JITCompile(RegexCode.kJITComplete)

RegexMatch = New PCRE2MatchDataMBS(RegexCode)

Break

But I see we have a crash in StartPosition for the uninitialized match data. I’ll fix that.

Yup. Latest plugin beta. I’ve tested mostly on High Sierra where I don’t get the crash. But the first test on Monterey gave me the exception. As I need to replace all text StartPosition is 0.

Well, feel free to pass me a sample project.

I haven’t managed to do an example. The app works fine on High Sierra. For Monterey I get the exception for both Intel and ARM. With the line

RegexCode.JITCompile(RegexCode.kJITComplete)

commented out the code works fine. But I really want the JIT. A simple example works fine. I use shared properties in the class and everything is in a thread. I tried to increase the stack size of the thread but that didn’t make a difference.

Stange, but maybe it fails for some reason to compile for you.
Works fine here on two computers.

I did a bit of goggling. The StackOverflow topic at

suggests to increase the stack size of the PCRE. The exception really only can be stack size related. The documentation has JITSize but the property is read-only.

Stack Size would be something else.
I may add a property to configure it.

But no idea why you would exceed the default stack limit with that expression.

I’ll add a SetStackSize function, but I think the JIT compiler may just fail to compile the function.
Maybe you could put a try around, so you run it without JIT, if the JIT compiler can’t compile it?

Some patterns don’t work for JIT, so the regular interpreter does it.

Of course, I have to add the try/catch for the PCREException.

Well, something must be different between High Sierra/Monterey on one side and a simple example and a full app on the other side. The pattern is about the most simple that I have. I had planned to convert more RegexMBS to the new PCRE classes.

I’ve tested other search patterns and they all result in the same exception:

RegexCompiler.Pattern = "[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,60}"
RegexCompiler.Pattern = "\b(https?://|www\.)([^<>\s]+)"
RegexCompiler.Pattern = "^(>+)(.*)"
RegexCompiler.Pattern = "[^\x{0009}\x{000A}\x{000D}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFF}]+"

What am I supposed to do with the new SetStackSize? The exception shows up for PCRE2CodeMBS and not for PCRE2MatchDataMBS.

The JitSize for PCRE2CodeMBS is 0. Even though I downloaded the latest beta there is no SetStackSize for PCRE2MatchDataMBS.

Well, the stack for JIT only is used when running the code, not for compiling.
If JITSize is zero, then you have no compiled version.
It still runs in interpreter mode.

I tried your code. All five expressions compile here and stop at the break without exception.

The new method can’t do any thing (even if it existed) because it’s after the exception. As I said above a simple example works fine. But this doesn’t help me anything if the code doesn’t work in my app.

I’ll try to reproduce the crash in an example in the next days.

I’d appreciate an example to reproduce.