Skip to content

Commit

Permalink
Build failure with clang - bugfix
Browse files Browse the repository at this point in the history
This fixes a bug with clang running on MSYS2. Windows expects to have
import and export declarations to reduce the size of the lookup tables.
gcc >4 introduced visibility, but a lot of code is not using this often
and it becomes a problem for code in win32/win64 due to lack of this.
CLANG for MSYS2 quietly injects the import/export declarations itself,
so it can make use of gcc code so we need to turn-off this feature if
compiling with CLANG on MSYS2 to avoid re-inserting this information 2x
  • Loading branch information
JoesCat committed Dec 27, 2021
1 parent 67b21e4 commit 3d04207
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 28 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -13,6 +13,7 @@ David Corbett <dscorbett>
genisysram <genisysram>
orbea <orbea>
Naohiro Aota gentoo.org
Biswapriyo Nath <Biswa96>

French Nameslist:
Jacques André, France
Expand Down
10 changes: 5 additions & 5 deletions buildnameslist.c
Expand Up @@ -494,12 +494,12 @@ static int dumpinit(FILE *out, FILE *header, int is_fr) {
fprintf( out, "\t\telse if ( lang==0 )\n\t\t\t*bn1=*bn0;\n\t}\n\treturn( error );\n}\n\n\n" );
}

fprintf( out, "static const struct unicode_nameannot nullarray%s[] = {\n", lg[l] );
fprintf( out, "UN_DLL_LOCAL\nstatic const struct unicode_nameannot nullarray%s[] = {\n", lg[l] );
for ( i=0; i<256/4 ; ++i )
fprintf( out, "\t{ NULL, NULL }, { NULL, NULL }, { NULL, NULL }, { NULL, NULL },\n" );
fprintf( out, "\t{ NULL, NULL }, { NULL, NULL }, { NULL, NULL }, { NULL, NULL }\n" );
fprintf( out, "};\n\n" );
fprintf( out, "static const struct unicode_nameannot nullarray2%s[] = {\n", lg[l] );
fprintf( out, "UN_DLL_LOCAL\nstatic const struct unicode_nameannot nullarray2%s[] = {\n", lg[l] );
for ( i=0; i<256/4 ; ++i )
fprintf( out, "\t{ NULL, NULL }, { NULL, NULL }, { NULL, NULL }, { NULL, NULL },\n" );
fprintf( out, "\t{ NULL, NULL }, { NULL, NULL },\n" );
Expand All @@ -511,7 +511,7 @@ static int dumpinit(FILE *out, FILE *header, int is_fr) {
fprintf( out, "\t{ NULL, \"\t* the value ?FFFF is guaranteed not to be a Unicode character at all\" },\n" );
}
fprintf( out, "};\n\n" );
fprintf( out, "static const struct unicode_nameannot * const nullnullarray%s[] = {\n", lg[l] );
fprintf( out, "UN_DLL_LOCAL\nstatic const struct unicode_nameannot * const nullnullarray%s[] = {\n", lg[l] );
for ( i=0; i<256/8 ; ++i )
fprintf( out, "\tnullarray%s, nullarray%s, nullarray%s, nullarray%s, nullarray%s, nullarray%s, nullarray%s, nullarray%s,\n", \
lg[l], lg[l], lg[l], lg[l], lg[l], lg[l], lg[l], lg[l] );
Expand Down Expand Up @@ -691,7 +691,7 @@ static int dumparrays(FILE *out, FILE *header, int is_fr ) {
}
if ( t==256 || (j==0xff && t==0xfe -1))
continue; /* Empty sub-plane */
fprintf( out, "static const struct unicode_nameannot %s%s_%02X_%02X[] = {\n", prefix, lg[l], i, j );
fprintf( out, "UN_DLL_LOCAL\nstatic const struct unicode_nameannot %s%s_%02X_%02X[] = {\n", prefix, lg[l], i, j );
for ( k=0; k<256; ++k ) {
fprintf( out, "/* %04X */ { ", (i<<16) + (j<<8) + k );
if ( uninames[is_fr][(i<<16) + (j<<8) + k]==NULL )
Expand All @@ -715,7 +715,7 @@ static int dumparrays(FILE *out, FILE *header, int is_fr ) {
break;
if ( t==0xFFFE )
continue; /* Empty plane */
fprintf( out, "static const struct unicode_nameannot * const %s%s_%02X[] = {\n", prefix, lg[l], i );
fprintf( out, "UN_DLL_LOCAL\nstatic const struct unicode_nameannot * const %s%s_%02X[] = {\n", prefix, lg[l], i );
for ( j=0; j<256; ++j ) {
for ( t=0; t<256; ++t ) {
if ( uninames[is_fr][(i<<16) + (j<<8) + t]!=NULL || uniannot[is_fr][(i<<16) + (j<<8) + t]!=NULL )
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -177,6 +177,7 @@ AX_CHECK_COMPILE_FLAG([-Wpointer-arith],[WCFLAGS="$WCFLAGS -Wpointer-arith"])
AX_CHECK_COMPILE_FLAG([-Wcast-qual],[WCFLAGS="$WCFLAGS -Wcast-qual"])
AX_CHECK_COMPILE_FLAG([-Wcast-align],[WCFLAGS="$WCFLAGS -Wcast-align"])
AX_CHECK_COMPILE_FLAG([-Wpadded],[WCFLAGS="$WCFLAGS -Wpadded"])
AX_CHECK_COMPILE_FLAG([-Wno-attributes],[WCFLAGS="$WCFLAGS -Wno-attributes"])

dnl currently for extra testing
dnl AX_CHECK_COMPILE_FLAG([-fPIC],[WCFLAGS="$WCFLAGS -fPIC"])
Expand Down
51 changes: 29 additions & 22 deletions nameslist-dll.h
@@ -1,9 +1,16 @@
/* Generic helper definitions for shared library support */
/* as explained in - https://gcc.gnu.org/wiki/Visibility */
#if defined _WIN32 || defined __CYGWIN__
#define UN_DLL_IMPORT __declspec(dllimport)
#define UN_DLL_EXPORT __declspec(dllexport)
#define UN_DLL_LOCAL
#if defined (_WIN32) || defined (__CYGWIN__) || (_WIN64) || defined (__CYGWIN64__)
#ifndef __clang__
#define UN_DLL_IMPORT __declspec(dllimport)
#define UN_DLL_EXPORT __declspec(dllexport)
#define UN_DLL_LOCAL
#else
/* CLANG already appears to add this. Turn this off. */
#define UN_DLL_IMPORT
#define UN_DLL_EXPORT
#define UN_DLL_LOCAL
#endif
#else
#if __GNUC__ >= 4
#define UN_DLL_IMPORT __attribute__ ((visibility ("default")))
Expand All @@ -20,26 +27,26 @@

#ifdef UNICODE_BLOCK_MAX
/* Definitions used by nameslist.c for functions{16..21} */
int uniNamesList_haveFR(unsigned int lang);
UN_DLL_LOCAL int uniNamesList_haveFR(unsigned int lang);
#ifdef WANTLIBOFR
/* make this visible to nameslist.c if adding French lib */
extern const char *uniNamesList_NamesListVersionFR(void);
extern const char *uniNamesList_nameFR(unsigned long uni);
extern const char *uniNamesList_annotFR(unsigned long uni);
extern int uniNamesList_blockCountFR(void);
extern int uniNamesList_blockNumberFR(unsigned long uni);
extern long uniNamesList_blockStartFR(int uniBlock);
extern long uniNamesList_blockEndFR(int uniBlock);
extern const char *uniNamesList_blockNameFR(int uniBlock);
extern UN_DLL_IMPORT const char *uniNamesList_NamesListVersionFR(void);
extern UN_DLL_IMPORT const char *uniNamesList_nameFR(unsigned long uni);
extern UN_DLL_IMPORT const char *uniNamesList_annotFR(unsigned long uni);
extern UN_DLL_IMPORT int uniNamesList_blockCountFR(void);
extern UN_DLL_IMPORT int uniNamesList_blockNumberFR(unsigned long uni);
extern UN_DLL_IMPORT long uniNamesList_blockStartFR(int uniBlock);
extern UN_DLL_IMPORT long uniNamesList_blockEndFR(int uniBlock);
extern UN_DLL_IMPORT const char *uniNamesList_blockNameFR(int uniBlock);
#else
/* make these internal stubs since there's no French lib */
const char *uniNamesList_NamesListVersionFR(void);
const char *uniNamesList_nameFR(unsigned long uni);
const char *uniNamesList_annotFR(unsigned long uni);
int uniNamesList_blockCountFR(void);
int uniNamesList_blockNumberFR(unsigned long uni);
long uniNamesList_blockStartFR(int uniBlock);
long uniNamesList_blockEndFR(int uniBlock);
const char *uniNamesList_blockNameFR(int uniBlock);
UN_DLL_LOCAL const char *uniNamesList_NamesListVersionFR(void);
UN_DLL_LOCAL const char *uniNamesList_nameFR(unsigned long uni);
UN_DLL_LOCAL const char *uniNamesList_annotFR(unsigned long uni);
UN_DLL_LOCAL int uniNamesList_blockCountFR(void);
UN_DLL_LOCAL int uniNamesList_blockNumberFR(unsigned long uni);
UN_DLL_LOCAL long uniNamesList_blockStartFR(int uniBlock);
UN_DLL_LOCAL long uniNamesList_blockEndFR(int uniBlock);
UN_DLL_LOCAL const char *uniNamesList_blockNameFR(int uniBlock);
#endif
#endif
#endif

0 comments on commit 3d04207

Please sign in to comment.