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