p |OP* |refkids |NULLOK OP* o|I32 type
Ap |void |regdump |NN const regexp* r
Ap |SV* |regclass_swash |NULLOK const regexp *prog|NN const struct regnode *n|bool doinit|NULLOK SV **listsvp|NULLOK SV **altsvp
-Ap |I32 |pregexec |NN regexp* prog|NN char* stringarg \
+Ap |I32 |pregexec |NN REGEXP * const prog|NN char* stringarg \
|NN char* strend|NN char* strbeg|I32 minend \
|NN SV* screamer|U32 nosave
Ap |void |pregfree |NULLOK struct regexp* r
Ap |void |regfree_internal|NULLOK struct regexp* r
Ap |char * |reg_stringify |NN MAGIC *mg|NULLOK STRLEN *lp|NULLOK U32 *flags|NULLOK I32 *haseval
#if defined(USE_ITHREADS)
-Ap |void* |regdupe_internal|NN const regexp* r|NN CLONE_PARAMS* param
+Ap |void* |regdupe_internal|NN REGEXP * const r|NN CLONE_PARAMS* param
#endif
Ap |REGEXP*|pregcomp |NN const SV * const pattern|const U32 flags
Ap |REGEXP*|re_compile |NN const SV * const pattern|const U32 flags
-Ap |char* |re_intuit_start|NN regexp* prog|NULLOK SV* sv|NN char* strpos \
- |NN char* strend|U32 flags \
+Ap |char* |re_intuit_start|NN REGEXP * const rx|NULLOK SV* sv|NN char* strpos \
+ |NN char* strend|const U32 flags \
|NULLOK struct re_scream_pos_data_s *data
-Ap |SV* |re_intuit_string|NN regexp* prog
-Ap |I32 |regexec_flags |NN regexp* prog|NN char* stringarg \
+Ap |SV* |re_intuit_string|NN REGEXP * const rx
+Ap |I32 |regexec_flags |NN REGEXP * const rx|NN char* stringarg \
|NN char* strend|NN char* strbeg|I32 minend \
|NN SV* screamer|NULLOK void* data|U32 flags
ApR |regnode*|regnext |NN regnode* p
-EXp |SV*|reg_named_buff_get |NN const REGEXP * const rx|NN SV* namesv|U32 flags
-EXp |SV*|reg_numbered_buff_get|NN const REGEXP * const rx|I32 paren|NULLOK SV* usesv
-EXp |SV*|reg_qr_pkg|NN const REGEXP * const rx
+EXp |SV*|reg_named_buff_get |NN REGEXP * const rx|NN SV * const namesv|const U32 flags
+EXp |void|reg_numbered_buff_get|NN REGEXP * const rx|const I32 paren|NULLOK SV * const usesv
+EXp |SV*|reg_qr_package|NN REGEXP * const rx
Ep |void |regprop |NULLOK const regexp *prog|NN SV* sv|NN const regnode* o
Ap |void |repeatcpy |NN char* to|NN const char* from|I32 len|I32 count
#if defined(PERL_CORE) || defined(PERL_EXT)
#define reg_named_buff_get Perl_reg_named_buff_get
#define reg_numbered_buff_get Perl_reg_numbered_buff_get
-#define reg_qr_pkg Perl_reg_qr_pkg
+#define reg_qr_package Perl_reg_qr_package
#endif
#if defined(PERL_CORE) || defined(PERL_EXT)
#define regprop Perl_regprop
#if defined(PERL_CORE) || defined(PERL_EXT)
#define reg_named_buff_get(a,b,c) Perl_reg_named_buff_get(aTHX_ a,b,c)
#define reg_numbered_buff_get(a,b,c) Perl_reg_numbered_buff_get(aTHX_ a,b,c)
-#define reg_qr_pkg(a) Perl_reg_qr_pkg(aTHX_ a)
+#define reg_qr_package(a) Perl_reg_qr_package(aTHX_ a)
#endif
#if defined(PERL_CORE) || defined(PERL_EXT)
#define regprop(a,b,c) Perl_regprop(aTHX_ a,b,c)
START_EXTERN_C
-extern regexp* my_re_compile (pTHX_ const SV * const pattern, const U32 flags);
-extern I32 my_regexec (pTHX_ regexp* prog, char* stringarg, char* strend,
+extern REGEXP* my_re_compile (pTHX_ const SV * const pattern, U32 pm_flags);
+extern I32 my_regexec (pTHX_ REGEXP * const prog, char* stringarg, char* strend,
char* strbeg, I32 minend, SV* screamer,
void* data, U32 flags);
-extern char* my_re_intuit_start (pTHX_ regexp *prog, SV *sv, char *strpos,
+extern char* my_re_intuit_start (pTHX_ REGEXP * const prog, SV *sv, char *strpos,
char *strend, U32 flags,
struct re_scream_pos_data_s *data);
-extern SV* my_re_intuit_string (pTHX_ regexp *prog);
-
-extern void my_regfree (pTHX_ struct regexp* r);
-extern SV* my_reg_numbered_buff_get(pTHX_ const REGEXP * const rx, I32 paren, SV* usesv);
-extern SV* my_reg_named_buff_get(pTHX_ const REGEXP * const rx, SV* namesv, U32 flags);
-extern SV* my_reg_qr_pkg(pTHX_ const REGEXP * const rx);
+extern SV* my_re_intuit_string (pTHX_ REGEXP * const prog);
+
+extern void my_regfree (pTHX_ REGEXP * const r);
+extern void my_reg_numbered_buff_get(pTHX_ REGEXP * const rx, const I32 paren,
+ SV * const usesv);
+extern SV* my_reg_named_buff_get(pTHX_ REGEXP * const rx, SV * const namesv,
+ const U32 flags);
+extern SV* my_reg_qr_package(pTHX_ REGEXP * const rx);
#if defined(USE_ITHREADS)
-extern void* my_regdupe (pTHX_ const regexp *r, CLONE_PARAMS *param);
+extern void* my_regdupe (pTHX_ REGEXP * const r, CLONE_PARAMS *param);
#endif
EXTERN_C const struct regexp_engine my_reg_engine;
my_regfree,
my_reg_numbered_buff_get,
my_reg_named_buff_get,
- my_reg_qr_pkg,
+ my_reg_qr_package,
#if defined(USE_ITHREADS)
my_regdupe
#endif
};
-regexp *
+REGEXP *
get_re_arg( pTHX_ SV *sv, U32 flags, MAGIC **mgp) {
MAGIC *mg;
if (sv) {
(mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
{
if (mgp) *mgp = mg;
- return (regexp *)mg->mg_obj;
+ return (REGEXP *)mg->mg_obj;
}
}
if (mgp) *mgp = NULL;
PROTOTYPE: $
PREINIT:
MAGIC *mg;
- regexp *re;
+ REGEXP *re;
PPCODE:
{
/*
SV * sv
PROTOTYPE: $
PREINIT:
- regexp *re;
+ REGEXP *re;
PPCODE:
{
if ( re = get_re_arg( aTHX_ sv, 0, 0) ) /* assign deliberate */
#define Perl_regdupe_internal my_regdupe
#define Perl_reg_numbered_buff_get my_reg_numbered_buff_get
#define Perl_reg_named_buff_get my_reg_named_buff_get
-#define Perl_reg_qr_pkg my_reg_qr_pkg
+#define Perl_reg_qr_package my_reg_qr_package
#define PERL_NO_GET_CONTEXT
Perl_regnext
Perl_reg_named_buff_get
Perl_reg_numbered_buff_get
-Perl_reg_qr_pkg
+Perl_reg_qr_package
Perl_repeatcpy
Perl_rninstr
Perl_rsignal
#define CALLREG_NAMEDBUF(rx,name,flags) \
CALL_FPTR((rx)->engine->named_buff_get)(aTHX_ (rx),(name),(flags))
-#define CALLREG_QRPKG(rx) \
- CALL_FPTR((rx)->engine->qr_pkg)(aTHX_ (rx))
+#define CALLREG_PACKAGE(rx) \
+ CALL_FPTR((rx)->engine->qr_package)(aTHX_ (rx))
#if defined(USE_ITHREADS)
#define CALLREGDUPE(prog,param) \
typedef struct regexp_engine {
REGEXP* (*comp) (pTHX_ const SV * const pattern, const U32 flags);
- I32 (*exec) (pTHX_ regexp* prog, char* stringarg, char* strend,
- char* strbeg, I32 minend, SV* screamer,
- void* data, U32 flags);
- char* (*intuit) (pTHX_ regexp *prog, SV *sv, char *strpos,
- char *strend, U32 flags,
- struct re_scream_pos_data_s *data);
- SV* (*checkstr) (pTHX_ regexp *prog);
- void (*free) (pTHX_ struct regexp* r);
- SV* (*numbered_buff_get) (pTHX_ const REGEXP * const rx, I32 paren, SV* usesv);
- SV* (*named_buff_get)(pTHX_ const REGEXP * const rx, SV* namesv, U32 flags);
- SV* (*qr_pkg)(pTHX_ const REGEXP * const rx);
+ I32 (*exec) (pTHX_ REGEXP * const rx, char* stringarg, char* strend,
+ char* strbeg, I32 minend, SV* screamer,
+ void* data, U32 flags);
+ char* (*intuit) (pTHX_ REGEXP * const rx, SV *sv, char *strpos,
+ char *strend, U32 flags,
+ struct re_scream_pos_data_s *data);
+ SV* (*checkstr) (pTHX_ REGEXP * const rx);
+ void (*free) (pTHX_ REGEXP * const rx);
+ void (*numbered_buff_get) (pTHX_ REGEXP * const rx,
+ const I32 paren, SV * const usesv);
+ SV* (*named_buff_get)(pTHX_ REGEXP * const rx, SV * const namesv,
+ const U32 flags);
+ SV* (*qr_package)(pTHX_ REGEXP * const rx);
#ifdef USE_ITHREADS
- void* (*dupe) (pTHX_ const regexp *r, CLONE_PARAMS *param);
+ void* (*dupe) (pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
#endif
} regexp_engine;
=item RXf_PMf_KEEPCOPY
-The C</k> flag.
+The C</p> flag.
=item RXf_UTF8
=head2 exec
- I32 exec(regexp* prog,
+ I32 exec(pTHX_ REGEXP * const rx,
char *stringarg, char* strend, char* strbeg,
I32 minend, SV* screamer,
void* data, U32 flags);
=head2 intuit
- char* intuit( regexp *prog,
+ char* intuit(pTHX_ REGEXP * const rx,
SV *sv, char *strpos, char *strend,
- U32 flags, struct re_scream_pos_data_s *data);
+ const U32 flags, struct re_scream_pos_data_s *data);
Find the start position where a regex match should be attempted,
or possibly whether the regex engine should not be run because the
=head2 checkstr
- SV* checkstr(regexp *prog);
+ SV* checkstr(pTHX_ REGEXP * const rx);
Return a SV containing a string that must appear in the pattern. Used
by C<split> for optimising matches.
=head2 free
- void free(regexp *prog);
+ void free(pTHX_ REGEXP * const rx);
Called by perl when it is freeing a regexp pattern so that the engine
can release any resources pointed to by the C<pprivate> member of the
=head2 numbered_buff_get
- SV* numbered_buff_get(pTHX_ const REGEXP * const rx, I32 paren, SV* usesv);
+ void numbered_buff_get(pTHX_ REGEXP * const rx, const I32 paren,
+ SV * const usesv);
-TODO: document
+Called to get the value of C<$`>, C<$'>, C<$&> (and their named
+equivalents, see L<perlvar>) and the numbered capture buffers (C<$1>,
+C<$2>, ...).
+
+The C<paren> paramater will be C<-2> for C<$`>, C<-1> for C<$'>, C<0>
+for C<$&>, C<1> for C<$1> and so forth.
+
+C<usesv> should be set to the scalar to return, the scalar is passed
+as an argument rather than being returned from the function because
+when it's called perl already has a scalar to store the value,
+creating another one would be redundant. The scalar can be set with
+C<sv_setsv>, C<sv_setpvn> and friends, see L<perlapi>.
+
+This callback is where perl untaints its own capture variables under
+taint mode (see L<perlsec>). See the C<Perl_reg_numbered_buff_get>
+function in F<regcomp.c> for how to untaint capture variables if
+that's something you'd like your engine to do as well.
=head2 named_buff_get
- SV* named_buff_get(pTHX_ const REGEXP * const rx, SV* namesv, U32 flags);
+ SV* named_buff_get(pTHX_ REGEXP * const rx, SV * const namesv,
+ const U32 flags);
-TODO: document
+Called to get the value of key in the C<%+> and C<%-> hashes,
+C<namesv> is the hash key being requested and if C<flags & 1> is true
+C<%-> is being requested (and C<%+> if it's not).
-=head2 qr_pkg
+=head2 qr_package
- SV* qr_pkg(pTHX_ const REGEXP * const rx);
+ SV* qr_package(pTHX_ REGEXP * const rx);
The package the qr// magic object is blessed into (as seen by C<ref
-qr//>). It is recommended that engines change this to its package
-name, for instance:
+qr//>). It is recommended that engines change this to their package
+name for identification regardless of whether they implement methods
+on the object.
+
+A callback implementation might be:
SV*
- Example_reg_qr_pkg(pTHX_ const REGEXP * const rx)
+ Example_reg_qr_package(pTHX_ REGEXP * const rx)
{
PERL_UNUSED_ARG(rx);
return newSVpvs("re::engine::Example");
=head2 dupe
- void* dupe(const regexp *r, CLONE_PARAMS *param);
+ void* dupe(pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
On threaded builds a regexp may need to be duplicated so that the pattern
can be used by mutiple threads. This routine is expected to handle the
Fast-Boyer-Moore searches on the string to find out if its worth using
the regex engine at all, and if so where in the string to search.
-=item C<startp>, C<endp>
-
-These fields store arrays that are used to hold the offsets of the begining
-and end of each capture group that has matched. -1 is used to indicate no match.
-
-These are the source for @- and @+.
-
=item C<subbeg> C<sublen> C<saved_copy>
#define SAVEPVN(p,n) ((p) ? savepvn(p,n) : NULL)
dVAR; dSP;
register PMOP * const pm = cPMOP;
REGEXP * rx = PM_GETRE(pm);
- SV * const pkg = CALLREG_QRPKG(rx);
+ SV * const pkg = CALLREG_PACKAGE(rx);
SV * const rv = sv_newmortal();
SV * const sv = newSVrv(rv, SvPV_nolen(pkg));
if (rx->extflags & RXf_TAINTED)
PERL_CALLCONV SV* Perl_regclass_swash(pTHX_ const regexp *prog, const struct regnode *n, bool doinit, SV **listsvp, SV **altsvp)
__attribute__nonnull__(pTHX_2);
-PERL_CALLCONV I32 Perl_pregexec(pTHX_ regexp* prog, char* stringarg, char* strend, char* strbeg, I32 minend, SV* screamer, U32 nosave)
+PERL_CALLCONV I32 Perl_pregexec(pTHX_ REGEXP * const prog, char* stringarg, char* strend, char* strbeg, I32 minend, SV* screamer, U32 nosave)
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_2)
__attribute__nonnull__(pTHX_3)
__attribute__nonnull__(pTHX_1);
#if defined(USE_ITHREADS)
-PERL_CALLCONV void* Perl_regdupe_internal(pTHX_ const regexp* r, CLONE_PARAMS* param)
+PERL_CALLCONV void* Perl_regdupe_internal(pTHX_ REGEXP * const r, CLONE_PARAMS* param)
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_2);
PERL_CALLCONV REGEXP* Perl_re_compile(pTHX_ const SV * const pattern, const U32 flags)
__attribute__nonnull__(pTHX_1);
-PERL_CALLCONV char* Perl_re_intuit_start(pTHX_ regexp* prog, SV* sv, char* strpos, char* strend, U32 flags, struct re_scream_pos_data_s *data)
+PERL_CALLCONV char* Perl_re_intuit_start(pTHX_ REGEXP * const rx, SV* sv, char* strpos, char* strend, const U32 flags, struct re_scream_pos_data_s *data)
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_3)
__attribute__nonnull__(pTHX_4);
-PERL_CALLCONV SV* Perl_re_intuit_string(pTHX_ regexp* prog)
+PERL_CALLCONV SV* Perl_re_intuit_string(pTHX_ REGEXP * const rx)
__attribute__nonnull__(pTHX_1);
-PERL_CALLCONV I32 Perl_regexec_flags(pTHX_ regexp* prog, char* stringarg, char* strend, char* strbeg, I32 minend, SV* screamer, void* data, U32 flags)
+PERL_CALLCONV I32 Perl_regexec_flags(pTHX_ REGEXP * const rx, char* stringarg, char* strend, char* strbeg, I32 minend, SV* screamer, void* data, U32 flags)
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_2)
__attribute__nonnull__(pTHX_3)
__attribute__nonnull__(pTHX_1);
-PERL_CALLCONV SV* Perl_reg_named_buff_get(pTHX_ const REGEXP * const rx, SV* namesv, U32 flags)
+PERL_CALLCONV SV* Perl_reg_named_buff_get(pTHX_ REGEXP * const rx, SV * const namesv, const U32 flags)
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_2);
-PERL_CALLCONV SV* Perl_reg_numbered_buff_get(pTHX_ const REGEXP * const rx, I32 paren, SV* usesv)
+PERL_CALLCONV void Perl_reg_numbered_buff_get(pTHX_ REGEXP * const rx, const I32 paren, SV * const usesv)
__attribute__nonnull__(pTHX_1);
-PERL_CALLCONV SV* Perl_reg_qr_pkg(pTHX_ const REGEXP * const rx)
+PERL_CALLCONV SV* Perl_reg_qr_package(pTHX_ REGEXP * const rx)
__attribute__nonnull__(pTHX_1);
SV*
-Perl_reg_named_buff_get(pTHX_ const REGEXP * const rx, SV* namesv, U32 flags)
+Perl_reg_named_buff_get(pTHX_ REGEXP * const rx, SV * const namesv, const U32 flags)
{
AV *retarray = NULL;
SV *ret;
&& rx->offs[nums[i]].start != -1
&& rx->offs[nums[i]].end != -1)
{
- ret = CALLREG_NUMBUF(rx,nums[i],NULL);
+ ret = newSVpvs("");
+ CALLREG_NUMBUF(rx,nums[i],ret);
if (!retarray)
return ret;
} else {
return NULL;
}
-SV*
-Perl_reg_numbered_buff_get(pTHX_ const REGEXP * const rx, I32 paren, SV* usesv)
+void
+Perl_reg_numbered_buff_get(pTHX_ REGEXP * const rx, const I32 paren, SV * const sv)
{
char *s = NULL;
I32 i = 0;
I32 s1, t1;
- SV *sv = usesv ? usesv : newSVpvs("");
if (!rx->subbeg) {
sv_setsv(sv,&PL_sv_undef);
- return sv;
+ return;
}
else
if (paren == -2 && rx->offs[0].start != -1) {
s = rx->subbeg + s1;
} else {
sv_setsv(sv,&PL_sv_undef);
- return sv;
+ return;
}
assert(rx->sublen >= (s - rx->subbeg) + i );
if (i >= 0) {
}
} else {
sv_setsv(sv,&PL_sv_undef);
+ return;
}
- return sv;
}
SV*
-Perl_reg_qr_pkg(pTHX_ const REGEXP * const rx)
+Perl_reg_qr_package(pTHX_ REGEXP * const rx)
{
PERL_UNUSED_ARG(rx);
return newSVpvs("Regexp");
}
SV *
-Perl_re_intuit_string(pTHX_ regexp *prog)
+Perl_re_intuit_string(pTHX_ REGEXP * const prog)
{ /* Assume that RE_INTUIT is set */
dVAR;
GET_RE_DEBUG_FLAGS_DECL;
*/
void *
-Perl_regdupe_internal(pTHX_ const regexp *r, CLONE_PARAMS *param)
+Perl_regdupe_internal(pTHX_ REGEXP * const r, CLONE_PARAMS *param)
{
dVAR;
regexp_internal *reti;
Perl_regfree_internal,
Perl_reg_numbered_buff_get,
Perl_reg_named_buff_get,
- Perl_reg_qr_pkg,
+ Perl_reg_qr_package,
#if defined(USE_ITHREADS)
Perl_regdupe_internal
#endif
- pregexec - match a regexp against a string
*/
I32
-Perl_pregexec(pTHX_ register regexp *prog, char *stringarg, register char *strend,
+Perl_pregexec(pTHX_ REGEXP * const prog, char* stringarg, register char *strend,
char *strbeg, I32 minend, SV *screamer, U32 nosave)
/* strend: pointer to null at end of string */
/* strbeg: real beginning of string */
deleted from the finite automaton. */
char *
-Perl_re_intuit_start(pTHX_ regexp *prog, SV *sv, char *strpos,
+Perl_re_intuit_start(pTHX_ REGEXP * const prog, SV *sv, char *strpos,
char *strend, U32 flags, re_scream_pos_data *data)
{
dVAR;
- regexec_flags - match a regexp against a string
*/
I32
-Perl_regexec_flags(pTHX_ register regexp *prog, char *stringarg, register char *strend,
+Perl_regexec_flags(pTHX_ REGEXP * const prog, char *stringarg, register char *strend,
char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
/* strend: pointer to null at end of string */
/* strbeg: real beginning of string */
*/
typedef struct regexp_engine {
REGEXP* (*comp) (pTHX_ const SV * const pattern, const U32 flags);
- I32 (*exec) (pTHX_ regexp* prog, char* stringarg, char* strend,
- char* strbeg, I32 minend, SV* screamer,
- void* data, U32 flags);
- char* (*intuit) (pTHX_ regexp *prog, SV *sv, char *strpos,
- char *strend, U32 flags,
- struct re_scream_pos_data_s *data);
- SV* (*checkstr) (pTHX_ regexp *prog);
- void (*free) (pTHX_ struct regexp* r);
- SV* (*numbered_buff_get) (pTHX_ const REGEXP * const rx, I32 paren, SV* usesv);
- SV* (*named_buff_get)(pTHX_ const REGEXP * const rx, SV* namesv, U32 flags);
- SV* (*qr_pkg)(pTHX_ const REGEXP * const rx);
+ I32 (*exec) (pTHX_ REGEXP * const rx, char* stringarg, char* strend,
+ char* strbeg, I32 minend, SV* screamer,
+ void* data, U32 flags);
+ char* (*intuit) (pTHX_ REGEXP * const rx, SV *sv, char *strpos,
+ char *strend, U32 flags,
+ struct re_scream_pos_data_s *data);
+ SV* (*checkstr) (pTHX_ REGEXP * const rx);
+ void (*free) (pTHX_ REGEXP * const rx);
+ void (*numbered_buff_get) (pTHX_ REGEXP * const rx,
+ const I32 paren, SV * const usesv);
+ SV* (*named_buff_get)(pTHX_ REGEXP * const rx, SV * const namesv,
+ const U32 flags);
+ SV* (*qr_package)(pTHX_ REGEXP * const rx);
#ifdef USE_ITHREADS
- void* (*dupe) (pTHX_ const regexp *r, CLONE_PARAMS *param);
+ void* (*dupe) (pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
#endif
} regexp_engine;