X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=libs%2Funiquenames.h;h=7ef0755e3a6e62f91ec7028d9ccd5af5c2f1225c;hb=HEAD;hp=8ff67f15b55150829fa103413b03593d4e3f1992;hpb=b7e36c120eb1546a6c6f97f30e42ab7f9a559c61;p=xonotic%2Fnetradiant.git diff --git a/libs/uniquenames.h b/libs/uniquenames.h index 8ff67f15..7ef0755e 100644 --- a/libs/uniquenames.h +++ b/libs/uniquenames.h @@ -106,9 +106,34 @@ inline void name_write( char* buffer, name_t name ){ inline name_t name_read( const char* name ){ const char* end = name + strlen( name ); + +#if GDEF_OS_MACOS + /* HACK: Apple shipped a clang built for macOS with an optimization enabled + that is not available on macOS. This compiler error may then be faced: + + ld: Undefined symbols: + _memrchr, referenced from: + name_read(char const*) in map.cpp.o + + This is a compiler error: + + > On Mac OSX (macOS version 12.4, sdk version 12.1) llvm can replace call + > to strrchr() with call to memrchr() when string length is known at + > compile time. This results in link error, because memrchr is not present + > in libSystem. + > -- https://github.com/llvm/llvm-project/issues/62254 + + We workaround this by making the string length not known at build time + on macOS to avoid triggering the unavailable compiler optimization. */ + + const char* volatile numbers = "1234567890"; +#else + const char* numbers = "1234567890"; +#endif + for ( const char* p = end; end != name; --p ) { - if ( strrchr( "1234567890", *p ) == NULL ) { + if ( strrchr( numbers, *p ) == NULL ) { break; } end = p; @@ -187,17 +212,25 @@ name_t make_unique( const name_t& name ) const { char buf[80]; name_t r( "","" ); name_write( buf, name ); + #ifdef _DEBUG globalErrorStream() << "find unique name for " << buf << "\n"; globalErrorStream() << "> currently registered names:\n"; + #endif for ( names_t::const_iterator i = m_names.begin(); i != m_names.end(); ++i ) { + #ifdef _DEBUG globalErrorStream() << ">> " << i->first.c_str() << ": "; + #endif for ( PostFixes::postfixes_t::const_iterator j = i->second.m_postfixes.begin(); j != i->second.m_postfixes.end(); ++j ) { j->first.write( buf ); + #ifdef _DEBUG globalErrorStream() << " '" << buf << "'"; + #endif } + #ifdef _DEBUG globalErrorStream() << "\n"; + #endif } names_t::const_iterator i = m_names.find( name.first ); if ( i == m_names.end() ) { @@ -208,7 +241,9 @@ name_t make_unique( const name_t& name ) const { r = name_t( name.first, ( *i ).second.make_unique( name.second ) ); } name_write( buf, r ); + #ifdef _DEBUG globalErrorStream() << "> unique name is " << buf << "\n"; + #endif return r; }