]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - Plugin.xs
Only look up to the first require scope for the require propagation workaround
[perl/modules/re-engine-Plugin.git] / Plugin.xs
1 /* This file is part of the re::engine::Plugin Perl module.
2  * See http://search.cpan.org/dist/re-engine-Plugin/ */
3
4 #define PERL_NO_GET_CONTEXT
5 #include "EXTERN.h"
6 #include "perl.h"
7 #include "XSUB.h"
8
9 #include "Plugin.h"
10
11 #define __PACKAGE__     "re::engine::Plugin"
12 #define __PACKAGE_LEN__ (sizeof(__PACKAGE__)-1)
13
14 #define REP_HAS_PERL(R, V, S) (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S))))))
15
16 #ifndef REP_WORKAROUND_REQUIRE_PROPAGATION
17 # define REP_WORKAROUND_REQUIRE_PROPAGATION !REP_HAS_PERL(5, 10, 1)
18 #endif
19
20 /* ... Thread safety and multiplicity ...................................... */
21
22 #ifndef REP_MULTIPLICITY
23 # if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT)
24 #  define REP_MULTIPLICITY 1
25 # else
26 #  define REP_MULTIPLICITY 0
27 # endif
28 #endif
29 #if REP_MULTIPLICITY && !defined(tTHX)
30 # define tTHX PerlInterpreter*
31 #endif
32
33 #if REP_MULTIPLICITY && defined(USE_ITHREADS) && defined(dMY_CXT) && defined(MY_CXT) && defined(START_MY_CXT) && defined(MY_CXT_INIT) && (defined(MY_CXT_CLONE) || defined(dMY_CXT_SV))
34 # define REP_THREADSAFE 1
35 # ifndef MY_CXT_CLONE
36 #  define MY_CXT_CLONE \
37     dMY_CXT_SV;                                                      \
38     my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1)); \
39     Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t); \
40     sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
41 # endif
42 #else
43 # define REP_THREADSAFE 0
44 # undef  dMY_CXT
45 # define dMY_CXT      dNOOP
46 # undef  MY_CXT
47 # define MY_CXT       rep_globaldata
48 # undef  START_MY_CXT
49 # define START_MY_CXT STATIC my_cxt_t MY_CXT;
50 # undef  MY_CXT_INIT
51 # define MY_CXT_INIT  NOOP
52 # undef  MY_CXT_CLONE
53 # define MY_CXT_CLONE NOOP
54 #endif
55
56 /* --- Helpers ------------------------------------------------------------- */
57
58 /* ... Thread-safe hints ................................................... */
59
60 typedef struct {
61  SV *comp;
62  SV *exec;
63 #if REP_WORKAROUND_REQUIRE_PROPAGATION
64  IV  cxreq;
65 #endif
66 } rep_hint_t;
67
68 #if REP_THREADSAFE
69
70 #define PTABLE_VAL_FREE(V) { \
71  rep_hint_t *h = (V);        \
72  SvREFCNT_dec(h->comp);      \
73  SvREFCNT_dec(h->exec);      \
74  PerlMemShared_free(h);      \
75 }
76
77 #define pPTBL  pTHX
78 #define pPTBL_ pTHX_
79 #define aPTBL  aTHX
80 #define aPTBL_ aTHX_
81
82 #include "ptable.h"
83
84 #define ptable_store(T, K, V) ptable_store(aTHX_ (T), (K), (V))
85 #define ptable_free(T)        ptable_free(aTHX_ (T))
86
87 #define MY_CXT_KEY __PACKAGE__ "::_guts" XS_VERSION
88
89 typedef struct {
90  ptable *tbl;
91  tTHX    owner;
92 } my_cxt_t;
93
94 START_MY_CXT
95
96 STATIC SV *rep_clone(pTHX_ SV *sv, tTHX owner) {
97 #define rep_clone(S, O) rep_clone(aTHX_ (S), (O))
98  CLONE_PARAMS  param;
99  AV           *stashes = NULL;
100  SV           *dupsv;
101
102  if (SvTYPE(sv) == SVt_PVHV && HvNAME_get(sv))
103   stashes = newAV();
104
105  param.stashes    = stashes;
106  param.flags      = 0;
107  param.proto_perl = owner;
108
109  dupsv = sv_dup(sv, &param);
110
111  if (stashes) {
112   av_undef(stashes);
113   SvREFCNT_dec(stashes);
114  }
115
116  return SvREFCNT_inc(dupsv);
117 }
118
119 STATIC void rep_ptable_clone(pTHX_ ptable_ent *ent, void *ud_) {
120  my_cxt_t   *ud = ud_;
121  rep_hint_t *h1 = ent->val;
122  rep_hint_t *h2;
123
124  if (ud->owner == aTHX)
125   return;
126
127  h2        = PerlMemShared_malloc(sizeof *h2);
128  h2->comp  = rep_clone(h1->comp, ud->owner);
129  SvREFCNT_inc(h2->comp);
130  h2->exec  = rep_clone(h1->exec, ud->owner);
131  SvREFCNT_inc(h2->exec);
132 #if REP_WORKAROUND_REQUIRE_PROPAGATION
133  h2->cxreq = h1->cxreq;
134 #endif
135
136  ptable_store(ud->tbl, ent->key, h2);
137 }
138
139 STATIC void rep_thread_cleanup(pTHX_ void *);
140
141 STATIC void rep_thread_cleanup(pTHX_ void *ud) {
142  int *level = ud;
143
144  if (*level) {
145   *level = 0;
146   LEAVE;
147   SAVEDESTRUCTOR_X(rep_thread_cleanup, level);
148   ENTER;
149  } else {
150   dMY_CXT;
151   PerlMemShared_free(level);
152   ptable_free(MY_CXT.tbl);
153  }
154 }
155
156 #endif /* REP_THREADSAFE */
157
158 STATIC SV *rep_validate_callback(SV *code) {
159  if (!SvROK(code))
160   return NULL;
161
162  code = SvRV(code);
163  if (SvTYPE(code) < SVt_PVCV)
164   return NULL;
165
166  return SvREFCNT_inc_simple_NN(code);
167 }
168
169 #if REP_WORKAROUND_REQUIRE_PROPAGATION
170 STATIC IV rep_require_tag(pTHX) {
171 #define rep_require_tag() rep_require_tag(aTHX)
172  const PERL_SI *si;
173
174  for (si = PL_curstackinfo; si; si = si->si_prev) {
175   I32 cxix;
176
177   for (cxix = si->si_cxix; cxix >= 0; --cxix) {
178    const PERL_CONTEXT *cx = si->si_cxstack + cxix;
179
180    if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE)
181     return PTR2IV(cx);
182   }
183  }
184
185  return PTR2IV(NULL);
186 }
187 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
188
189 STATIC SV *rep_tag(pTHX_ SV *comp, SV *exec) {
190 #define rep_tag(C, E) rep_tag(aTHX_ (C), (E))
191  rep_hint_t *h;
192  dMY_CXT;
193
194  h = PerlMemShared_malloc(sizeof *h);
195  h->comp  = rep_validate_callback(comp);
196  h->exec  = rep_validate_callback(exec);
197 #if REP_WORKAROUND_REQUIRE_PROPAGATION
198  h->cxreq = rep_require_tag();
199 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
200
201 #if REP_THREADSAFE
202  /* We only need for the key to be an unique tag for looking up the value later.
203   * Allocated memory provides convenient unique identifiers, so that's why we
204   * use the hint as the key itself. */
205  ptable_store(MY_CXT.tbl, h, h);
206 #endif /* REP_THREADSAFE */
207
208  return newSViv(PTR2IV(h));
209 }
210
211 STATIC const rep_hint_t *rep_detag(pTHX_ const SV *hint) {
212 #define rep_detag(H) rep_detag(aTHX_ (H))
213  rep_hint_t *h;
214  dMY_CXT;
215
216  if (!(hint && SvIOK(hint)))
217   return NULL;
218
219  h = INT2PTR(rep_hint_t *, SvIVX(hint));
220 #if REP_THREADSAFE
221  h = ptable_fetch(MY_CXT.tbl, h);
222 #endif /* REP_THREADSAFE */
223
224 #if REP_WORKAROUND_REQUIRE_PROPAGATION
225  if (rep_require_tag() != h->cxreq)
226   return NULL;
227 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
228
229  return h;
230 }
231
232 STATIC U32 rep_hash = 0;
233
234 STATIC const rep_hint_t *rep_hint(pTHX) {
235 #define rep_hint() rep_hint(aTHX)
236  SV *hint;
237
238  /* We already require 5.9.5 for the regexp engine API. */
239  hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash,
240                                        NULL,
241                                        __PACKAGE__, __PACKAGE_LEN__,
242                                        0,
243                                        rep_hash);
244
245  return rep_detag(hint);
246 }
247
248 REGEXP *
249 #if PERL_VERSION <= 10
250 Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
251 #else
252 Plugin_comp(pTHX_ SV * const pattern, U32 flags)
253 #endif
254 {
255     dSP;
256     struct regexp * rx;
257     REGEXP *RX;
258     I32 buffers;
259     re__engine__Plugin re;
260     const rep_hint_t *h;
261
262     h = rep_hint();
263     if (!h) /* This looks like a pragma leak. Apply the default behaviour */
264         return re_compile(pattern, flags);
265
266     /* exp/xend version of the pattern & length */
267     STRLEN plen;
268     char*  exp = SvPV((SV*)pattern, plen);
269
270     /* Our blessed object */
271     SV *obj = newSV(0);
272     SvREFCNT_inc(obj);
273     Newxz(re, 1, struct replug);
274     sv_setref_pv(obj, "re::engine::Plugin", (void*)re);
275
276     newREGEXP(RX);
277     rx = rxREGEXP(RX);
278
279     re->rx = rx;                   /* Make the rx accessible from self->rx */
280     rx->intflags = flags;          /* Flags for internal use */
281     rx->extflags = flags;          /* Flags for perl to use */
282     rx->engine = RE_ENGINE_PLUGIN; /* Compile to use this engine */
283
284 #if PERL_VERSION <= 10
285     rx->refcnt = 1;                /* Refcount so we won't be destroyed */
286
287     /* Precompiled pattern for pp_regcomp to use */
288     rx->prelen = plen;
289     rx->precomp = savepvn(exp, rx->prelen);
290
291     /* Set up qr// stringification to be equivalent to the supplied
292      * pattern, this should be done via overload eventually.
293      */
294     rx->wraplen = rx->prelen;
295     Newx(rx->wrapped, rx->wraplen, char);
296     Copy(rx->precomp, rx->wrapped, rx->wraplen, char);
297 #endif
298
299     /* Store our private object */
300     rx->pprivate = obj;
301
302     /* Store the pattern for ->pattern */
303     re->pattern = (SV*)pattern;
304     SvREFCNT_inc(re->pattern);
305
306     /* If there's an exec callback, store it into the private object so
307      * that it will be the one to be called, even if the engine changes
308      * in between */
309     if (h->exec) {
310         re->cb_exec = h->exec;
311         SvREFCNT_inc_simple_void_NN(h->exec);
312     }
313
314     re->cb_num_capture_buff_FETCH  = NULL;
315     re->cb_num_capture_buff_STORE  = NULL;
316     re->cb_num_capture_buff_LENGTH = NULL;
317
318     /* Call our callback function if one was defined, if not we've
319      * already set up all the stuff we're going to to need for
320      * subsequent exec and other calls */
321     if (h->comp) {
322         ENTER;    
323         SAVETMPS;
324    
325         PUSHMARK(SP);
326         XPUSHs(obj);
327         PUTBACK;
328
329         call_sv(h->comp, G_DISCARD);
330
331         FREETMPS;
332         LEAVE;
333     }
334
335     /* If any of the comp-time accessors were called we'll have to
336      * update the regexp struct with the new info.
337      */
338
339     buffers = rx->nparens;
340
341     Newxz(rx->offs, buffers + 1, regexp_paren_pair);
342
343     return RX;
344 }
345
346 I32
347 Plugin_exec(pTHX_ REGEXP * const RX, char *stringarg, char *strend,
348             char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
349 {
350     dSP;
351     I32 matched;
352     struct regexp *rx = rxREGEXP(RX);
353     GET_SELF_FROM_PPRIVATE(rx->pprivate);
354
355     if (self->cb_exec) {
356         /* Store the current str for ->str */
357         self->str = (SV*)sv;
358         SvREFCNT_inc(self->str);
359
360         ENTER;
361         SAVETMPS;
362    
363         PUSHMARK(SP);
364         XPUSHs(rx->pprivate);
365         XPUSHs(sv);
366         PUTBACK;
367
368         call_sv(self->cb_exec, G_SCALAR);
369  
370         SPAGAIN;
371
372         SV * ret = POPs;
373
374         if (SvTRUE(ret))
375             matched = 1;
376         else
377             matched = 0;
378
379         PUTBACK;
380         FREETMPS;
381         LEAVE;
382     } else {
383         matched = 0;
384     }
385
386     return matched;
387 }
388
389 char *
390 Plugin_intuit(pTHX_ REGEXP * const RX, SV *sv, char *strpos,
391                      char *strend, U32 flags, re_scream_pos_data *data)
392 {
393     PERL_UNUSED_ARG(RX);
394     PERL_UNUSED_ARG(sv);
395     PERL_UNUSED_ARG(strpos);
396     PERL_UNUSED_ARG(strend);
397     PERL_UNUSED_ARG(flags);
398     PERL_UNUSED_ARG(data);
399     return NULL;
400 }
401
402 SV *
403 Plugin_checkstr(pTHX_ REGEXP * const RX)
404 {
405     PERL_UNUSED_ARG(RX);
406     return NULL;
407 }
408
409 void
410 Plugin_free(pTHX_ REGEXP * const RX)
411 {
412     struct regexp *rx = rxREGEXP(RX);
413     GET_SELF_FROM_PPRIVATE(rx->pprivate);
414
415     SvREFCNT_dec(self->pattern);
416     SvREFCNT_dec(self->str);
417
418     SvREFCNT_dec(self->cb_exec);
419
420     SvREFCNT_dec(self->cb_num_capture_buff_FETCH);
421     SvREFCNT_dec(self->cb_num_capture_buff_STORE);
422     SvREFCNT_dec(self->cb_num_capture_buff_LENGTH);
423
424     self->rx = NULL;
425     Safefree(self);
426
427 /*
428     dSP;
429     SV * callback;
430
431     callback = self->cb_free;
432
433     if (callback) {
434         ENTER;
435         SAVETMPS;
436    
437         PUSHMARK(SP);
438         XPUSHs(rx->pprivate);
439         PUTBACK;
440
441         call_sv(callback, G_DISCARD);
442
443         PUTBACK;
444         FREETMPS;
445         LEAVE;
446     }
447     return;
448 */
449 }
450
451 void *
452 Plugin_dupe(pTHX_ REGEXP * const RX, CLONE_PARAMS *param)
453 {
454     struct regexp *rx = rxREGEXP(RX);
455     Perl_croak(aTHX_ "dupe not supported yet");
456     return rx->pprivate;
457 }
458
459
460 void
461 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const RX, const I32 paren,
462                            SV * const sv)
463 {
464     dSP;
465     I32 items;
466     SV * callback;
467     struct regexp *rx = rxREGEXP(RX);
468     GET_SELF_FROM_PPRIVATE(rx->pprivate);
469
470     callback = self->cb_num_capture_buff_FETCH;
471
472     if (callback) {
473         ENTER;
474         SAVETMPS;
475    
476         PUSHMARK(SP);
477         XPUSHs(rx->pprivate);
478         XPUSHs(sv_2mortal(newSViv(paren)));
479         PUTBACK;
480
481         items = call_sv(callback, G_SCALAR);
482         
483         if (items == 1) {
484             SPAGAIN;
485
486             SV * ret = POPs;
487             sv_setsv(sv, ret);
488         } else {
489             sv_setsv(sv, &PL_sv_undef);
490         }
491
492         PUTBACK;
493         FREETMPS;
494         LEAVE;
495     } else {
496         sv_setsv(sv, &PL_sv_undef);
497     }
498 }
499
500 void
501 Plugin_numbered_buff_STORE(pTHX_ REGEXP * const RX, const I32 paren,
502                            SV const * const value)
503 {
504     dSP;
505     SV * callback;
506     struct regexp *rx = rxREGEXP(RX);
507     GET_SELF_FROM_PPRIVATE(rx->pprivate);
508
509     callback = self->cb_num_capture_buff_STORE;
510
511     if (callback) {
512         ENTER;
513         SAVETMPS;
514    
515         PUSHMARK(SP);
516         XPUSHs(rx->pprivate);
517         XPUSHs(sv_2mortal(newSViv(paren)));
518         XPUSHs(SvREFCNT_inc((SV *) value));
519         PUTBACK;
520
521         call_sv(callback, G_DISCARD);
522
523         PUTBACK;
524         FREETMPS;
525         LEAVE;
526     }
527 }
528
529 I32
530 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const RX, const SV * const sv,
531                               const I32 paren)
532 {
533     dSP;
534     SV * callback;
535     struct regexp *rx = rxREGEXP(RX);
536     GET_SELF_FROM_PPRIVATE(rx->pprivate);
537
538     callback = self->cb_num_capture_buff_LENGTH;
539
540     if (callback) {
541         ENTER;
542         SAVETMPS;
543    
544         PUSHMARK(SP);
545         XPUSHs(rx->pprivate);
546         XPUSHs(sv_2mortal(newSViv(paren)));
547         PUTBACK;
548
549         call_sv(callback, G_SCALAR);
550
551         SPAGAIN;
552
553         IV ret = POPi;
554
555         PUTBACK;
556         FREETMPS;
557         LEAVE;
558
559         return (I32)ret;
560     } else {
561         /* TODO: call FETCH and get the length on that value */
562         return 0;
563     }
564 }
565
566
567 SV*
568 Plugin_named_buff (pTHX_ REGEXP * const RX, SV * const key, SV * const value,
569                    const U32 flags)
570 {
571     return NULL;
572 }
573
574 SV*
575 Plugin_named_buff_iter (pTHX_ REGEXP * const RX, const SV * const lastkey,
576                         const U32 flags)
577 {
578     return NULL;
579 }
580
581 SV*
582 Plugin_package(pTHX_ REGEXP * const RX)
583 {
584     PERL_UNUSED_ARG(RX);
585     return newSVpvs("re::engine::Plugin");
586 }
587
588 #if REP_THREADSAFE
589
590 STATIC U32 rep_initialized = 0;
591
592 STATIC void rep_teardown(pTHX_ void *root) {
593  dMY_CXT;
594
595  if (!rep_initialized || aTHX != root)
596   return;
597
598  ptable_free(MY_CXT.tbl);
599
600  rep_initialized = 0;
601 }
602
603 STATIC void rep_setup(pTHX) {
604 #define rep_setup() rep_setup(aTHX)
605  if (rep_initialized)
606   return;
607
608  MY_CXT_INIT;
609  MY_CXT.tbl   = ptable_new();
610  MY_CXT.owner = aTHX;
611
612  call_atexit(rep_teardown, aTHX);
613
614  rep_initialized = 1;
615 }
616
617 #else  /*  REP_THREADSAFE */
618
619 #define rep_setup()
620
621 #endif /* !REP_THREADSAFE */
622
623 STATIC U32 rep_booted = 0;
624
625 /* --- XS ------------------------------------------------------------------ */
626
627 MODULE = re::engine::Plugin     PACKAGE = re::engine::Plugin
628
629 PROTOTYPES: DISABLE
630
631 BOOT:
632 {
633     if (!rep_booted++) {
634         PERL_HASH(rep_hash, __PACKAGE__, __PACKAGE_LEN__);
635     }
636
637     rep_setup();
638 }
639
640 #if REP_THREADSAFE
641
642 void
643 CLONE(...)
644 PREINIT:
645     ptable *t;
646     int    *level;
647 CODE:
648     {
649         my_cxt_t ud;
650         dMY_CXT;
651         ud.tbl   = t = ptable_new();
652         ud.owner = MY_CXT.owner;
653         ptable_walk(MY_CXT.tbl, rep_ptable_clone, &ud);
654     }
655     {
656         MY_CXT_CLONE;
657         MY_CXT.tbl   = t;
658         MY_CXT.owner = aTHX;
659     }
660
661 #endif
662
663 void
664 pattern(re::engine::Plugin self, ...)
665 PPCODE:
666     XPUSHs(self->pattern);
667
668 void
669 str(re::engine::Plugin self, ...)
670 PPCODE:
671     XPUSHs(self->str);
672
673 char*
674 mod(re::engine::Plugin self, ...)
675 PPCODE:
676     /* /i */
677     if (self->rx->intflags & PMf_FOLD) {
678       XPUSHs(sv_2mortal(newSVpvs("i")));
679       XPUSHs(&PL_sv_yes);
680     }
681
682     /* /m */
683     if (self->rx->intflags & PMf_MULTILINE) {
684       XPUSHs(sv_2mortal(newSVpvs("m")));
685       XPUSHs(&PL_sv_yes);
686     }
687
688     /* /s */
689     if (self->rx->intflags & PMf_SINGLELINE) {
690       XPUSHs(sv_2mortal(newSVpvs("s")));
691       XPUSHs(&PL_sv_yes);
692     }
693
694     /* /x */
695     if (self->rx->intflags & PMf_EXTENDED) {
696       XPUSHs(sv_2mortal(newSVpvs("x")));
697       XPUSHs(&PL_sv_yes);
698     }
699
700     /* /p */
701     if (self->rx->intflags & RXf_PMf_KEEPCOPY) {
702       XPUSHs(sv_2mortal(newSVpvs("p")));
703       XPUSHs(&PL_sv_yes);
704     }
705
706 void
707 stash(re::engine::Plugin self, ...)
708 PPCODE:
709     if (items > 1) {
710         self->stash = ST(1);
711         SvREFCNT_inc(self->stash);
712         XSRETURN_EMPTY;
713     } else {
714         XPUSHs(self->stash);
715     }
716
717 void
718 minlen(re::engine::Plugin self, ...)
719 PPCODE:
720     if (items > 1) {
721         self->rx->minlen = (I32)SvIV(ST(1));
722         XSRETURN_EMPTY;
723     } else {
724         if (self->rx->minlen) {
725             XPUSHs(sv_2mortal(newSViv(self->rx->minlen)));
726         } else {
727             XPUSHs(sv_2mortal(&PL_sv_undef));
728         }
729     }
730
731 void
732 gofs(re::engine::Plugin self, ...)
733 PPCODE:
734     if (items > 1) {
735         self->rx->gofs = (U32)SvIV(ST(1));
736         XSRETURN_EMPTY;
737     } else {
738         if (self->rx->gofs) {
739             XPUSHs(sv_2mortal(newSVuv(self->rx->gofs)));
740         } else {
741             XPUSHs(sv_2mortal(&PL_sv_undef));
742         }
743     }
744
745 void
746 nparens(re::engine::Plugin self, ...)
747 PPCODE:
748     if (items > 1) {
749         self->rx->nparens = (U32)SvIV(ST(1));
750         XSRETURN_EMPTY;
751     } else {
752         if (self->rx->nparens) {
753             XPUSHs(sv_2mortal(newSVuv(self->rx->nparens)));
754         } else {
755             XPUSHs(sv_2mortal(&PL_sv_undef));
756         }
757     }
758
759 void
760 _exec(re::engine::Plugin self, ...)
761 PPCODE:
762     if (items > 1) {
763         SvREFCNT_dec(self->cb_exec);
764         self->cb_exec = ST(1);
765         SvREFCNT_inc(self->cb_exec);
766     }
767
768 void
769 _num_capture_buff_FETCH(re::engine::Plugin self, ...)
770 PPCODE:
771     if (items > 1) {
772         SvREFCNT_dec(self->cb_num_capture_buff_FETCH);
773         self->cb_num_capture_buff_FETCH = ST(1);
774         SvREFCNT_inc(self->cb_num_capture_buff_FETCH);
775     }
776
777 void
778 _num_capture_buff_STORE(re::engine::Plugin self, ...)
779 PPCODE:
780     if (items > 1) {
781         SvREFCNT_dec(self->cb_num_capture_buff_STORE);
782         self->cb_num_capture_buff_STORE = ST(1);
783         SvREFCNT_inc(self->cb_num_capture_buff_STORE);
784     }
785
786 void
787 _num_capture_buff_LENGTH(re::engine::Plugin self, ...)
788 PPCODE:
789     if (items > 1) {
790         SvREFCNT_dec(self->cb_num_capture_buff_LENGTH);
791         self->cb_num_capture_buff_LENGTH = ST(1);
792         SvREFCNT_inc(self->cb_num_capture_buff_LENGTH);
793     }
794
795 SV *
796 _tag(SV *comp, SV *exec)
797 CODE:
798     RETVAL = rep_tag(comp, exec);
799 OUTPUT:
800     RETVAL
801
802 void
803 ENGINE()
804 PPCODE:
805     XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));