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