You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/07/17 21:01:43 UTC

[lucy-commits] [3/3] git commit: refs/heads/dynamic-method-offsets - Mark VTableSpec and MethSpec arrays as const

Mark VTableSpec and MethSpec arrays as const


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/d82c5bc2
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/d82c5bc2
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/d82c5bc2

Branch: refs/heads/dynamic-method-offsets
Commit: d82c5bc2b823701828a3e9f5eabea0b8f47dd69d
Parents: b2a49b7
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Jul 17 20:25:24 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Wed Jul 17 20:53:30 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/src/CFCBindClass.c       | 11 ++++++-----
 clownfish/compiler/src/CFCBindCore.c        |  8 ++++----
 clownfish/runtime/core/Clownfish/VTable.c   | 22 +++++++++++-----------
 clownfish/runtime/core/Clownfish/VTable.cfh |  2 +-
 4 files changed, 22 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/d82c5bc2/clownfish/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindClass.c b/clownfish/compiler/src/CFCBindClass.c
index f0a86a2..f507596 100644
--- a/clownfish/compiler/src/CFCBindClass.c
+++ b/clownfish/compiler/src/CFCBindClass.c
@@ -312,7 +312,8 @@ CFCBindClass_to_c_data(CFCBindClass *self) {
                 // symbol and then store a pointer to that symbol inside the
                 // VTableSpec struct.
                 novel_ms_var
-                    = CFCUtil_cat(novel_ms_var, "static cfish_NovelMethSpec ",
+                    = CFCUtil_cat(novel_ms_var,
+                                  "static const cfish_NovelMethSpec ",
                                   vt_var, "_NOVEL_METHS[] = {\n", NULL);
             }
             else {
@@ -327,8 +328,8 @@ CFCBindClass_to_c_data(CFCBindClass *self) {
                 // Start an array of cfish_OverriddenMethSpec structs.
                 overridden_ms_var
                     = CFCUtil_cat(overridden_ms_var,
-                                  "static cfish_OverriddenMethSpec ", vt_var,
-                                  "_OVERRIDDEN_METHS[] = {\n", NULL);
+                                  "static const cfish_OverriddenMethSpec ",
+                                  vt_var, "_OVERRIDDEN_METHS[] = {\n", NULL);
             }
             else {
                 overridden_ms_var
@@ -343,8 +344,8 @@ CFCBindClass_to_c_data(CFCBindClass *self) {
                 // Start an array of cfish_InheritedMethSpec structs.
                 inherited_ms_var
                     = CFCUtil_cat(inherited_ms_var,
-                                  "static cfish_InheritedMethSpec ", vt_var,
-                                  "_INHERITED_METHS[] = {\n", NULL);
+                                  "static const cfish_InheritedMethSpec ",
+                                  vt_var, "_INHERITED_METHS[] = {\n", NULL);
             }
             else {
                 inherited_ms_var = CFCUtil_cat(inherited_ms_var, ",\n", NULL);

http://git-wip-us.apache.org/repos/asf/lucy/blob/d82c5bc2/clownfish/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindCore.c b/clownfish/compiler/src/CFCBindCore.c
index 41f634b..af28e6a 100644
--- a/clownfish/compiler/src/CFCBindCore.c
+++ b/clownfish/compiler/src/CFCBindCore.c
@@ -250,9 +250,9 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
         "    uint32_t       num_novel_meths;\n"
         "    uint32_t       num_overridden_meths;\n"
         "    uint32_t       num_inherited_meths;\n"
-        "    cfish_NovelMethSpec      *novel_meth_specs;\n"
-        "    cfish_OverriddenMethSpec *overridden_meth_specs;\n"
-        "    cfish_InheritedMethSpec  *inherited_meth_specs;\n"
+        "    const cfish_NovelMethSpec      *novel_meth_specs;\n"
+        "    const cfish_OverriddenMethSpec *overridden_meth_specs;\n"
+        "    const cfish_InheritedMethSpec  *inherited_meth_specs;\n"
         "} cfish_VTableSpec;\n"
         "\n"
         "#ifdef CFISH_USE_SHORT_NAMES\n"
@@ -355,7 +355,7 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) {
     char *includes     = CFCUtil_strdup("");
     char *c_data       = CFCUtil_strdup("");
     char *vt_specs = CFCUtil_strdup(
-        "static cfish_VTableSpec vtable_specs[] = {\n");
+        "static const cfish_VTableSpec vtable_specs[] = {\n");
     int num_specs = 0;
     CFCClass **ordered  = CFCHierarchy_ordered_classes(hierarchy);
     for (int i = 0; ordered[i] != NULL; i++) {

http://git-wip-us.apache.org/repos/asf/lucy/blob/d82c5bc2/clownfish/runtime/core/Clownfish/VTable.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/VTable.c b/clownfish/runtime/core/Clownfish/VTable.c
index 11222e9..58391b2 100644
--- a/clownfish/runtime/core/Clownfish/VTable.c
+++ b/clownfish/runtime/core/Clownfish/VTable.c
@@ -52,7 +52,7 @@ S_claim_parcel_id(void);
 LockFreeRegistry *VTable_registry = NULL;
 
 void
-VTable_bootstrap(VTableSpec *specs, size_t num_specs)
+VTable_bootstrap(const VTableSpec *specs, size_t num_specs)
 {
     int32_t parcel_id = S_claim_parcel_id();
 
@@ -64,8 +64,8 @@ VTable_bootstrap(VTableSpec *specs, size_t num_specs)
      * - Initialize method pointers.
      */
     for (size_t i = 0; i < num_specs; ++i) {
-        VTableSpec *spec   = &specs[i];
-        VTable     *parent = spec->parent ? *spec->parent : NULL;
+        const VTableSpec *spec = &specs[i];
+        VTable *parent = spec->parent ? *spec->parent : NULL;
 
         size_t ivars_offset = 0;
         if (spec->ivars_offset_ptr != NULL) {
@@ -103,18 +103,18 @@ VTable_bootstrap(VTableSpec *specs, size_t num_specs)
         }
 
         for (size_t i = 0; i < spec->num_inherited_meths; ++i) {
-            InheritedMethSpec *mspec = &spec->inherited_meth_specs[i];
+            const InheritedMethSpec *mspec = &spec->inherited_meth_specs[i];
             *mspec->offset = *mspec->parent_offset;
         }
 
         for (size_t i = 0; i < spec->num_overridden_meths; ++i) {
-            OverriddenMethSpec *mspec = &spec->overridden_meth_specs[i];
+            const OverriddenMethSpec *mspec = &spec->overridden_meth_specs[i];
             *mspec->offset = *mspec->parent_offset;
             VTable_override(vtable, mspec->func, *mspec->offset);
         }
 
         for (size_t i = 0; i < spec->num_novel_meths; ++i) {
-            NovelMethSpec *mspec = &spec->novel_meth_specs[i];
+            const NovelMethSpec *mspec = &spec->novel_meth_specs[i];
             *mspec->offset = novel_offset;
             novel_offset += sizeof(cfish_method_t);
             VTable_override(vtable, mspec->func, *mspec->offset);
@@ -128,8 +128,8 @@ VTable_bootstrap(VTableSpec *specs, size_t num_specs)
      * - Initialize refcount.
      */
     for (size_t i = 0; i < num_specs; ++i) {
-        VTableSpec *spec   = &specs[i];
-        VTable     *vtable = *spec->vtable;
+        const VTableSpec *spec = &specs[i];
+        VTable *vtable = *spec->vtable;
 
         VTable_init_obj(VTABLE, vtable);
     }
@@ -141,14 +141,14 @@ VTable_bootstrap(VTableSpec *specs, size_t num_specs)
      * - Register vtable.
      */
     for (size_t i = 0; i < num_specs; ++i) {
-        VTableSpec *spec   = &specs[i];
-        VTable     *vtable = *spec->vtable;
+        const VTableSpec *spec = &specs[i];
+        VTable *vtable = *spec->vtable;
 
         vtable->name    = CB_newf("%s", spec->name);
         vtable->methods = VA_new(0);
 
         for (size_t i = 0; i < spec->num_novel_meths; ++i) {
-            NovelMethSpec *mspec = &spec->novel_meth_specs[i];
+            const NovelMethSpec *mspec = &spec->novel_meth_specs[i];
             CharBuf *name = CB_newf("%s", mspec->name);
             Method *method = Method_new(name, mspec->callback_func,
                                         *mspec->offset);

http://git-wip-us.apache.org/repos/asf/lucy/blob/d82c5bc2/clownfish/runtime/core/Clownfish/VTable.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/VTable.cfh b/clownfish/runtime/core/Clownfish/VTable.cfh
index 6d62f44..c065495 100644
--- a/clownfish/runtime/core/Clownfish/VTable.cfh
+++ b/clownfish/runtime/core/Clownfish/VTable.cfh
@@ -38,7 +38,7 @@ class Clownfish::VTable inherits Clownfish::Obj {
     inert size_t offset_of_parent;
 
     inert void
-    bootstrap(cfish_VTableSpec *specs, size_t num_specs);
+    bootstrap(const cfish_VTableSpec *specs, size_t num_specs);
 
     /** Return a singleton.  If a VTable can be found in the registry based on
      * the supplied class name, it will be returned.  Otherwise, a new VTable