Merge the last remaining case duplication in sv_upgrade
Nicholas Clark [Fri, 18 Nov 2005 17:37:39 +0000 (17:37 +0000)]
p4raw-id: //depot/perl@26164

sv.c

diff --git a/sv.c b/sv.c
index 6a342cb..3498cbf 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -1384,7 +1384,8 @@ static const struct body_details bodies_by_type[] = {
 
 /* no arena for you! */
 
-#define new_NOARENA(s) my_safecalloc(s)
+#define new_NOARENA(details) \
+       my_safecalloc((details)->size - (details)->offset)
 
 #define new_XPVFM()    my_safemalloc(sizeof(XPVFM))
 #define del_XPVFM(p)   my_safefree(p)
@@ -1564,16 +1565,14 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 new_type)
        }
        break;
 
-    case SVt_PVIO:
-    case SVt_PVFM:
-       new_body = new_NOARENA(new_type_details->size);
-       goto post_zero;
 
     case SVt_PVIV:
        /* XXX Is this still needed?  Was it ever needed?   Surely as there is
           no route from NV to PVIV, NOK can never be true  */
        assert(!SvNOKp(sv));
        assert(!SvNOK(sv));
+    case SVt_PVIO:
+    case SVt_PVFM:
     case SVt_PVBM:
     case SVt_PVGV:
     case SVt_PVCV:
@@ -1582,19 +1581,19 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 new_type)
     case SVt_PVNV:
     case SVt_PV:
 
+       assert(new_type_details->size);
 #ifndef PURIFY
-       /* This points to the start of the allocated area.  */
-       new_body_inline(new_body, bodies_by_type[new_type].size, new_type);
-       Zero(new_body, bodies_by_type[new_type].size, char);
+       if(new_type_details->arena) {
+           /* This points to the start of the allocated area.  */
+           new_body_inline(new_body, new_type_details->size, new_type);
+           Zero(new_body, new_type_details->size, char);
+           new_body = ((char *)new_body) + new_type_details->offset;
+       } else {
+           new_body = new_NOARENA(new_type_details);
+       }
 #else
        /* We always allocated the full length item with PURIFY */
-       new_body = my_safemalloc(bodies_by_type[new_type].size - bodies_by_type[new_type].offset);
-       Zero(new_body, bodies_by_type[new_type].size - bodies_by_type[new_type].offset, char);
-
-#endif
-    post_zero:
-#ifndef PURIFY
-       new_body = ((char *)new_body) + bodies_by_type[new_type].offset;
+       new_body = new_NOARENA(new_type_details);
 #endif
        SvANY(sv) = new_body;