Use weak linking of wcsdup and wcscasecmp on OS X

Fixes https://github.com/fish-shell/fish-shell/issues/240
This commit is contained in:
ridiculousfish 2012-07-20 14:33:08 -07:00
parent cf9bfe9e66
commit 966bbd476f
5 changed files with 99 additions and 72 deletions

View file

@ -1075,7 +1075,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
EXECUTABLE_NAME = fish_launcher;
GCC_DYNAMIC_NO_PIC = NO;
@ -1086,7 +1085,6 @@
);
GCC_WARN_UNINITIALIZED_AUTOS = YES;
INFOPLIST_FILE = osx/Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = fish;
WRAPPER_EXTENSION = app;
};
@ -1096,14 +1094,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EXECUTABLE_NAME = fish_launcher;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
INFOPLIST_FILE = osx/Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = fish;
WRAPPER_EXTENSION = app;
};
@ -1113,12 +1109,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@ -1127,12 +1121,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
@ -1141,7 +1133,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
@ -1150,7 +1141,6 @@
"$(inherited)",
);
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@ -1159,12 +1149,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
@ -1173,7 +1161,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
@ -1182,7 +1169,6 @@
"$(inherited)",
);
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@ -1191,12 +1177,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
@ -1205,12 +1189,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = fish;
};
name = Debug;
@ -1219,12 +1201,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = fish;
};
name = Release;
@ -1233,7 +1213,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
@ -1242,7 +1221,6 @@
"$(inherited)",
);
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@ -1251,12 +1229,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;

View file

@ -2060,3 +2060,20 @@ scoped_lock::scoped_lock(pthread_mutex_t &mutex) : lock_obj(&mutex), locked(fals
scoped_lock::~scoped_lock() {
if (locked) this->unlock();
}
wcstokenizer::wcstokenizer(const wcstring &s, const wcstring &separator) : sep(separator) {
buffer = wcsdup(s.c_str());
str = buffer;
state = NULL;
}
bool wcstokenizer::next(wcstring &result) {
wchar_t *tmp = wcstok(str, sep.c_str(), &state);
str = NULL;
if (tmp) result = tmp;
return tmp != NULL;
}
wcstokenizer::~wcstokenizer() {
free(buffer);
}

View file

@ -486,28 +486,15 @@ public:
~scoped_lock();
};
/* Wrapper around wcstok */
class wcstokenizer {
wchar_t *buffer, *str, *state;
const wcstring sep;
public:
wcstokenizer(const wcstring &s, const wcstring &separator) : sep(separator) {
wchar_t *wcsdup(const wchar_t *s);
buffer = wcsdup(s.c_str());
str = buffer;
state = NULL;
}
bool next(wcstring &result) {
wchar_t *tmp = wcstok(str, sep.c_str(), &state);
str = NULL;
if (tmp) result = tmp;
return tmp != NULL;
}
~wcstokenizer() {
free(buffer);
}
wcstokenizer(const wcstring &s, const wcstring &separator);
bool next(wcstring &result);
~wcstokenizer();
};
/**

View file

@ -803,8 +803,9 @@ wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **save_ptr)
#endif
#ifndef HAVE_WCSDUP
wchar_t *wcsdup( const wchar_t *in )
/* Fallback implementations of wcsdup and wcscasecmp. On systems where these are not needed (e.g. building on Linux) these should end up just being stripped, as they are static functions that are not referenced in this file.
*/
static wchar_t *wcsdup_fallback(const wchar_t *in)
{
size_t len=wcslen(in);
wchar_t *out = (wchar_t *)malloc( sizeof( wchar_t)*(len+1));
@ -815,23 +816,9 @@ wchar_t *wcsdup( const wchar_t *in )
memcpy( out, in, sizeof( wchar_t)*(len+1));
return out;
}
#endif
#ifndef HAVE_WCSLEN
size_t wcslen(const wchar_t *in)
{
const wchar_t *end=in;
while( *end )
end++;
return end-in;
}
#endif
#ifndef HAVE_WCSCASECMP
int wcscasecmp( const wchar_t *a, const wchar_t *b )
int wcscasecmp_fallback( const wchar_t *a, const wchar_t *b )
{
if( *a == 0 )
{
@ -845,11 +832,55 @@ int wcscasecmp( const wchar_t *a, const wchar_t *b )
if( diff != 0 )
return diff;
else
return wcscasecmp( a+1,b+1);
return wcscasecmp_fallback( a+1,b+1);
}
#if __APPLE__ && __DARWIN_C_LEVEL >= 200809L
/* Note parens avoid the macro expansion */
wchar_t *wcsdup_use_weak(const wchar_t *a)
{
if (wcsdup != NULL)
return (wcsdup)(a);
return wcsdup_fallback(a);
}
int wcscasecmp_use_weak(const wchar_t *a, const wchar_t *b)
{
if (wcscasecmp != NULL)
return (wcscasecmp)(a, b);
return wcscasecmp_fallback(a, b);
}
#else //__APPLE__
#ifndef HAVE_WCSDUP
wchar_t *wcsdup( const wchar_t *in )
{
return wcsdup_fallback(in);
}
#endif
#ifndef HAVE_WCSCASECMP
int wcscasecmp( const wchar_t *a, const wchar_t *b )
{
return wcscasecmp_fallback(a, b);
}
#endif
#endif //__APPLE__
#ifndef HAVE_WCSLEN
size_t wcslen(const wchar_t *in)
{
const wchar_t *end=in;
while( *end )
end++;
return end-in;
}
#endif
#ifndef HAVE_WCSNCASECMP
int wcsncasecmp( const wchar_t *a, const wchar_t *b, int count )
{

View file

@ -209,7 +209,20 @@ int wcwidth( wchar_t c );
#endif
#ifndef HAVE_WCSDUP
/** On OS X, use weak linking for wcsdup and wcscasecmp. Weak linking allows you to call the function only if it exists at runtime. You can detect it by testing the function pointer against NULL. To avoid making the callers do that, redefine wcsdup to wcsdup_use_weak, and likewise with wcscasecmp. This lets us use the same binary on SnowLeopard (10.6) and Lion+ (10.7), even though these functions only exist on 10.7+.
On other platforms, use what's detected at build time.
*/
#if __APPLE__ && __DARWIN_C_LEVEL >= 200809L
wchar_t *wcsdup_use_weak(const wchar_t *);
int wcscasecmp_use_weak(const wchar_t *, const wchar_t *);
#define wcsdup(a) wcsdup_use_weak((a))
#define wcscasecmp(a, b) wcscasecmp_use_weak((a), (b))
#else
#ifndef HAVE_WCSDUP
/**
Create a duplicate string. Wide string version of strdup. Will
@ -217,18 +230,9 @@ int wcwidth( wchar_t c );
*/
wchar_t *wcsdup(const wchar_t *in);
#endif
#endif
#ifndef HAVE_WCSLEN
/**
Fallback for wcsen. Returns the length of the specified string.
*/
size_t wcslen(const wchar_t *in);
#endif
#ifndef HAVE_WCSCASECMP
#ifndef HAVE_WCSCASECMP
/**
Case insensitive string compare function. Wide string version of
strcasecmp.
@ -242,8 +246,20 @@ size_t wcslen(const wchar_t *in);
*/
int wcscasecmp( const wchar_t *a, const wchar_t *b );
#endif
#endif //__APPLE__
#ifndef HAVE_WCSLEN
/**
Fallback for wclsen. Returns the length of the specified string.
*/
size_t wcslen(const wchar_t *in);
#endif
#ifndef HAVE_WCSNCASECMP
/**