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