Revert "gio, glib: Use G_OS_DARWIN for code that is for such environments"

This reverts commit 476e33c3f3.

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
This commit is contained in:
Philip Withnall
2022-11-02 10:01:09 +00:00
parent 483b6f2214
commit 7b52ccbfc4
26 changed files with 61 additions and 61 deletions

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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 <sys/ucred.h>
#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__ */

View File

@@ -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"));

View File

@@ -23,7 +23,7 @@
#include <gio/gio.h>
#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN)
#if defined(G_OS_UNIX) && !defined(HAVE_COCOA)
#include <gio/gdesktopappinfo.h>
#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

View File

@@ -23,7 +23,7 @@
#include <gio/gio.h>
#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN)
#if defined(G_OS_UNIX) && !defined(HAVE_COCOA)
#include <gio/gdesktopappinfo.h>
#endif

View File

@@ -61,7 +61,7 @@
#endif
#include <glib/gstdio.h>
#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 (&registered_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 <dlfcn.h>
@@ -1293,7 +1293,7 @@ get_gio_module_dir (void)
}
}
#endif
#endif /* G_OS_DARWIN */
#endif
#endif
}

View File

@@ -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 <sys/uio.h>
* 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

View File

@@ -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

View File

@@ -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];

View File

@@ -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");

View File

@@ -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

View File

@@ -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 ());

View File

@@ -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"

View File

@@ -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");