From 19b15d34a152bf19a851f8306847eeab61180b17 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 12 Jul 2017 15:41:12 -0400 Subject: [PATCH] Cleaned up what symbols are exported from the library. --- CMakeLists.txt | 2 +- src/archiver_vdf.c | 4 ++-- src/physfs.c | 1 - src/physfs_internal.h | 38 +++++++++++++++++++++++++++++++------- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dc17ec..3205915 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ endif() include_directories(./src) if(APPLE) - set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-fno-common -framework CoreFoundation -framework IOKit") + set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework CoreFoundation -framework IOKit") endif() if(CMAKE_COMPILER_IS_GNUCC) diff --git a/src/archiver_vdf.c b/src/archiver_vdf.c index 7631fa0..7e8c356 100644 --- a/src/archiver_vdf.c +++ b/src/archiver_vdf.c @@ -25,8 +25,8 @@ #define VDF_CRC16 0x8005 #define VDF_HASHTABLE_SIZE 65536 -const char* VDF_SIGNATURE_G1 = "PSVDSC_V2.00\r\n\r\n"; -const char* VDF_SIGNATURE_G2 = "PSVDSC_V2.00\n\r\n\r"; +static const char* VDF_SIGNATURE_G1 = "PSVDSC_V2.00\r\n\r\n"; +static const char* VDF_SIGNATURE_G2 = "PSVDSC_V2.00\n\r\n\r"; typedef union { diff --git a/src/physfs.c b/src/physfs.c index b6b5e55..d8e089d 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -1123,7 +1123,6 @@ static int doRegisterArchiver(const PHYSFS_Archiver *_archiver); static int initStaticArchivers(void) { #define REGISTER_STATIC_ARCHIVER(arc) { \ - extern const PHYSFS_Archiver __PHYSFS_Archiver_##arc; \ if (!doRegisterArchiver(&__PHYSFS_Archiver_##arc)) { \ return 0; \ } \ diff --git a/src/physfs_internal.h b/src/physfs_internal.h index a53d8c5..4abdb42 100644 --- a/src/physfs_internal.h +++ b/src/physfs_internal.h @@ -14,13 +14,6 @@ #error Do not include this header from your applications. #endif -/* Make sure everything that includes this header exports no symbols by - default. physfs.h uses function attributes to mark only the public API as - visible. */ -#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) -#pragma GCC visibility push(hidden) -#endif - /* Turn off MSVC warnings that are aggressively anti-portability. */ #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS 1 @@ -69,6 +62,33 @@ extern "C" { #define _FILE_OFFSET_BITS 64 #endif +/* All public APIs need to be in physfs.h with a PHYSFS_DECL. + All file-private symbols need to be marked "static". + Everything shared between PhysicsFS sources needs to be in this + file between the visibility pragma blocks. */ +#if PHYSFS_MINIMUM_GCC_VERSION(4,0) || defined(__clang__) +#define PHYSFS_HAVE_PRAGMA_VISIBILITY 1 +#endif + +#if PHYSFS_HAVE_PRAGMA_VISIBILITY +#pragma GCC visibility push(hidden) +#endif + +/* These are the build-in archivers. We list them all as "extern" here without + #ifdefs to keep it tidy, but obviously you need to make sure these are + wrapped in PHYSFS_SUPPORTS_* checks before actually referencing them. */ +extern const PHYSFS_Archiver __PHYSFS_Archiver_DIR; +extern const PHYSFS_Archiver __PHYSFS_Archiver_ZIP; +extern const PHYSFS_Archiver __PHYSFS_Archiver_LZMA; +extern const PHYSFS_Archiver __PHYSFS_Archiver_GRP; +extern const PHYSFS_Archiver __PHYSFS_Archiver_QPAK; +extern const PHYSFS_Archiver __PHYSFS_Archiver_HOG; +extern const PHYSFS_Archiver __PHYSFS_Archiver_MVL; +extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD; +extern const PHYSFS_Archiver __PHYSFS_Archiver_SLB; +extern const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660; +extern const PHYSFS_Archiver __PHYSFS_Archiver_VDF; + /* a real C99-compliant snprintf() is in Visual Studio 2015, but just use this everywhere for binary compatibility. */ #if defined(_MSC_VER) @@ -655,6 +675,10 @@ int __PHYSFS_platformGrabMutex(void *mutex); */ void __PHYSFS_platformReleaseMutex(void *mutex); +#if PHYSFS_HAVE_PRAGMA_VISIBILITY +#pragma GCC visibility pop +#endif + #ifdef __cplusplus } #endif