Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#29450: build: replace custom MAC_OSX macro wi…
Browse files Browse the repository at this point in the history
…th existing `__APPLE__`

6c6b244 build: Replace MAC_OSX macro with existing __APPLE__ (Lőrinc)

Pull request description:

  This PR aims to standardize and simplify macOS-specific checks within our codebase by replacing the custom-defined `MAC_OSX` macro with the existing `__APPLE__`macro, defined in e.g. https://sourceforge.net/p/predef/wiki/OperatingSystems/#macos

  We already use `__APPLE__` in our own codebase for e.g. https://github.com/bitcoin/bitcoin/blob/master/src/crypto/sha256.cpp#L22

  Local Verification confirms that `MAC_OSX` isn't defined, but `__APPLE__` is:
  ```bash
  % echo | cpp -dM | egrep 'MAC_OSX|__MACOS__|__APPLE__'
  #define __APPLE__ 1
  ```

ACKs for top commit:
  fanquake:
    ACK 6c6b244 - at this point it seems unlikely that we'll need to accomodate non-macOS Apple, so consolidating to `__APPLE__` seems ok for now.

Tree-SHA512: dbf87c96211d9d55426ee85d76ef1e05cda3efd1c9248b0974a82834dafc1c1aece3165bd46e4252f0460dc97079bdbcebe98bbd81e9de0d7399c0bc69d5c050
  • Loading branch information
fanquake committed Oct 24, 2024
2 parents d94adc7 + 6c6b244 commit 2f40e45
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_compile_definitions(core_interface INTERFACE
MAC_OSX
OBJC_OLD_DISPATCH_PROTOTYPES=0
)
target_compile_definitions(core_interface INTERFACE OBJC_OLD_DISPATCH_PROTOTYPES=0)
# These flags are specific to ld64, and may cause issues with other linkers.
# For example: GNU ld will interpret -dead_strip as -de and then try and use
# "ad_strip" as the symbol for the entry point.
Expand Down
4 changes: 2 additions & 2 deletions src/common/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
for (int i = 1; i < argc; i++) {
std::string key(argv[i]);

#ifdef MAC_OSX
#ifdef __APPLE__
// At the first time when a user gets the "App downloaded from the
// internet" warning, and clicks the Open button, macOS passes
// a unique process serial number (PSN) as -psn_... command-line
Expand Down Expand Up @@ -741,7 +741,7 @@ fs::path GetDefaultDataDir()
pathRet = fs::path("/");
else
pathRet = fs::path(pszHome);
#ifdef MAC_OSX
#ifdef __APPLE__
// macOS
return pathRet / "Library/Application Support/Bitcoin";
#else
Expand Down
2 changes: 1 addition & 1 deletion src/common/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void SetupEnvironment()
#endif
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
// may be invalid, in which case the "C.UTF-8" locale is used as fallback.
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
#if !defined(WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
try {
std::locale(""); // Raises a runtime error if current locale is invalid
} catch (const std::runtime_error&) {
Expand Down
4 changes: 2 additions & 2 deletions src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <sys/time.h>
#endif

#if defined(HAVE_GETRANDOM) || (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX))
#if defined(HAVE_GETRANDOM) || (defined(HAVE_GETENTROPY_RAND) && defined(__APPLE__))
#include <sys/random.h>
#endif

Expand Down Expand Up @@ -387,7 +387,7 @@ void GetOSRand(unsigned char *ent32)
The function call is always successful.
*/
arc4random_buf(ent32, NUM_OS_RANDOM_BYTES);
#elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)
#elif defined(HAVE_GETENTROPY_RAND) && defined(__APPLE__)
if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) {
RandFailure();
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/fs_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool FileCommit(FILE* file)
LogPrintf("FlushFileBuffers failed: %s\n", Win32ErrorString(GetLastError()));
return false;
}
#elif defined(MAC_OSX) && defined(F_FULLFSYNC)
#elif defined(__APPLE__) && defined(F_FULLFSYNC)
if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success
LogPrintf("fcntl F_FULLFSYNC failed: %s\n", SysErrorString(errno));
return false;
Expand Down Expand Up @@ -195,7 +195,7 @@ void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length)
nFileSize.u.HighPart = nEndPos >> 32;
SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
SetEndOfFile(hFile);
#elif defined(MAC_OSX)
#elif defined(__APPLE__)
// OSX specific version
// NOTE: Contrary to other OS versions, the OSX version assumes that
// NOTE: offset is the size of the file.
Expand Down
2 changes: 1 addition & 1 deletion src/util/threadnames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void SetThreadName(const char* name)
::prctl(PR_SET_NAME, name, 0, 0, 0);
#elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
pthread_set_name_np(pthread_self(), name);
#elif defined(MAC_OSX)
#elif defined(__APPLE__)
pthread_setname_np(name);
#else
// Prevent warnings for unused parameters...
Expand Down

0 comments on commit 2f40e45

Please sign in to comment.