PCRE2_SET_COMPILE_RECURSION_GUARD(3)

πŸ’… PCRE2_SET_COMPILE_RECURSION_GUARD(3) πŸ’…

okay so this icon is from the Library Functions Manual β€” the header even squishes the title into PCRE2_SET_...RSION_GUARD(3), iykyk πŸ’€. It’s the PCRE2 page, and PCRE2 means Perl-compatible regular expressions (revised API). bestie, it’s giving low-level regex setup with main character energy ✨.


🌸 NAME 🌸

PCRE2 - Perl-compatible regular expressions (revised API) πŸ¦‹

✨ SYNOPSIS ✨

#include <pcre2.h>

int pcre2_set_compile_recursion_guard(pcre2_compile_context *ccontext,
  int (*guard_function)(uint32_t, void *), void *user_data);

πŸ’– DESCRIPTION πŸ’–

okay so pcre2_set_compile_recursion_guard() defines, inside a compile context, a function that gets called whenever pcre2_compile() starts to compile a parenthesized part of a pattern. literally every time it dives into a parenthesized chunk, your little guard function gets the invite πŸ’Œ.

The first argument to that function gives the current depth of parenthesis nesting. The second is user data that you supplied when the function was set up. The callout function should return zero if all is well, or non-zero to force an error. no cap, that’s the whole vibe check: zero = we’re good, non-zero = nope, error time πŸ”₯.

This feature is provided so applications can check the available system stack space, in order to avoid running out. extremely useful, because stack overflow is not the cute kind of overflow 🫠. The result of pcre2_set_compile_recursion_guard() is always zero. periodt.

There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the pcre2posix page. go read those if you want the full lore πŸ“š.


bestie reminder: this page is about setting up the guard callback in a compile context, not about writing the regex itself. keep the signature exactly as shown and let the function do its thing πŸ’….

✨ cute sign-off: PCRE2 10.47 β€’ 26 November 2014 β€’ PCRE2_SET_COMPILE_RECURSION_GUARD(3) ✨

πŸ“¦ where this page comes from