]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blobdiff - Plugin.xs
This is 0.12
[perl/modules/re-engine-Plugin.git] / Plugin.xs
index c16dfba3ed652bc61b82192036b858183fc49692..d75c0869a22602177a49fbb1568341eba5ddee82 100644 (file)
--- a/Plugin.xs
+++ b/Plugin.xs
@@ -192,17 +192,13 @@ Plugin_comp(pTHX_ SV * const pattern, U32 flags)
 Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
 #endif
 {
- dSP;
- struct regexp *rx;
- REGEXP *RX;
-
- re__engine__Plugin re;
  const xsh_hints_user_t *h;
-
+ REGEXP            *RX;
+ struct regexp     *rx;
+ re__engine__Plugin re;
+ char  *pbuf;
  STRLEN plen;
- char *pbuf;
-
- SV *obj;
+ SV    *obj;
 
  h = rep_hint();
  if (!h) /* This looks like a pragma leak. Apply the default behaviour */
@@ -213,7 +209,7 @@ Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
 
  /* Our blessed object */
  obj = newSV(0);
Newxz(re, 1, struct replug);
XSH_LOCAL_ALLOC(re, 1, struct replug);
  sv_setref_pv(obj, XSH_PACKAGE, (void *) re);
 
  newREGEXP(RX);
@@ -245,18 +241,17 @@ Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
  re->pattern  = (SV *) pattern;
  SvREFCNT_inc_simple_void(re->pattern);
 
- /* If there's an exec callback, store it into the private object so that it
-  * will be the one to be called, even if the engine changes in between */
- if (h->exec) {
-  re->cb_exec = h->exec;
-  SvREFCNT_inc_simple_void_NN(h->exec);
- }
+ re->str   = NULL;
+ re->stash = NULL;
 
- /* Same goes for the free callback, if there's one. */
- if (h->free) {
-  re->cb_free = h->free;
-  SvREFCNT_inc_simple_void_NN(h->free);
- }
+ /* Store the default exec callback (which may be NULL) into the regexp
+  * object. */
+ re->cb_exec = h->exec;
+ SvREFCNT_inc_simple_void(h->exec);
+
+ /* Same goes for the free callback. */
+ re->cb_free = h->free;
+ SvREFCNT_inc_simple_void(h->free);
 
  re->cb_num_capture_buff_FETCH  = NULL;
  re->cb_num_capture_buff_STORE  = NULL;
@@ -265,6 +260,8 @@ Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
  /* Call our callback function if one was defined, if not we've already set up
   * all the stuff we're going to to need for subsequent exec and other calls */
  if (h->comp) {
+  dSP;
+
   ENTER;
   SAVETMPS;
 
@@ -290,7 +287,7 @@ Plugin_exec(pTHX_ REGEXP * const RX, char *stringarg, char *strend,
             char *strbeg, REP_ENG_EXEC_MINEND_TYPE minend,
             SV *sv, void *data, U32 flags)
 {
- struct regexp *rx;
+ struct regexp     *rx;
  re__engine__Plugin self;
  I32 matched;
 
@@ -367,10 +364,9 @@ Plugin_checkstr(pTHX_ REGEXP * const RX)
 void
 Plugin_free(pTHX_ REGEXP * const RX)
 {
- struct regexp *rx;
+ struct regexp     *rx;
  re__engine__Plugin self;
  SV *callback;
- dSP;
 
  if (PL_dirty)
   return;
@@ -381,6 +377,8 @@ Plugin_free(pTHX_ REGEXP * const RX)
  callback = self->cb_free;
 
  if (callback) {
+  dSP;
+
   ENTER;
   SAVETMPS;
 
@@ -407,7 +405,7 @@ Plugin_free(pTHX_ REGEXP * const RX)
 
  self->rx = NULL;
 
Safefree(self);
XSH_LOCAL_FREE(self, 1, struct replug);
 
  SvREFCNT_dec(rx->pprivate);
 
@@ -429,7 +427,7 @@ void
 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const RX, const I32 paren,
                            SV * const sv)
 {
- struct regexp *rx;
+ struct regexp     *rx;
  re__engine__Plugin self;
  SV *callback;
 
@@ -447,7 +445,7 @@ Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const RX, const I32 paren,
 
   PUSHMARK(SP);
   XPUSHs(rx->pprivate);
-  XPUSHs(sv_2mortal(newSViv(paren)));
+  mXPUSHi(paren);
   PUTBACK;
 
   items = call_sv(callback, G_SCALAR);
@@ -473,7 +471,7 @@ void
 Plugin_numbered_buff_STORE(pTHX_ REGEXP * const RX, const I32 paren,
                            SV const * const value)
 {
- struct regexp *rx;
+ struct regexp     *rx;
  re__engine__Plugin self;
  SV *callback;
 
@@ -490,7 +488,7 @@ Plugin_numbered_buff_STORE(pTHX_ REGEXP * const RX, const I32 paren,
 
   PUSHMARK(SP);
   XPUSHs(rx->pprivate);
-  XPUSHs(sv_2mortal(newSViv(paren)));
+  mXPUSHi(paren);
   XPUSHs((SV *) value);
   PUTBACK;
 
@@ -506,7 +504,7 @@ I32
 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const RX, const SV * const sv,
                             const I32 paren)
 {
- struct regexp *rx;
+ struct regexp     *rx;
  re__engine__Plugin self;
  SV *callback;
 
@@ -524,7 +522,7 @@ Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const RX, const SV * const sv,
 
   PUSHMARK(SP);
   XPUSHs(rx->pprivate);
-  XPUSHs(sv_2mortal(newSViv(paren)));
+  mXPUSHi(paren);
   PUTBACK;
 
   call_sv(callback, G_SCALAR);
@@ -654,13 +652,11 @@ PPCODE:
  if (items > 1) {
   self->rx->minlen = (I32)SvIV(ST(1));
   XSRETURN_EMPTY;
- } else {
-  if (self->rx->minlen) {
-   XPUSHs(sv_2mortal(newSViv(self->rx->minlen)));
-  } else {
-   XPUSHs(sv_2mortal(&PL_sv_undef));
-  }
+ } else if (self->rx->minlen) {
+  mXPUSHi(self->rx->minlen);
   XSRETURN(1);
+ } else {
+  XSRETURN_UNDEF;
  }
 
 void
@@ -669,13 +665,11 @@ PPCODE:
  if (items > 1) {
   self->rx->gofs = (U32)SvIV(ST(1));
   XSRETURN_EMPTY;
- } else {
-  if (self->rx->gofs) {
-   XPUSHs(sv_2mortal(newSVuv(self->rx->gofs)));
-  } else {
-   XPUSHs(sv_2mortal(&PL_sv_undef));
-  }
+ } else if (self->rx->gofs) {
+  mXPUSHu(self->rx->gofs);
   XSRETURN(1);
+ } else {
+  XSRETURN_UNDEF;
  }
 
 void
@@ -684,13 +678,11 @@ PPCODE:
  if (items > 1) {
   self->rx->nparens = (U32)SvIV(ST(1));
   XSRETURN_EMPTY;
- } else {
-  if (self->rx->nparens) {
-   XPUSHs(sv_2mortal(newSVuv(self->rx->nparens)));
-  } else {
-   XPUSHs(sv_2mortal(&PL_sv_undef));
-  }
+ } else if (self->rx->nparens) {
+  mXPUSHu(self->rx->nparens);
   XSRETURN(1);
+ } else {
+  XSRETURN_UNDEF;
  }
 
 void
@@ -758,5 +750,5 @@ OUTPUT:
 void
 ENGINE()
 PPCODE:
XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));
mXPUSHi(PTR2IV(&engine_plugin));
  XSRETURN(1);