Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API functions for regex global pos magic #22971

Open
wants to merge 4 commits into
base: blead
Choose a base branch
from

Conversation

leonerd
Copy link
Contributor

@leonerd leonerd commented Feb 3, 2025

This PR adds a set of API functions for XS to see or modify any pos() magic position on an SV.

While reviewing some of my modules' more internals-hackery uses of the MAGIC API, I found a place where I have to reach deep into innards of how PERL_MAGIC_regexp_global works, in order to see or manipulate the pos() position annotation on a string SV. See this XS function:
https://metacpan.org/release/PEVANS/Term-TermKey-0.17/source/lib/Term/TermKey.xs#L713

This makes the code very tightly dependent on exact details of how Perl's magic currently works.

By adding these API functions (which can be easily emulated by earlier perls), the XS code can now be made much more robust against inner changes that may later affect how Perl implements this.

I'm not super convinced by the naming prefix on these - sv_regexp_global_pos_... might be considered rather too long. Will take suggestions on better ideas.

  • This set of changes requires a perldelta entry, and I haven't yet written it. I'll do so before merge.

@leonerd leonerd added the squash-before-merge Author must squash the commits down before merging to blead label Feb 3, 2025
@leonerd
Copy link
Contributor Author

leonerd commented Feb 3, 2025

Will also take ideas on whether some kind of flag should be provided to request operating by byte counts instead of character counts.

Ugh, actually as soon as I go to actually try out using this new API in my module mentioned above, I find that module specifically wants to operate in byte counts, rather than character counts.

I guess some kind of flag is warranted there then after all. I will think on this tomorrow.

@leonerd leonerd force-pushed the regex_global_pos-API branch from 40db8e6 to b125b8b Compare February 4, 2025 13:22
@leonerd
Copy link
Contributor Author

leonerd commented Feb 4, 2025

Now with (ab)use of SV_CATBYTES flag to request counting in bytes rather than chars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squash-before-merge Author must squash the commits down before merging to blead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant