]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - Magic.xs
Execute magic callbacks into separate stacks
[perl/modules/Variable-Magic.git] / Magic.xs
index d579f9ee0e0f4ed31666cc4f9ba9f17add425c0a..432eeed37ba1039d8c4f9f01da4598632e2da201 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
 # define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling)
 #endif
 
+#ifndef OP_NAME
+# define OP_NAME(O) (PL_op_name[(O)->op_type])
+#endif
+
+#ifndef OP_CLASS
+# define OP_CLASS(O) (PL_opargs[(O)->op_type] & OA_CLASS_MASK)
+#endif
+
 #ifdef DEBUGGING
 # define VMG_ASSERT(C) assert(C)
 #else
@@ -420,7 +428,8 @@ static const char *const vmg_opclassnames[] = {
  NULL
 };
 
-static opclass vmg_opclass(const OP *o) {
+static opclass vmg_opclass(pTHX_ const OP *o) {
+#define vmg_opclass(O) vmg_opclass(aTHX_ (O))
 #if 0
  if (!o)
   return OPc_NULL;
@@ -455,7 +464,7 @@ static opclass vmg_opclass(const OP *o) {
   return OPc_PADOP;
 #endif
 
- switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
+ switch (OP_CLASS(o)) {
   case OA_BASEOP:
    return OPc_BASEOP;
   case OA_UNOP:
@@ -473,7 +482,11 @@ static opclass vmg_opclass(const OP *o) {
   case OA_PADOP:
    return OPc_PADOP;
   case OA_PVOP_OR_SVOP:
-   return (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))
+   return (
+#if VMG_HAS_PERL(5, 13, 7)
+           (o->op_type != OP_CUSTOM) &&
+#endif
+           (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF)))
 #if defined(USE_ITHREADS) && VMG_HAS_PERL(5, 8, 9)
            ? OPc_PADOP : OPc_PVOP;
 #else
@@ -844,6 +857,8 @@ static SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, SV **args, I32 items) {
  ENTER;
  SAVETMPS;
 
+ PUSHSTACKi(PERLSI_MAGIC);
+
  PUSHMARK(SP);
  EXTEND(SP, items + 1);
  PUSHs(sv_2mortal(newRV_inc(sv)));
@@ -862,6 +877,8 @@ static SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, SV **args, I32 items) {
 #endif
  PUTBACK;
 
+ POPSTACK;
+
  FREETMPS;
  LEAVE;
 
@@ -1143,8 +1160,12 @@ static SV *vmg_op_info(pTHX_ unsigned int opinfo) {
 
  switch (opinfo) {
   case VMG_OP_INFO_NAME: {
-   OPCODE t = PL_op->op_type;
-   return sv_2mortal(newSVpvn(PL_op_name[t], vmg_op_name_len[t]));
+   const char *name;
+   STRLEN      name_len;
+   OPCODE      t = PL_op->op_type;
+   name     = OP_NAME(PL_op);
+   name_len = (t == OP_CUSTOM) ? strlen(name) : vmg_op_name_len[t];
+   return sv_2mortal(newSVpvn(name, name_len));
   }
   case VMG_OP_INFO_OBJECT: {
    dMY_CXT;
@@ -1243,6 +1264,8 @@ static int vmg_cb_call(pTHX_ SV *cb, unsigned int flags, SV *sv, ...) {
  ENTER;
  SAVETMPS;
 
+ PUSHSTACKi(PERLSI_MAGIC);
+
  PUSHMARK(SP);
  EXTEND(SP, args + 1);
  PUSHs(sv_2mortal(newRV_inc(sv)));
@@ -1277,6 +1300,8 @@ static int vmg_cb_call(pTHX_ SV *cb, unsigned int flags, SV *sv, ...) {
   svr = NULL;
  PUTBACK;
 
+ POPSTACK;
+
  FREETMPS;
  LEAVE;
 
@@ -1353,6 +1378,8 @@ static U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) {
  ENTER;
  SAVETMPS;
 
+ PUSHSTACKi(PERLSI_MAGIC);
+
  PUSHMARK(SP);
  EXTEND(SP, 3);
  PUSHs(sv_2mortal(newRV_inc(sv)));
@@ -1380,6 +1407,8 @@ static U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) {
   --ret;
  PUTBACK;
 
+ POPSTACK;
+
  FREETMPS;
  LEAVE;
 
@@ -1554,6 +1583,8 @@ static int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) {
  ENTER;
  SAVETMPS;
 
+ PUSHSTACKi(PERLSI_MAGIC);
+
  PUSHMARK(SP);
  EXTEND(SP, 2);
  PUSHs(sv_2mortal(newRV_inc(sv)));
@@ -1581,6 +1612,8 @@ static int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) {
   ret = (int) SvIV(svr);
  PUTBACK;
 
+ POPSTACK;
+
  FREETMPS;
  LEAVE;