Use per-parcel defines for symbol visibility

Use macro LUCY_VISIBLE for externally visible symbols. This macro will
be set to CHY_EXPORT when compiling with -DCFP_LUCY and to CHY_IMPORT
otherwise.


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

Branch: refs/heads/chaz-cflags
Commit: f908dc0c51e051d7f0283b5ae62262cb84244394
Parents: 4a231ed
Author: Nick Wellnhofer <[email protected]>
Authored: Wed Apr 3 19:47:53 2013 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Wed Apr 3 19:47:53 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/src/CFCBindClass.c  |   18 +++++++-----------
 clownfish/compiler/src/CFCBindCore.c   |   14 +++++++++-----
 clownfish/compiler/src/CFCBindMethod.c |    8 +++-----
 common/charmonizer.main                |    2 ++
 perl/xs/XSBind.h                       |   20 +++++++++-----------
 5 files changed, 30 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/f908dc0c/clownfish/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindClass.c 
b/clownfish/compiler/src/CFCBindClass.c
index cfa6a65..ca93610 100644
--- a/clownfish/compiler/src/CFCBindClass.c
+++ b/clownfish/compiler/src/CFCBindClass.c
@@ -155,6 +155,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);
     char *struct_def            = S_struct_definition(self);
     char *parent_include        = S_parent_include(self);
     char *sub_declarations      = S_sub_declarations(self);
@@ -163,9 +164,6 @@ 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"
@@ -207,7 +205,7 @@ S_to_c_header_dynamic(CFCBindClass *self) {
         "/* Declare the VTable singleton for this class.\n"
         " */\n"
         "\n"
-        "extern %s cfish_VTable *%s;\n"
+        "extern %sVISIBLE cfish_VTable *%s;\n"
         "\n"
         "/* Define \"short names\" for this class's symbols.\n"
         " */\n"
@@ -218,7 +216,7 @@ S_to_c_header_dynamic(CFCBindClass *self) {
         = CFCUtil_sprintf(pattern, parent_include, privacy_symbol,
                           struct_def, privacy_symbol, inert_var_defs,
                           sub_declarations, method_typedefs, method_defs,
-                          visibility, vt_var, short_names);
+                          PREFIX, vt_var, short_names);
 
     FREEMEM(struct_def);
     FREEMEM(parent_include);
@@ -453,8 +451,7 @@ 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 ";
+    const char *PREFIX = CFCClass_get_PREFIX(self->client);
     CFCFunction **functions = CFCClass_functions(self->client);
     CFCMethod** fresh_methods = CFCClass_fresh_methods(self->client);
     char *declarations = CFCUtil_strdup("");
@@ -462,7 +459,7 @@ S_sub_declarations(CFCBindClass *self) {
         CFCFunction *func = functions[i];
         char *dec = CFCBindFunc_func_declaration(func);
         if (!CFCFunction_inline(func)) {
-            declarations = CFCUtil_cat(declarations, visibility, NULL);
+            declarations = CFCUtil_cat(declarations, PREFIX, "VISIBLE ", NULL);
         }
         declarations = CFCUtil_cat(declarations, dec, "\n\n", NULL);
         FREEMEM(dec);
@@ -480,13 +477,12 @@ 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 ";
+    const char *PREFIX = CFCClass_get_PREFIX(self->client);
     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 ", visibility,
+        declarations = CFCUtil_cat(declarations, "extern ", PREFIX, "VISIBLE ",
                                    global_c, ";\n", NULL);
     }
     return declarations;

http://git-wip-us.apache.org/repos/asf/lucy/blob/f908dc0c/clownfish/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindCore.c 
b/clownfish/compiler/src/CFCBindCore.c
index 7cf461e..2512750 100644
--- a/clownfish/compiler/src/CFCBindCore.c
+++ b/clownfish/compiler/src/CFCBindCore.c
@@ -141,14 +141,12 @@ S_write_parcel_h(CFCBindCore *self) {
         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();
 
-    const char *visibility = strcmp(prefix, "lucy_") == 0
-                             ? "CHY_EXPORT" : "CHY_IMPORT";
-
     const char pattern[] =
         "%s\n"
         "#ifndef CFCPARCEL_H\n"
@@ -161,6 +159,12 @@ S_write_parcel_h(CFCBindCore *self) {
         "#include <stddef.h>\n"
         "#include \"charmony.h\"\n"
         "\n"
+        "#ifdef CFP_LUCY\n"
+        "  #define LUCY_VISIBLE CHY_EXPORT\n"
+        "#else\n"
+        "  #define LUCY_VISIBLE CHY_IMPORT\n"
+        "#endif\n"
+        "\n"
         "%s\n"
         "%s\n"
         "\n"
@@ -193,7 +197,7 @@ S_write_parcel_h(CFCBindCore *self) {
         "     ((_full_meth ## _t)cfish_super_method(_vtable, \\\n"
         "                                           _full_meth ## _OFFSET))\n"
         "\n"
-        "extern %s size_t cfish_VTable_offset_of_parent;\n"
+        "extern %sVISIBLE 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"
@@ -252,7 +256,7 @@ S_write_parcel_h(CFCBindCore *self) {
         "%s\n"
         "\n";
     char *file_content
-        = CFCUtil_sprintf(pattern, self->header, aliases, typedefs, visibility,
+        = CFCUtil_sprintf(pattern, self->header, aliases, typedefs, PREFIX,
                           prefix, prefix, self->footer);
 
     // Unlink then write file.

http://git-wip-us.apache.org/repos/asf/lucy/blob/f908dc0c/clownfish/compiler/src/CFCBindMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindMethod.c 
b/clownfish/compiler/src/CFCBindMethod.c
index eec71f1..512fc1c 100644
--- a/clownfish/compiler/src/CFCBindMethod.c
+++ b/clownfish/compiler/src/CFCBindMethod.c
@@ -86,13 +86,11 @@ S_final_method_def(CFCMethod *method, CFCClass *klass) {
 static char*
 S_virtual_method_def(CFCMethod *method, CFCClass *klass) {
     CFCParamList *param_list = CFCMethod_get_param_list(method);
+    const char *PREFIX         = CFCClass_get_PREFIX(klass);
     const char *invoker_struct = CFCClass_full_struct_sym(klass);
     const char *common_struct 
         = CFCType_get_specifier(CFCMethod_self_type(method));
 
-    const char *visibility = CFCClass_included(klass)
-                             ? "CHY_IMPORT" : "CHY_EXPORT";
-
     char *full_meth_sym   = CFCMethod_full_method_sym(method, klass);
     char *full_offset_sym = CFCMethod_full_offset_sym(method, klass);
     char *full_typedef    = CFCMethod_full_typedef(method, klass);
@@ -114,7 +112,7 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) {
     const char *maybe_return = CFCType_is_void(return_type) ? "" : "return ";
 
     const char pattern[] =
-        "extern %s size_t %s;\n"
+        "extern %sVISIBLE size_t %s;\n"
         "static CHY_INLINE %s\n"
         "%s(const %s *self%s) {\n"
         "    char *const method_address = *(char**)self + %s;\n"
@@ -122,7 +120,7 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) {
         "    %smethod((%s*)self%s);\n"
         "}\n";
     char *method_def
-        = CFCUtil_sprintf(pattern, visibility, full_offset_sym, ret_type_str,
+        = CFCUtil_sprintf(pattern, PREFIX, 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,

http://git-wip-us.apache.org/repos/asf/lucy/blob/f908dc0c/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/common/charmonizer.main b/common/charmonizer.main
index eb93309..c007856 100644
--- a/common/charmonizer.main
+++ b/common/charmonizer.main
@@ -86,6 +86,8 @@ S_add_compiler_flags(struct chaz_CLIArgs *args) {
     if (args->charmony_pm) {
         chaz_CFlags_add_define(extra_cflags, "HAS_BOOL", NULL);
     }
+
+    chaz_CFlags_add_define(extra_cflags, "CFP_LUCY", NULL);
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/lucy/blob/f908dc0c/perl/xs/XSBind.h
----------------------------------------------------------------------
diff --git a/perl/xs/XSBind.h b/perl/xs/XSBind.h
index 1c74a54..347f5c0 100644
--- a/perl/xs/XSBind.h
+++ b/perl/xs/XSBind.h
@@ -37,8 +37,6 @@
 #define NEED_newRV_noinc_GLOBAL
 #include "ppport.h"
 
-#define XSBIND_EXTERN CHY_EXPORT
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -46,7 +44,7 @@ extern "C" {
 /** Given either a class name or a perl object, manufacture a new Clownfish
  * object suitable for supplying to a cfish_Foo_init() function.
  */
-XSBIND_EXTERN cfish_Obj*
+LUCY_VISIBLE cfish_Obj*
 cfish_XSBind_new_blank_obj(SV *either_sv);
 
 /** Test whether an SV is defined.  Handles "get" magic, unlike SvOK on its
@@ -66,13 +64,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.
  */
-XSBIND_EXTERN cfish_Obj*
+LUCY_VISIBLE 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.
  */
-XSBIND_EXTERN cfish_Obj*
+LUCY_VISIBLE cfish_Obj*
 cfish_XSBind_maybe_sv_to_cfish_obj(SV *sv, cfish_VTable *vtable,
                                    void *allocation);
 
@@ -118,24 +116,24 @@ cfish_XSBind_cfish_obj_to_sv_noinc(cfish_Obj *obj) {
  * 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.
  */
-XSBIND_EXTERN SV*
+LUCY_VISIBLE 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.
  */
-XSBIND_EXTERN cfish_Obj*
+LUCY_VISIBLE cfish_Obj*
 cfish_XSBind_perl_to_cfish(SV *sv);
 
 /** Convert a ByteBuf into a new string SV.
  */
-XSBIND_EXTERN SV*
+LUCY_VISIBLE SV*
 cfish_XSBind_bb_to_sv(const cfish_ByteBuf *bb);
 
 /** Convert a CharBuf into a new UTF-8 string SV.
  */
-XSBIND_EXTERN SV*
+LUCY_VISIBLE SV*
 cfish_XSBind_cb_to_sv(const cfish_CharBuf *cb);
 
 /** Perl-specific wrapper for Err#trap.  The "routine" must be either a
@@ -146,7 +144,7 @@ cfish_XSBind_trap(SV *routine, SV *context);
 
 /** Turn on overloading for the supplied Perl object and its class.
  */
-XSBIND_EXTERN void
+LUCY_VISIBLE void
 cfish_XSBind_enable_overload(void *pobj);
 
 /** Process hash-style params passed to an XS subroutine.  The varargs must be
@@ -210,7 +208,7 @@ cfish_XSBind_enable_overload(void *pobj);
  * (generally, the XS variable "items").
  * @return true on success, false on failure (sets Err_error).
  */
-XSBIND_EXTERN bool
+LUCY_VISIBLE bool
 cfish_XSBind_allot_params(SV** stack, int32_t start,
                           int32_t num_stack_elems, ...);
 

Reply via email to