Eliminate struct regexp_allocated and xpvio_allocated.
authorNicholas Clark <nick@ccl4.org>
Fri, 17 Jul 2009 15:17:58 +0000 (16:17 +0100)
committerNicholas Clark <nick@ccl4.org>
Fri, 17 Jul 2009 16:39:46 +0000 (17:39 +0100)
Calculate memory allocation using regexp and XPVIO, and the offset of the first
real structure member. This avoids tripping over alignment differences between
X* and x*_allocated, because x*_allocated doesn't have a double in it.

regcomp.c
regexp.h
sv.c
sv.h

index 50b0632..22c02c8 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -9452,7 +9452,8 @@ Perl_reg_temp_copy (pTHX_ REGEXP *rx)
        a case of zero-ing that, rather than copying the current length.  */
     SvPV_set(ret_x, RX_WRAPPED(rx));
     SvFLAGS(ret_x) |= SvFLAGS(rx) & (SVf_POK|SVp_POK|SVf_UTF8);
-    StructCopy(&(r->xpv_cur), &(ret->xpv_cur), struct regexp_allocated);
+    memcpy(&(ret->xpv_cur), &(r->xpv_cur),
+          sizeof(regexp) - STRUCT_OFFSET(regexp, xpv_cur));
     SvLEN_set(ret_x, 0);
     Newx(ret->offs, npar, regexp_paren_pair);
     Copy(r->offs, ret->offs, npar, regexp_paren_pair);
index e8a8cc0..fe67142 100644 (file)
--- a/regexp.h
+++ b/regexp.h
@@ -107,12 +107,6 @@ typedef struct regexp {
        _REGEXP_COMMON;
 } regexp;
 
-struct regexp_allocated {
-       _XPV_ALLOCATED_HEAD;
-       _XPVMG_HEAD;
-       _REGEXP_COMMON;
-};
-
 /*        HV *paren_names;      Optional hash of paren names
          now stored in the IV union */
 
diff --git a/sv.c b/sv.c
index 4699a4e..76fd6e4 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -975,10 +975,11 @@ static const struct body_details bodies_by_type[] = {
       HASARENA, FIT_ARENA(0, sizeof(XPVMG)) },
 
     /* something big */
-    { sizeof(struct regexp_allocated), sizeof(struct regexp_allocated),
-      + relative_STRUCT_OFFSET(struct regexp_allocated, regexp, xpv_cur),
+    { sizeof(regexp) - STRUCT_OFFSET(regexp, xpv_cur),
+      sizeof(regexp) - STRUCT_OFFSET(regexp, xpv_cur),
+      + STRUCT_OFFSET(regexp, xpv_cur),
       SVt_REGEXP, FALSE, NONV, HASARENA,
-      FIT_ARENA(0, sizeof(struct regexp_allocated))
+      FIT_ARENA(0, sizeof(regexp) - STRUCT_OFFSET(regexp, xpv_cur))
     },
 
     /* 48 */
@@ -1011,9 +1012,11 @@ static const struct body_details bodies_by_type[] = {
       SVt_PVFM, TRUE, NONV, NOARENA, FIT_ARENA(20, sizeof(xpvfm_allocated)) },
 
     /* XPVIO is 84 bytes, fits 48x */
-    { sizeof(xpvio_allocated), sizeof(xpvio_allocated),
-      + relative_STRUCT_OFFSET(xpvio_allocated, XPVIO, xpv_cur),
-      SVt_PVIO, TRUE, NONV, HASARENA, FIT_ARENA(24, sizeof(xpvio_allocated)) },
+    { sizeof(XPVIO) - STRUCT_OFFSET(XPVIO, xpv_cur),
+      sizeof(XPVIO) - STRUCT_OFFSET(XPVIO, xpv_cur),
+      + STRUCT_OFFSET(XPVIO, xpv_cur),
+      SVt_PVIO, TRUE, NONV, HASARENA,
+      FIT_ARENA(24, sizeof(XPVIO) - STRUCT_OFFSET(XPVIO, xpv_cur)) },
 };
 
 #define new_body_type(sv_type)         \
diff --git a/sv.h b/sv.h
index b10843e..0d275d2 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -567,12 +567,6 @@ struct xpvio {
     _XPVIO_TAIL;
 };
 
-typedef struct {
-    _XPV_ALLOCATED_HEAD;
-    _XPVMG_HEAD;
-    _XPVIO_TAIL;
-} xpvio_allocated;
-
 #define xio_dirp       xio_dirpu.xiou_dirp
 #define xio_any                xio_dirpu.xiou_any