Skip to content

Conversation

@carenas
Copy link
Contributor

@carenas carenas commented Aug 6, 2025

would allow something like:

re = pcre2_compile(...);
can_jit = !pcre2_jit_compile(re, PCRE2_JIT_TEST_ALLOC);
md = pcre2_match_data_create_from_pattern(re, ...);
if (re != NULL && md != NULL) do {
  /* do some work here, including matches and maybe even some on demand JIT compilation */
} while (!done_matching_or_replacing)
/* do some cleanup here, no need to check for NULL when calling the corresponding `_free()` functions */

which matches a similar construct that uses pcre2_match_data_create() instead.

Copy link
Collaborator

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@NWilson NWilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose I can see why someone may want to do this, and it never hurts to add a null-check to make the behaviour defined. OK!

Prevents crashing in that case, and matches how other API calls handle
bad parameters.

It is also useful to simplify error checking in the caller side, as it
allows delaying checks for compiler failure and handling it together with
a match data creation failure.
@carenas carenas changed the title pcre2_match_data: allow pcre2_match_data_create_from_pattern(NULL, cx) pcre2_match_data: allow pcre2_match_data_create_from_pattern() with a NULL as the first parameter Aug 10, 2025
@NWilson NWilson merged commit c66e1a5 into PCRE2Project:master Aug 11, 2025
31 of 32 checks passed
@carenas carenas deleted the databort branch August 11, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants