You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2013/06/14 05:47:42 UTC

[lucy-commits] [4/5] git commit: refs/heads/LUCY-256-thunk-hack1 - Add thunk declarations to parcel headers.

Add thunk declarations to parcel headers.


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

Branch: refs/heads/LUCY-256-thunk-hack1
Commit: 2621c292619314be7e15786faf67cd66828dd6ec
Parents: 9b52f05
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Thu Jun 13 20:42:30 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Thu Jun 13 20:42:30 2013 -0700

----------------------------------------------------------------------
 clownfish/compiler/src/CFCBindCore.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/2621c292/clownfish/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindCore.c b/clownfish/compiler/src/CFCBindCore.c
index a145a7a..794c5dd 100644
--- a/clownfish/compiler/src/CFCBindCore.c
+++ b/clownfish/compiler/src/CFCBindCore.c
@@ -154,6 +154,26 @@ S_write_aliases_txt(CFCBindCore *self, CFCParcel *parcel) {
     FREEMEM(file_content);
 }
 
+static char*
+S_gen_cfish_thunk_declarations() {
+    int offset = 56; // offsetof(cfish_VTable, methods)
+    int max_methods = 256;
+    char *thunks = CFCUtil_strdup("\n");
+    static const char pattern[] =
+        "CFISH_VISIBLE void\n"
+        "cfish_thunk%d(const void *vself);\n"
+        "\n";
+    char buf[sizeof(pattern) + 32];
+
+    for (int i = 0; i < max_methods; i++) {
+        sprintf(buf, pattern, offset);
+        thunks = CFCUtil_cat(thunks, buf, NULL);
+        offset += 8; // sizeof(void*)
+    }
+
+    return thunks;
+}
+
 /* Write the "parcel.h" header file, which contains common symbols needed by
  * all classes, plus typedefs for all class structs.
  */
@@ -295,6 +315,10 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
         FREEMEM(dep_parcels);
     }
 
+    char *thunk_decs = (strcmp(prefix, "cfish_") == 0)
+                       ? S_gen_cfish_thunk_declarations()
+                       : CFCUtil_strdup("");
+
     const char pattern[] =
         "%s\n"
         "#ifndef CFISH_%sPARCEL_H\n"
@@ -316,6 +340,7 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
         "%s" // Typedefs.
         "\n"
         "%s" // Extra definitions.
+        "%s" // Thunk declarations.
         "%sVISIBLE void\n"
         "%sbootstrap_inheritance();\n"
         "\n"
@@ -336,8 +361,8 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
     char *file_content
         = CFCUtil_sprintf(pattern, self->header, PREFIX, PREFIX,
                           extra_includes, privacy_sym, PREFIX, PREFIX,
-                          typedefs, extra_defs, PREFIX, prefix, PREFIX, prefix,
-                          prefix, PREFIX, self->footer);
+                          typedefs, extra_defs, thunk_decs, PREFIX, prefix,
+                          PREFIX, prefix, prefix, PREFIX, self->footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
@@ -350,6 +375,7 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
     FREEMEM(charmony_defines);
     FREEMEM(typedefs);
     FREEMEM(extra_includes);
+    FREEMEM(thunk_decs);
     FREEMEM(file_content);
 }