]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blobdiff - Plugin.xs
Don't mix declarations and code
[perl/modules/re-engine-Plugin.git] / Plugin.xs
index d64951ea73016f3fcdc3a5dec3d0404c43246b0a..10562b280736b66a659d6bb5fca734a029c65da3 100644 (file)
--- a/Plugin.xs
+++ b/Plugin.xs
 
 #define REP_HAS_PERL(R, V, S) (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S))))))
 
-#undef ENTERn
-#if defined(ENTER_with_name) && !REP_HAS_PERL(5, 11, 4)
-# define ENTERn(N) ENTER_with_name(N)
-#else
-# define ENTERn(N) ENTER
-#endif
-
-#undef LEAVEn
-#if defined(LEAVE_with_name) && !REP_HAS_PERL(5, 11, 4)
-# define LEAVEn(N) LEAVE_with_name(N)
-#else
-# define LEAVEn(N) LEAVE
-#endif
-
 #ifndef REP_WORKAROUND_REQUIRE_PROPAGATION
 # define REP_WORKAROUND_REQUIRE_PROPAGATION !REP_HAS_PERL(5, 10, 1)
 #endif
@@ -150,21 +136,12 @@ STATIC void rep_ptable_clone(pTHX_ ptable_ent *ent, void *ud_) {
  ptable_store(ud->tbl, ent->key, h2);
 }
 
-STATIC void rep_thread_cleanup(pTHX_ void *);
+#include "reap.h"
 
 STATIC void rep_thread_cleanup(pTHX_ void *ud) {
- int *level = ud;
-
- if (*level) {
-  *level = 0;
-  LEAVE;
-  SAVEDESTRUCTOR_X(rep_thread_cleanup, level);
-  ENTER;
- } else {
-  dMY_CXT;
-  PerlMemShared_free(level);
-  ptable_free(MY_CXT.tbl);
- }
+ dMY_CXT;
+
+ ptable_free(MY_CXT.tbl);
 }
 
 #endif /* REP_THREADSAFE */
@@ -249,12 +226,17 @@ STATIC const rep_hint_t *rep_hint(pTHX) {
 #define rep_hint() rep_hint(aTHX)
  SV *hint;
 
+#ifdef cop_hints_fetch_pvn
+ hint = cop_hints_fetch_pvn(PL_curcop,
+                            __PACKAGE__, __PACKAGE_LEN__, rep_hash, 0);
+#else
  /* We already require 5.9.5 for the regexp engine API. */
  hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash,
                                        NULL,
                                        __PACKAGE__, __PACKAGE_LEN__,
                                        0,
                                        rep_hash);
+#endif
 
  return rep_detag(hint);
 }
@@ -269,20 +251,24 @@ Plugin_comp(pTHX_ SV * const pattern, U32 flags)
     dSP;
     struct regexp * rx;
     REGEXP *RX;
-    I32 buffers;
+
     re__engine__Plugin re;
     const rep_hint_t *h;
 
+    STRLEN plen;
+    char *pbuf;
+
+    SV *obj;
+
     h = rep_hint();
     if (!h) /* This looks like a pragma leak. Apply the default behaviour */
         return re_compile(pattern, flags);
 
     /* exp/xend version of the pattern & length */
-    STRLEN plen;
-    char*  exp = SvPV((SV*)pattern, plen);
+    pbuf = SvPV((SV*)pattern, plen);
 
     /* Our blessed object */
-    SV *obj = newSV(0);
+    obj = newSV(0);
     SvREFCNT_inc(obj);
     Newxz(re, 1, struct replug);
     sv_setref_pv(obj, "re::engine::Plugin", (void*)re);
@@ -300,7 +286,7 @@ Plugin_comp(pTHX_ SV * const pattern, U32 flags)
 
     /* Precompiled pattern for pp_regcomp to use */
     rx->prelen = plen;
-    rx->precomp = savepvn(exp, rx->prelen);
+    rx->precomp = savepvn(pbuf, rx->prelen);
 
     /* Set up qr// stringification to be equivalent to the supplied
      * pattern, this should be done via overload eventually.
@@ -322,7 +308,7 @@ Plugin_comp(pTHX_ SV * const pattern, U32 flags)
      * in between */
     if (h->exec) {
         re->cb_exec = h->exec;
-       SvREFCNT_inc_simple_void_NN(h->exec);
+        SvREFCNT_inc_simple_void_NN(h->exec);
     }
 
     re->cb_num_capture_buff_FETCH  = NULL;
@@ -350,9 +336,7 @@ Plugin_comp(pTHX_ SV * const pattern, U32 flags)
      * update the regexp struct with the new info.
      */
 
-    buffers = rx->nparens;
-
-    Newxz(rx->offs, buffers + 1, regexp_paren_pair);
+    Newxz(rx->offs, rx->nparens + 1, regexp_paren_pair);
 
     return RX;
 }
@@ -367,6 +351,8 @@ Plugin_exec(pTHX_ REGEXP * const RX, char *stringarg, char *strend,
     GET_SELF_FROM_PPRIVATE(rx->pprivate);
 
     if (self->cb_exec) {
+        SV *ret;
+
         /* Store the current str for ->str */
         self->str = (SV*)sv;
         SvREFCNT_inc(self->str);
@@ -383,8 +369,7 @@ Plugin_exec(pTHX_ REGEXP * const RX, char *stringarg, char *strend,
  
         SPAGAIN;
 
-        SV * ret = POPs;
-
+        ret = POPs;
         if (SvTRUE(ret))
             matched = 1;
         else
@@ -495,9 +480,10 @@ Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const RX, const I32 paren,
         items = call_sv(callback, G_SCALAR);
         
         if (items == 1) {
-            SPAGAIN;
+            SV *ret;
 
-            SV * ret = POPs;
+            SPAGAIN;
+            ret = POPs;
             sv_setsv(sv, ret);
         } else {
             sv_setsv(sv, &PL_sv_undef);
@@ -552,6 +538,8 @@ Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const RX, const SV * const sv,
     callback = self->cb_num_capture_buff_LENGTH;
 
     if (callback) {
+        IV ret;
+
         ENTER;
         SAVETMPS;
    
@@ -564,7 +552,7 @@ Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const RX, const SV * const sv,
 
         SPAGAIN;
 
-        IV ret = POPi;
+        ret = POPi;
 
         PUTBACK;
         FREETMPS;
@@ -638,7 +626,7 @@ STATIC U32 rep_booted = 0;
 
 /* --- XS ------------------------------------------------------------------ */
 
-MODULE = re::engine::Plugin    PACKAGE = re::engine::Plugin
+MODULE = re::engine::Plugin       PACKAGE = re::engine::Plugin
 
 PROTOTYPES: DISABLE
 
@@ -657,29 +645,23 @@ void
 CLONE(...)
 PREINIT:
     ptable *t;
-    int    *level;
-CODE:
-    {
-       my_cxt_t ud;
-       dMY_CXT;
-       ud.tbl   = t = ptable_new();
-       ud.owner = MY_CXT.owner;
-       ptable_walk(MY_CXT.tbl, rep_ptable_clone, &ud);
-    }
+PPCODE:
     {
-       MY_CXT_CLONE;
-       MY_CXT.tbl   = t;
-       MY_CXT.owner = aTHX;
+        my_cxt_t ud;
+        dMY_CXT;
+        ud.tbl   = t = ptable_new();
+        ud.owner = MY_CXT.owner;
+        ptable_walk(MY_CXT.tbl, rep_ptable_clone, &ud);
     }
     {
-       level = PerlMemShared_malloc(sizeof *level);
-       *level = 1;
-       LEAVEn("sub");
-       SAVEDESTRUCTOR_X(rep_thread_cleanup, level);
-       ENTERn("sub");
+        MY_CXT_CLONE;
+        MY_CXT.tbl   = t;
+        MY_CXT.owner = aTHX;
     }
+    reap(3, rep_thread_cleanup, NULL);
+    XSRETURN(0);
 
-#endif
+#endif /* REP_THREADSAFE */
 
 void
 pattern(re::engine::Plugin self, ...)