Skip to content

Commit

Permalink
Checking in changes from https://github.com/kleisauke/wasm-vips.
Browse files Browse the repository at this point in the history
These are the original set of changes very kindly organized and released
in a patch by https://github.com/kleisauke. The details of this patch
are in this thread:
emscripten-core/emscripten#11066.
  • Loading branch information
RamiHg committed Dec 23, 2022
1 parent 069fd1d commit 95b6d0e
Show file tree
Hide file tree
Showing 108 changed files with 913 additions and 649 deletions.
4 changes: 2 additions & 2 deletions gio/gappinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ g_app_info_launch_default_for_uri (const char *uri,
g_object_unref (app_info);
}

#ifdef G_OS_UNIX
#if defined(G_OS_UNIX) && !defined(G_PLATFORM_WASM)
if (!res && glib_should_use_portal ())
{
const char *parent_window = NULL;
Expand Down Expand Up @@ -1068,7 +1068,7 @@ launch_default_for_uri_portal_open_uri_cb (GObject *object,
static void
launch_default_for_uri_portal_open_uri (GTask *task, GError *error)
{
#ifdef G_OS_UNIX
#if defined(G_OS_UNIX) && !defined(G_PLATFORM_WASM)
LaunchDefaultForUriData *data = g_task_get_task_data (task);
GCancellable *cancellable = g_task_get_cancellable (task);

Expand Down
18 changes: 12 additions & 6 deletions gio/gapplication.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ enum

static guint g_application_signals[NR_SIGNALS];

static void g_application_action_group_iface_init (GActionGroupInterface *);
static void g_application_action_map_iface_init (GActionMapInterface *);
static void g_application_action_group_iface_init (GActionGroupInterface *iface,
gpointer iface_data);
static void g_application_action_map_iface_init (GActionMapInterface *iface,
gpointer iface_data);
G_DEFINE_TYPE_WITH_CODE (GApplication, g_application, G_TYPE_OBJECT,
G_ADD_PRIVATE (GApplication)
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_application_action_group_iface_init)
Expand All @@ -314,7 +316,8 @@ typedef struct
} GApplicationExportedActions;

static GType g_application_exported_actions_get_type (void);
static void g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface);
static void g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface,
gpointer iface_data);
G_DEFINE_TYPE_WITH_CODE (GApplicationExportedActions, g_application_exported_actions, G_TYPE_SIMPLE_ACTION_GROUP,
G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, g_application_exported_actions_iface_init))

Expand Down Expand Up @@ -358,7 +361,8 @@ g_application_exported_actions_init (GApplicationExportedActions *actions)
}

static void
g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface)
g_application_exported_actions_iface_init (GRemoteActionGroupInterface *iface,
gpointer iface_data)
{
iface->activate_action_full = g_application_exported_actions_activate_action_full;
iface->change_action_state_full = g_application_exported_actions_change_action_state_full;
Expand Down Expand Up @@ -2731,7 +2735,8 @@ g_application_remove_action (GActionMap *action_map,
}

static void
g_application_action_group_iface_init (GActionGroupInterface *iface)
g_application_action_group_iface_init (GActionGroupInterface *iface,
gpointer iface_data)
{
iface->list_actions = g_application_list_actions;
iface->query_action = g_application_query_action;
Expand All @@ -2740,7 +2745,8 @@ g_application_action_group_iface_init (GActionGroupInterface *iface)
}

static void
g_application_action_map_iface_init (GActionMapInterface *iface)
g_application_action_map_iface_init (GActionMapInterface *iface,
gpointer iface_data)
{
iface->lookup_action = g_application_lookup_action;
iface->add_action = g_application_add_action;
Expand Down
4 changes: 3 additions & 1 deletion gio/gapplicationcommandline.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ g_application_command_line_real_printerr_literal (GApplicationCommandLine *cmdli
static GInputStream *
g_application_command_line_real_get_stdin (GApplicationCommandLine *cmdline)
{
#ifdef G_OS_UNIX
#ifdef G_PLATFORM_WASM
return NULL;
#elif defined(G_OS_UNIX)
return g_unix_input_stream_new (0, FALSE);
#else
return g_win32_input_stream_new (GetStdHandle (STD_INPUT_HANDLE), FALSE);
Expand Down
6 changes: 4 additions & 2 deletions gio/gbufferedinputstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ static gssize g_buffered_input_stream_real_fill_finish (GBufferedInputStream *s
GAsyncResult *result,
GError **error);

static void g_buffered_input_stream_seekable_iface_init (GSeekableIface *iface);
static void g_buffered_input_stream_seekable_iface_init (GSeekableIface *iface,
gpointer iface_data);
static goffset g_buffered_input_stream_tell (GSeekable *seekable);
static gboolean g_buffered_input_stream_can_seek (GSeekable *seekable);
static gboolean g_buffered_input_stream_seek (GSeekable *seekable,
Expand Down Expand Up @@ -302,7 +303,8 @@ g_buffered_input_stream_finalize (GObject *object)
}

static void
g_buffered_input_stream_seekable_iface_init (GSeekableIface *iface)
g_buffered_input_stream_seekable_iface_init (GSeekableIface *iface,
gpointer iface_data)
{
iface->tell = g_buffered_input_stream_tell;
iface->can_seek = g_buffered_input_stream_can_seek;
Expand Down
6 changes: 4 additions & 2 deletions gio/gbufferedoutputstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ static gboolean g_buffered_output_stream_close_finish (GOutputStream *str
GAsyncResult *result,
GError **error);

static void g_buffered_output_stream_seekable_iface_init (GSeekableIface *iface);
static void g_buffered_output_stream_seekable_iface_init (GSeekableIface *iface,
gpointer iface_data);
static goffset g_buffered_output_stream_tell (GSeekable *seekable);
static gboolean g_buffered_output_stream_can_seek (GSeekable *seekable);
static gboolean g_buffered_output_stream_seek (GSeekable *seekable,
Expand Down Expand Up @@ -348,7 +349,8 @@ g_buffered_output_stream_init (GBufferedOutputStream *stream)
}

static void
g_buffered_output_stream_seekable_iface_init (GSeekableIface *iface)
g_buffered_output_stream_seekable_iface_init (GSeekableIface *iface,
gpointer iface_data)
{
iface->tell = g_buffered_output_stream_tell;
iface->can_seek = g_buffered_output_stream_can_seek;
Expand Down
12 changes: 8 additions & 4 deletions gio/gbytesicon.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ enum
PROP_BYTES
};

static void g_bytes_icon_icon_iface_init (GIconIface *iface);
static void g_bytes_icon_loadable_icon_iface_init (GLoadableIconIface *iface);
static void g_bytes_icon_icon_iface_init (GIconIface *iface,
gpointer iface_data);
static void g_bytes_icon_loadable_icon_iface_init (GLoadableIconIface *iface,
gpointer iface_data);
G_DEFINE_TYPE_WITH_CODE (GBytesIcon, g_bytes_icon, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_ICON, g_bytes_icon_icon_iface_init)
G_IMPLEMENT_INTERFACE (G_TYPE_LOADABLE_ICON, g_bytes_icon_loadable_icon_iface_init))
Expand Down Expand Up @@ -210,7 +212,8 @@ g_bytes_icon_serialize (GIcon *icon)
}

static void
g_bytes_icon_icon_iface_init (GIconIface *iface)
g_bytes_icon_icon_iface_init (GIconIface *iface,
gpointer iface_data)
{
iface->hash = g_bytes_icon_hash;
iface->equal = g_bytes_icon_equal;
Expand Down Expand Up @@ -263,7 +266,8 @@ g_bytes_icon_load_finish (GLoadableIcon *icon,
}

static void
g_bytes_icon_loadable_icon_iface_init (GLoadableIconIface *iface)
g_bytes_icon_loadable_icon_iface_init (GLoadableIconIface *iface,
gpointer iface_data)
{
iface->load = g_bytes_icon_load;
iface->load_async = g_bytes_icon_load_async;
Expand Down
12 changes: 8 additions & 4 deletions gio/gcharsetconverter.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ enum {
* GIConv.
*/

static void g_charset_converter_iface_init (GConverterIface *iface);
static void g_charset_converter_initable_iface_init (GInitableIface *iface);
static void g_charset_converter_iface_init (GConverterIface *iface,
gpointer iface_data);
static void g_charset_converter_initable_iface_init (GInitableIface *iface,
gpointer iface_data);

/**
* GCharsetConverter:
Expand Down Expand Up @@ -423,7 +425,8 @@ g_charset_converter_get_num_fallbacks (GCharsetConverter *converter)
}

static void
g_charset_converter_iface_init (GConverterIface *iface)
g_charset_converter_iface_init (GConverterIface *iface,
gpointer iface_data)
{
iface->convert = g_charset_converter_convert;
iface->reset = g_charset_converter_reset;
Expand Down Expand Up @@ -468,7 +471,8 @@ g_charset_converter_initable_init (GInitable *initable,
}

static void
g_charset_converter_initable_iface_init (GInitableIface *iface)
g_charset_converter_initable_iface_init (GInitableIface *iface,
gpointer iface_data)
{
iface->init = g_charset_converter_initable_init;
}
7 changes: 4 additions & 3 deletions gio/gconverterinputstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ static gssize g_converter_input_stream_read_nonblocking (GPollableInputStream
static GSource *g_converter_input_stream_create_source (GPollableInputStream *stream,
GCancellable *cancellable);

static void g_converter_input_stream_pollable_iface_init (GPollableInputStreamInterface *iface);

static void g_converter_input_stream_pollable_iface_init (GPollableInputStreamInterface *iface,
gpointer iface_data);
G_DEFINE_TYPE_WITH_CODE (GConverterInputStream,
g_converter_input_stream,
G_TYPE_FILTER_INPUT_STREAM,
Expand Down Expand Up @@ -129,7 +129,8 @@ g_converter_input_stream_class_init (GConverterInputStreamClass *klass)
}

static void
g_converter_input_stream_pollable_iface_init (GPollableInputStreamInterface *iface)
g_converter_input_stream_pollable_iface_init (GPollableInputStreamInterface *iface,
gpointer iface_data)
{
iface->can_poll = g_converter_input_stream_can_poll;
iface->is_readable = g_converter_input_stream_is_readable;
Expand Down
6 changes: 4 additions & 2 deletions gio/gconverteroutputstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ static gssize g_converter_output_stream_write_nonblocking (GPollableOutputStre
static GSource *g_converter_output_stream_create_source (GPollableOutputStream *stream,
GCancellable *cancellable);

static void g_converter_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface);
static void g_converter_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface,
gpointer iface_data);

G_DEFINE_TYPE_WITH_CODE (GConverterOutputStream,
g_converter_output_stream,
Expand Down Expand Up @@ -145,7 +146,8 @@ g_converter_output_stream_class_init (GConverterOutputStreamClass *klass)
}

static void
g_converter_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface)
g_converter_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface,
gpointer iface_data)
{
iface->can_poll = g_converter_output_stream_can_poll;
iface->is_writable = g_converter_output_stream_is_writable;
Expand Down
6 changes: 4 additions & 2 deletions gio/gdataoutputstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static void g_data_output_stream_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);

static void g_data_output_stream_seekable_iface_init (GSeekableIface *iface);
static void g_data_output_stream_seekable_iface_init (GSeekableIface *iface,
gpointer iface_data);
static goffset g_data_output_stream_tell (GSeekable *seekable);
static gboolean g_data_output_stream_can_seek (GSeekable *seekable);
static gboolean g_data_output_stream_seek (GSeekable *seekable,
Expand Down Expand Up @@ -162,7 +163,8 @@ g_data_output_stream_init (GDataOutputStream *stream)
}

static void
g_data_output_stream_seekable_iface_init (GSeekableIface *iface)
g_data_output_stream_seekable_iface_init (GSeekableIface *iface,
gpointer iface_data)
{
iface->tell = g_data_output_stream_tell;
iface->can_seek = g_data_output_stream_can_seek;
Expand Down
12 changes: 8 additions & 4 deletions gio/gdbusactiongroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ action_info_new_from_iter (GVariantIter *iter)
return info;
}

static void g_dbus_action_group_remote_iface_init (GRemoteActionGroupInterface *iface);
static void g_dbus_action_group_iface_init (GActionGroupInterface *iface);
static void g_dbus_action_group_remote_iface_init (GRemoteActionGroupInterface *iface,
gpointer iface_data);
static void g_dbus_action_group_iface_init (GActionGroupInterface *iface,
gpointer iface_data);
G_DEFINE_TYPE_WITH_CODE (GDBusActionGroup, g_dbus_action_group, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_dbus_action_group_iface_init)
G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, g_dbus_action_group_remote_iface_init))
Expand Down Expand Up @@ -459,14 +461,16 @@ g_dbus_action_group_class_init (GDBusActionGroupClass *class)
}

static void
g_dbus_action_group_remote_iface_init (GRemoteActionGroupInterface *iface)
g_dbus_action_group_remote_iface_init (GRemoteActionGroupInterface *iface,
gpointer iface_data)
{
iface->activate_action_full = g_dbus_action_group_activate_action_full;
iface->change_action_state_full = g_dbus_action_group_change_action_state_full;
}

static void
g_dbus_action_group_iface_init (GActionGroupInterface *iface)
g_dbus_action_group_iface_init (GActionGroupInterface *iface,
gpointer iface_data)
{
iface->list_actions = g_dbus_action_group_list_actions;
iface->query_action = g_dbus_action_group_query_action;
Expand Down
12 changes: 8 additions & 4 deletions gio/gdbusconnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,10 @@ static void schedule_method_call (GDBusConnection *connection,

static guint signals[LAST_SIGNAL] = { 0 };

static void initable_iface_init (GInitableIface *initable_iface);
static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
static void initable_iface_init (GInitableIface *initable_iface,
gpointer iface_data);
static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface,
gpointer iface_data);

G_DEFINE_TYPE_WITH_CODE (GDBusConnection, g_dbus_connection, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
Expand Down Expand Up @@ -2662,15 +2664,17 @@ initable_init (GInitable *initable,
}

static void
initable_iface_init (GInitableIface *initable_iface)
initable_iface_init (GInitableIface *initable_iface,
gpointer iface_data)
{
initable_iface->init = initable_init;
}

/* ---------------------------------------------------------------------------------------------------- */

static void
async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
async_initable_iface_init (GAsyncInitableIface *async_initable_iface,
gpointer iface_data)
{
/* Use default */
}
Expand Down
12 changes: 8 additions & 4 deletions gio/gdbusdaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ enum
static guint g_dbus_daemon_signals[NR_SIGNALS];


static void initable_iface_init (GInitableIface *initable_iface);
static void g_dbus_daemon_iface_init (_GFreedesktopDBusIface *iface);
static void initable_iface_init (GInitableIface *initable_iface,
gpointer iface_data);
static void g_dbus_daemon_iface_init (_GFreedesktopDBusIface *iface,
gpointer iface_data);

#define g_dbus_daemon_get_type _g_dbus_daemon_get_type
G_DEFINE_TYPE_WITH_CODE (GDBusDaemon, g_dbus_daemon, _G_TYPE_FREEDESKTOP_DBUS_SKELETON,
Expand Down Expand Up @@ -1718,7 +1720,8 @@ g_dbus_daemon_class_init (GDBusDaemonClass *klass)
}

static void
g_dbus_daemon_iface_init (_GFreedesktopDBusIface *iface)
g_dbus_daemon_iface_init (_GFreedesktopDBusIface *iface,
gpointer iface_data)
{
iface->handle_add_match = handle_add_match;
iface->handle_get_connection_selinux_security_context = handle_get_connection_selinux_security_context;
Expand All @@ -1740,7 +1743,8 @@ g_dbus_daemon_iface_init (_GFreedesktopDBusIface *iface)
}

static void
initable_iface_init (GInitableIface *initable_iface)
initable_iface_init (GInitableIface *initable_iface,
gpointer iface_data)
{
initable_iface->init = initable_init;
}
Expand Down
18 changes: 12 additions & 6 deletions gio/gdbusobjectmanagerclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,12 @@ enum

static guint signals[LAST_SIGNAL] = { 0 };

static void initable_iface_init (GInitableIface *initable_iface);
static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
static void dbus_object_manager_interface_init (GDBusObjectManagerIface *iface);
static void initable_iface_init (GInitableIface *initable_iface,
gpointer iface_data);
static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface,
gpointer iface_data);
static void dbus_object_manager_interface_init (GDBusObjectManagerIface *iface,
gpointer iface_data);

G_DEFINE_TYPE_WITH_CODE (GDBusObjectManagerClient, g_dbus_object_manager_client, G_TYPE_OBJECT,
G_ADD_PRIVATE (GDBusObjectManagerClient)
Expand Down Expand Up @@ -1516,13 +1519,15 @@ initable_init (GInitable *initable,
}

static void
initable_iface_init (GInitableIface *initable_iface)
initable_iface_init (GInitableIface *initable_iface,
gpointer iface_data)
{
initable_iface->init = initable_init;
}

static void
async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
async_initable_iface_init (GAsyncInitableIface *async_initable_iface,
gpointer iface_data)
{
/* for now, just use default: run GInitable code in thread */
}
Expand Down Expand Up @@ -1863,7 +1868,8 @@ g_dbus_object_manager_client_get_objects (GDBusObjectManager *_manager)


static void
dbus_object_manager_interface_init (GDBusObjectManagerIface *iface)
dbus_object_manager_interface_init (GDBusObjectManagerIface *iface,
gpointer iface_data)
{
iface->get_object_path = g_dbus_object_manager_client_get_object_path;
iface->get_objects = g_dbus_object_manager_client_get_objects;
Expand Down
Loading

4 comments on commit 95b6d0e

@kleisauke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, see also the "Upstream patches" item at https://github.com/users/kleisauke/projects/1 for the reason why these GLib patches are not upstreamed yet.

@RamiHg
Copy link
Owner Author

@RamiHg RamiHg commented on 95b6d0e Dec 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I should have browsed your repos to see if you had already forked these projects! It would have made things much easier for me :). FYI I'm going to delete this repo and fork your glib repo instead.

Yeah, I didn't expect (nor, TBH, did I plan for) these projects to accept the Emscripten changes. It would definitely be nice to not have to maintain all these forks. But my main intention is to publish the source code of a huge GPLv2 project that I just finished porting to Emscripten.

While we're on the topic of GLib: the function pointer conversion rule in the link you mentioned is technically 100% compatible with Emscripten. GLib's doc says that a pointer has to be castable to void* and back again - presumably to the same pointer type.

What they're doing is taking a function pointer, maybe casting it to void*, but then casting it back to another completely different pointer type! According to the C language spec on function pointer casts (emphasis mine):

Any pointer to function can be cast to a pointer to any other function type [...]. If the converted pointer is used to make a function call, the behavior is undefined (unless the function types are compatible).

And according to the same spec, functions (at least non-K&R-style) are compatible if:

"... the number of parameters ... is the same, and the corresponding [parameters] ... have compatible types".

I'm sure I'm preaching to the choir here - but it's insane that they're doing this in the first place. We just happened to be lucky that most ABIs, so far, don't break if you append extra arguments. Well, most ABIs until Emscripten :).

Anyway, my point is that they should absolutely at least take our function pointer conversion fixes. The conversion fixes are mostly free because the compiler should be able to easily inline the trampolines (or ignore the extra parameter declaration). There was only one case (adding g_test suites/cases) where I had to add an allocation, but that was because I was in a hurry; I'm sure there's a way to do it cheaply.

Cheers, and thanks releasing all your ports!

@kleisauke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inb4 delete (preventing me from correctly responding to this).

@kleisauke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, did you see comment: emscripten-core/emscripten#11066 (comment)?

FWIW, commit kleisauke@4ed9ec0 causes an ABI break, so I think this will not be included in GLib 2.0.

Please sign in to comment.