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

allow user to provide regex object storage #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

marler8997
Copy link

@marler8997 marler8997 commented Mar 5, 2021

I've added a new function re_compile_to that takes a pointer to an array of objects and characters. This allows a user to specify their own storage for their regex objects. This way a user can compile multiple regex objects and keep them around if they so choose. At the same time this also means that the user will need to know the value of MAX_REGEXP_OBJECTS and MAX_CHAR_CLASSLEN, so I made those configurable by putting them inside their own #ifdefs. This way a user can customize them with -DMAX_REGEXP_OBJECTS=XXX and -DMAX_CHAR_CLASS_LEN=YYY.

Note that if #62 is accepted, this we won't need to expose the regex_t struct in re.h. So maybe we should decide on #62 first?

I've added a new function re_compile_to that takes a pointer to an array of objects and characters.  This allows a user to specify their own storage for their regex objects. This way a user can compile multiple regex objects and keep them around if they so choose.  At the same time this also means that the user will need to know the value of MAX_REGEXP_OBJECTS and MAX_CHAR_CLASSLEN, so I made those configurable by putting them inside their own "#ifdef"s.  This way a user can customize them with -DMAX_REGEXP_OBJECTS=XXX and -DMAX_CHAR_CLASS_LEN=YYY.
@marler8997
Copy link
Author

marler8997 commented Mar 5, 2021

shoot I just realized this won't work because the user doesn't have access to the definition of regex_t, so they can't create an array of them

EDIT: I added a 2nd commit to make this work by moving the definition of regex_t into re.h.

If the user is to provide their own storage for regex_t, they need to know it's size.
@marler8997
Copy link
Author

I've added a 2nd commit that moves the definition of regex_t into re.h. This way the user knows the size of the regex_t so it can manage its own storage of them.

@marler8997
Copy link
Author

If this is accepted, one more addition I would suggest is a way to query the size of a compiled regex. This way, one could compile a regex, then afterward check how many objects and characters is is using, then allocate the exact storage required and re-compile them into the new storage location.

@skyformat99
Copy link

good

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.

2 participants