X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fre-engine-Plugin.git;a=blobdiff_plain;f=Plugin.xs;h=2ebc28deebb9c3be4afe92773fcc1aaaec4efc23;hp=6d003d9c53272b2a9358d8633d31e052dc38796d;hb=08a530304d4173611ea49823baeb3ec158024630;hpb=dd88e700bfcc92fc03db9d994ec747ca1c14ade7 diff --git a/Plugin.xs b/Plugin.xs index 6d003d9..2ebc28d 100644 --- a/Plugin.xs +++ b/Plugin.xs @@ -44,13 +44,11 @@ Plugin_comp(pTHX_ const SV * const pattern, const U32 flags) dSP; REGEXP * rx; re__engine__Plugin re; - I32 count; I32 buffers; /* exp/xend version of the pattern & length */ STRLEN plen; char* exp = SvPV((SV*)pattern, plen); - char* xend = exp + plen; /* The REGEXP structure to return to perl */ Newxz(rx, 1, REGEXP); @@ -67,7 +65,7 @@ Plugin_comp(pTHX_ const SV * const pattern, const U32 flags) rx->extflags = flags; /* Flags for perl to use */ rx->engine = RE_ENGINE_PLUGIN; /* Compile to use this engine */ - /* Precompiled regexp for pp_regcomp to use */ + /* Precompiled pattern for pp_regcomp to use */ rx->prelen = plen; rx->precomp = savepvn(exp, rx->prelen); @@ -112,7 +110,7 @@ Plugin_comp(pTHX_ const SV * const pattern, const U32 flags) buffers = rx->nparens; - Newxz(rx->offs, buffers, regexp_paren_pair); + Newxz(rx->offs, buffers + 1, regexp_paren_pair); return rx; } @@ -210,12 +208,13 @@ Plugin_free(pTHX_ REGEXP * const rx) } void * -Plugin_dupe(pTHX_ const REGEXP * rx, CLONE_PARAMS *param) +Plugin_dupe(pTHX_ REGEXP * const rx, CLONE_PARAMS *param) { - Perl_croak("dupe not supported yet"); + Perl_croak(aTHX_ "dupe not supported yet"); return rx->pprivate; } + void Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const rx, const I32 paren, SV * const sv) @@ -260,7 +259,6 @@ Plugin_numbered_buff_STORE(pTHX_ REGEXP * const rx, const I32 paren, SV const * const value) { dSP; - I32 items; SV * callback; GET_SELF_FROM_PPRIVATE(rx->pprivate); @@ -289,7 +287,6 @@ Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const rx, const SV * const sv, const I32 paren) { dSP; - I32 items; SV * callback; GET_SELF_FROM_PPRIVATE(rx->pprivate); @@ -323,264 +320,17 @@ Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const rx, const SV * const sv, SV* -Plugin_named_buff_FETCH(pTHX_ REGEXP * const rx, SV * const key, U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_FETCH; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(key)); - XPUSHs(sv_2mortal(newSViv(flags & 1 ? 1 : 0))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV* ret = POPs; - SvREFCNT_inc(ret); - - PUTBACK; - FREETMPS; - LEAVE; - - return ret; - } else { - return NULL; - } -} - -void -Plugin_named_buff_STORE(pTHX_ REGEXP * const rx, SV * const key, - SV * const value, const U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_STORE; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(key)); - XPUSHs(SvREFCNT_inc(value)); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_DISCARD); - - PUTBACK; - FREETMPS; - LEAVE; - } -} - -void -Plugin_named_buff_DELETE(pTHX_ REGEXP * const rx, SV * const key, const U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_DELETE; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(key)); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_DISCARD); - - PUTBACK; - FREETMPS; - LEAVE; - } -} - -void -Plugin_named_buff_CLEAR(pTHX_ REGEXP * const rx, const U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_CLEAR; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_DISCARD); - - PUTBACK; - FREETMPS; - LEAVE; - } -} - -bool -Plugin_named_buff_EXISTS(pTHX_ REGEXP * const rx, SV * const key, - const U32 flags) -{ - dSP; - SV * callback; - bool truthiness = FALSE; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_EXISTS; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(key)); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV * ret = POPs; - truthiness = SvTRUE(ret); - - PUTBACK; - FREETMPS; - LEAVE; - } - - return truthiness; -} - -SV* -Plugin_named_buff_FIRSTKEY(pTHX_ REGEXP * const rx, const U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_FIRSTKEY; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV * ret = POPs; - SvREFCNT_inc(ret); - - PUTBACK; - FREETMPS; - LEAVE; - - return ret; - } else { - return NULL; - } -} - -SV* -Plugin_named_buff_NEXTKEY(pTHX_ REGEXP * const rx, SV * const lastkey, - const U32 flags) +Plugin_named_buff (pTHX_ REGEXP * const rx, SV * const key, SV * const value, + const U32 flags) { - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_NEXTKEY; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(lastkey)); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV * ret = POPs; - SvREFCNT_inc(ret); - - PUTBACK; - FREETMPS; - LEAVE; - - return ret; - } else { - return NULL; - } + return NULL; } SV* -Plugin_named_buff_SCALAR(pTHX_ REGEXP * const rx, const U32 flags) +Plugin_named_buff_iter (pTHX_ REGEXP * const rx, const SV * const lastkey, + const U32 flags) { - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_SCALAR; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV * ret = POPs; - SvREFCNT_inc(ret); - - PUTBACK; - FREETMPS; - LEAVE; - - return ret; - } else { - return NULL; - } + return NULL; } SV* @@ -603,7 +353,7 @@ str(re::engine::Plugin self, ...) PPCODE: XPUSHs(self->str); -void +char* mod(re::engine::Plugin self, ...) PPCODE: /* /i */ @@ -713,70 +463,6 @@ PPCODE: SvREFCNT_inc(self->cb_num_capture_buff_LENGTH); } -void -_named_capture_buff_FETCH(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_FETCH = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_FETCH); - } - -void -_named_capture_buff_STORE(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_STORE = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_STORE); - } - -void -_named_capture_buff_DELETE(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_DELETE = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_DELETE); - } - -void -_named_capture_buff_CLEAR(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_CLEAR = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_CLEAR); - } - -void -_named_capture_buff_EXISTS(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_EXISTS = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_EXISTS); - } - -void -_named_capture_buff_FIRSTKEY(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_FIRSTKEY = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_FIRSTKEY); - } - -void -_named_capture_buff_NEXTKEY(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_NEXTKEY = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_NEXTKEY); - } - -void -_named_capture_buff_SCALAR(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_SCALAR = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_SCALAR); - } - void ENGINE() PPCODE: