]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - Magic.xs
Use 0 (store as-is) as the len when casting magic on the wizard
[perl/modules/Variable-Magic.git] / Magic.xs
index 5e76f8a73b25bdc688950214d81cf256b71c7f90..f4ec2923552d7a56da825e4232a27fa7ff0b7f46 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -12,8 +12,6 @@
 
 #define __PACKAGE__ "Variable::Magic"
 
-#define R(S) fprintf(stderr, "R(" #S ") = %d\n", SvREFCNT(S))
-
 #define PERL_VERSION_GE(R, V, S) (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S))))))
 
 #define PERL_VERSION_LE(R, V, S) (PERL_REVISION < (R) || (PERL_REVISION == (R) && (PERL_VERSION < (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION <= (S))))))
 
 #define VMG_HAS_PERL_AND(P, R, V, S) (PERL_VERSION_GE((R), (V), (S)) && (!VMG_PERL_PATCHLEVEL || (VMG_PERL_PATCHLEVEL >= (P))))
 
-/* --- Compatibility ------------------------------------------------------- */
+/* --- Threads and multiplicity -------------------------------------------- */
 
-#ifndef Newx
-# define Newx(v, n, c) New(0, v, n, c)
+#ifndef NOOP
+# define NOOP
 #endif
 
-#ifndef SvMAGIC_set
-# define SvMAGIC_set(sv, val) (SvMAGIC(sv) = (val))
+#ifndef dNOOP
+# define dNOOP
 #endif
 
-#ifndef mPUSHi
-# define mPUSHi(I) PUSHs(sv_2mortal(newSViv(I)))
+#if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT)
+# define VMG_MULTIPLICITY 1
+# ifndef tTHX
+#  define tTHX PerlInterpreter*
+# endif
+#else
+# define VMG_MULTIPLICITY 0
 #endif
 
-#ifndef dMY_CXT
-# define dMY_CXT
+#if VMG_MULTIPLICITY && defined(dMY_CXT) && defined(MY_CXT) && defined(START_MY_CXT) && defined(MY_CXT_INIT) && defined(MY_CXT_CLONE)
+# define VMG_THREADSAFE 1
+#else
+# define VMG_THREADSAFE 0
+# undef  dMY_CXT
+# define dMY_CXT      dNOOP
 # undef  MY_CXT
 # define MY_CXT vmg_globaldata
 # undef  START_MY_CXT
 # define START_MY_CXT STATIC my_cxt_t MY_CXT;
 # undef  MY_CXT_INIT
-# define MY_CXT_INIT
+# define MY_CXT_INIT  NOOP
 # undef  MY_CXT_CLONE
-# undef  aMY_CXT
-# undef  pMY_CXT
-# define VMG_THREADSAFE 0
-#else
-# define VMG_THREADSAFE 1
+# define MY_CXT_CLONE NOOP
+#endif
+
+/* --- Compatibility ------------------------------------------------------- */
+
+#ifndef Newx
+# define Newx(v, n, c) New(0, v, n, c)
+#endif
+
+#ifndef SvMAGIC_set
+# define SvMAGIC_set(sv, val) (SvMAGIC(sv) = (val))
+#endif
+
+#ifndef mPUSHi
+# define mPUSHi(I) PUSHs(sv_2mortal(newSViv(I)))
 #endif
 
 #ifndef PERL_MAGIC_ext
@@ -623,6 +640,9 @@ STATIC int vmg_wizard_free(pTHX_ SV *wiz, MAGIC *mg) {
  MGWIZ *w;
  dMY_CXT;
 
+ if (PL_dirty) /* during global destruction, the context is already freed */
+  return 0;
+
  w = SV2MGWIZ(wiz);
 
  if (hv_delete(MY_CXT.wizz, buf, sprintf(buf, "%u", w->sig), 0)) {
@@ -832,7 +852,7 @@ CODE:
 #endif /* VMG_UVAR */
 
  sv = MGWIZ2SV(w);
- mg = sv_magicext(sv, NULL, PERL_MAGIC_ext, &vmg_wizard_vtbl, NULL, -1);
+ mg = sv_magicext(sv, NULL, PERL_MAGIC_ext, &vmg_wizard_vtbl, NULL, 0);
  mg->mg_private = SIG_WIZ;
  SvREADONLY_on(sv);