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 2012/04/14 16:04:46 UTC

[lucy-commits] svn commit: r1326106 - in /lucy/trunk/clownfish/src: CFCBindClass.c CFCBindClass.h CFCBindCore.c CFCPerl.c

Author: nwellnhof
Date: Sat Apr 14 14:04:46 2012
New Revision: 1326106

URL: http://svn.apache.org/viewvc?rev=1326106&view=rev
Log:
Move VTable registration code from boot.c to parcel.c

It doesn't depend on the host language.

Modified:
    lucy/trunk/clownfish/src/CFCBindClass.c
    lucy/trunk/clownfish/src/CFCBindClass.h
    lucy/trunk/clownfish/src/CFCBindCore.c
    lucy/trunk/clownfish/src/CFCPerl.c

Modified: lucy/trunk/clownfish/src/CFCBindClass.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindClass.c?rev=1326106&r1=1326105&r2=1326106&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindClass.c (original)
+++ lucy/trunk/clownfish/src/CFCBindClass.c Sat Apr 14 14:04:46 2012
@@ -514,6 +514,32 @@ CFCBindClass_to_vtable_bootstrap(CFCBind
     return code;
 }
 
+// Return C code registering the class's VTable.
+char*
+CFCBindClass_to_vtable_register(CFCBindClass *self) {
+    CFCClass    *client     = self->client;
+
+    if (CFCClass_inert(client)) {
+        return CFCUtil_strdup("");
+    }
+
+    const char  *vt_var     = CFCClass_full_vtable_var(client);
+
+    // Ignore return value from VTable_add_to_registry, since it's OK if
+    // multiple threads contend for adding these permanent VTables and some
+    // fail.
+    char pattern[] =
+        "    cfish_VTable_add_to_registry(%s);\n";
+
+    size_t size = sizeof(pattern)
+                  + strlen(vt_var)
+                  + 20;
+    char *code = (char*)MALLOCATE(size);
+    sprintf(code, pattern, vt_var);
+
+    return code;
+}
+
 // Declare cfish_Callback objects.
 static char*
 S_callback_declarations(CFCBindClass *self) {

Modified: lucy/trunk/clownfish/src/CFCBindClass.h
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindClass.h?rev=1326106&r1=1326105&r2=1326106&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindClass.h (original)
+++ lucy/trunk/clownfish/src/CFCBindClass.h Sat Apr 14 14:04:46 2012
@@ -59,6 +59,11 @@ CFCBindClass_to_c_data(CFCBindClass *sel
 char*
 CFCBindClass_to_vtable_bootstrap(CFCBindClass *self);
 
+/** Return the autogenerated C code necessary to register class.
+ */
+char*
+CFCBindClass_to_vtable_register(CFCBindClass *self);
+
 #ifdef __cplusplus
 }
 #endif

Modified: lucy/trunk/clownfish/src/CFCBindCore.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindCore.c?rev=1326106&r1=1326105&r2=1326106&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindCore.c (original)
+++ lucy/trunk/clownfish/src/CFCBindCore.c Sat Apr 14 14:04:46 2012
@@ -262,6 +262,7 @@ S_write_parcel_c(CFCBindCore *self) {
     char *includes     = CFCUtil_strdup("");
     char *c_data       = CFCUtil_strdup("");
     char *vt_bootstrap = CFCUtil_strdup("");
+    char *vt_register  = CFCUtil_strdup("");
     CFCClass **ordered = CFCHierarchy_ordered_classes(hierarchy);
     if (!ordered[0]) {
         CFCUtil_die("No classes found.");
@@ -277,6 +278,9 @@ S_write_parcel_c(CFCBindCore *self) {
         char *vt_boot = CFCBindClass_to_vtable_bootstrap(class_binding);
         vt_bootstrap = CFCUtil_cat(vt_bootstrap, vt_boot, NULL);
         FREEMEM(vt_boot);
+        char *vt_reg = CFCBindClass_to_vtable_register(class_binding);
+        vt_register = CFCUtil_cat(vt_register, vt_reg, NULL);
+        FREEMEM(vt_reg);
         CFCBase_decref((CFCBase*)class_binding);
         const char *privacy_sym = CFCClass_privacy_symbol(klass);
         privacy_syms = CFCUtil_cat(privacy_syms, "#define ",
@@ -305,6 +309,8 @@ S_write_parcel_c(CFCBindCore *self) {
         "void\n"
         "%sbootstrap_parcel() {\n"
         "%s"
+        "\n"
+        "%s"
         "}\n"
         "\n"
         "%s\n";
@@ -315,11 +321,12 @@ S_write_parcel_c(CFCBindCore *self) {
                   + strlen(c_data)
                   + strlen(prefix)
                   + strlen(vt_bootstrap)
+                  + strlen(vt_register)
                   + strlen(self->footer)
                   + 50;
     char *file_content = (char*)MALLOCATE(size);
     sprintf(file_content, pattern, self->header, privacy_syms, includes,
-            c_data, prefix, vt_bootstrap, self->footer);
+            c_data, prefix, vt_bootstrap, vt_register, self->footer);
 
     // Unlink then open file.
     const char *src_dest = CFCHierarchy_get_source_dest(hierarchy);
@@ -333,5 +340,6 @@ S_write_parcel_c(CFCBindCore *self) {
     FREEMEM(includes);
     FREEMEM(c_data);
     FREEMEM(vt_bootstrap);
+    FREEMEM(vt_register);
 }
 

Modified: lucy/trunk/clownfish/src/CFCPerl.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCPerl.c?rev=1326106&r1=1326105&r2=1326106&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCPerl.c (original)
+++ lucy/trunk/clownfish/src/CFCPerl.c Sat Apr 14 14:04:46 2012
@@ -235,7 +235,7 @@ static void
 S_write_boot_c(CFCPerl *self) {
     CFCClass **ordered   = CFCHierarchy_ordered_classes(self->hierarchy);
     char *pound_includes = CFCUtil_strdup("");
-    char *registrations  = CFCUtil_strdup("");
+    char *alias_adds     = CFCUtil_strdup("");
     char *isa_pushes     = CFCUtil_strdup("");
     const char *prefix   = CFCParcel_get_prefix(self->parcel);
 
@@ -250,13 +250,6 @@ S_write_boot_c(CFCPerl *self) {
 
         if (CFCClass_inert(klass)) { continue; }
 
-        // Ignore return value from VTable_add_to_registry, since it's OK if
-        // multiple threads contend for adding these permanent VTables and some
-        // fail.
-        registrations
-            = CFCUtil_cat(registrations, "    cfish_VTable_add_to_registry(",
-                          CFCClass_full_vtable_var(klass), ");\n", NULL);
-
         // Add aliases for selected KinoSearch classes which allow old indexes
         // to be read.
         CFCPerlClass *class_binding = CFCPerlClass_singleton(class_name);
@@ -274,16 +267,16 @@ S_write_boot_c(CFCPerl *self) {
                     "        (cfish_CharBuf*)alias);\n";
 
                 size_t new_size = sizeof(pattern)
-                                  + strlen(registrations)
+                                  + strlen(alias_adds)
                                   + alias_len
                                   + 20    // stringified alias_len
                                   + strlen(vtable_var)
                                   + 50;
-                char *new_registrations = (char*)MALLOCATE(new_size);
-                sprintf(new_registrations, pattern, registrations, alias,
+                char *new_alias_adds = (char*)MALLOCATE(new_size);
+                sprintf(new_alias_adds, pattern, alias_adds, alias,
                         (unsigned)alias_len, vtable_var);
-                FREEMEM(registrations);
-                registrations = new_registrations;
+                FREEMEM(alias_adds);
+                alias_adds = new_alias_adds;
             }
         }
 
@@ -315,10 +308,11 @@ S_write_boot_c(CFCPerl *self) {
         "%s() {\n"
         "    %sbootstrap_parcel();\n"
         "\n"
-        "    AV *isa;\n"
         "    cfish_ZombieCharBuf *alias = CFISH_ZCB_WRAP_STR(\"\", 0);\n"
-        "%s\n"
-        "%s\n"
+        "%s"
+        "\n"
+        "    AV *isa;\n"
+        "%s"
         "}\n"
         "\n"
         "%s\n"
@@ -330,18 +324,18 @@ S_write_boot_c(CFCPerl *self) {
                   + strlen(pound_includes)
                   + strlen(self->boot_func)
                   + strlen(prefix)
-                  + strlen(registrations)
+                  + strlen(alias_adds)
                   + strlen(isa_pushes)
                   + strlen(self->footer)
                   + 100;
     char *content = (char*)MALLOCATE(size);
     sprintf(content, pattern, self->header, self->boot_h_file, pound_includes,
-            self->boot_func, prefix, registrations, isa_pushes, self->footer);
+            self->boot_func, prefix, alias_adds, isa_pushes, self->footer);
     CFCUtil_write_file(self->boot_c_path, content, strlen(content));
 
     FREEMEM(content);
     FREEMEM(isa_pushes);
-    FREEMEM(registrations);
+    FREEMEM(alias_adds);
     FREEMEM(pound_includes);
     FREEMEM(ordered);
 }