lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [01/15] git commit: refs/heads/install-c-library - Add parcel prefix to parcel.c and parcel.h
Date Sat, 18 May 2013 19:23:46 GMT
Updated Branches:
  refs/heads/install-c-library [created] 27018f3ba


Add parcel prefix to parcel.c and parcel.h

The parcel header file must be publicly available, so add parcel prefix
to avoid name clashes.


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

Branch: refs/heads/install-c-library
Commit: 6716917eccfc96ce61f04535539400a5146e60cc
Parents: 637d4e6
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Fri May 17 22:42:56 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sat May 18 13:11:55 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/src/CFCBindClass.c |   12 ++++---
 clownfish/compiler/src/CFCBindCore.c  |   47 ++++++++++++++++-----------
 clownfish/compiler/src/CFCPerl.c      |   25 +++++++++-----
 clownfish/compiler/src/CFCRuby.c      |   17 +++-------
 common/charmonizer.c                  |    5 ++-
 common/charmonizer.main               |    5 ++-
 6 files changed, 62 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/6716917e/clownfish/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindClass.c b/clownfish/compiler/src/CFCBindClass.c
index 21a6daf..e483530 100644
--- a/clownfish/compiler/src/CFCBindClass.c
+++ b/clownfish/compiler/src/CFCBindClass.c
@@ -119,13 +119,14 @@ CFCBindClass_to_c_header(CFCBindClass *self) {
 
 static char*
 S_to_c_header_inert(CFCBindClass *self) {
+    const char *prefix    = CFCClass_get_prefix(self->client);
     char *inert_func_decs = S_sub_declarations(self);
     char *inert_var_defs  = S_inert_var_declarations(self);
     char *short_names     = S_short_names(self);
 
     char pattern[] =
         "#include \"charmony.h\"\n"
-        "#include \"parcel.h\"\n"
+        "#include \"%sparcel.h\"\n"
         "\n"
         "/* Declare this class's inert variables.\n"
         " */\n"
@@ -142,8 +143,8 @@ S_to_c_header_inert(CFCBindClass *self) {
         "\n"
         "%s\n"
         "\n";
-    char *content = CFCUtil_sprintf(pattern, inert_var_defs, inert_func_decs,
-                                    short_names);
+    char *content = CFCUtil_sprintf(pattern, prefix, inert_var_defs,
+                                    inert_func_decs, short_names);
 
     FREEMEM(inert_var_defs);
     FREEMEM(inert_func_decs);
@@ -155,6 +156,7 @@ static char*
 S_to_c_header_dynamic(CFCBindClass *self) {
     const char *privacy_symbol  = CFCClass_privacy_symbol(self->client);
     const char *vt_var          = CFCClass_full_vtable_var(self->client);
+    const char *prefix          = CFCClass_get_prefix(self->client);
     const char *PREFIX          = CFCClass_get_PREFIX(self->client);
     char *struct_def            = S_struct_definition(self);
     char *parent_include        = S_parent_include(self);
@@ -166,7 +168,7 @@ S_to_c_header_dynamic(CFCBindClass *self) {
 
     char pattern[] =
         "#include \"charmony.h\"\n"
-        "#include \"parcel.h\"\n"
+        "#include \"%sparcel.h\"\n"
         "\n"
         "/* Include the header for this class's parent. \n"
         " */\n"
@@ -213,7 +215,7 @@ S_to_c_header_dynamic(CFCBindClass *self) {
         "%s\n"
         "\n";
     char *content
-        = CFCUtil_sprintf(pattern, parent_include, privacy_symbol,
+        = CFCUtil_sprintf(pattern, prefix, parent_include, privacy_symbol,
                           struct_def, privacy_symbol, inert_var_defs,
                           sub_declarations, method_typedefs, method_defs,
                           PREFIX, vt_var, short_names);

http://git-wip-us.apache.org/repos/asf/lucy/blob/6716917e/clownfish/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindCore.c b/clownfish/compiler/src/CFCBindCore.c
index 662d20e..642569b 100644
--- a/clownfish/compiler/src/CFCBindCore.c
+++ b/clownfish/compiler/src/CFCBindCore.c
@@ -137,12 +137,13 @@ S_write_parcel_h(CFCBindCore *self) {
             parcel = CFCClass_get_parcel(klass);
         }
     }
+    FREEMEM(ordered);
+
     if (!parcel) {
         CFCUtil_die("No source classes found.");
     }
     const char *prefix = CFCParcel_get_prefix(parcel);
     const char *PREFIX = CFCParcel_get_PREFIX(parcel);
-    FREEMEM(ordered);
 
     // Create Clownfish aliases if necessary.
     char *aliases = CFCBindAliases_c_aliases();
@@ -269,7 +270,8 @@ S_write_parcel_h(CFCBindCore *self) {
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
-    char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "parcel.h", inc_dest);
+    char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "%sparcel.h", inc_dest,
+                                     prefix);
     remove(filepath);
     CFCUtil_write_file(filepath, file_content, strlen(file_content));
     FREEMEM(filepath);
@@ -324,19 +326,20 @@ S_write_parcel_c(CFCBindCore *self) {
         }
         parcel = CFCClass_get_parcel(klass);
     }
+    vt_specs = CFCUtil_cat(vt_specs, "\n};\n", NULL);
+    FREEMEM(ordered);
+
     if (!parcel) {
         CFCUtil_die("No source classes found.");
     }
     const char *prefix = CFCParcel_get_prefix(parcel);
-    vt_specs = CFCUtil_cat(vt_specs, "\n};\n", NULL);
-    FREEMEM(ordered);
 
     char pattern[] =
         "%s\n"
         "\n"
         "#define C_LUCY_VTABLE\n"
         "%s\n"
-        "#include \"parcel.h\"\n"
+        "#include \"%sparcel.h\"\n"
         "#include \"callbacks.h\"\n"
         "#include \"Clownfish/VTable.h\"\n"
         "%s\n"
@@ -358,13 +361,14 @@ S_write_parcel_c(CFCBindCore *self) {
         "\n"
         "%s\n";
     char *file_content
-        = CFCUtil_sprintf(pattern, self->header, privacy_syms, includes,
-                          c_data, vt_specs, prefix, num_specs, prefix,
-                          self->footer);
+        = CFCUtil_sprintf(pattern, self->header, privacy_syms, prefix,
+                          includes, c_data, vt_specs, prefix, num_specs,
+                          prefix, self->footer);
 
     // Unlink then open file.
     const char *src_dest = CFCHierarchy_get_source_dest(hierarchy);
-    char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "parcel.c", src_dest);
+    char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "%sparcel.c", src_dest,
+                                     prefix);
     remove(filepath);
     CFCUtil_write_file(filepath, file_content, strlen(file_content));
     FREEMEM(filepath);
@@ -383,6 +387,7 @@ void
 CFCBindCore_write_callbacks_h(CFCBindCore *self) {
     CFCHierarchy  *hierarchy   = self->hierarchy;
     CFCClass     **ordered     = CFCHierarchy_ordered_classes(hierarchy);
+    CFCParcel     *parcel      = NULL;
     char          *includes    = CFCUtil_strdup("");
     char          *all_cb_decs = CFCUtil_strdup("");
 
@@ -399,11 +404,21 @@ CFCBindCore_write_callbacks_h(CFCBindCore *self) {
             all_cb_decs = CFCUtil_cat(all_cb_decs, cb_decs, NULL);
             FREEMEM(cb_decs);
             CFCBase_decref((CFCBase*)class_binding);
+
+            if (parcel && CFCClass_get_parcel(klass) != parcel) {
+                CFCUtil_die("Multiple parcels not yet supported.");
+            }
+            parcel = CFCClass_get_parcel(klass);
         }
     }
 
     FREEMEM(ordered);
 
+    if (!parcel) {
+        CFCUtil_die("No source classes found.");
+    }
+    const char *prefix = CFCParcel_get_prefix(parcel);
+
     const char pattern[] =
         "%s\n"
         "#ifndef CFCCALLBACKS_H\n"
@@ -413,7 +428,7 @@ CFCBindCore_write_callbacks_h(CFCBindCore *self) {
         "extern \"C\" {\n"
         "#endif\n"
         "\n"
-        "#include \"parcel.h\"\n"
+        "#include \"%sparcel.h\"\n"
         "%s"
         "\n"
         "%s"
@@ -426,15 +441,9 @@ CFCBindCore_write_callbacks_h(CFCBindCore *self) {
         "\n"
         "%s\n"
         "\n";
-    size_t size = sizeof(pattern)
-                  + strlen(self->header)
-                  + strlen(includes)
-                  + strlen(all_cb_decs)
-                  + strlen(self->footer)
-                  + 50;
-    char *file_content = (char*)MALLOCATE(size);
-    sprintf(file_content, pattern, self->header, includes, all_cb_decs,
-            self->footer);
+    char *file_content
+        = CFCUtil_sprintf(pattern, self->header, prefix, includes, all_cb_decs,
+                          self->footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);

http://git-wip-us.apache.org/repos/asf/lucy/blob/6716917e/clownfish/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerl.c b/clownfish/compiler/src/CFCPerl.c
index d8e3ef6..419799f 100644
--- a/clownfish/compiler/src/CFCPerl.c
+++ b/clownfish/compiler/src/CFCPerl.c
@@ -48,6 +48,7 @@ struct CFCPerl {
     char *boot_h_path;
     char *boot_c_path;
     char *boot_func;
+    char *parcel_h_file;
 };
 
 // Modify a string in place, swapping out "::" for the supplied character.
@@ -112,6 +113,9 @@ CFCPerl_init(CFCPerl *self, CFCParcel *parcel, CFCHierarchy *hierarchy,
         }
     }
 
+    // Derive the name of the "parcel.h" file.
+    self->parcel_h_file = CFCUtil_sprintf("%sparcel.h", prefix);
+
     return self;
 }
 
@@ -129,6 +133,7 @@ CFCPerl_destroy(CFCPerl *self) {
     FREEMEM(self->boot_h_path);
     FREEMEM(self->boot_c_path);
     FREEMEM(self->boot_func);
+    FREEMEM(self->parcel_h_file);
     CFCBase_destroy((CFCBase*)self);
 }
 
@@ -283,7 +288,7 @@ S_write_boot_c(CFCPerl *self) {
         "#include \"perl.h\"\n"
         "#include \"XSUB.h\"\n"
         "#include \"%s\"\n"
-        "#include \"parcel.h\"\n"
+        "#include \"%s\"\n"
         "#include \"Clownfish/CharBuf.h\"\n"
         "#include \"Clownfish/VTable.h\"\n"
         "%s\n"
@@ -303,8 +308,8 @@ S_write_boot_c(CFCPerl *self) {
         "\n";
     char *content
         = CFCUtil_sprintf(pattern, self->header, self->boot_h_file,
-                          pound_includes, self->boot_func, prefix, alias_adds,
-                          isa_pushes, self->footer);
+                          self->parcel_h_file, pound_includes, self->boot_func,
+                          prefix, alias_adds, isa_pushes, self->footer);
     CFCUtil_write_file(self->boot_c_path, content, strlen(content));
 
     FREEMEM(content);
@@ -360,7 +365,7 @@ S_xs_file_contents(CFCPerl *self, const char *generated_xs,
         "%s"
         "\n"
         "#include \"XSBind.h\"\n"
-        "#include \"parcel.h\"\n"
+        "#include \"%s\"\n"
         "#include \"%s\"\n"
         "\n"
         "#include \"Clownfish/Util/Memory.h\"\n"
@@ -383,9 +388,10 @@ S_xs_file_contents(CFCPerl *self, const char *generated_xs,
         "\n"
         "%s";
     char *contents
-        = CFCUtil_sprintf(pattern, self->header, self->boot_h_file,
-                          generated_xs, self->boot_class, self->boot_class,
-                          xs_init, hand_rolled_xs, self->footer);
+        = CFCUtil_sprintf(pattern, self->header, self->parcel_h_file,
+                          self->boot_h_file, generated_xs, self->boot_class,
+                          self->boot_class, xs_init, hand_rolled_xs,
+                          self->footer);
 
     return contents;
 }
@@ -497,7 +503,7 @@ S_write_callbacks_c(CFCPerl *self) {
         "\n"
         "#include \"XSBind.h\"\n"
         "#include \"callbacks.h\"\n"
-        "#include \"parcel.h\"\n"
+        "#include \"%s\"\n"
         "\n"
         "static void\n"
         "S_finish_callback_void(const char *meth_name) {\n"
@@ -570,7 +576,8 @@ S_write_callbacks_c(CFCPerl *self) {
         "    return retval;\n"
         "}\n"
         "\n";
-    char *content = CFCUtil_sprintf(pattern, self->header);
+    char *content
+        = CFCUtil_sprintf(pattern, self->header, self->parcel_h_file);
 
     for (size_t i = 0; ordered[i] != NULL; i++) {
         CFCClass *klass = ordered[i];

http://git-wip-us.apache.org/repos/asf/lucy/blob/6716917e/clownfish/compiler/src/CFCRuby.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCRuby.c b/clownfish/compiler/src/CFCRuby.c
index 6921522..678327d 100644
--- a/clownfish/compiler/src/CFCRuby.c
+++ b/clownfish/compiler/src/CFCRuby.c
@@ -196,7 +196,7 @@ S_write_boot_c(CFCRuby *self) {
         "\n"
         "#include \"charmony.h\"\n"
         "#include \"%s\"\n"
-        "#include \"parcel.h\"\n"
+        "#include \"%sparcel.h\"\n"
         "#include \"Clownfish/CharBuf.h\"\n"
         "#include \"Clownfish/VTable.h\"\n"
         "%s\n"
@@ -211,17 +211,10 @@ S_write_boot_c(CFCRuby *self) {
         "%s\n"
         "\n";
 
-    size_t size = sizeof(pattern)
-                  + strlen(self->header)
-                  + strlen(self->boot_h_file)
-                  + strlen(pound_includes)
-                  + strlen(self->boot_func)
-                  + strlen(prefix)
-                  + strlen(self->footer)
-                  + 100;
-    char *content = (char*)MALLOCATE(size);
-    sprintf(content, pattern, self->header, self->boot_h_file, pound_includes,
-            self->boot_func, prefix, self->footer);
+    char *content
+        = CFCUtil_sprintf(pattern, self->header, self->boot_h_file, prefix,
+                          pound_includes, self->boot_func, prefix,
+                          self->footer);
     CFCUtil_write_file(self->boot_c_path, content, strlen(content));
 
     FREEMEM(content);

http://git-wip-us.apache.org/repos/asf/lucy/blob/6716917e/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/common/charmonizer.c b/common/charmonizer.c
index 6d2cfb7..3b51644 100644
--- a/common/charmonizer.c
+++ b/common/charmonizer.c
@@ -6839,7 +6839,7 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     free(scratch);
 
     scratch = chaz_Util_join("", "autogen", dir_sep, "source", dir_sep,
-                             "parcel", obj_ext, NULL);
+                             "lucy_parcel", obj_ext, NULL);
     chaz_MakeVar_append(var, scratch);
     free(scratch);
 
@@ -6878,7 +6878,8 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     free(scratch);
 
     /* Needed for parallel builds. */
-    scratch = chaz_Util_join(dir_sep, "autogen", "source", "parcel.c", NULL);
+    scratch = chaz_Util_join(dir_sep, "autogen", "source", "lucy_parcel.c",
+                             NULL);
     rule = chaz_MakeFile_add_rule(makefile, scratch, "autogen");
     free(scratch);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/6716917e/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/common/charmonizer.main b/common/charmonizer.main
index 831e5f4..f0cad62 100644
--- a/common/charmonizer.main
+++ b/common/charmonizer.main
@@ -242,7 +242,7 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     free(scratch);
 
     scratch = chaz_Util_join("", "autogen", dir_sep, "source", dir_sep,
-                             "parcel", obj_ext, NULL);
+                             "lucy_parcel", obj_ext, NULL);
     chaz_MakeVar_append(var, scratch);
     free(scratch);
 
@@ -281,7 +281,8 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     free(scratch);
 
     /* Needed for parallel builds. */
-    scratch = chaz_Util_join(dir_sep, "autogen", "source", "parcel.c", NULL);
+    scratch = chaz_Util_join(dir_sep, "autogen", "source", "lucy_parcel.c",
+                             NULL);
     rule = chaz_MakeFile_add_rule(makefile, scratch, "autogen");
     free(scratch);
 


Mime
View raw message