Merge branch 'wip/3v1n0/add-darwin-os' into 'main'

meson: Define G_OS_DARWIN when compiling under OSX or iOS

See merge request GNOME/glib!2981
This commit is contained in:
Philip Withnall 2022-10-20 11:41:48 +00:00
commit e6fa40bf99
29 changed files with 89 additions and 58 deletions

View File

@ -196,6 +196,11 @@ GCond *cond
# Definitions for different operating systems
<MACRO>
<NAME>G_OS_DARWIN</NAME>
#define G_OS_DARWIN
</MACRO>
<MACRO>
<NAME>G_OS_UNIX</NAME>
#define G_OS_UNIX

View File

@ -140,6 +140,7 @@ GLIB_VERSION_PREV_STABLE
<TITLE>Standard Macros</TITLE>
<FILE>macros</FILE>
<SUBSECTION>
G_OS_DARWIN
G_OS_WIN32
G_OS_UNIX

View File

@ -2486,7 +2486,7 @@ g_application_run (GApplication *application,
sizeof (arguments[0]) * (argc + 1));
}
}
#elif defined(__APPLE__)
#elif defined(G_OS_DARWIN)
{
gint i, j;

View File

@ -692,7 +692,7 @@ g_credentials_set_unix_user (GCredentials *credentials,
return ret;
}
#ifdef __APPLE__
#ifdef G_OS_DARWIN
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 /* __APPLE__ */
#endif /* G_OS_DARWIN */
#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(__APPLE__)
#elif defined(G_OS_DARWIN)
#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
#endif /* defined(G_OS_DARWIN) */
#endif /* __G_CREDENTIALS_PRIVATE_H__ */

View File

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

View File

@ -61,7 +61,7 @@
#endif
#include <glib/gstdio.h>
#if defined(G_OS_UNIX) && !defined(HAVE_COCOA)
#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN)
#include "gdesktopappinfo.h"
#endif
#ifdef HAVE_COCOA
@ -1185,7 +1185,7 @@ _g_io_modules_ensure_extension_points_registered (void)
if (g_once_init_enter (&registered_extensions))
{
#if defined(G_OS_UNIX) && !defined(HAVE_COCOA)
#if defined(G_OS_UNIX) && !defined(G_OS_DARWIN)
#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);
@ -1264,7 +1264,7 @@ get_gio_module_dir (void)
g_free (install_dir);
#else
module_dir = g_strdup (GIO_MODULE_DIR);
#ifdef __APPLE__
#ifdef G_OS_DARWIN
#include "TargetConditionals.h"
#if TARGET_OS_OSX
#include <dlfcn.h>
@ -1286,7 +1286,7 @@ get_gio_module_dir (void)
}
}
#endif
#endif
#endif /* G_OS_DARWIN */
#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(__APPLE__)
#elif defined(G_OS_DARWIN)
/* 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
#else /* !G_OS_DARWIN */
/* 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 __APPLE__
# ifdef G_OS_DARWIN
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(HAVE_COCOA)
#if !defined(G_OS_WIN32) && !defined(G_OS_DARWIN)
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 __APPLE__
#ifndef G_OS_DARWIN
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 /* __APPLE__ */
#endif /* G_OS_DARWIN */
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 __APPLE__
#ifdef G_OS_DARWIN
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 __APPLE__
#ifdef G_OS_DARWIN
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 __APPLE__
#ifndef G_OS_DARWIN
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 __APPLE__
#ifdef G_OS_DARWIN
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 __APPLE__
#ifndef G_OS_DARWIN
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(__APPLE__) || defined(G_OS_WIN32)
#if defined(G_OS_DARWIN) || 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(__APPLE__) && !defined(G_OS_WIN32)
#if !defined(G_OS_DARWIN) && !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 __APPLE__
#ifdef G_OS_DARWIN
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 __APPLE__
#ifdef G_OS_DARWIN
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 HAVE_COCOA
#ifndef G_OS_DARWIN
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(__APPLE__)
#if defined(G_OS_WIN32) || defined(G_OS_DARWIN)
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 HAVE_COCOA
#ifndef G_OS_DARWIN
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(__APPLE__)
#if defined(G_OS_WIN32) || defined(G_OS_DARWIN)
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(__APPLE__)
#if defined(G_OS_WIN32) || defined(G_OS_DARWIN)
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(__APPLE__)
#if defined(G_OS_WIN32) || defined(G_OS_DARWIN)
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(__APPLE__)
#elif defined(G_OS_DARWIN)
/* 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

@ -1647,6 +1647,17 @@
* 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:
*

View File

@ -77,7 +77,7 @@ static void stack_trace (const char * const *args);
#endif
/* Default to using LLDB for backtraces on macOS. */
#ifdef __APPLE__
#ifdef G_OS_DARWIN
#define USE_LLDB
#endif

View File

@ -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 (__APPLE__) || (defined(_WIN32) && (defined(__clang__) || defined(__GNUC__)))
#elif defined (G_OS_DARWIN) || (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

View File

@ -1493,7 +1493,7 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
if (getrlimit (RLIMIT_NOFILE, &rl) == 0 && rl.rlim_max != RLIM_INFINITY)
open_max = rl.rlim_max;
#endif
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(G_OS_DARWIN)
/* Use sysconf() function provided by the system if it is known to be
* async-signal safe.
*

View File

@ -1806,7 +1806,7 @@ g_close (gint fd,
* Disabling the message for now until someone with access to a
* macOS machine can investigate.
* See https://gitlab.gnome.org/GNOME/glib/-/issues/2785 */
#ifndef HAVE_COCOA
#ifndef G_OS_DARWIN
g_critical ("g_close(fd:%d) failed with EBADF. The tracking of file descriptors got messed up", fd);
#endif
}

View File

@ -1414,7 +1414,7 @@ get_windows_version (gboolean with_windows)
}
#endif
#if defined (G_OS_UNIX) && !defined (__APPLE__)
#if defined (G_OS_UNIX) && !defined (G_OS_DARWIN)
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 (__APPLE__) */
#endif /* defined (G_OS_UNIX) && !defined (G_OS_DARWIN) */
/**
* 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 (__APPLE__)
#if defined (G_OS_DARWIN)
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 HAVE_COCOA
#ifdef G_OS_DARWIN
/* Implemented in gutils-macos.m */
void load_user_special_dirs_macos (gchar **table);

View File

@ -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 HAVE_CARBON
#ifdef G_OS_DARWIN
"a-.a",
"a.a",
"aa.a",

View File

@ -725,7 +725,7 @@ test_strftime (void)
#else
{ "%B", "January" },
{ "%b", "Jan" },
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(G_OS_DARWIN)
{ "%C", "00" },
{ "%c", "Mon Jan 1 00:00:00 0001" },
{ "%E", "E" },

View File

@ -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 __APPLE__ /* OSX just returns the number */
#ifndef G_OS_DARWIN /* 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 __APPLE__ /* OSX just returns the number */
#ifndef G_OS_DARWIN /* 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 __APPLE__ /* OSX returns latin "AM", not japanese */
#ifndef G_OS_DARWIN /* 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 __APPLE__ /* OSX returns YYYY/MM/DD in ASCII */
#ifndef G_OS_DARWIN /* 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");

View File

@ -20,8 +20,19 @@
* Author: Philip Withnall <withnall@endlessm.com>
*/
#include "config.h"
#include <glib.h>
#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)

View File

@ -897,7 +897,7 @@ test_upper_bound (void)
g_assert_cmpint (res, ==, 20);
}
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if !defined(G_OS_DARWIN) && !defined(__FreeBSD__)
static gint test_vasprintf_va (gchar **string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
@ -917,19 +917,19 @@ test_vasprintf_va (gchar **string,
return len;
}
#endif /* !defined(__APPLE__) && !defined(__FreeBSD__) */
#endif /* !defined(G_OS_DARWIN) && !defined(__FreeBSD__) */
static void
test_vasprintf_invalid_format_placeholder (void)
{
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if !defined(G_OS_DARWIN) && !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(__APPLE__) && !defined(__FreeBSD__)
#if !defined(G_OS_DARWIN) && !defined(__FreeBSD__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wformat-extra-args"

View File

@ -739,7 +739,7 @@ test_os_info (void)
{
gchar *name;
gchar *contents = NULL;
#if defined (G_OS_UNIX) && !(defined (G_OS_WIN32) || defined (__APPLE__))
#if defined (G_OS_UNIX) && !(defined (G_OS_WIN32) || defined (G_OS_DARWIN))
struct utsname info;
#endif
@ -749,7 +749,7 @@ test_os_info (void)
G_OS_INFO_KEY_NAME,
name == NULL ? "(null)" : name);
#if defined (G_OS_WIN32) || defined (__APPLE__)
#if defined (G_OS_WIN32) || defined (G_OS_DARWIN)
/* These OSs have a special case so NAME should always succeed */
g_assert_nonnull (name);
#elif defined (G_OS_UNIX)

View File

@ -126,9 +126,9 @@
#undef PLAT_amd64_solaris
#if defined(__APPLE__) && defined(__i386__)
#if defined(G_OS_DARWIN) && defined(__i386__)
# define PLAT_x86_darwin 1
#elif defined(__APPLE__) && defined(__x86_64__)
#elif defined(G_OS_DARWIN) && defined(__x86_64__)
# define PLAT_amd64_darwin 1
#elif (defined(__MINGW32__) && defined(__i386__)) \
|| defined(__CYGWIN32__) \

View File

@ -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 (__APPLE__) && defined (__ppc64__))
#if !defined (__cplusplus) && (G_GNUC_CHECK_VERSION(2, 7)) && !(defined (G_OS_DARWIN) && defined (__ppc64__))
#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
static GType type_name##_get_type_once (void); \
\

View File

@ -235,6 +235,9 @@ 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