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/23 21:33:29 UTC

[lucy-commits] svn commit: r1329395 - in /lucy/trunk: clownfish/perl/lib/Clownfish/CFC/Perl/Build.pm clownfish/src/CFCBindClass.c clownfish/src/CFCBindCore.c clownfish/src/CFCBindMethod.c perl/xs/XSBind.c perl/xs/XSBind.h

Author: nwellnhof
Date: Mon Apr 23 19:33:28 2012
New Revision: 1329395

URL: http://svn.apache.org/viewvc?rev=1329395&view=rev
Log:
Switch to -fvisibility=hidden and start using CHY_EXPORT and CHY_IMPORT

Modified:
    lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Perl/Build.pm
    lucy/trunk/clownfish/src/CFCBindClass.c
    lucy/trunk/clownfish/src/CFCBindCore.c
    lucy/trunk/clownfish/src/CFCBindMethod.c
    lucy/trunk/perl/xs/XSBind.c
    lucy/trunk/perl/xs/XSBind.h

Modified: lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Perl/Build.pm
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Perl/Build.pm?rev=1329395&r1=1329394&r2=1329395&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Perl/Build.pm (original)
+++ lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Perl/Build.pm Mon Apr 23 19:33:28 2012
@@ -378,6 +378,14 @@ sub ACTION_compile_custom_xs {
     for my $source_dir (@$source_dirs) {
         push @$c_files, @{ $self->rscan_dir( $source_dir, qr/\.c$/ ) };
     }
+    # Compile with -fvisibility=hidden on GCC >= 4.0
+    my $cc_flags = $self->extra_compiler_flags;
+    if ( $self->config('gccversion') ) {
+        my @version_nums = split( /\./, $self->config('gccversion') );
+        if ( $version_nums[0] >= 4 ) {
+            $cc_flags = [ @$cc_flags, '-fvisibility=hidden' ];
+        }
+    }
     for my $c_file (@$c_files) {
         my $o_file   = $c_file;
         my $ccs_file = $c_file;
@@ -389,7 +397,7 @@ sub ACTION_compile_custom_xs {
         $self->add_to_cleanup($ccs_file);
         $cbuilder->compile(
             source               => $c_file,
-            extra_compiler_flags => $self->extra_compiler_flags,
+            extra_compiler_flags => $cc_flags,
             include_dirs         => $self->include_dirs,
             object_file          => $o_file,
         );
@@ -413,6 +421,7 @@ sub ACTION_compile_custom_xs {
     unshift @objects, $perl_binding_o_file;
     $self->add_to_cleanup($perl_binding_o_file);
     if ( !$self->up_to_date( $perl_binding_c_file, $perl_binding_o_file ) ) {
+        # Don't use -fvisibility=hidden for XS
         $cbuilder->compile(
             source               => $perl_binding_c_file,
             extra_compiler_flags => $self->extra_compiler_flags,

Modified: lucy/trunk/clownfish/src/CFCBindClass.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindClass.c?rev=1329395&r1=1329394&r2=1329395&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindClass.c (original)
+++ lucy/trunk/clownfish/src/CFCBindClass.c Mon Apr 23 19:33:28 2012
@@ -183,6 +183,9 @@ S_to_c_header_dynamic(CFCBindClass *self
     char *method_defs           = S_method_defs(self);
     char *short_names           = S_short_names(self);
 
+    const char *visibility = CFCClass_included(self->client)
+                             ? "CHY_IMPORT" : "CHY_EXPORT";
+
     char pattern[] =
         "#include \"charmony.h\"\n"
         "#include \"parcel.h\"\n"
@@ -221,10 +224,10 @@ S_to_c_header_dynamic(CFCBindClass *self
         "\n"
         "%s\n"
         "\n"
-        "/* Define the VTable singleton for this class.\n"
+        "/* Declare the VTable singleton for this class.\n"
         " */\n"
         "\n"
-        "extern cfish_VTable *%s;\n"
+        "extern %s cfish_VTable *%s;\n"
         "\n"
         "/* Define \"short names\" for this class's symbols.\n"
         " */\n"
@@ -241,6 +244,7 @@ S_to_c_header_dynamic(CFCBindClass *self
                   + strlen(sub_declarations)
                   + strlen(method_typedefs)
                   + strlen(method_defs)
+                  + strlen(visibility)
                   + strlen(vt_var)
                   + strlen(short_names)
                   + 100;
@@ -248,7 +252,7 @@ S_to_c_header_dynamic(CFCBindClass *self
     char *content = (char*)MALLOCATE(size);
     sprintf(content, pattern, parent_include, privacy_symbol, struct_def,
             privacy_symbol, inert_var_defs, sub_declarations, method_typedefs,
-            method_defs, vt_var, short_names);
+            method_defs, visibility, vt_var, short_names);
 
     FREEMEM(struct_def);
     FREEMEM(parent_include);
@@ -545,12 +549,17 @@ S_parent_include(CFCBindClass *self) {
 // Add a C function definition for each method and each function.
 static char*
 S_sub_declarations(CFCBindClass *self) {
+    const char *visibility = CFCClass_included(self->client)
+                             ? "CHY_IMPORT " : "CHY_EXPORT ";
     CFCFunction **functions = CFCClass_functions(self->client);
     CFCMethod** fresh_methods = CFCClass_fresh_methods(self->client);
     char *declarations = CFCUtil_strdup("");
     for (int i = 0; functions[i] != NULL; i++) {
         CFCFunction *func = functions[i];
         char *dec = CFCBindFunc_func_declaration(func);
+        if (!CFCFunction_inline(func)) {
+            declarations = CFCUtil_cat(declarations, visibility, NULL);
+        }
         declarations = CFCUtil_cat(declarations, dec, "\n\n", NULL);
         FREEMEM(dec);
     }
@@ -567,12 +576,14 @@ S_sub_declarations(CFCBindClass *self) {
 // Declare class (a.k.a. "inert") variables.
 static char*
 S_inert_var_declarations(CFCBindClass *self) {
+    const char *visibility = CFCClass_included(self->client)
+                             ? "CHY_IMPORT " : "CHY_EXPORT ";
     CFCVariable **inert_vars = CFCClass_inert_vars(self->client);
     char *declarations = CFCUtil_strdup("");
     for (int i = 0; inert_vars[i] != NULL; i++) {
         const char *global_c = CFCVariable_global_c(inert_vars[i]);
-        declarations = CFCUtil_cat(declarations, "extern ", global_c, ";\n",
-                                   NULL);
+        declarations = CFCUtil_cat(declarations, "extern ", visibility,
+                                   global_c, ";\n", NULL);
     }
     return declarations;
 }

Modified: lucy/trunk/clownfish/src/CFCBindCore.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindCore.c?rev=1329395&r1=1329394&r2=1329395&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindCore.c (original)
+++ lucy/trunk/clownfish/src/CFCBindCore.c Mon Apr 23 19:33:28 2012
@@ -144,6 +144,9 @@ S_write_parcel_h(CFCBindCore *self) {
     // Create Clownfish aliases if necessary.
     char *aliases = CFCBindAliases_c_aliases();
 
+    const char *visibility = strcmp(prefix, "lucy_") == 0
+                             ? "CHY_EXPORT" : "CHY_IMPORT";
+
     const char pattern[] =
         "%s\n"
         "#ifndef CFCPARCEL_H\n"
@@ -188,7 +191,7 @@ S_write_parcel_h(CFCBindCore *self) {
         "     ((_full_meth ## _t)cfish_super_method(_vtable, \\\n"
         "                                           _full_meth ## _OFFSET))\n"
         "\n"
-        "extern size_t cfish_VTable_offset_of_parent;\n"
+        "extern %s size_t cfish_VTable_offset_of_parent;\n"
         "static CHY_INLINE cfish_method_t\n"
         "cfish_super_method(const void *vtable, size_t offset) {\n"
         "    char *vt_as_char = (char*)vtable;\n"
@@ -235,14 +238,13 @@ S_write_parcel_h(CFCBindCore *self) {
                   + strlen(self->header)
                   + strlen(aliases)
                   + strlen(typedefs)
+                  + strlen(visibility)
                   + 2 * strlen(prefix)
                   + strlen(self->footer)
                   + 100;
     char *file_content = (char*)MALLOCATE(size);
-    sprintf(file_content, pattern,
-            self->header, aliases, typedefs,
-            prefix, prefix,
-            self->footer);
+    sprintf(file_content, pattern, self->header, aliases, typedefs, visibility,
+            prefix, prefix, self->footer);
 
     // Unlink then write file.
     const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);

Modified: lucy/trunk/clownfish/src/CFCBindMethod.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCBindMethod.c?rev=1329395&r1=1329394&r2=1329395&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCBindMethod.c (original)
+++ lucy/trunk/clownfish/src/CFCBindMethod.c Mon Apr 23 19:33:28 2012
@@ -141,6 +141,9 @@ S_virtual_method_def(CFCMethod *method, 
     const char *common_struct 
         = CFCType_get_specifier(CFCMethod_self_type(method));
 
+    const char *visibility = CFCClass_included(klass)
+                             ? "CHY_IMPORT" : "CHY_EXPORT";
+
     size_t meth_sym_size = CFCMethod_full_method_sym(method, klass, NULL, 0);
     char *full_meth_sym = (char*)MALLOCATE(meth_sym_size);
     CFCMethod_full_method_sym(method, klass, full_meth_sym, meth_sym_size);
@@ -170,7 +173,7 @@ S_virtual_method_def(CFCMethod *method, 
     const char *maybe_return = CFCType_is_void(return_type) ? "" : "return ";
 
     const char pattern[] =
-        "extern size_t %s;\n"
+        "extern %s size_t %s;\n"
         "static CHY_INLINE %s\n"
         "%s(const %s *self%s) {\n"
         "    char *const method_address = *(char**)self + %s;\n"
@@ -179,6 +182,7 @@ S_virtual_method_def(CFCMethod *method, 
         "}\n";
 
     size_t size = sizeof(pattern)
+                  + strlen(visibility)
                   + strlen(full_offset_sym)
                   + strlen(ret_type_str)
                   + strlen(full_meth_sym)
@@ -192,7 +196,7 @@ S_virtual_method_def(CFCMethod *method, 
                   + strlen(arg_names_minus_invoker)
                   + 40;
     char *method_def = (char*)MALLOCATE(size);
-    sprintf(method_def, pattern, full_offset_sym, ret_type_str,
+    sprintf(method_def, pattern, visibility, full_offset_sym, ret_type_str,
             full_meth_sym, invoker_struct, params_minus_invoker,
             full_offset_sym, full_typedef, full_typedef, maybe_return,
             common_struct, arg_names_minus_invoker);

Modified: lucy/trunk/perl/xs/XSBind.c
URL: http://svn.apache.org/viewvc/lucy/trunk/perl/xs/XSBind.c?rev=1329395&r1=1329394&r2=1329395&view=diff
==============================================================================
--- lucy/trunk/perl/xs/XSBind.c (original)
+++ lucy/trunk/perl/xs/XSBind.c Mon Apr 23 19:33:28 2012
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#define C_CFISH_XSBIND
 #define C_LUCY_OBJ
 #define NEED_newRV_noinc
 #include "XSBind.h"

Modified: lucy/trunk/perl/xs/XSBind.h
URL: http://svn.apache.org/viewvc/lucy/trunk/perl/xs/XSBind.h?rev=1329395&r1=1329394&r2=1329395&view=diff
==============================================================================
--- lucy/trunk/perl/xs/XSBind.h (original)
+++ lucy/trunk/perl/xs/XSBind.h Mon Apr 23 19:33:28 2012
@@ -41,10 +41,16 @@ extern "C" {
 #define NEED_newRV_noinc_GLOBAL
 #include "ppport.h"
 
+#ifdef C_CFISH_XSBIND
+#define XSBIND_EXTERN CHY_EXPORT
+#else
+#define XSBIND_EXTERN CHY_IMPORT
+#endif
+
 /** Given either a class name or a perl object, manufacture a new Clownfish
  * object suitable for supplying to a cfish_Foo_init() function.
  */
-cfish_Obj*
+XSBIND_EXTERN cfish_Obj*
 cfish_XSBind_new_blank_obj(SV *either_sv);
 
 /** Test whether an SV is defined.  Handles "get" magic, unlike SvOK on its
@@ -64,13 +70,13 @@ cfish_XSBind_sv_defined(SV *sv) {
  * <code>allocation</code>, assign the SV's string to it, and return that
  * instead.  If all else fails, throw an exception.
  */
-cfish_Obj*
+XSBIND_EXTERN cfish_Obj*
 cfish_XSBind_sv_to_cfish_obj(SV *sv, cfish_VTable *vtable, void *allocation);
 
 /** As XSBind_sv_to_cfish_obj above, but returns NULL instead of throwing an
  * exception.
  */
-cfish_Obj*
+XSBIND_EXTERN cfish_Obj*
 cfish_XSBind_maybe_sv_to_cfish_obj(SV *sv, cfish_VTable *vtable,
                                    void *allocation);
 
@@ -116,24 +122,24 @@ cfish_XSBind_cfish_obj_to_sv_noinc(cfish
  * SVs, ByteBufs to SVs, VArrays to Perl array refs, Hashes to Perl hashrefs,
  * and any other object to a Perl object wrapping the Clownfish Obj.
  */
-SV*
+XSBIND_EXTERN SV*
 cfish_XSBind_cfish_to_perl(cfish_Obj *obj);
 
 /** Deep conversion of Perl data structures to Clownfish objects -- Perl hash
  * to Hash, Perl array to VArray, Clownfish objects stripped of their
  * wrappers, and everything else stringified and turned to a CharBuf.
  */
-cfish_Obj*
+XSBIND_EXTERN cfish_Obj*
 cfish_XSBind_perl_to_cfish(SV *sv);
 
 /** Convert a ByteBuf into a new string SV.
  */
-SV*
+XSBIND_EXTERN SV*
 cfish_XSBind_bb_to_sv(const cfish_ByteBuf *bb);
 
 /** Convert a CharBuf into a new UTF-8 string SV.
  */
-SV*
+XSBIND_EXTERN SV*
 cfish_XSBind_cb_to_sv(const cfish_CharBuf *cb);
 
 /** Perl-specific wrapper for Err#trap.  The "routine" must be either a
@@ -144,7 +150,7 @@ cfish_XSBind_trap(SV *routine, SV *conte
 
 /** Turn on overloading for the supplied Perl object and its class.
  */
-void
+XSBIND_EXTERN void
 cfish_XSBind_enable_overload(void *pobj);
 
 /** Process hash-style params passed to an XS subroutine.  The varargs must be
@@ -208,7 +214,7 @@ cfish_XSBind_enable_overload(void *pobj)
  * (generally, the XS variable "items").
  * @return true on success, false on failure (sets Err_error).
  */
-chy_bool_t
+XSBIND_EXTERN chy_bool_t
 cfish_XSBind_allot_params(SV** stack, int32_t start,
                           int32_t num_stack_elems, ...);