]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - Magic.xs
Don't even define a CLONE sub when the module isn't thread safe
[perl/modules/Variable-Magic.git] / Magic.xs
index 76e88216920933deb17c06986a20112e7060d73f..5b4576aed6b1da7f3dfdc55e987aeb52495034a3 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -594,7 +594,7 @@ STATIC int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) {
  if (SvTYPE(wiz) == SVTYPEMASK)
   return 0;
 
- /* So that it can survive tmp cleanup in vmg_cb_call */
+ /* So that it survives the temp cleanup in vmg_cb_call */
  SvREFCNT_inc(sv);
 
 #if !VMG_HAS_PERL_MAINT(5, 11, 0, 32686)
@@ -604,14 +604,14 @@ STATIC int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) {
  SvMAGIC_set(sv, mg);
 #endif
 
- /* Perl_mg_free will get rid of the magic and decrement mg->mg_obj and
-  * mg->mg_ptr reference count */
  ret = vmg_cb_call1e(SV2MGWIZ(wiz)->cb_free, sv, mg->mg_obj);
 
  /* Calling SvREFCNT_dec() will trigger destructors in an infinite loop, so
   * we have to rely on SvREFCNT() being a lvalue. Heck, even the core does it */
  --SvREFCNT(sv);
 
+ /* Perl_mg_free will get rid of the magic and decrement mg->mg_obj and
+  * mg->mg_ptr reference count */
  return ret;
 }
 
@@ -694,7 +694,7 @@ STATIC I32 vmg_svt_val(pTHX_ IV action, SV *sv) {
     continue;
    case 2:
     if (!newkey)
-     newkey = key = umg->mg_obj = sv_2mortal(newSVsv(umg->mg_obj));
+     newkey = key = umg->mg_obj = sv_mortalcopy(umg->mg_obj);
   }
   switch (action) {
    case 0:
@@ -971,13 +971,14 @@ BOOT:
  newCONSTSUB(stash, "VMG_THREADSAFE",      newSVuv(VMG_THREADSAFE));
 }
 
+#if VMG_THREADSAFE
+
 void
 CLONE(...)
 PROTOTYPE: DISABLE
 PREINIT:
  HV *hv;
 CODE:
-#if VMG_THREADSAFE
  {
   HE *key;
   dMY_CXT;
@@ -1000,6 +1001,7 @@ CODE:
   MY_CXT_CLONE;
   MY_CXT = hv;
  }
+
 #endif /* VMG_THREADSAFE */
 
 SV *_wizard(...)