Fix C++ build

callbacks.c must include the class headers in order to know that the
callbacks are declared extern "C".


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

Branch: refs/heads/master
Commit: 9d1d2d6b8b0e0156ee80feeda7466635d6d68ecd
Parents: 3561433
Author: Nick Wellnhofer <[email protected]>
Authored: Wed May 20 12:13:02 2015 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Wed May 20 14:32:23 2015 +0200

----------------------------------------------------------------------
 compiler/src/CFCPerl.c                    | 56 +++++++++++++-------------
 runtime/core/Clownfish/LockFreeRegistry.c |  3 +-
 2 files changed, 29 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9d1d2d6b/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index 18dee3c..7916a5b 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -512,16 +512,28 @@ CFCPerl_write_callbacks(CFCPerl *self) {
 
 static void
 S_write_callbacks_c(CFCPerl *self) {
-    CFCClass  **ordered  = CFCHierarchy_ordered_classes(self->hierarchy);
-    CFCParcel **parcels  = CFCParcel_all_parcels();
-    char       *includes = CFCUtil_strdup("");
+    CFCClass **ordered  = CFCHierarchy_ordered_classes(self->hierarchy);
+    char      *includes = CFCUtil_strdup("");
+    char      *cb_defs  = CFCUtil_strdup("");
 
-    for (int i = 0; parcels[i]; i++) {
-        CFCParcel *parcel = parcels[i];
-        if (!CFCParcel_included(parcel)) {
-            const char *prefix = CFCParcel_get_prefix(parcel);
-            includes = CFCUtil_cat(includes, "#include \"", prefix,
-                                   "parcel.h\"\n", NULL);
+    for (size_t i = 0; ordered[i] != NULL; i++) {
+        CFCClass *klass = ordered[i];
+        if (CFCClass_included(klass) || CFCClass_inert(klass)) { continue; }
+
+        const char *include_h = CFCClass_include_h(klass);
+        includes = CFCUtil_cat(includes, "#include \"", include_h,
+                               "\"\n", NULL);
+
+        CFCMethod **fresh_methods = CFCClass_fresh_methods(klass);
+        for (int meth_num = 0; fresh_methods[meth_num] != NULL; meth_num++) {
+            CFCMethod *method = fresh_methods[meth_num];
+
+            // Define callback.
+            if (CFCMethod_novel(method) && !CFCMethod_final(method)) {
+                char *cb_def = CFCPerlMethod_callback_def(method, klass);
+                cb_defs = CFCUtil_cat(cb_defs, cb_def, "\n", NULL);
+                FREEMEM(cb_def);
+            }
         }
     }
 
@@ -603,27 +615,12 @@ S_write_callbacks_c(CFCPerl *self) {
         "    }\n"
         "    return retval;\n"
         "}\n"
+       "\n"
+       "%s" // Callback definitions.
+       "%s" // Footer.
         "\n";
-    char *content = CFCUtil_sprintf(pattern, self->c_header, includes);
-
-    for (size_t i = 0; ordered[i] != NULL; i++) {
-        CFCClass *klass = ordered[i];
-        if (CFCClass_included(klass) || CFCClass_inert(klass)) { continue; }
-
-        CFCMethod **fresh_methods = CFCClass_fresh_methods(klass);
-        for (int meth_num = 0; fresh_methods[meth_num] != NULL; meth_num++) {
-            CFCMethod *method = fresh_methods[meth_num];
-
-            // Define callback.
-            if (CFCMethod_novel(method) && !CFCMethod_final(method)) {
-                char *cb_def = CFCPerlMethod_callback_def(method, klass);
-                content = CFCUtil_cat(content, cb_def, "\n", NULL);
-                FREEMEM(cb_def);
-            }
-        }
-    }
-
-    content = CFCUtil_cat(content, self->c_footer, NULL);
+    char *content = CFCUtil_sprintf(pattern, self->c_header, includes, cb_defs,
+                                    self->c_footer);
 
     // Write if changed.
     const char *src_dest = CFCHierarchy_get_source_dest(self->hierarchy);
@@ -633,6 +630,7 @@ S_write_callbacks_c(CFCPerl *self) {
 
     FREEMEM(filepath);
     FREEMEM(content);
+    FREEMEM(cb_defs);
     FREEMEM(includes);
     FREEMEM(ordered);
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9d1d2d6b/runtime/core/Clownfish/LockFreeRegistry.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/LockFreeRegistry.c 
b/runtime/core/Clownfish/LockFreeRegistry.c
index 2385f02..307710b 100644
--- a/runtime/core/Clownfish/LockFreeRegistry.c
+++ b/runtime/core/Clownfish/LockFreeRegistry.c
@@ -39,7 +39,8 @@ typedef struct cfish_LFRegEntry {
 
 LockFreeRegistry*
 LFReg_new(size_t capacity) {
-    LockFreeRegistry *self = CALLOCATE(1, sizeof(LockFreeRegistry));
+    LockFreeRegistry *self
+        = (LockFreeRegistry*)CALLOCATE(1, sizeof(LockFreeRegistry));
     self->capacity = capacity;
     self->entries  = CALLOCATE(capacity, sizeof(void*));
     return self;

Reply via email to