diff --git a/src/ml_glib.c b/src/ml_glib.c index d71f25d5..725f340c 100644 --- a/src/ml_glib.c +++ b/src/ml_glib.c @@ -300,11 +300,15 @@ ML_1 (g_source_remove, Int_val, Unit) static GPollFunc poll_func = NULL; +int polling = 0; + static gint ml_poll (GPollFD *ufds, guint nfsd, gint timeout) { gint res; caml_enter_blocking_section(); + polling = 1; res = poll_func(ufds, nfsd, timeout); + polling = 0; caml_leave_blocking_section(); return res; } diff --git a/src/ml_glib.h b/src/ml_glib.h index 64e3a8b4..a4d689f9 100644 --- a/src/ml_glib.h +++ b/src/ml_glib.h @@ -37,3 +37,5 @@ CAMLexport GSList *GSList_val (value list, value_out); CAMLexport void ml_register_exn_map (GQuark domain, char *caml_name); CAMLexport void ml_raise_gerror(GError *) Noreturn; + +extern int polling; diff --git a/src/ml_gobject.c b/src/ml_gobject.c index 4159a285..f654312d 100644 --- a/src/ml_gobject.c +++ b/src/ml_gobject.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "wrappers.h" #include "ml_glib.h" @@ -178,7 +179,7 @@ static void notify_destroy(gpointer unit, GClosure *c) remove_global_root((value*)&c->data); } -static void marshal (GClosure *closure, GValue *ret, +static void marshal_core (GClosure *closure, GValue *ret, guint nargs, const GValue *args, gpointer hint, gpointer marshall_data) { @@ -194,6 +195,20 @@ static void marshal (GClosure *closure, GValue *ret, CAMLreturn0; } +static void marshal (GClosure *closure, GValue *ret, + guint nargs, const GValue *args, + gpointer hint, gpointer marshall_data) +{ + if (polling) { // https://github.com/garrigue/lablgtk/issues/141 + caml_leave_blocking_section(); + polling = 0; + marshal_core(closure, ret, nargs, args, hint, marshall_data); + polling = 1; + caml_enter_blocking_section(); + } else + marshal_core(closure, ret, nargs, args, hint, marshall_data); +} + CAMLprim value ml_g_closure_new (value clos) { GClosure* closure = g_closure_new_simple(sizeof(GClosure), (gpointer)clos);