]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - Plugin.xs
07a5d259d0854c66e7ddaee7e842630f53975642
[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     I32 buffers;
255     re__engine__Plugin re;
256     const rep_hint_t *h;
257
258     h = rep_hint();
259     if (!h) /* This looks like a pragma leak. Apply the default behaviour */
260         return re_compile(pattern, flags);
261
262     /* exp/xend version of the pattern & length */
263     STRLEN plen;
264     char*  exp = SvPV((SV*)pattern, plen);
265
266     /* Our blessed object */
267     SV *obj = newSV(0);
268     SvREFCNT_inc(obj);
269     Newxz(re, 1, struct replug);
270     sv_setref_pv(obj, "re::engine::Plugin", (void*)re);
271
272     newREGEXP(RX);
273     rx = rxREGEXP(RX);
274
275     re->rx = rx;                   /* Make the rx accessible from self->rx */
276     rx->intflags = flags;          /* Flags for internal use */
277     rx->extflags = flags;          /* Flags for perl to use */
278     rx->engine = RE_ENGINE_PLUGIN; /* Compile to use this engine */
279
280 #if PERL_VERSION <= 10
281     rx->refcnt = 1;                /* Refcount so we won't be destroyed */
282
283     /* Precompiled pattern for pp_regcomp to use */
284     rx->prelen = plen;
285     rx->precomp = savepvn(exp, rx->prelen);
286
287     /* Set up qr// stringification to be equivalent to the supplied
288      * pattern, this should be done via overload eventually.
289      */
290     rx->wraplen = rx->prelen;
291     Newx(rx->wrapped, rx->wraplen, char);
292     Copy(rx->precomp, rx->wrapped, rx->wraplen, char);
293 #endif
294
295     /* Store our private object */
296     rx->pprivate = obj;
297
298     /* Store the pattern for ->pattern */
299     re->pattern = (SV*)pattern;
300     SvREFCNT_inc(re->pattern);
301
302     /* If there's an exec callback, store it into the private object so
303      * that it will be the one to be called, even if the engine changes
304      * in between */
305     if (h->exec) {
306         re->cb_exec = h->exec;
307         SvREFCNT_inc_simple_void_NN(h->exec);
308     }
309
310     re->cb_num_capture_buff_FETCH  = NULL;
311     re->cb_num_capture_buff_STORE  = NULL;
312     re->cb_num_capture_buff_LENGTH = NULL;
313
314     /* Call our callback function if one was defined, if not we've
315      * already set up all the stuff we're going to to need for
316      * subsequent exec and other calls */
317     if (h->comp) {
318         ENTER;    
319         SAVETMPS;
320    
321         PUSHMARK(SP);
322         XPUSHs(obj);
323         PUTBACK;
324
325         call_sv(h->comp, G_DISCARD);
326
327         FREETMPS;
328         LEAVE;
329     }
330
331     /* If any of the comp-time accessors were called we'll have to
332      * update the regexp struct with the new info.
333      */
334
335     buffers = rx->nparens;
336
337     Newxz(rx->offs, buffers + 1, regexp_paren_pair);
338
339     return RX;
340 }
341
342 I32
343 Plugin_exec(pTHX_ REGEXP * const RX, char *stringarg, char *strend,
344             char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
345 {
346     dSP;
347     I32 matched;
348     struct regexp *rx = rxREGEXP(RX);
349     GET_SELF_FROM_PPRIVATE(rx->pprivate);
350
351     if (self->cb_exec) {
352         /* Store the current str for ->str */
353         self->str = (SV*)sv;
354         SvREFCNT_inc(self->str);
355
356         ENTER;
357         SAVETMPS;
358    
359         PUSHMARK(SP);
360         XPUSHs(rx->pprivate);
361         XPUSHs(sv);
362         PUTBACK;
363
364         call_sv(self->cb_exec, G_SCALAR);
365  
366         SPAGAIN;
367
368         SV * ret = POPs;
369
370         if (SvTRUE(ret))
371             matched = 1;
372         else
373             matched = 0;
374
375         PUTBACK;
376         FREETMPS;
377         LEAVE;
378     } else {
379         matched = 0;
380     }
381
382     return matched;
383 }
384
385 char *
386 Plugin_intuit(pTHX_ REGEXP * const RX, SV *sv, char *strpos,
387                      char *strend, U32 flags, re_scream_pos_data *data)
388 {
389     PERL_UNUSED_ARG(RX);
390     PERL_UNUSED_ARG(sv);
391     PERL_UNUSED_ARG(strpos);
392     PERL_UNUSED_ARG(strend);
393     PERL_UNUSED_ARG(flags);
394     PERL_UNUSED_ARG(data);
395     return NULL;
396 }
397
398 SV *
399 Plugin_checkstr(pTHX_ REGEXP * const RX)
400 {
401     PERL_UNUSED_ARG(RX);
402     return NULL;
403 }
404
405 void
406 Plugin_free(pTHX_ REGEXP * const RX)
407 {
408     struct regexp *rx = rxREGEXP(RX);
409     GET_SELF_FROM_PPRIVATE(rx->pprivate);
410
411     SvREFCNT_dec(self->pattern);
412     SvREFCNT_dec(self->str);
413
414     SvREFCNT_dec(self->cb_exec);
415
416     SvREFCNT_dec(self->cb_num_capture_buff_FETCH);
417     SvREFCNT_dec(self->cb_num_capture_buff_STORE);
418     SvREFCNT_dec(self->cb_num_capture_buff_LENGTH);
419
420     self->rx = NULL;
421     Safefree(self);
422
423 /*
424     dSP;
425     SV * callback;
426
427     callback = self->cb_free;
428
429     if (callback) {
430         ENTER;
431         SAVETMPS;
432    
433         PUSHMARK(SP);
434         XPUSHs(rx->pprivate);
435         PUTBACK;
436
437         call_sv(callback, G_DISCARD);
438
439         PUTBACK;
440         FREETMPS;
441         LEAVE;
442     }
443     return;
444 */
445 }
446
447 void *
448 Plugin_dupe(pTHX_ REGEXP * const RX, CLONE_PARAMS *param)
449 {
450     struct regexp *rx = rxREGEXP(RX);
451     Perl_croak(aTHX_ "dupe not supported yet");
452     return rx->pprivate;
453 }
454
455
456 void
457 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const RX, const I32 paren,
458                            SV * const sv)
459 {
460     dSP;
461     I32 items;
462     SV * callback;
463     struct regexp *rx = rxREGEXP(RX);
464     GET_SELF_FROM_PPRIVATE(rx->pprivate);
465
466     callback = self->cb_num_capture_buff_FETCH;
467
468     if (callback) {
469         ENTER;
470         SAVETMPS;
471    
472         PUSHMARK(SP);
473         XPUSHs(rx->pprivate);
474         XPUSHs(sv_2mortal(newSViv(paren)));
475         PUTBACK;
476
477         items = call_sv(callback, G_SCALAR);
478         
479         if (items == 1) {
480             SPAGAIN;
481
482             SV * ret = POPs;
483             sv_setsv(sv, ret);
484         } else {
485             sv_setsv(sv, &PL_sv_undef);
486         }
487
488         PUTBACK;
489         FREETMPS;
490         LEAVE;
491     } else {
492         sv_setsv(sv, &PL_sv_undef);
493     }
494 }
495
496 void
497 Plugin_numbered_buff_STORE(pTHX_ REGEXP * const RX, const I32 paren,
498                            SV const * const value)
499 {
500     dSP;
501     SV * callback;
502     struct regexp *rx = rxREGEXP(RX);
503     GET_SELF_FROM_PPRIVATE(rx->pprivate);
504
505     callback = self->cb_num_capture_buff_STORE;
506
507     if (callback) {
508         ENTER;
509         SAVETMPS;
510    
511         PUSHMARK(SP);
512         XPUSHs(rx->pprivate);
513         XPUSHs(sv_2mortal(newSViv(paren)));
514         XPUSHs(SvREFCNT_inc((SV *) value));
515         PUTBACK;
516
517         call_sv(callback, G_DISCARD);
518
519         PUTBACK;
520         FREETMPS;
521         LEAVE;
522     }
523 }
524
525 I32
526 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const RX, const SV * const sv,
527                               const I32 paren)
528 {
529     dSP;
530     SV * callback;
531     struct regexp *rx = rxREGEXP(RX);
532     GET_SELF_FROM_PPRIVATE(rx->pprivate);
533
534     callback = self->cb_num_capture_buff_LENGTH;
535
536     if (callback) {
537         ENTER;
538         SAVETMPS;
539    
540         PUSHMARK(SP);
541         XPUSHs(rx->pprivate);
542         XPUSHs(sv_2mortal(newSViv(paren)));
543         PUTBACK;
544
545         call_sv(callback, G_SCALAR);
546
547         SPAGAIN;
548
549         IV ret = POPi;
550
551         PUTBACK;
552         FREETMPS;
553         LEAVE;
554
555         return (I32)ret;
556     } else {
557         /* TODO: call FETCH and get the length on that value */
558         return 0;
559     }
560 }
561
562
563 SV*
564 Plugin_named_buff (pTHX_ REGEXP * const RX, SV * const key, SV * const value,
565                    const U32 flags)
566 {
567     return NULL;
568 }
569
570 SV*
571 Plugin_named_buff_iter (pTHX_ REGEXP * const RX, const SV * const lastkey,
572                         const U32 flags)
573 {
574     return NULL;
575 }
576
577 SV*
578 Plugin_package(pTHX_ REGEXP * const RX)
579 {
580     PERL_UNUSED_ARG(RX);
581     return newSVpvs("re::engine::Plugin");
582 }
583
584 #if REP_THREADSAFE
585
586 STATIC U32 rep_initialized = 0;
587
588 STATIC void rep_teardown(pTHX_ void *root) {
589  dMY_CXT;
590
591  if (!rep_initialized || aTHX != root)
592   return;
593
594  ptable_free(MY_CXT.tbl);
595
596  rep_initialized = 0;
597 }
598
599 STATIC void rep_setup(pTHX) {
600 #define rep_setup() rep_setup(aTHX)
601  if (rep_initialized)
602   return;
603
604  MY_CXT_INIT;
605  MY_CXT.tbl   = ptable_new();
606  MY_CXT.owner = aTHX;
607
608  call_atexit(rep_teardown, aTHX);
609
610  rep_initialized = 1;
611 }
612
613 #else  /*  REP_THREADSAFE */
614
615 #define rep_setup()
616
617 #endif /* !REP_THREADSAFE */
618
619 STATIC U32 rep_booted = 0;
620
621 /* --- XS ------------------------------------------------------------------ */
622
623 MODULE = re::engine::Plugin       PACKAGE = re::engine::Plugin
624
625 PROTOTYPES: DISABLE
626
627 BOOT:
628 {
629     if (!rep_booted++) {
630         PERL_HASH(rep_hash, __PACKAGE__, __PACKAGE_LEN__);
631     }
632
633     rep_setup();
634 }
635
636 #if REP_THREADSAFE
637
638 void
639 CLONE(...)
640 PREINIT:
641     ptable *t;
642 PPCODE:
643     {
644         my_cxt_t ud;
645         dMY_CXT;
646         ud.tbl   = t = ptable_new();
647         ud.owner = MY_CXT.owner;
648         ptable_walk(MY_CXT.tbl, rep_ptable_clone, &ud);
649     }
650     {
651         MY_CXT_CLONE;
652         MY_CXT.tbl   = t;
653         MY_CXT.owner = aTHX;
654     }
655     reap(3, rep_thread_cleanup, NULL);
656     XSRETURN(0);
657
658 #endif /* REP_THREADSAFE */
659
660 void
661 pattern(re::engine::Plugin self, ...)
662 PPCODE:
663     XPUSHs(self->pattern);
664
665 void
666 str(re::engine::Plugin self, ...)
667 PPCODE:
668     XPUSHs(self->str);
669
670 char*
671 mod(re::engine::Plugin self, ...)
672 PPCODE:
673     /* /i */
674     if (self->rx->intflags & PMf_FOLD) {
675       XPUSHs(sv_2mortal(newSVpvs("i")));
676       XPUSHs(&PL_sv_yes);
677     }
678
679     /* /m */
680     if (self->rx->intflags & PMf_MULTILINE) {
681       XPUSHs(sv_2mortal(newSVpvs("m")));
682       XPUSHs(&PL_sv_yes);
683     }
684
685     /* /s */
686     if (self->rx->intflags & PMf_SINGLELINE) {
687       XPUSHs(sv_2mortal(newSVpvs("s")));
688       XPUSHs(&PL_sv_yes);
689     }
690
691     /* /x */
692     if (self->rx->intflags & PMf_EXTENDED) {
693       XPUSHs(sv_2mortal(newSVpvs("x")));
694       XPUSHs(&PL_sv_yes);
695     }
696
697     /* /p */
698     if (self->rx->intflags & RXf_PMf_KEEPCOPY) {
699       XPUSHs(sv_2mortal(newSVpvs("p")));
700       XPUSHs(&PL_sv_yes);
701     }
702
703 void
704 stash(re::engine::Plugin self, ...)
705 PPCODE:
706     if (items > 1) {
707         self->stash = ST(1);
708         SvREFCNT_inc(self->stash);
709         XSRETURN_EMPTY;
710     } else {
711         XPUSHs(self->stash);
712     }
713
714 void
715 minlen(re::engine::Plugin self, ...)
716 PPCODE:
717     if (items > 1) {
718         self->rx->minlen = (I32)SvIV(ST(1));
719         XSRETURN_EMPTY;
720     } else {
721         if (self->rx->minlen) {
722             XPUSHs(sv_2mortal(newSViv(self->rx->minlen)));
723         } else {
724             XPUSHs(sv_2mortal(&PL_sv_undef));
725         }
726     }
727
728 void
729 gofs(re::engine::Plugin self, ...)
730 PPCODE:
731     if (items > 1) {
732         self->rx->gofs = (U32)SvIV(ST(1));
733         XSRETURN_EMPTY;
734     } else {
735         if (self->rx->gofs) {
736             XPUSHs(sv_2mortal(newSVuv(self->rx->gofs)));
737         } else {
738             XPUSHs(sv_2mortal(&PL_sv_undef));
739         }
740     }
741
742 void
743 nparens(re::engine::Plugin self, ...)
744 PPCODE:
745     if (items > 1) {
746         self->rx->nparens = (U32)SvIV(ST(1));
747         XSRETURN_EMPTY;
748     } else {
749         if (self->rx->nparens) {
750             XPUSHs(sv_2mortal(newSVuv(self->rx->nparens)));
751         } else {
752             XPUSHs(sv_2mortal(&PL_sv_undef));
753         }
754     }
755
756 void
757 _exec(re::engine::Plugin self, ...)
758 PPCODE:
759     if (items > 1) {
760         SvREFCNT_dec(self->cb_exec);
761         self->cb_exec = ST(1);
762         SvREFCNT_inc(self->cb_exec);
763     }
764
765 void
766 _num_capture_buff_FETCH(re::engine::Plugin self, ...)
767 PPCODE:
768     if (items > 1) {
769         SvREFCNT_dec(self->cb_num_capture_buff_FETCH);
770         self->cb_num_capture_buff_FETCH = ST(1);
771         SvREFCNT_inc(self->cb_num_capture_buff_FETCH);
772     }
773
774 void
775 _num_capture_buff_STORE(re::engine::Plugin self, ...)
776 PPCODE:
777     if (items > 1) {
778         SvREFCNT_dec(self->cb_num_capture_buff_STORE);
779         self->cb_num_capture_buff_STORE = ST(1);
780         SvREFCNT_inc(self->cb_num_capture_buff_STORE);
781     }
782
783 void
784 _num_capture_buff_LENGTH(re::engine::Plugin self, ...)
785 PPCODE:
786     if (items > 1) {
787         SvREFCNT_dec(self->cb_num_capture_buff_LENGTH);
788         self->cb_num_capture_buff_LENGTH = ST(1);
789         SvREFCNT_inc(self->cb_num_capture_buff_LENGTH);
790     }
791
792 SV *
793 _tag(SV *comp, SV *exec)
794 CODE:
795     RETVAL = rep_tag(comp, exec);
796 OUTPUT:
797     RETVAL
798
799 void
800 ENGINE()
801 PPCODE:
802     XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));