From 7b52ccbfc4e12e3f3f8346e87fdd783203e4b4fa Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 2 Nov 2022 10:01:09 +0000 Subject: [PATCH 1/4] Revert "gio, glib: Use G_OS_DARWIN for code that is for such environments" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 476e33c3f3632bd32370fadc67b10d61da9a4098. We’ve decided to remove `G_OS_DARWIN` in favour of recommending people use `__APPLE__` instead. As per the discussion on #2802 and linked issues, * Adding a new define shifts the complexity from “which of these platform-provided defines do I use” to “which platform-provided defines does G_OS_DARWIN use” * There should ideally be no cases where a user of GLib has to use their own platform-specific code, since GLib should be providing appropriate abstractions * Providing a single `G_OS_DARWIN` to cover all Apple products (macOS and iOS) hides the complexity of what the user is actually testing: are they testing for the Mach kernel, the Carbon and/or Cocoa user space toolkits, macOS vs iOS vs tvOS, etc Helps: #2802 --- gio/gapplication.c | 2 +- gio/gcredentials.c | 4 ++-- gio/gcredentialsprivate.h | 4 ++-- gio/gio-querymodules.c | 2 +- gio/gio-tool-launch.c | 6 +++--- gio/gio-tool-open.c | 2 +- gio/giomodule.c | 10 +++++----- gio/gioprivate.h | 4 ++-- gio/glib-compile-resources.c | 2 +- gio/glocalfileinfo.c | 2 +- gio/tests/contenttype.c | 22 +++++++++++----------- gio/tests/file.c | 12 ++++++------ gio/tests/gdbus-server-auth.c | 2 +- gio/tests/giomodule.c | 2 +- gio/tests/resources.c | 2 +- glib/gbacktrace.c | 2 +- glib/gbacktrace.h | 2 +- glib/gutils.c | 8 ++++---- glib/tests/collate.c | 2 +- glib/tests/date.c | 2 +- glib/tests/gdatetime.c | 8 ++++---- glib/tests/test-printf.c | 8 ++++---- glib/tests/utils.c | 4 ++-- glib/valgrind.h | 4 ++-- gmodule/gmodule.c | 2 +- gobject/gtype.h | 2 +- 26 files changed, 61 insertions(+), 61 deletions(-) diff --git a/gio/gapplication.c b/gio/gapplication.c index 724d2f4b4..1d602c763 100644 --- a/gio/gapplication.c +++ b/gio/gapplication.c @@ -2486,7 +2486,7 @@ g_application_run (GApplication *application, sizeof (arguments[0]) * (argc + 1)); } } -#elif defined(G_OS_DARWIN) +#elif defined(__APPLE__) { gint i, j; diff --git a/gio/gcredentials.c b/gio/gcredentials.c index cf35db63c..ba5be63a6 100644 --- a/gio/gcredentials.c +++ b/gio/gcredentials.c @@ -692,7 +692,7 @@ g_credentials_set_unix_user (GCredentials *credentials, return ret; } -#ifdef G_OS_DARWIN +#ifdef __APPLE__ void _g_credentials_set_local_peerid (GCredentials *credentials, pid_t pid) @@ -702,6 +702,6 @@ _g_credentials_set_local_peerid (GCredentials *credentials, credentials->pid = pid; } -#endif /* G_OS_DARWIN */ +#endif /* __APPLE__ */ #endif /* G_OS_UNIX */ diff --git a/gio/gcredentialsprivate.h b/gio/gcredentialsprivate.h index f692f1af7..0310a7542 100644 --- a/gio/gcredentialsprivate.h +++ b/gio/gcredentialsprivate.h @@ -160,7 +160,7 @@ #define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1 #define G_CREDENTIALS_HAS_PID 1 -#elif defined(G_OS_DARWIN) +#elif defined(__APPLE__) #include #define G_CREDENTIALS_SUPPORTED 1 #define G_CREDENTIALS_USE_APPLE_XUCRED 1 @@ -182,6 +182,6 @@ void _g_credentials_set_local_peerid (GCredentials *credentials, #define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1 #define G_CREDENTIALS_HAS_PID 1 -#endif /* defined(G_OS_DARWIN) */ +#endif #endif /* __G_CREDENTIALS_PRIVATE_H__ */ diff --git a/gio/gio-querymodules.c b/gio/gio-querymodules.c index 3766e4303..145d6ddae 100644 --- a/gio/gio-querymodules.c +++ b/gio/gio-querymodules.c @@ -35,7 +35,7 @@ static gboolean is_valid_module_name (const gchar *basename) { #if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN) - #if defined(G_OS_DARWIN) + #if defined(__APPLE__) return g_str_has_prefix (basename, "lib") && (g_str_has_suffix (basename, ".so") || g_str_has_suffix (basename, ".dylib")); diff --git a/gio/gio-tool-launch.c b/gio/gio-tool-launch.c index a272e3a4c..18a9c5fb9 100644 --- a/gio/gio-tool-launch.c +++ b/gio/gio-tool-launch.c @@ -23,7 +23,7 @@ #include -#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN) +#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) #include #endif @@ -40,7 +40,7 @@ handle_launch (int argc, char *argv[], gboolean do_help) { GOptionContext *context; GError *error = NULL; -#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN) +#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) int i; GAppInfo *app = NULL; GAppLaunchContext *app_context = NULL; @@ -83,7 +83,7 @@ handle_launch (int argc, char *argv[], gboolean do_help) g_option_context_free (context); -#if !defined(G_OS_UNIX) || defined(G_OS_DARWIN) +#if !defined(G_OS_UNIX) || defined(HAVE_COCOA) print_error (_("The launch command is not currently supported on this platform")); retval = 1; #else diff --git a/gio/gio-tool-open.c b/gio/gio-tool-open.c index 1bd1d197b..da8914a7c 100644 --- a/gio/gio-tool-open.c +++ b/gio/gio-tool-open.c @@ -23,7 +23,7 @@ #include -#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN) +#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) #include #endif diff --git a/gio/giomodule.c b/gio/giomodule.c index f8af005a6..b1a55e4c6 100644 --- a/gio/giomodule.c +++ b/gio/giomodule.c @@ -61,7 +61,7 @@ #endif #include -#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN) +#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) #include "gdesktopappinfo.h" #endif #ifdef HAVE_COCOA @@ -430,7 +430,7 @@ is_valid_module_name (const gchar *basename, gboolean result; #if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN) - #if defined(G_OS_DARWIN) + #if defined(__APPLE__) if (!g_str_has_prefix (basename, "lib") || !(g_str_has_suffix (basename, ".so") || g_str_has_suffix (basename, ".dylib"))) @@ -1192,7 +1192,7 @@ _g_io_modules_ensure_extension_points_registered (void) if (g_once_init_enter (®istered_extensions)) { -#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN) +#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) #if !GLIB_CHECK_VERSION (3, 0, 0) ep = g_io_extension_point_register (G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME); g_io_extension_point_set_required_type (ep, G_TYPE_DESKTOP_APP_INFO_LOOKUP); @@ -1271,7 +1271,7 @@ get_gio_module_dir (void) g_free (install_dir); #else module_dir = g_strdup (GIO_MODULE_DIR); -#ifdef G_OS_DARWIN +#ifdef __APPLE__ #include "TargetConditionals.h" #if TARGET_OS_OSX #include @@ -1293,7 +1293,7 @@ get_gio_module_dir (void) } } #endif -#endif /* G_OS_DARWIN */ +#endif #endif } diff --git a/gio/gioprivate.h b/gio/gioprivate.h index 4404385e7..a65b9bd64 100644 --- a/gio/gioprivate.h +++ b/gio/gioprivate.h @@ -45,11 +45,11 @@ void g_socket_connection_set_cached_remote_address (GSocketConnection *connectio #define G_IOV_MAX IOV_MAX #elif defined(UIO_MAXIOV) #define G_IOV_MAX UIO_MAXIOV -#elif defined(G_OS_DARWIN) +#elif defined(__APPLE__) /* For macOS/iOS, UIO_MAXIOV is documented in writev(2), but * only declares it if defined(KERNEL) */ #define G_IOV_MAX 512 -#else /* !G_OS_DARWIN */ +#else /* 16 is the minimum value required by POSIX */ #define G_IOV_MAX 16 #endif diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c index a6501d421..0f873d486 100644 --- a/gio/glib-compile-resources.c +++ b/gio/glib-compile-resources.c @@ -735,7 +735,7 @@ get_compiler_id (const char *compiler) #ifdef G_OS_UNIX const char *compiler_env = g_getenv ("CC"); -# ifdef G_OS_DARWIN +# ifdef __APPLE__ if (compiler_env == NULL || *compiler_env == '\0') compiler = "clang"; else diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index cb93d7638..bfc25504f 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -1380,7 +1380,7 @@ get_content_type (const char *basename, content_type = g_content_type_guess (basename, NULL, 0, &result_uncertain); -#if !defined(G_OS_WIN32) && !defined(G_OS_DARWIN) +#if !defined(G_OS_WIN32) && !defined(HAVE_COCOA) if (!fast && result_uncertain && path != NULL) { guchar sniff_buffer[4096]; diff --git a/gio/tests/contenttype.c b/gio/tests/contenttype.c index 466d9f252..7fd97f453 100644 --- a/gio/tests/contenttype.c +++ b/gio/tests/contenttype.c @@ -58,7 +58,7 @@ test_guess (void) /* Sadly win32 & OSX just don't have as large and robust of a mime type database as Linux */ #ifndef G_OS_WIN32 -#ifndef G_OS_DARWIN +#ifndef __APPLE__ res = g_content_type_guess ("foo", data, sizeof (data) - 1, &uncertain); expected = g_content_type_from_mime_type ("text/plain"); g_assert_content_type_equals (expected, res); @@ -111,7 +111,7 @@ test_guess (void) g_assert_false (uncertain); g_free (res); g_free (expected); -#endif /* G_OS_DARWIN */ +#endif /* __APPLE__ */ res = g_content_type_guess (NULL, (guchar *)"%!PS-Adobe-2.0 EPSF-1.2", 23, &uncertain); expected = g_content_type_from_mime_type ("image/x-eps"); @@ -175,7 +175,7 @@ test_list (void) gchar *plain; gchar *xml; -#ifdef G_OS_DARWIN +#ifdef __APPLE__ g_test_skip ("The OSX backend does not implement g_content_types_get_registered()"); return; #endif @@ -250,7 +250,7 @@ test_icon (void) const gchar *const *names; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); -#ifdef G_OS_DARWIN +#ifdef __APPLE__ g_assert_true (g_strv_contains (names, "text-*")); #elif defined(G_OS_WIN32) g_assert_cmpuint (g_strv_length ((GStrv) names), >, 0); @@ -274,7 +274,7 @@ test_icon (void) g_assert_true (g_strv_contains (names, "text-x-generic")); #else g_assert_true (g_strv_contains (names, "application-rtf")); -#ifndef G_OS_DARWIN +#ifndef __APPLE__ g_assert_true (g_strv_contains (names, "x-office-document")); #endif #endif @@ -298,7 +298,7 @@ test_symbolic_icon (void) const gchar *const *names; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); -#ifdef G_OS_DARWIN +#ifdef __APPLE__ g_assert_true (g_strv_contains (names, "text-*-symbolic")); g_assert_true (g_strv_contains (names, "text-*")); #else @@ -321,7 +321,7 @@ test_symbolic_icon (void) names = g_themed_icon_get_names (G_THEMED_ICON (icon)); g_assert_true (g_strv_contains (names, "application-rtf-symbolic")); g_assert_true (g_strv_contains (names, "application-rtf")); -#ifndef G_OS_DARWIN +#ifndef __APPLE__ g_assert_true (g_strv_contains (names, "x-office-document-symbolic")); g_assert_true (g_strv_contains (names, "x-office-document")); #endif @@ -344,7 +344,7 @@ test_tree (void) gchar **types; gsize i; -#if defined(G_OS_DARWIN) || defined(G_OS_WIN32) +#if defined(__APPLE__) || defined(G_OS_WIN32) g_test_skip ("The OSX & Windows backends do not implement g_content_type_guess_for_tree()"); return; #endif @@ -370,7 +370,7 @@ test_type_is_a_special_case (void) /* Everything but the inode type is application/octet-stream */ res = g_content_type_is_a ("inode/directory", "application/octet-stream"); g_assert_false (res); -#if !defined(G_OS_DARWIN) && !defined(G_OS_WIN32) +#if !defined(__APPLE__) && !defined(G_OS_WIN32) res = g_content_type_is_a ("anything", "application/octet-stream"); g_assert_true (res); #endif @@ -388,7 +388,7 @@ test_guess_svg_from_data (void) gboolean uncertain = TRUE; gchar *res = g_content_type_guess (NULL, (guchar *)svgfilecontent, sizeof (svgfilecontent) - 1, &uncertain); -#ifdef G_OS_DARWIN +#ifdef __APPLE__ g_assert_cmpstr (res, ==, "public.svg-image"); #elif defined(G_OS_WIN32) g_test_skip ("svg type detection from content is not implemented on WIN32"); @@ -402,7 +402,7 @@ test_guess_svg_from_data (void) static void test_mime_from_content (void) { -#ifdef G_OS_DARWIN +#ifdef __APPLE__ gchar *mime_type; mime_type = g_content_type_get_mime_type ("com.microsoft.bmp"); g_assert_cmpstr (mime_type, ==, "image/bmp"); diff --git a/gio/tests/file.c b/gio/tests/file.c index 6a63a344f..79c6d57bb 100644 --- a/gio/tests/file.c +++ b/gio/tests/file.c @@ -2472,7 +2472,7 @@ get_size_from_du (const gchar *path, guint64 *size) GError *error = NULL; gchar *du_path = NULL; -#ifndef G_OS_DARWIN +#ifndef HAVE_COCOA du_path = g_find_program_in_path ("du"); #endif @@ -3499,7 +3499,7 @@ test_query_default_handler_uri (void) GFile *file; GFile *invalid_file; -#if defined(G_OS_WIN32) || defined(G_OS_DARWIN) +#if defined(G_OS_WIN32) || defined(__APPLE__) g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); return; #endif @@ -3556,7 +3556,7 @@ test_query_zero_length_content_type (void) NULL, &error); g_assert_no_error (error); -#ifndef G_OS_DARWIN +#ifndef HAVE_COCOA g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "text/plain"); #else g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "public.text"); @@ -3580,7 +3580,7 @@ test_query_default_handler_file (void) const char buffer[] = "Text file!\n"; const guint8 binary_buffer[] = "\xde\xad\xbe\xff"; -#if defined(G_OS_WIN32) || defined(G_OS_DARWIN) +#if defined(G_OS_WIN32) || defined(__APPLE__) g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); return; #endif @@ -3676,7 +3676,7 @@ test_query_default_handler_file_async (void) const guint8 binary_buffer[] = "\xde\xad\xbe\xff"; GError *error = NULL; -#if defined(G_OS_WIN32) || defined(G_OS_DARWIN) +#if defined(G_OS_WIN32) || defined(__APPLE__) g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); return; #endif @@ -3766,7 +3766,7 @@ test_query_default_handler_uri_async (void) GFile *file; GFile *invalid_file; -#if defined(G_OS_WIN32) || defined(G_OS_DARWIN) +#if defined(G_OS_WIN32) || defined(__APPLE__) g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); return; #endif diff --git a/gio/tests/gdbus-server-auth.c b/gio/tests/gdbus-server-auth.c index 9c56aac72..c683f61da 100644 --- a/gio/tests/gdbus-server-auth.c +++ b/gio/tests/gdbus-server-auth.c @@ -247,7 +247,7 @@ assert_expected_uid_pid (InteropFlags flags, * on Linux. */ g_assert_cmpint (uid, ==, getuid ()); g_assert_cmpint (pid, ==, getpid ()); -#elif defined(G_OS_DARWIN) +#elif defined(__APPLE__) /* We know (or at least suspect) that both GDBus and libdbus support * passing the uid only on macOS. */ g_assert_cmpint (uid, ==, getuid ()); diff --git a/gio/tests/giomodule.c b/gio/tests/giomodule.c index 349cec83d..77522d9b6 100644 --- a/gio/tests/giomodule.c +++ b/gio/tests/giomodule.c @@ -31,7 +31,7 @@ #else #define MODULE_FILENAME(x) "lib" x ".dll" #endif -#elif defined(G_OS_DARWIN) +#elif defined(__APPLE__) #define MODULE_FILENAME(x) "lib" x ".dylib" #else #define MODULE_FILENAME(x) "lib" x ".so" diff --git a/gio/tests/resources.c b/gio/tests/resources.c index 353ef7796..f567914d7 100644 --- a/gio/tests/resources.c +++ b/gio/tests/resources.c @@ -805,7 +805,7 @@ test_uri_query_info (void) g_assert_nonnull (content_type); mime_type = g_content_type_get_mime_type (content_type); g_assert_nonnull (mime_type); -#ifdef G_OS_DARWIN +#ifdef __APPLE__ g_assert_cmpstr (mime_type, ==, "text/*"); #else g_assert_cmpstr (mime_type, ==, "text/plain"); diff --git a/glib/gbacktrace.c b/glib/gbacktrace.c index bd18d1e0d..9c52a7d29 100644 --- a/glib/gbacktrace.c +++ b/glib/gbacktrace.c @@ -77,7 +77,7 @@ static void stack_trace (const char * const *args); #endif /* Default to using LLDB for backtraces on macOS. */ -#ifdef G_OS_DARWIN +#ifdef __APPLE__ #define USE_LLDB #endif diff --git a/glib/gbacktrace.h b/glib/gbacktrace.h index 3280132d8..11293b318 100644 --- a/glib/gbacktrace.h +++ b/glib/gbacktrace.h @@ -63,7 +63,7 @@ void g_on_error_stack_trace (const gchar *prg_name); # define G_BREAKPOINT() G_STMT_START{ __debugbreak(); }G_STMT_END #elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2 # define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END -#elif defined (G_OS_DARWIN) || (defined(_WIN32) && (defined(__clang__) || defined(__GNUC__))) +#elif defined (__APPLE__) || (defined(_WIN32) && (defined(__clang__) || defined(__GNUC__))) # define G_BREAKPOINT() G_STMT_START{ __builtin_trap(); }G_STMT_END #else /* !__i386__ && !__alpha__ */ # define G_BREAKPOINT() G_STMT_START{ raise (SIGTRAP); }G_STMT_END diff --git a/glib/gutils.c b/glib/gutils.c index fccd60162..78ccd6121 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1414,7 +1414,7 @@ get_windows_version (gboolean with_windows) } #endif -#if defined (G_OS_UNIX) && !defined (G_OS_DARWIN) +#if defined (G_OS_UNIX) && !defined (__APPLE__) static gchar * get_os_info_from_os_release (const gchar *key_name, const gchar *buffer) @@ -1543,7 +1543,7 @@ get_os_info_from_uname (const gchar *key_name) else return NULL; } -#endif /* defined (G_OS_UNIX) && !defined (G_OS_DARWIN) */ +#endif /* defined (G_OS_UNIX) && !defined (__APPLE__) */ /** * g_get_os_info: @@ -1566,7 +1566,7 @@ get_os_info_from_uname (const gchar *key_name) gchar * g_get_os_info (const gchar *key_name) { -#if defined (G_OS_DARWIN) +#if defined (__APPLE__) if (g_strcmp0 (key_name, G_OS_INFO_KEY_NAME) == 0) return g_strdup ("macOS"); else @@ -2080,7 +2080,7 @@ g_get_user_runtime_dir (void) return user_runtime_dir; } -#ifdef G_OS_DARWIN +#ifdef HAVE_COCOA /* Implemented in gutils-macos.m */ void load_user_special_dirs_macos (gchar **table); diff --git a/glib/tests/collate.c b/glib/tests/collate.c index f3907976f..bd9ea234f 100644 --- a/glib/tests/collate.c +++ b/glib/tests/collate.c @@ -235,7 +235,7 @@ const gchar *sorted2[] = { const gchar *file_sorted2[] = { /* Filename collation in OS X follows Finder style which gives * a slightly different order from usual Linux locales. */ -#ifdef G_OS_DARWIN +#ifdef HAVE_CARBON "a-.a", "a.a", "aa.a", diff --git a/glib/tests/date.c b/glib/tests/date.c index 8113ad574..b26b6376e 100644 --- a/glib/tests/date.c +++ b/glib/tests/date.c @@ -725,7 +725,7 @@ test_strftime (void) #else { "%B", "January" }, { "%b", "Jan" }, -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(G_OS_DARWIN) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) { "%C", "00" }, { "%c", "Mon Jan 1 00:00:00 0001" }, { "%E", "E" }, diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c index 3a0d2bd28..7874d258d 100644 --- a/glib/tests/gdatetime.c +++ b/glib/tests/gdatetime.c @@ -1694,14 +1694,14 @@ test_non_utf8_printf (void) */ TEST_PRINTF ("%a", "\345\234\237"); TEST_PRINTF ("%A", "\345\234\237\346\233\234\346\227\245"); -#ifndef G_OS_DARWIN /* OSX just returns the number */ +#ifndef __APPLE__ /* OSX just returns the number */ TEST_PRINTF ("%b", "10\346\234\210"); #endif TEST_PRINTF ("%B", "10\346\234\210"); TEST_PRINTF ("%d", "24"); TEST_PRINTF_DATE (2009, 1, 1, "%d", "01"); TEST_PRINTF ("%e", "24"); // fixme -#ifndef G_OS_DARWIN /* OSX just returns the number */ +#ifndef __APPLE__ /* OSX just returns the number */ TEST_PRINTF ("%h", "10\346\234\210"); #endif TEST_PRINTF ("%H", "00"); @@ -1718,7 +1718,7 @@ test_non_utf8_printf (void) TEST_PRINTF_TIME (10, 13, 13, "%l", "10"); TEST_PRINTF ("%m", "10"); TEST_PRINTF ("%M", "00"); -#ifndef G_OS_DARWIN /* OSX returns latin "AM", not japanese */ +#ifndef __APPLE__ /* OSX returns latin "AM", not japanese */ TEST_PRINTF ("%p", "\345\215\210\345\211\215"); TEST_PRINTF_TIME (13, 13, 13, "%p", "\345\215\210\345\276\214"); TEST_PRINTF ("%P", "\345\215\210\345\211\215"); @@ -1731,7 +1731,7 @@ test_non_utf8_printf (void) TEST_PRINTF ("%S", "00"); TEST_PRINTF ("%t", " "); TEST_PRINTF ("%u", "6"); -#ifndef G_OS_DARWIN /* OSX returns YYYY/MM/DD in ASCII */ +#ifndef __APPLE__ /* OSX returns YYYY/MM/DD in ASCII */ TEST_PRINTF ("%x", "2009\345\271\26410\346\234\21024\346\227\245"); #endif TEST_PRINTF ("%X", "00\346\231\20200\345\210\20600\347\247\222"); diff --git a/glib/tests/test-printf.c b/glib/tests/test-printf.c index 5b80c04d2..261b03812 100644 --- a/glib/tests/test-printf.c +++ b/glib/tests/test-printf.c @@ -899,7 +899,7 @@ test_upper_bound (void) g_assert_cmpint (res, ==, 20); } -#if !defined(G_OS_DARWIN) && !defined(__FreeBSD__) +#if !defined(__APPLE__) && !defined(__FreeBSD__) static gint test_vasprintf_va (gchar **string, const gchar *format, ...) G_GNUC_PRINTF (2, 3); @@ -919,19 +919,19 @@ test_vasprintf_va (gchar **string, return len; } -#endif /* !defined(G_OS_DARWIN) && !defined(__FreeBSD__) */ +#endif /* !defined(__APPLE__) && !defined(__FreeBSD__) */ static void test_vasprintf_invalid_format_placeholder (void) { -#if !defined(G_OS_DARWIN) && !defined(__FreeBSD__) +#if !defined(__APPLE__) && !defined(__FreeBSD__) gint len = 0; gchar *buf = "some non-null string"; #endif g_test_summary ("Test error handling for invalid format placeholder in g_vasprintf()"); -#if !defined(G_OS_DARWIN) && !defined(__FreeBSD__) +#if !defined(__APPLE__) && !defined(__FreeBSD__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat-extra-args" diff --git a/glib/tests/utils.c b/glib/tests/utils.c index 2e3a0a4b2..5d73bbc9e 100644 --- a/glib/tests/utils.c +++ b/glib/tests/utils.c @@ -741,7 +741,7 @@ test_os_info (void) { gchar *name; gchar *contents = NULL; -#if defined (G_OS_UNIX) && !(defined (G_OS_WIN32) || defined (G_OS_DARWIN)) +#if defined (G_OS_UNIX) && !(defined (G_OS_WIN32) || defined (__APPLE__)) struct utsname info; #endif @@ -751,7 +751,7 @@ test_os_info (void) G_OS_INFO_KEY_NAME, name == NULL ? "(null)" : name); -#if defined (G_OS_WIN32) || defined (G_OS_DARWIN) +#if defined (G_OS_WIN32) || defined (__APPLE__) /* These OSs have a special case so NAME should always succeed */ g_assert_nonnull (name); #elif defined (G_OS_UNIX) diff --git a/glib/valgrind.h b/glib/valgrind.h index a83af4171..a7f1f5655 100644 --- a/glib/valgrind.h +++ b/glib/valgrind.h @@ -126,9 +126,9 @@ #undef PLAT_amd64_solaris -#if defined(G_OS_DARWIN) && defined(__i386__) +#if defined(__APPLE__) && defined(__i386__) # define PLAT_x86_darwin 1 -#elif defined(G_OS_DARWIN) && defined(__x86_64__) +#elif defined(__APPLE__) && defined(__x86_64__) # define PLAT_amd64_darwin 1 #elif (defined(__MINGW32__) && defined(__i386__)) \ || defined(__CYGWIN32__) \ diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c index 9f9e1a042..00a2c055f 100644 --- a/gmodule/gmodule.c +++ b/gmodule/gmodule.c @@ -618,7 +618,7 @@ g_module_open_full (const gchar *file_name, * .dylib and .dll in those cases. */ prefixes[prefix_idx++] = ""; #endif - #ifdef G_OS_DARWIN + #ifdef __APPLE__ if (!g_str_has_suffix (basename, ".dylib") && !g_str_has_suffix (basename, ".so")) { diff --git a/gobject/gtype.h b/gobject/gtype.h index 8be826b40..a81049142 100644 --- a/gobject/gtype.h +++ b/gobject/gtype.h @@ -2314,7 +2314,7 @@ type_name##_get_type (void) \ /* Only use this in non-C++ on GCC >= 2.7, except for Darwin/ppc64. * See https://bugzilla.gnome.org/show_bug.cgi?id=647145 */ -#if !defined (__cplusplus) && (G_GNUC_CHECK_VERSION(2, 7)) && !(defined (G_OS_DARWIN) && defined (__ppc64__)) +#if !defined (__cplusplus) && (G_GNUC_CHECK_VERSION(2, 7)) && !(defined (__APPLE__) && defined (__ppc64__)) #define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \ static GType type_name##_get_type_once (void); \ \ From 9ebb491d554b08d4817f1a5e55378e6027de148a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 2 Nov 2022 10:05:52 +0000 Subject: [PATCH 2/4] Revert "meson: Define G_OS_DARWIN when compiling under OSX or iOS" This reverts commit e85635daa07e9c669ded75c476d67d02aa85c7c1. See the previous revert for rationale. Fixes: #2802 --- docs/reference/glib/glib-overrides.txt | 5 ----- docs/reference/glib/glib-sections.txt.in | 1 - glib/docs.c | 11 ----------- glib/tests/macros.c | 11 ----------- meson.build | 3 --- 5 files changed, 31 deletions(-) diff --git a/docs/reference/glib/glib-overrides.txt b/docs/reference/glib/glib-overrides.txt index 8f29a48d4..991fcf2d0 100644 --- a/docs/reference/glib/glib-overrides.txt +++ b/docs/reference/glib/glib-overrides.txt @@ -196,11 +196,6 @@ GCond *cond # Definitions for different operating systems - -G_OS_DARWIN -#define G_OS_DARWIN - - G_OS_UNIX #define G_OS_UNIX diff --git a/docs/reference/glib/glib-sections.txt.in b/docs/reference/glib/glib-sections.txt.in index f81b454d3..face9dec6 100644 --- a/docs/reference/glib/glib-sections.txt.in +++ b/docs/reference/glib/glib-sections.txt.in @@ -140,7 +140,6 @@ GLIB_VERSION_PREV_STABLE Standard Macros macros -G_OS_DARWIN G_OS_WIN32 G_OS_UNIX diff --git a/glib/docs.c b/glib/docs.c index 9883cfbf7..0171da41f 100644 --- a/glib/docs.c +++ b/glib/docs.c @@ -1997,17 +1997,6 @@ * These macros provide a few commonly-used features. */ -/** - * G_OS_DARWIN: - * - * This macro is defined only on Apple operating systems (macOS or iOS). - * So you can bracket Apple-specific code in `\#ifdef G_OS_DARWIN`. - * - * Note that %G_OS_UNIX is also set. - * - * Since: 2.76 - */ - /** * G_OS_WIN32: * diff --git a/glib/tests/macros.c b/glib/tests/macros.c index cbbc0f6de..efe632b52 100644 --- a/glib/tests/macros.c +++ b/glib/tests/macros.c @@ -20,19 +20,8 @@ * Author: Philip Withnall */ -#include "config.h" - #include -#if defined (__APPLE__) || defined (HAVE_COCOA) || defined (HAVE_CARBON) -# ifndef G_OS_UNIX - G_STATIC_ASSERT (FALSE); -# endif -# ifndef G_OS_DARWIN - G_STATIC_ASSERT (FALSE); -# endif -#endif - /* Test that G_STATIC_ASSERT_EXPR can be used as an expression */ static void test_assert_static (void) diff --git a/meson.build b/meson.build index 40842c918..2d434ad8e 100644 --- a/meson.build +++ b/meson.build @@ -276,9 +276,6 @@ if host_system == 'windows' elif host_system == 'cygwin' glib_os = '''#define G_OS_UNIX #define G_WITH_CYGWIN''' -elif host_system in ['darwin', 'ios'] - glib_os = '''#define G_OS_UNIX -#define G_OS_DARWIN''' else glib_os = '#define G_OS_UNIX' endif From ad4c59c3c65f15217ba0ef53099ee7f6a79be161 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 2 Nov 2022 10:19:35 +0000 Subject: [PATCH 3/4] docs: Mention __APPLE__ instead of G_OS_DARWIN for detecting Darwin See discussion on #2802 and in the previous two commits. Signed-off-by: Philip Withnall Fixes: #2802 --- glib/docs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/glib/docs.c b/glib/docs.c index 0171da41f..1ca7927fb 100644 --- a/glib/docs.c +++ b/glib/docs.c @@ -2018,13 +2018,10 @@ * - Linux kernel and GNU user-space: `\#if defined(__linux__) && defined(__GLIBC__)` * - FreeBSD kernel (any libc, including glibc): `\#ifdef __FreeBSD_kernel__` * - FreeBSD kernel and user-space: `\#ifdef __FreeBSD__` + * - Apple operating systems (macOS, iOS, tvOS), regardless of whether + * Cocoa/Carbon toolkits are available: `\#ifdef __APPLE__` * * See for more. - * - * GLib defines OS-detection macros for some categories of systems - * that can be less straightforward to detect, such as %G_OS_DARWIN, but - * intentionally does not provide its own equivalents of macros like - * `__linux__`. */ /** From 5af339aedf34637e52f88b5cdbbb1a8325452c5c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 3 Nov 2022 18:22:18 +0000 Subject: [PATCH 4/4] gio: Check __APPLE__ in a few places instead of HAVE_COCOA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `HAVE_COCOA` should be used only in the places where we’re actually depending on the Cocoa toolkit. It should not be used as a general way of detecting building on a Darwin-based OS such as macOS. Conversely, there are a few places in the code where we do want to specifically detect the Cocoa toolkit (and others where we specifically want to detect Carbon), so keep `HAVE_COCOA` and `HAVE_CARBON` around. Signed-off-by: Philip Withnall Helps: #2802 --- gio/gio-tool-launch.c | 6 +++--- gio/gio-tool-open.c | 2 +- gio/giomodule.c | 6 +++--- gio/glocalfileinfo.c | 2 +- gio/tests/file.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gio/gio-tool-launch.c b/gio/gio-tool-launch.c index 18a9c5fb9..6b0d742f1 100644 --- a/gio/gio-tool-launch.c +++ b/gio/gio-tool-launch.c @@ -23,7 +23,7 @@ #include -#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) +#if defined(G_OS_UNIX) && !defined(__APPLE__) #include #endif @@ -40,7 +40,7 @@ handle_launch (int argc, char *argv[], gboolean do_help) { GOptionContext *context; GError *error = NULL; -#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) +#if defined(G_OS_UNIX) && !defined(__APPLE__) int i; GAppInfo *app = NULL; GAppLaunchContext *app_context = NULL; @@ -83,7 +83,7 @@ handle_launch (int argc, char *argv[], gboolean do_help) g_option_context_free (context); -#if !defined(G_OS_UNIX) || defined(HAVE_COCOA) +#if !defined(G_OS_UNIX) || defined(__APPLE__) print_error (_("The launch command is not currently supported on this platform")); retval = 1; #else diff --git a/gio/gio-tool-open.c b/gio/gio-tool-open.c index da8914a7c..fbc4c4bcc 100644 --- a/gio/gio-tool-open.c +++ b/gio/gio-tool-open.c @@ -23,7 +23,7 @@ #include -#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) +#if defined(G_OS_UNIX) && !defined(__APPLE__) #include #endif diff --git a/gio/giomodule.c b/gio/giomodule.c index b1a55e4c6..11ce7d8b9 100644 --- a/gio/giomodule.c +++ b/gio/giomodule.c @@ -61,14 +61,14 @@ #endif #include -#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) +#if defined(G_OS_UNIX) && !defined(__APPLE__) #include "gdesktopappinfo.h" #endif #ifdef HAVE_COCOA #include "gosxappinfo.h" #endif -#ifdef HAVE_COCOA +#ifdef __APPLE__ #include #endif @@ -1192,7 +1192,7 @@ _g_io_modules_ensure_extension_points_registered (void) if (g_once_init_enter (®istered_extensions)) { -#if defined(G_OS_UNIX) && !defined(HAVE_COCOA) +#if defined(G_OS_UNIX) && !defined(__APPLE__) #if !GLIB_CHECK_VERSION (3, 0, 0) ep = g_io_extension_point_register (G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME); g_io_extension_point_set_required_type (ep, G_TYPE_DESKTOP_APP_INFO_LOOKUP); diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index bfc25504f..b63f7826c 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -1380,7 +1380,7 @@ get_content_type (const char *basename, content_type = g_content_type_guess (basename, NULL, 0, &result_uncertain); -#if !defined(G_OS_WIN32) && !defined(HAVE_COCOA) +#if !defined(G_OS_WIN32) && !defined(__APPLE__) if (!fast && result_uncertain && path != NULL) { guchar sniff_buffer[4096]; diff --git a/gio/tests/file.c b/gio/tests/file.c index 79c6d57bb..4fec7aa09 100644 --- a/gio/tests/file.c +++ b/gio/tests/file.c @@ -2472,7 +2472,7 @@ get_size_from_du (const gchar *path, guint64 *size) GError *error = NULL; gchar *du_path = NULL; -#ifndef HAVE_COCOA +#ifndef __APPLE__ du_path = g_find_program_in_path ("du"); #endif @@ -3556,7 +3556,7 @@ test_query_zero_length_content_type (void) NULL, &error); g_assert_no_error (error); -#ifndef HAVE_COCOA +#ifndef __APPLE__ g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "text/plain"); #else g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "public.text");