From 57219d6e61094b333a7d46d5b9997a70ddee37ea Mon Sep 17 00:00:00 2001 From: Petter Urkedal Date: Sat, 14 Jan 2012 11:11:12 +0100 Subject: [PATCH] Fix visibility of symbols in libcord. * include/gc_config_macros.h: Make the export specifications usable also to the cord library. * include/cord.h, include/private/cord_pos.h: Define CORD_API and annotate the public API. --- cord/cord.am | 1 + include/cord.h | 80 +++++++++++++++++++++----------------- include/gc_config_macros.h | 42 +++++++++----------- include/private/cord_pos.h | 20 +++++----- 4 files changed, 74 insertions(+), 69 deletions(-) diff --git a/cord/cord.am b/cord/cord.am index 56a81fde..f95fedf8 100644 --- a/cord/cord.am +++ b/cord/cord.am @@ -3,6 +3,7 @@ lib_LTLIBRARIES += libcord.la libcord_la_LIBADD = $(top_builddir)/libgc.la libcord_la_LDFLAGS = -version-info 1:3:0 -no-undefined +libcord_la_CPPFLAGS = $(AM_CPPFLAGS) -DCORD_BUILD -DGC_DLL libcord_la_SOURCES = \ cord/cordbscs.c \ diff --git a/include/cord.h b/include/cord.h index 76400535..8d35c011 100644 --- a/include/cord.h +++ b/include/cord.h @@ -57,6 +57,14 @@ #include #include +#include "gc_config_macros.h" + +#ifdef CORD_BUILD +# define CORD_API GC_API_EXPORT +#else +# define CORD_API GC_API_IMPORT +#endif + /* Cords have type const char *. This is cheating quite a bit, and not */ /* 100% portable. But it means that nonempty character string */ /* constants may be used as cords directly, provided the string is */ @@ -73,27 +81,27 @@ typedef const char * CORD; /* Concatenate two cords. If the arguments are C strings, they may */ /* not be subsequently altered. */ -CORD CORD_cat(CORD x, CORD y); +CORD_API CORD CORD_cat(CORD x, CORD y); /* Concatenate a cord and a C string with known length. Except for the */ /* empty string case, this is a special case of CORD_cat. Since the */ /* length is known, it can be faster. */ /* The string y is shared with the resulting CORD. Hence it should */ /* not be altered by the caller. */ -CORD CORD_cat_char_star(CORD x, const char * y, size_t leny); +CORD_API CORD CORD_cat_char_star(CORD x, const char * y, size_t leny); /* Compute the length of a cord */ -size_t CORD_len(CORD x); +CORD_API size_t CORD_len(CORD x); /* Cords may be represented by functions defining the ith character */ typedef char (* CORD_fn)(size_t i, void * client_data); /* Turn a functional description into a cord. */ -CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len); +CORD_API CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len); /* Return the substring (subcord really) of x with length at most n, */ /* starting at position i. (The initial character has position 0.) */ -CORD CORD_substr(CORD x, size_t i, size_t n); +CORD_API CORD CORD_substr(CORD x, size_t i, size_t n); /* Return the argument, but rebalanced to allow more efficient */ /* character retrieval, substring operations, and comparisons. */ @@ -103,7 +111,7 @@ CORD CORD_substr(CORD x, size_t i, size_t n); /* or the embedded functional descriptions take longer to evaluate. */ /* May reallocate significant parts of the cord. The argument is not */ /* modified; only the result is balanced. */ -CORD CORD_balance(CORD x); +CORD_API CORD CORD_balance(CORD x); /* The following traverse a cord by applying a function to each */ /* character. This is occasionally appropriate, especially where */ @@ -127,19 +135,19 @@ typedef int (* CORD_batched_iter_fn)(const char * s, void * client_data); /* end of this string is reached, or when f1 or f2 return != 0. In the */ /* latter case CORD_iter returns != 0. Otherwise it returns 0. */ /* The specified value of i must be < CORD_len(x). */ -int CORD_iter5(CORD x, size_t i, CORD_iter_fn f1, - CORD_batched_iter_fn f2, void * client_data); +CORD_API int CORD_iter5(CORD x, size_t i, CORD_iter_fn f1, + CORD_batched_iter_fn f2, void * client_data); /* A simpler version that starts at 0, and without f2: */ -int CORD_iter(CORD x, CORD_iter_fn f1, void * client_data); +CORD_API int CORD_iter(CORD x, CORD_iter_fn f1, void * client_data); #define CORD_iter(x, f1, cd) CORD_iter5(x, 0, f1, CORD_NO_FN, cd) /* Similar to CORD_iter5, but end-to-beginning. No provisions for */ /* CORD_batched_iter_fn. */ -int CORD_riter4(CORD x, size_t i, CORD_iter_fn f1, void * client_data); +CORD_API int CORD_riter4(CORD x, size_t i, CORD_iter_fn f1, void * client_data); /* A simpler version that starts at the end: */ -int CORD_riter(CORD x, CORD_iter_fn f1, void * client_data); +CORD_API int CORD_riter(CORD x, CORD_iter_fn f1, void * client_data); /* Functions that operate on cord positions. The easy way to traverse */ /* cords. A cord position is logically a pair consisting of a cord */ @@ -194,36 +202,37 @@ extern void (* CORD_oom_fn)(void); /* Dump the representation of x to stdout in an implementation defined */ /* manner. Intended for debugging only. */ -void CORD_dump(CORD x); +CORD_API void CORD_dump(CORD x); /* The following could easily be implemented by the client. They are */ /* provided in cordxtra.c for convenience. */ /* Concatenate a character to the end of a cord. */ -CORD CORD_cat_char(CORD x, char c); +CORD_API CORD CORD_cat_char(CORD x, char c); /* Concatenate n cords. */ -CORD CORD_catn(int n, /* CORD */ ...); +CORD_API CORD CORD_catn(int n, /* CORD */ ...); /* Return the character in CORD_substr(x, i, 1) */ -char CORD_fetch(CORD x, size_t i); +CORD_API char CORD_fetch(CORD x, size_t i); /* Return < 0, 0, or > 0, depending on whether x < y, x = y, x > y */ -int CORD_cmp(CORD x, CORD y); +CORD_API int CORD_cmp(CORD x, CORD y); /* A generalization that takes both starting positions for the */ /* comparison, and a limit on the number of characters to be compared. */ -int CORD_ncmp(CORD x, size_t x_start, CORD y, size_t y_start, size_t len); +CORD_API int CORD_ncmp(CORD x, size_t x_start, CORD y, size_t y_start, + size_t len); /* Find the first occurrence of s in x at position start or later. */ /* Return the position of the first character of s in x, or */ /* CORD_NOT_FOUND if there is none. */ -size_t CORD_str(CORD x, size_t start, CORD s); +CORD_API size_t CORD_str(CORD x, size_t start, CORD s); /* Return a cord consisting of i copies of (possibly NUL) c. Dangerous */ /* in conjunction with CORD_to_char_star. */ /* The resulting representation takes constant space, independent of i. */ -CORD CORD_chars(char c, size_t i); +CORD_API CORD CORD_chars(char c, size_t i); #define CORD_nul(i) CORD_chars('\0', (i)) /* Turn a file into cord. The file must be seekable. Its contents */ @@ -242,33 +251,33 @@ CORD CORD_chars(char c, size_t i); /* position in the file, i.e. the number of characters that can be */ /* or were read with fread. On UNIX systems this is always true. On */ /* MS Windows systems, f must be opened in binary mode. */ -CORD CORD_from_file(FILE * f); +CORD_API CORD CORD_from_file(FILE * f); /* Equivalent to the above, except that the entire file will be read */ /* and the file pointer will be closed immediately. */ /* The binary mode restriction from above does not apply. */ -CORD CORD_from_file_eager(FILE * f); +CORD_API CORD CORD_from_file_eager(FILE * f); /* Equivalent to the above, except that the file will be read on demand.*/ /* The binary mode restriction applies. */ -CORD CORD_from_file_lazy(FILE * f); +CORD_API CORD CORD_from_file_lazy(FILE * f); /* Turn a cord into a C string. The result shares no structure with */ /* x, and is thus modifiable. */ -char * CORD_to_char_star(CORD x); +CORD_API char * CORD_to_char_star(CORD x); /* Turn a C string into a CORD. The C string is copied, and so may */ /* subsequently be modified. */ -CORD CORD_from_char_star(const char *s); +CORD_API CORD CORD_from_char_star(const char *s); /* Identical to the above, but the result may share structure with */ /* the argument and is thus not modifiable. */ -const char * CORD_to_const_char_star(CORD x); +CORD_API const char * CORD_to_const_char_star(CORD x); /* Write a cord to a file, starting at the current position. No */ /* trailing NULs are newlines are added. */ /* Returns EOF if a write error occurs, 1 otherwise. */ -int CORD_put(CORD x, FILE * f); +CORD_API int CORD_put(CORD x, FILE * f); /* "Not found" result for the following two functions. */ #define CORD_NOT_FOUND ((size_t)(-1)) @@ -276,12 +285,12 @@ int CORD_put(CORD x, FILE * f); /* A vague analog of strchr. Returns the position (an integer, not */ /* a pointer) of the first occurrence of (char) c inside x at position */ /* i or later. The value i must be < CORD_len(x). */ -size_t CORD_chr(CORD x, size_t i, int c); +CORD_API size_t CORD_chr(CORD x, size_t i, int c); /* A vague analog of strrchr. Returns index of the last occurrence */ /* of (char) c inside x at position i or earlier. The value i */ /* must be < CORD_len(x). */ -size_t CORD_rchr(CORD x, size_t i, int c); +CORD_API size_t CORD_rchr(CORD x, size_t i, int c); /* The following are also not primitive, but are implemented in */ @@ -292,7 +301,8 @@ size_t CORD_rchr(CORD x, size_t i, int c); /* width, precision, etc. have the same semantics as for %s. */ /* (Note that %c, %C, and %S were already taken.) */ /* 2. The format string is represented as a CORD. */ -/* 3. CORD_sprintf and CORD_vsprintf assign the result through the 1st */ /* argument. Unlike their ANSI C versions, there is no need to guess */ +/* 3. CORD_sprintf and CORD_vsprintf assign the result through the 1st */ +/* argument. Unlike their ANSI C versions, there is no need to guess */ /* the correct buffer size. */ /* 4. Most of the conversions are implement through the native */ /* vsprintf. Hence they are usually no faster, and */ @@ -312,12 +322,12 @@ size_t CORD_rchr(CORD x, size_t i, int c); #include -int CORD_sprintf(CORD * out, CORD format, ...); -int CORD_vsprintf(CORD * out, CORD format, va_list args); -int CORD_fprintf(FILE * f, CORD format, ...); -int CORD_vfprintf(FILE * f, CORD format, va_list args); -int CORD_printf(CORD format, ...); -int CORD_vprintf(CORD format, va_list args); +CORD_API int CORD_sprintf(CORD * out, CORD format, ...); +CORD_API int CORD_vsprintf(CORD * out, CORD format, va_list args); +CORD_API int CORD_fprintf(FILE * f, CORD format, ...); +CORD_API int CORD_vfprintf(FILE * f, CORD format, va_list args); +CORD_API int CORD_printf(CORD format, ...); +CORD_API int CORD_vprintf(CORD format, va_list args); #endif /* CORD_NO_IO */ diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h index d3b5f6a6..fd8bd2a1 100644 --- a/include/gc_config_macros.h +++ b/include/gc_config_macros.h @@ -17,7 +17,7 @@ /* This should never be included directly; it is included only from gc.h. */ /* We separate it only to make gc.h more suitable as documentation. */ -#if defined(GC_H) +#if defined(GC_H) || defined(CORD_H) /* Some tests for old macros. These violate our namespace rules and */ /* will disappear shortly. Use the GC_ names. */ @@ -172,38 +172,32 @@ #if defined(GC_DLL) && !defined(GC_API) # if defined(__MINGW32__) || defined(__CEGCC__) -# ifdef GC_BUILD -# define GC_API __declspec(dllexport) -# else -# define GC_API __declspec(dllimport) -# endif - +# define GC_API_EXPORT __declspec(dllexport) +# define GC_API_IMPORT __declspec(dllimport) # elif defined(_MSC_VER) || defined(__DMC__) || defined(__BORLANDC__) \ || defined(__CYGWIN__) -# ifdef GC_BUILD -# define GC_API extern __declspec(dllexport) -# else -# define GC_API __declspec(dllimport) -# endif - +# define GC_API_EXPORT extern __declspec(dllexport) +# define GC_API_IMPORT __declspec(dllimport) # elif defined(__WATCOMC__) -# ifdef GC_BUILD -# define GC_API extern __declspec(dllexport) -# else -# define GC_API extern __declspec(dllimport) -# endif - +# define GC_API_EXPORT extern __declspec(dllexport) +# define GC_API_IMPORT extern __declspec(dllimport) # elif defined(__GNUC__) /* Only matters if used in conjunction with -fvisibility=hidden option. */ -# if defined(GC_BUILD) && (__GNUC__ >= 4 \ - || defined(GC_VISIBILITY_HIDDEN_SET)) -# define GC_API extern __attribute__((__visibility__("default"))) +# if __GNUC__ >= 4 || defined(GC_VISIBILITY_HIDDEN_SET) +# define GC_API_EXPORT extern __attribute__((__visibility__("default"))) +# define GC_API_IMPORT extern __attribute__((__visibility__("default"))) # endif # endif #endif /* GC_DLL */ +#ifndef GC_API_EXPORT +# define GC_API_EXPORT extern +# define GC_API_IMPORT extern +#endif -#ifndef GC_API -# define GC_API extern +#ifdef GC_BUILD +# define GC_API GC_API_EXPORT +#else +# define GC_API GC_API_IMPORT #endif #ifndef GC_CALL diff --git a/include/private/cord_pos.h b/include/private/cord_pos.h index 80e5841d..ce4be854 100644 --- a/include/private/cord_pos.h +++ b/include/private/cord_pos.h @@ -53,34 +53,34 @@ typedef struct CORD_Pos { } CORD_pos[1]; /* Extract the cord from a position: */ -CORD CORD_pos_to_cord(CORD_pos p); +CORD_API CORD CORD_pos_to_cord(CORD_pos p); /* Extract the current index from a position: */ -size_t CORD_pos_to_index(CORD_pos p); +CORD_API size_t CORD_pos_to_index(CORD_pos p); /* Fetch the character located at the given position: */ -char CORD_pos_fetch(CORD_pos p); +CORD_API char CORD_pos_fetch(CORD_pos p); /* Initialize the position to refer to the give cord and index. */ /* Note that this is the most expensive function on positions: */ -void CORD_set_pos(CORD_pos p, CORD x, size_t i); +CORD_API void CORD_set_pos(CORD_pos p, CORD x, size_t i); /* Advance the position to the next character. */ /* P must be initialized and valid. */ /* Invalidates p if past end: */ -void CORD_next(CORD_pos p); +CORD_API void CORD_next(CORD_pos p); /* Move the position to the preceding character. */ /* P must be initialized and valid. */ /* Invalidates p if past beginning: */ -void CORD_prev(CORD_pos p); +CORD_API void CORD_prev(CORD_pos p); /* Is the position valid, i.e. inside the cord? */ -int CORD_pos_valid(CORD_pos p); +CORD_API int CORD_pos_valid(CORD_pos p); -char CORD__pos_fetch(CORD_pos); -void CORD__next(CORD_pos); -void CORD__prev(CORD_pos); +CORD_API char CORD__pos_fetch(CORD_pos); +CORD_API void CORD__next(CORD_pos); +CORD_API void CORD__prev(CORD_pos); #define CORD_pos_fetch(p) \ (((p)[0].cur_end != 0)? \ -- 2.49.0