]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - Plugin.xs
036185f6faa97917ceb3660a746422aa0425a901
[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 #include "reap.h"
140
141 STATIC void rep_thread_cleanup(pTHX_ void *ud) {
142  dMY_CXT;
143
144  ptable_free(MY_CXT.tbl);
145 }
146
147 #endif /* REP_THREADSAFE */
148
149 STATIC SV *rep_validate_callback(SV *code) {
150  if (!SvROK(code))
151   return NULL;
152
153  code = SvRV(code);
154  if (SvTYPE(code) < SVt_PVCV)
155   return NULL;
156
157  return SvREFCNT_inc_simple_NN(code);
158 }
159
160 #if REP_WORKAROUND_REQUIRE_PROPAGATION
161 STATIC IV rep_require_tag(pTHX) {
162 #define rep_require_tag() rep_require_tag(aTHX)
163  const PERL_SI *si;
164
165  for (si = PL_curstackinfo; si; si = si->si_prev) {
166   I32 cxix;
167
168   for (cxix = si->si_cxix; cxix >= 0; --cxix) {
169    const PERL_CONTEXT *cx = si->si_cxstack + cxix;
170
171    if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE)
172     return PTR2IV(cx);
173   }
174  }
175
176  return PTR2IV(NULL);
177 }
178 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
179
180 STATIC SV *rep_tag(pTHX_ SV *comp, SV *exec) {
181 #define rep_tag(C, E) rep_tag(aTHX_ (C), (E))
182  rep_hint_t *h;
183  dMY_CXT;
184
185  h = PerlMemShared_malloc(sizeof *h);
186  h->comp  = rep_validate_callback(comp);
187  h->exec  = rep_validate_callback(exec);
188 #if REP_WORKAROUND_REQUIRE_PROPAGATION
189  h->cxreq = rep_require_tag();
190 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
191
192 #if REP_THREADSAFE
193  /* We only need for the key to be an unique tag for looking up the value later.
194   * Allocated memory provides convenient unique identifiers, so that's why we
195   * use the hint as the key itself. */
196  ptable_store(MY_CXT.tbl, h, h);
197 #endif /* REP_THREADSAFE */
198
199  return newSViv(PTR2IV(h));
200 }
201
202 STATIC const rep_hint_t *rep_detag(pTHX_ const SV *hint) {
203 #define rep_detag(H) rep_detag(aTHX_ (H))
204  rep_hint_t *h;
205  dMY_CXT;
206
207  if (!(hint && SvIOK(hint)))
208   return NULL;
209
210  h = INT2PTR(rep_hint_t *, SvIVX(hint));
211 #if REP_THREADSAFE
212  h = ptable_fetch(MY_CXT.tbl, h);
213 #endif /* REP_THREADSAFE */
214
215 #if REP_WORKAROUND_REQUIRE_PROPAGATION
216  if (rep_require_tag() != h->cxreq)
217   return NULL;
218 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
219
220  return h;
221 }
222
223 STATIC U32 rep_hash = 0;
224
225 STATIC const rep_hint_t *rep_hint(pTHX) {
226 #define rep_hint() rep_hint(aTHX)
227  SV *hint;
228
229 #ifdef cop_hints_fetch_pvn
230  hint = cop_hints_fetch_pvn(PL_curcop,
231                             __PACKAGE__, __PACKAGE_LEN__, rep_hash, 0);
232 #else
233  /* We already require 5.9.5 for the regexp engine API. */
234  hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash,
235                                        NULL,
236                                        __PACKAGE__, __PACKAGE_LEN__,
237                                        0,
238                                        rep_hash);
239 #endif
240
241  return rep_detag(hint);
242 }
243
244 REGEXP *
245 #if PERL_VERSION <= 10
246 Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
247 #else
248 Plugin_comp(pTHX_ SV * const pattern, U32 flags)
249 #endif
250 {
251     dSP;
252     struct regexp * rx;
253     REGEXP *RX;
254
255     re__engine__Plugin re;
256     const rep_hint_t *h;
257
258     STRLEN plen;
259     char *pbuf;
260
261     SV *obj;
262
263     h = rep_hint();
264     if (!h) /* This looks like a pragma leak. Apply the default behaviour */
265         return re_compile(pattern, flags);
266
267     /* exp/xend version of the pattern & length */
268     pbuf = SvPV((SV*)pattern, plen);
269
270     /* Our blessed object */
271     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(pbuf, 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     Newxz(rx->offs, rx->nparens + 1, regexp_paren_pair);
340
341     return RX;
342 }
343
344 I32
345 Plugin_exec(pTHX_ REGEXP * const RX, char *stringarg, char *strend,
346             char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
347 {
348     dSP;
349     I32 matched;
350     struct regexp *rx = rxREGEXP(RX);
351     GET_SELF_FROM_PPRIVATE(rx->pprivate);
352
353     if (self->cb_exec) {
354         SV *ret;
355
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         ret = POPs;
373         if (SvTRUE(ret))
374             matched = 1;
375         else
376             matched = 0;
377
378         PUTBACK;
379         FREETMPS;
380         LEAVE;
381     } else {
382         matched = 0;
383     }
384
385     return matched;
386 }
387
388 char *
389 Plugin_intuit(pTHX_ REGEXP * const RX, SV *sv, char *strpos,
390                      char *strend, U32 flags, re_scream_pos_data *data)
391 {
392     PERL_UNUSED_ARG(RX);
393     PERL_UNUSED_ARG(sv);
394     PERL_UNUSED_ARG(strpos);
395     PERL_UNUSED_ARG(strend);
396     PERL_UNUSED_ARG(flags);
397     PERL_UNUSED_ARG(data);
398     return NULL;
399 }
400
401 SV *
402 Plugin_checkstr(pTHX_ REGEXP * const RX)
403 {
404     PERL_UNUSED_ARG(RX);
405     return NULL;
406 }
407
408 void
409 Plugin_free(pTHX_ REGEXP * const RX)
410 {
411     struct regexp *rx = rxREGEXP(RX);
412     GET_SELF_FROM_PPRIVATE(rx->pprivate);
413
414     SvREFCNT_dec(self->pattern);
415     SvREFCNT_dec(self->str);
416
417     SvREFCNT_dec(self->cb_exec);
418
419     SvREFCNT_dec(self->cb_num_capture_buff_FETCH);
420     SvREFCNT_dec(self->cb_num_capture_buff_STORE);
421     SvREFCNT_dec(self->cb_num_capture_buff_LENGTH);
422
423     self->rx = NULL;
424     Safefree(self);
425
426 /*
427     dSP;
428     SV * callback;
429
430     callback = self->cb_free;
431
432     if (callback) {
433         ENTER;
434         SAVETMPS;
435    
436         PUSHMARK(SP);
437         XPUSHs(rx->pprivate);
438         PUTBACK;
439
440         call_sv(callback, G_DISCARD);
441
442         PUTBACK;
443         FREETMPS;
444         LEAVE;
445     }
446     return;
447 */
448 }
449
450 void *
451 Plugin_dupe(pTHX_ REGEXP * const RX, CLONE_PARAMS *param)
452 {
453     struct regexp *rx = rxREGEXP(RX);
454     Perl_croak(aTHX_ "dupe not supported yet");
455     return rx->pprivate;
456 }
457
458
459 void
460 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const RX, const I32 paren,
461                            SV * const sv)
462 {
463     dSP;
464     I32 items;
465     SV * callback;
466     struct regexp *rx = rxREGEXP(RX);
467     GET_SELF_FROM_PPRIVATE(rx->pprivate);
468
469     callback = self->cb_num_capture_buff_FETCH;
470
471     if (callback) {
472         ENTER;
473         SAVETMPS;
474    
475         PUSHMARK(SP);
476         XPUSHs(rx->pprivate);
477         XPUSHs(sv_2mortal(newSViv(paren)));
478         PUTBACK;
479
480         items = call_sv(callback, G_SCALAR);
481         
482         if (items == 1) {
483             SV *ret;
484
485             SPAGAIN;
486             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((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         IV ret;
542
543         ENTER;
544         SAVETMPS;
545    
546         PUSHMARK(SP);
547         XPUSHs(rx->pprivate);
548         XPUSHs(sv_2mortal(newSViv(paren)));
549         PUTBACK;
550
551         call_sv(callback, G_SCALAR);
552
553         SPAGAIN;
554
555         ret = POPi;
556
557         PUTBACK;
558         FREETMPS;
559         LEAVE;
560
561         return (I32)ret;
562     } else {
563         /* TODO: call FETCH and get the length on that value */
564         return 0;
565     }
566 }
567
568
569 SV*
570 Plugin_named_buff (pTHX_ REGEXP * const RX, SV * const key, SV * const value,
571                    const U32 flags)
572 {
573     return NULL;
574 }
575
576 SV*
577 Plugin_named_buff_iter (pTHX_ REGEXP * const RX, const SV * const lastkey,
578                         const U32 flags)
579 {
580     return NULL;
581 }
582
583 SV*
584 Plugin_package(pTHX_ REGEXP * const RX)
585 {
586     PERL_UNUSED_ARG(RX);
587     return newSVpvs("re::engine::Plugin");
588 }
589
590 #if REP_THREADSAFE
591
592 STATIC U32 rep_initialized = 0;
593
594 STATIC void rep_teardown(pTHX_ void *root) {
595  dMY_CXT;
596
597  if (!rep_initialized || aTHX != root)
598   return;
599
600  ptable_free(MY_CXT.tbl);
601
602  rep_initialized = 0;
603 }
604
605 STATIC void rep_setup(pTHX) {
606 #define rep_setup() rep_setup(aTHX)
607  if (rep_initialized)
608   return;
609
610  MY_CXT_INIT;
611  MY_CXT.tbl   = ptable_new();
612  MY_CXT.owner = aTHX;
613
614  call_atexit(rep_teardown, aTHX);
615
616  rep_initialized = 1;
617 }
618
619 #else  /*  REP_THREADSAFE */
620
621 #define rep_setup()
622
623 #endif /* !REP_THREADSAFE */
624
625 STATIC U32 rep_booted = 0;
626
627 /* --- XS ------------------------------------------------------------------ */
628
629 MODULE = re::engine::Plugin       PACKAGE = re::engine::Plugin
630
631 PROTOTYPES: DISABLE
632
633 BOOT:
634 {
635     if (!rep_booted++) {
636         PERL_HASH(rep_hash, __PACKAGE__, __PACKAGE_LEN__);
637     }
638
639     rep_setup();
640 }
641
642 #if REP_THREADSAFE
643
644 void
645 CLONE(...)
646 PREINIT:
647     ptable *t;
648 PPCODE:
649     {
650         my_cxt_t ud;
651         dMY_CXT;
652         ud.tbl   = t = ptable_new();
653         ud.owner = MY_CXT.owner;
654         ptable_walk(MY_CXT.tbl, rep_ptable_clone, &ud);
655     }
656     {
657         MY_CXT_CLONE;
658         MY_CXT.tbl   = t;
659         MY_CXT.owner = aTHX;
660     }
661     reap(3, rep_thread_cleanup, NULL);
662     XSRETURN(0);
663
664 #endif /* REP_THREADSAFE */
665
666 void
667 pattern(re::engine::Plugin self, ...)
668 PPCODE:
669     XPUSHs(self->pattern);
670
671 void
672 str(re::engine::Plugin self, ...)
673 PPCODE:
674     XPUSHs(self->str);
675
676 void
677 mod(re::engine::Plugin self)
678 PREINIT:
679     U32 flags;
680     char mods[5 + 1];
681     int n = 0, i;
682 PPCODE:
683     flags = self->rx->intflags;
684     if (flags & PMf_FOLD)         /* /i */
685         mods[n++] = 'i';
686     if (flags & PMf_MULTILINE)    /* /m */
687         mods[n++] = 'm';
688     if (flags & PMf_SINGLELINE)   /* /s */
689         mods[n++] = 's';
690     if (flags & PMf_EXTENDED)     /* /x */
691         mods[n++] = 'x';
692     if (flags & RXf_PMf_KEEPCOPY) /* /p */
693         mods[n++] = 'p';
694     mods[n] = '\0';
695     EXTEND(SP, 2 * n);
696     for (i = 0; i < n; ++i) {
697         mPUSHp(mods + i, 1);
698         PUSHs(&PL_sv_yes);
699     }
700     XSRETURN(2 * n);
701
702 void
703 stash(re::engine::Plugin self, ...)
704 PPCODE:
705     if (items > 1) {
706         self->stash = ST(1);
707         SvREFCNT_inc(self->stash);
708         XSRETURN_EMPTY;
709     } else {
710         XPUSHs(self->stash);
711     }
712
713 void
714 minlen(re::engine::Plugin self, ...)
715 PPCODE:
716     if (items > 1) {
717         self->rx->minlen = (I32)SvIV(ST(1));
718         XSRETURN_EMPTY;
719     } else {
720         if (self->rx->minlen) {
721             XPUSHs(sv_2mortal(newSViv(self->rx->minlen)));
722         } else {
723             XPUSHs(sv_2mortal(&PL_sv_undef));
724         }
725     }
726
727 void
728 gofs(re::engine::Plugin self, ...)
729 PPCODE:
730     if (items > 1) {
731         self->rx->gofs = (U32)SvIV(ST(1));
732         XSRETURN_EMPTY;
733     } else {
734         if (self->rx->gofs) {
735             XPUSHs(sv_2mortal(newSVuv(self->rx->gofs)));
736         } else {
737             XPUSHs(sv_2mortal(&PL_sv_undef));
738         }
739     }
740
741 void
742 nparens(re::engine::Plugin self, ...)
743 PPCODE:
744     if (items > 1) {
745         self->rx->nparens = (U32)SvIV(ST(1));
746         XSRETURN_EMPTY;
747     } else {
748         if (self->rx->nparens) {
749             XPUSHs(sv_2mortal(newSVuv(self->rx->nparens)));
750         } else {
751             XPUSHs(sv_2mortal(&PL_sv_undef));
752         }
753     }
754
755 void
756 _exec(re::engine::Plugin self, ...)
757 PPCODE:
758     if (items > 1) {
759         SvREFCNT_dec(self->cb_exec);
760         self->cb_exec = ST(1);
761         SvREFCNT_inc(self->cb_exec);
762     }
763
764 void
765 _num_capture_buff_FETCH(re::engine::Plugin self, ...)
766 PPCODE:
767     if (items > 1) {
768         SvREFCNT_dec(self->cb_num_capture_buff_FETCH);
769         self->cb_num_capture_buff_FETCH = ST(1);
770         SvREFCNT_inc(self->cb_num_capture_buff_FETCH);
771     }
772
773 void
774 _num_capture_buff_STORE(re::engine::Plugin self, ...)
775 PPCODE:
776     if (items > 1) {
777         SvREFCNT_dec(self->cb_num_capture_buff_STORE);
778         self->cb_num_capture_buff_STORE = ST(1);
779         SvREFCNT_inc(self->cb_num_capture_buff_STORE);
780     }
781
782 void
783 _num_capture_buff_LENGTH(re::engine::Plugin self, ...)
784 PPCODE:
785     if (items > 1) {
786         SvREFCNT_dec(self->cb_num_capture_buff_LENGTH);
787         self->cb_num_capture_buff_LENGTH = ST(1);
788         SvREFCNT_inc(self->cb_num_capture_buff_LENGTH);
789     }
790
791 SV *
792 _tag(SV *comp, SV *exec)
793 CODE:
794     RETVAL = rep_tag(comp, exec);
795 OUTPUT:
796     RETVAL
797
798 void
799 ENGINE()
800 PPCODE:
801     XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));