]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - Plugin.xs
Identify the require scope by the outmost cv outside of the current one
[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  require_tag;
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_simple(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_simple_void(h2->comp);
130  h2->exec        = rep_clone(h1->exec, ud->owner);
131  SvREFCNT_inc_simple_void(h2->exec);
132 #if REP_WORKAROUND_REQUIRE_PROPAGATION
133  h2->require_tag = PTR2IV(rep_clone(INT2PTR(SV *, h1->require_tag), ud->owner));
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 CV *cv, *outside;
164
165  cv = PL_compcv;
166
167  if (!cv) {
168   /* If for some reason the pragma is operational at run-time, try to discover
169    * the current cv in use. */
170   const PERL_SI *si;
171
172   for (si = PL_curstackinfo; si; si = si->si_prev) {
173    I32 cxix;
174
175    for (cxix = si->si_cxix; cxix >= 0; --cxix) {
176     const PERL_CONTEXT *cx = si->si_cxstack + cxix;
177
178     switch (CxTYPE(cx)) {
179      case CXt_SUB:
180      case CXt_FORMAT:
181       /* The propagation workaround is only needed up to 5.10.0 and at that
182        * time format and sub contexts were still identical. And even later the
183        * cv members offsets should have been kept the same. */
184       cv = cx->blk_sub.cv;
185       goto get_enclosing_cv;
186      case CXt_EVAL:
187       cv = cx->blk_eval.cv;
188       goto get_enclosing_cv;
189      default:
190       break;
191     }
192    }
193   }
194
195   cv = PL_main_cv;
196  }
197
198 get_enclosing_cv:
199  for (outside = CvOUTSIDE(cv); outside; outside = CvOUTSIDE(cv))
200   cv = outside;
201
202  return PTR2IV(cv);
203 }
204 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
205
206 STATIC SV *rep_tag(pTHX_ SV *comp, SV *exec) {
207 #define rep_tag(C, E) rep_tag(aTHX_ (C), (E))
208  rep_hint_t *h;
209  dMY_CXT;
210
211  h              = PerlMemShared_malloc(sizeof *h);
212  h->comp        = rep_validate_callback(comp);
213  h->exec        = rep_validate_callback(exec);
214 #if REP_WORKAROUND_REQUIRE_PROPAGATION
215  h->require_tag = rep_require_tag();
216 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
217
218 #if REP_THREADSAFE
219  /* We only need for the key to be an unique tag for looking up the value later.
220   * Allocated memory provides convenient unique identifiers, so that's why we
221   * use the hint as the key itself. */
222  ptable_store(MY_CXT.tbl, h, h);
223 #endif /* REP_THREADSAFE */
224
225  return newSViv(PTR2IV(h));
226 }
227
228 STATIC const rep_hint_t *rep_detag(pTHX_ const SV *hint) {
229 #define rep_detag(H) rep_detag(aTHX_ (H))
230  rep_hint_t *h;
231  dMY_CXT;
232
233  if (!(hint && SvIOK(hint)))
234   return NULL;
235
236  h = INT2PTR(rep_hint_t *, SvIVX(hint));
237 #if REP_THREADSAFE
238  h = ptable_fetch(MY_CXT.tbl, h);
239 #endif /* REP_THREADSAFE */
240
241 #if REP_WORKAROUND_REQUIRE_PROPAGATION
242  if (rep_require_tag() != h->require_tag)
243   return NULL;
244 #endif /* REP_WORKAROUND_REQUIRE_PROPAGATION */
245
246  return h;
247 }
248
249 STATIC U32 rep_hash = 0;
250
251 STATIC const rep_hint_t *rep_hint(pTHX) {
252 #define rep_hint() rep_hint(aTHX)
253  SV *hint;
254
255 #ifdef cop_hints_fetch_pvn
256  hint = cop_hints_fetch_pvn(PL_curcop,
257                             __PACKAGE__, __PACKAGE_LEN__, rep_hash, 0);
258 #else
259  /* We already require 5.9.5 for the regexp engine API. */
260  hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash,
261                                        NULL,
262                                        __PACKAGE__, __PACKAGE_LEN__,
263                                        0,
264                                        rep_hash);
265 #endif
266
267  return rep_detag(hint);
268 }
269
270 REGEXP *
271 #if PERL_VERSION <= 10
272 Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
273 #else
274 Plugin_comp(pTHX_ SV * const pattern, U32 flags)
275 #endif
276 {
277     dSP;
278     struct regexp * rx;
279     REGEXP *RX;
280
281     re__engine__Plugin re;
282     const rep_hint_t *h;
283
284     STRLEN plen;
285     char *pbuf;
286
287     SV *obj;
288
289     h = rep_hint();
290     if (!h) /* This looks like a pragma leak. Apply the default behaviour */
291         return re_compile(pattern, flags);
292
293     /* exp/xend version of the pattern & length */
294     pbuf = SvPV((SV*)pattern, plen);
295
296     /* Our blessed object */
297     obj = newSV(0);
298     SvREFCNT_inc_simple_void_NN(obj);
299     Newxz(re, 1, struct replug);
300     sv_setref_pv(obj, "re::engine::Plugin", (void*)re);
301
302     newREGEXP(RX);
303     rx = rxREGEXP(RX);
304
305     re->rx = rx;                   /* Make the rx accessible from self->rx */
306     rx->intflags = flags;          /* Flags for internal use */
307     rx->extflags = flags;          /* Flags for perl to use */
308     rx->engine = RE_ENGINE_PLUGIN; /* Compile to use this engine */
309
310 #if PERL_VERSION <= 10
311     rx->refcnt = 1;                /* Refcount so we won't be destroyed */
312
313     /* Precompiled pattern for pp_regcomp to use */
314     rx->prelen = plen;
315     rx->precomp = savepvn(pbuf, rx->prelen);
316
317     /* Set up qr// stringification to be equivalent to the supplied
318      * pattern, this should be done via overload eventually.
319      */
320     rx->wraplen = rx->prelen;
321     Newx(rx->wrapped, rx->wraplen, char);
322     Copy(rx->precomp, rx->wrapped, rx->wraplen, char);
323 #endif
324
325     /* Store our private object */
326     rx->pprivate = obj;
327
328     /* Store the pattern for ->pattern */
329     re->pattern = (SV*)pattern;
330     SvREFCNT_inc_simple_void(re->pattern);
331
332     /* If there's an exec callback, store it into the private object so
333      * that it will be the one to be called, even if the engine changes
334      * in between */
335     if (h->exec) {
336         re->cb_exec = h->exec;
337         SvREFCNT_inc_simple_void_NN(h->exec);
338     }
339
340     re->cb_num_capture_buff_FETCH  = NULL;
341     re->cb_num_capture_buff_STORE  = NULL;
342     re->cb_num_capture_buff_LENGTH = NULL;
343
344     /* Call our callback function if one was defined, if not we've
345      * already set up all the stuff we're going to to need for
346      * subsequent exec and other calls */
347     if (h->comp) {
348         ENTER;    
349         SAVETMPS;
350    
351         PUSHMARK(SP);
352         XPUSHs(obj);
353         PUTBACK;
354
355         call_sv(h->comp, G_DISCARD);
356
357         FREETMPS;
358         LEAVE;
359     }
360
361     /* If any of the comp-time accessors were called we'll have to
362      * update the regexp struct with the new info.
363      */
364
365     Newxz(rx->offs, rx->nparens + 1, regexp_paren_pair);
366
367     return RX;
368 }
369
370 I32
371 Plugin_exec(pTHX_ REGEXP * const RX, char *stringarg, char *strend,
372             char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
373 {
374     dSP;
375     I32 matched;
376     struct regexp *rx = rxREGEXP(RX);
377     GET_SELF_FROM_PPRIVATE(rx->pprivate);
378
379     if (self->cb_exec) {
380         SV *ret;
381
382         /* Store the current str for ->str */
383         SvREFCNT_dec(self->str);
384         self->str = sv;
385         SvREFCNT_inc_simple_void(self->str);
386
387         ENTER;
388         SAVETMPS;
389    
390         PUSHMARK(SP);
391         XPUSHs(rx->pprivate);
392         XPUSHs(sv);
393         PUTBACK;
394
395         call_sv(self->cb_exec, G_SCALAR);
396  
397         SPAGAIN;
398
399         ret = POPs;
400         if (SvTRUE(ret))
401             matched = 1;
402         else
403             matched = 0;
404
405         PUTBACK;
406         FREETMPS;
407         LEAVE;
408     } else {
409         matched = 0;
410     }
411
412     return matched;
413 }
414
415 char *
416 Plugin_intuit(pTHX_ REGEXP * const RX, SV *sv, char *strpos,
417                      char *strend, U32 flags, re_scream_pos_data *data)
418 {
419     PERL_UNUSED_ARG(RX);
420     PERL_UNUSED_ARG(sv);
421     PERL_UNUSED_ARG(strpos);
422     PERL_UNUSED_ARG(strend);
423     PERL_UNUSED_ARG(flags);
424     PERL_UNUSED_ARG(data);
425     return NULL;
426 }
427
428 SV *
429 Plugin_checkstr(pTHX_ REGEXP * const RX)
430 {
431     PERL_UNUSED_ARG(RX);
432     return NULL;
433 }
434
435 void
436 Plugin_free(pTHX_ REGEXP * const RX)
437 {
438     struct regexp *rx = rxREGEXP(RX);
439     GET_SELF_FROM_PPRIVATE(rx->pprivate);
440
441     SvREFCNT_dec(self->pattern);
442     SvREFCNT_dec(self->str);
443
444     SvREFCNT_dec(self->cb_exec);
445
446     SvREFCNT_dec(self->cb_num_capture_buff_FETCH);
447     SvREFCNT_dec(self->cb_num_capture_buff_STORE);
448     SvREFCNT_dec(self->cb_num_capture_buff_LENGTH);
449
450     self->rx = NULL;
451     Safefree(self);
452
453 /*
454     dSP;
455     SV * callback;
456
457     callback = self->cb_free;
458
459     if (callback) {
460         ENTER;
461         SAVETMPS;
462    
463         PUSHMARK(SP);
464         XPUSHs(rx->pprivate);
465         PUTBACK;
466
467         call_sv(callback, G_DISCARD);
468
469         PUTBACK;
470         FREETMPS;
471         LEAVE;
472     }
473     return;
474 */
475 }
476
477 void *
478 Plugin_dupe(pTHX_ REGEXP * const RX, CLONE_PARAMS *param)
479 {
480     struct regexp *rx = rxREGEXP(RX);
481     Perl_croak(aTHX_ "dupe not supported yet");
482     return rx->pprivate;
483 }
484
485
486 void
487 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const RX, const I32 paren,
488                            SV * const sv)
489 {
490     dSP;
491     I32 items;
492     SV * callback;
493     struct regexp *rx = rxREGEXP(RX);
494     GET_SELF_FROM_PPRIVATE(rx->pprivate);
495
496     callback = self->cb_num_capture_buff_FETCH;
497
498     if (callback) {
499         ENTER;
500         SAVETMPS;
501    
502         PUSHMARK(SP);
503         XPUSHs(rx->pprivate);
504         XPUSHs(sv_2mortal(newSViv(paren)));
505         PUTBACK;
506
507         items = call_sv(callback, G_SCALAR);
508         
509         if (items == 1) {
510             SV *ret;
511
512             SPAGAIN;
513             ret = POPs;
514             sv_setsv(sv, ret);
515         } else {
516             sv_setsv(sv, &PL_sv_undef);
517         }
518
519         PUTBACK;
520         FREETMPS;
521         LEAVE;
522     } else {
523         sv_setsv(sv, &PL_sv_undef);
524     }
525 }
526
527 void
528 Plugin_numbered_buff_STORE(pTHX_ REGEXP * const RX, const I32 paren,
529                            SV const * const value)
530 {
531     dSP;
532     SV * callback;
533     struct regexp *rx = rxREGEXP(RX);
534     GET_SELF_FROM_PPRIVATE(rx->pprivate);
535
536     callback = self->cb_num_capture_buff_STORE;
537
538     if (callback) {
539         ENTER;
540         SAVETMPS;
541    
542         PUSHMARK(SP);
543         XPUSHs(rx->pprivate);
544         XPUSHs(sv_2mortal(newSViv(paren)));
545         XPUSHs((SV *) value);
546         PUTBACK;
547
548         call_sv(callback, G_DISCARD);
549
550         PUTBACK;
551         FREETMPS;
552         LEAVE;
553     }
554 }
555
556 I32
557 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const RX, const SV * const sv,
558                               const I32 paren)
559 {
560     dSP;
561     SV * callback;
562     struct regexp *rx = rxREGEXP(RX);
563     GET_SELF_FROM_PPRIVATE(rx->pprivate);
564
565     callback = self->cb_num_capture_buff_LENGTH;
566
567     if (callback) {
568         IV ret;
569
570         ENTER;
571         SAVETMPS;
572    
573         PUSHMARK(SP);
574         XPUSHs(rx->pprivate);
575         XPUSHs(sv_2mortal(newSViv(paren)));
576         PUTBACK;
577
578         call_sv(callback, G_SCALAR);
579
580         SPAGAIN;
581
582         ret = POPi;
583
584         PUTBACK;
585         FREETMPS;
586         LEAVE;
587
588         return (I32)ret;
589     } else {
590         /* TODO: call FETCH and get the length on that value */
591         return 0;
592     }
593 }
594
595
596 SV*
597 Plugin_named_buff (pTHX_ REGEXP * const RX, SV * const key, SV * const value,
598                    const U32 flags)
599 {
600     return NULL;
601 }
602
603 SV*
604 Plugin_named_buff_iter (pTHX_ REGEXP * const RX, const SV * const lastkey,
605                         const U32 flags)
606 {
607     return NULL;
608 }
609
610 SV*
611 Plugin_package(pTHX_ REGEXP * const RX)
612 {
613     PERL_UNUSED_ARG(RX);
614     return newSVpvs("re::engine::Plugin");
615 }
616
617 #if REP_THREADSAFE
618
619 STATIC U32 rep_initialized = 0;
620
621 STATIC void rep_teardown(pTHX_ void *root) {
622  dMY_CXT;
623
624  if (!rep_initialized || aTHX != root)
625   return;
626
627  ptable_free(MY_CXT.tbl);
628
629  rep_initialized = 0;
630 }
631
632 STATIC void rep_setup(pTHX) {
633 #define rep_setup() rep_setup(aTHX)
634  if (rep_initialized)
635   return;
636
637  MY_CXT_INIT;
638  MY_CXT.tbl   = ptable_new();
639  MY_CXT.owner = aTHX;
640
641  call_atexit(rep_teardown, aTHX);
642
643  rep_initialized = 1;
644 }
645
646 #else  /*  REP_THREADSAFE */
647
648 #define rep_setup()
649
650 #endif /* !REP_THREADSAFE */
651
652 STATIC U32 rep_booted = 0;
653
654 /* --- XS ------------------------------------------------------------------ */
655
656 MODULE = re::engine::Plugin       PACKAGE = re::engine::Plugin
657
658 PROTOTYPES: DISABLE
659
660 BOOT:
661 {
662     if (!rep_booted++) {
663         PERL_HASH(rep_hash, __PACKAGE__, __PACKAGE_LEN__);
664     }
665
666     rep_setup();
667 }
668
669 #if REP_THREADSAFE
670
671 void
672 CLONE(...)
673 PREINIT:
674     ptable *t;
675 PPCODE:
676     {
677         my_cxt_t ud;
678         dMY_CXT;
679         ud.tbl   = t = ptable_new();
680         ud.owner = MY_CXT.owner;
681         ptable_walk(MY_CXT.tbl, rep_ptable_clone, &ud);
682     }
683     {
684         MY_CXT_CLONE;
685         MY_CXT.tbl   = t;
686         MY_CXT.owner = aTHX;
687     }
688     reap(3, rep_thread_cleanup, NULL);
689     XSRETURN(0);
690
691 #endif /* REP_THREADSAFE */
692
693 void
694 pattern(re::engine::Plugin self, ...)
695 PPCODE:
696     XPUSHs(self->pattern);
697
698 void
699 str(re::engine::Plugin self, ...)
700 PPCODE:
701     XPUSHs(self->str);
702
703 void
704 mod(re::engine::Plugin self)
705 PREINIT:
706     U32 flags;
707     char mods[5 + 1];
708     int n = 0, i;
709 PPCODE:
710     flags = self->rx->intflags;
711     if (flags & PMf_FOLD)         /* /i */
712         mods[n++] = 'i';
713     if (flags & PMf_MULTILINE)    /* /m */
714         mods[n++] = 'm';
715     if (flags & PMf_SINGLELINE)   /* /s */
716         mods[n++] = 's';
717     if (flags & PMf_EXTENDED)     /* /x */
718         mods[n++] = 'x';
719     if (flags & RXf_PMf_KEEPCOPY) /* /p */
720         mods[n++] = 'p';
721     mods[n] = '\0';
722     EXTEND(SP, 2 * n);
723     for (i = 0; i < n; ++i) {
724         mPUSHp(mods + i, 1);
725         PUSHs(&PL_sv_yes);
726     }
727     XSRETURN(2 * n);
728
729 void
730 stash(re::engine::Plugin self, ...)
731 PPCODE:
732     if (items > 1) {
733         SvREFCNT_dec(self->stash);
734         self->stash = ST(1);
735         SvREFCNT_inc_simple_void(self->stash);
736         XSRETURN_EMPTY;
737     } else {
738         XPUSHs(self->stash);
739     }
740
741 void
742 minlen(re::engine::Plugin self, ...)
743 PPCODE:
744     if (items > 1) {
745         self->rx->minlen = (I32)SvIV(ST(1));
746         XSRETURN_EMPTY;
747     } else {
748         if (self->rx->minlen) {
749             XPUSHs(sv_2mortal(newSViv(self->rx->minlen)));
750         } else {
751             XPUSHs(sv_2mortal(&PL_sv_undef));
752         }
753     }
754
755 void
756 gofs(re::engine::Plugin self, ...)
757 PPCODE:
758     if (items > 1) {
759         self->rx->gofs = (U32)SvIV(ST(1));
760         XSRETURN_EMPTY;
761     } else {
762         if (self->rx->gofs) {
763             XPUSHs(sv_2mortal(newSVuv(self->rx->gofs)));
764         } else {
765             XPUSHs(sv_2mortal(&PL_sv_undef));
766         }
767     }
768
769 void
770 nparens(re::engine::Plugin self, ...)
771 PPCODE:
772     if (items > 1) {
773         self->rx->nparens = (U32)SvIV(ST(1));
774         XSRETURN_EMPTY;
775     } else {
776         if (self->rx->nparens) {
777             XPUSHs(sv_2mortal(newSVuv(self->rx->nparens)));
778         } else {
779             XPUSHs(sv_2mortal(&PL_sv_undef));
780         }
781     }
782
783 void
784 _exec(re::engine::Plugin self, ...)
785 PPCODE:
786     if (items > 1) {
787         SvREFCNT_dec(self->cb_exec);
788         self->cb_exec = ST(1);
789         SvREFCNT_inc_simple_void(self->cb_exec);
790     }
791
792 void
793 _num_capture_buff_FETCH(re::engine::Plugin self, ...)
794 PPCODE:
795     if (items > 1) {
796         SvREFCNT_dec(self->cb_num_capture_buff_FETCH);
797         self->cb_num_capture_buff_FETCH = ST(1);
798         SvREFCNT_inc_simple_void(self->cb_num_capture_buff_FETCH);
799     }
800
801 void
802 _num_capture_buff_STORE(re::engine::Plugin self, ...)
803 PPCODE:
804     if (items > 1) {
805         SvREFCNT_dec(self->cb_num_capture_buff_STORE);
806         self->cb_num_capture_buff_STORE = ST(1);
807         SvREFCNT_inc_simple_void(self->cb_num_capture_buff_STORE);
808     }
809
810 void
811 _num_capture_buff_LENGTH(re::engine::Plugin self, ...)
812 PPCODE:
813     if (items > 1) {
814         SvREFCNT_dec(self->cb_num_capture_buff_LENGTH);
815         self->cb_num_capture_buff_LENGTH = ST(1);
816         SvREFCNT_inc_simple_void(self->cb_num_capture_buff_LENGTH);
817     }
818
819 SV *
820 _tag(SV *comp, SV *exec)
821 CODE:
822     RETVAL = rep_tag(comp, exec);
823 OUTPUT:
824     RETVAL
825
826 void
827 ENGINE()
828 PPCODE:
829     XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));