On Tue, Feb 18, 2014 at 08:52:42PM +0000, Nicholas Clark wrote:

> Hence the first two patches (to Rakudo and Moar) that get a pointer to the
> MVMCollectable contained within every object. Which applies on its own,
> without adding any compiler warnings.

Fail. 2 copies of the Moar patch. And no copies of the patch attached here.
(This is what goes wrong when you use the same commit message. And then mess
up your paths)

Nicholas Clark
>From 3cef6db54879e41a2fb8d2d85255052da6d30a94 Mon Sep 17 00:00:00 2001
From: Nicholas Clark <n...@ccl4.org>
Date: Tue, 18 Feb 2014 21:32:22 +0100
Subject: [PATCH 1/1] Pass an MVMCollectable* to MVM_ASSIGN_REF(), without
 using casts.

All derivatives of MVMObject and MVMSTable contain a nested MVMCollectable
struct. By using structure member access, we can get a pointer to it without
using a cast. This encourages type safety, and reduces the number of casts
and hence places that might conceal strict aliasing violations.
---
 src/vm/moar/ops/container.c |  2 +-
 src/vm/moar/ops/perl6_ops.c | 28 ++++++++++++++--------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/vm/moar/ops/container.c b/src/vm/moar/ops/container.c
index 09e3d06..c1c591d 100644
--- a/src/vm/moar/ops/container.c
+++ b/src/vm/moar/ops/container.c
@@ -23,7 +23,7 @@ static void finish_store(MVMThreadContext *tc, MVMObject *cont, MVMObject *obj)
     MVMObject *whence;
 
     /* Store the value. */
-    MVM_ASSIGN_REF(tc, cont, rs->value, obj);
+    MVM_ASSIGN_REF(tc, &(cont->header), rs->value, obj);
 
     /* Run any whence closure. */
     whence = rs->whence;
diff --git a/src/vm/moar/ops/perl6_ops.c b/src/vm/moar/ops/perl6_ops.c
index bfea65b..336e695 100644
--- a/src/vm/moar/ops/perl6_ops.c
+++ b/src/vm/moar/ops/perl6_ops.c
@@ -150,12 +150,12 @@ static void p6settypes(MVMThreadContext *tc) {
         default_cont_desc = MVM_repr_alloc_init(tc, ContainerDescriptor);
         MVM_gc_root_add_permanent(tc, (MVMCollectable **)&default_cont_desc);
         element = MVM_string_ascii_decode_nt(tc, tc->instance->VMString, "<element>");
-        MVM_ASSIGN_REF(tc, default_cont_desc,
+        MVM_ASSIGN_REF(tc, &(default_cont_desc->header),
             ((Rakudo_ContainerDescriptor *)default_cont_desc)->of, Mu);
-        MVM_ASSIGN_REF(tc, default_cont_desc,
+        MVM_ASSIGN_REF(tc, &(default_cont_desc->header),
             ((Rakudo_ContainerDescriptor *)default_cont_desc)->name, element);
         ((Rakudo_ContainerDescriptor *)default_cont_desc)->rw = 1;
-        MVM_ASSIGN_REF(tc, default_cont_desc,
+        MVM_ASSIGN_REF(tc, &(default_cont_desc->header),
             ((Rakudo_ContainerDescriptor *)default_cont_desc)->the_default, Any);
     }
 
@@ -208,7 +208,7 @@ static void p6parcel(MVMThreadContext *tc) {
     MVMObject *parcel = MVM_repr_alloc_init(tc, Parcel);
     MVMObject *vmarr  = GET_REG(tc, 2).o;
     MVMObject *fill   = GET_REG(tc, 4).o;
-    MVM_ASSIGN_REF(tc, parcel, ((Rakudo_Parcel *)parcel)->storage, vmarr);
+    MVM_ASSIGN_REF(tc, &(parcel->header), ((Rakudo_Parcel *)parcel)->storage, vmarr);
 
     if (fill) {
         MVMint64 elems = MVM_repr_elems(tc, vmarr);
@@ -227,8 +227,8 @@ static MVMObject * make_listiter(MVMThreadContext *tc, MVMObject *items, MVMObje
     MVMROOT(tc, items, {
     MVMROOT(tc, list, {
         result = MVM_repr_alloc_init(tc, ListIter);
-        MVM_ASSIGN_REF(tc, result, ((Rakudo_ListIter *)result)->rest, items);
-        MVM_ASSIGN_REF(tc, result, ((Rakudo_ListIter *)result)->list, list);
+        MVM_ASSIGN_REF(tc, &(result->header), ((Rakudo_ListIter *)result)->rest, items);
+        MVM_ASSIGN_REF(tc, &(result->header), ((Rakudo_ListIter *)result)->list, list);
     });
     });
     return result;
@@ -246,9 +246,9 @@ static void p6list(MVMThreadContext *tc) {
             MVMObject *items = GET_REG(tc, 2).o;
             if (items) {
                 MVMObject *iter = make_listiter(tc, items, list);
-                MVM_ASSIGN_REF(tc, list, ((Rakudo_List *)list)->nextiter, iter);
+                MVM_ASSIGN_REF(tc, &(list->header), ((Rakudo_List *)list)->nextiter, iter);
             }
-            MVM_ASSIGN_REF(tc, list, ((Rakudo_List *)list)->flattens, GET_REG(tc, 6).o);
+            MVM_ASSIGN_REF(tc, &(list->header), ((Rakudo_List *)list)->flattens, GET_REG(tc, 6).o);
         });
         GET_REG(tc, 0).o = list;
     }
@@ -281,7 +281,7 @@ static void p6listitems(MVMThreadContext *tc) {
         if (!items || !IS_CONCRETE(items) || REPR(items)->ID != MVM_REPR_ID_MVMArray) {
             MVMROOT(tc, list, {
                 items = MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTArray);
-                MVM_ASSIGN_REF(tc, list, ((Rakudo_List *)list)->items, items);
+                MVM_ASSIGN_REF(tc, &(list->header), ((Rakudo_List *)list)->items, items);
             });
         }
         GET_REG(tc, 0).o = items;
@@ -311,8 +311,8 @@ static void p6scalarfromdesc(MVMThreadContext *tc) {
     if (!descriptor) {
         descriptor = default_cont_desc;
     }
-    MVM_ASSIGN_REF(tc, new_scalar, ((Rakudo_Scalar *)new_scalar)->descriptor, descriptor);
-    MVM_ASSIGN_REF(tc, new_scalar, ((Rakudo_Scalar *)new_scalar)->value,
+    MVM_ASSIGN_REF(tc, &(new_scalar->header), ((Rakudo_Scalar *)new_scalar)->descriptor, descriptor);
+    MVM_ASSIGN_REF(tc, &(new_scalar->header), ((Rakudo_Scalar *)new_scalar)->value,
         ((Rakudo_ContainerDescriptor *)descriptor)->the_default);
     GET_REG(tc, 0).o = new_scalar;
 }
@@ -329,7 +329,7 @@ static void p6recont_ro(MVMThreadContext *tc) {
             /* We have an rw container; re-containerize it. */
             MVMROOT(tc, check, {
                 MVMObject *result = MVM_repr_alloc_init(tc, Scalar);
-                MVM_ASSIGN_REF(tc, result, ((Rakudo_Scalar *)result)->value,
+                MVM_ASSIGN_REF(tc, &(result->header), ((Rakudo_Scalar *)result)->value,
                     ((Rakudo_Scalar *)check)->value);
                 GET_REG(tc, 0).o = result;
             });
@@ -350,7 +350,7 @@ static void p6var(MVMThreadContext *tc) {
      if (STABLE(wrappee)->container_spec) {
         MVMROOT(tc, wrappee, {
             MVMObject *wrapper = MVM_repr_alloc_init(tc, Scalar);
-            MVM_ASSIGN_REF(tc, wrapper, ((Rakudo_Scalar *)wrapper)->value, wrappee);
+            MVM_ASSIGN_REF(tc, &(wrapper->header), ((Rakudo_Scalar *)wrapper)->value, wrappee);
             GET_REG(tc, 0).o = wrapper;
         });
      }
@@ -392,7 +392,7 @@ static void p6decontrv(MVMThreadContext *tc) {
         if (cd && cd->rw) {
             MVMROOT(tc, retval, {
                 MVMObject *cont = MVM_repr_alloc_init(tc, Scalar);
-                MVM_ASSIGN_REF(tc, cont, ((Rakudo_Scalar *)cont)->value,
+                MVM_ASSIGN_REF(tc, &(cont->header), ((Rakudo_Scalar *)cont)->value,
                     ((Rakudo_Scalar *)retval)->value);
                 retval = cont;
             });
-- 
1.8.4.2

Reply via email to