1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-03-28 18:40:03 +01:00

girffi.h: add g_callable_info_get_closure_native_address() API

Commit 6bab939bf ("girffi.c: fix return value for g_callable_info_prepare_closure()")
effectively changes semantics of return value from code pointer to data pinter (closure).

`gjs` (and probably other software) relies on old (incorrect) semantics of
g_callable_info_prepare_closure(): https://gitlab.gnome.org/GNOME/gjs/-/issues/428

This change exposes the API that allows extracting directly
callacble code pointer. `gjs` will have to adapt to the new API.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
This commit is contained in:
Sergei Trofimovich 2021-07-17 18:19:17 +01:00 committed by Emmanuele Bassi
parent 6a8dce273a
commit 5e053279b5
2 changed files with 22 additions and 0 deletions

@ -349,6 +349,7 @@ g_function_invoker_destroy (GIFunctionInvoker *invoker)
typedef struct {
ffi_closure ffi_closure;
gpointer writable_self;
gpointer native_address;
} GIClosureWrapper;
/**
@ -386,6 +387,7 @@ g_callable_info_prepare_closure (GICallableInfo *callable_info,
return NULL;
}
closure->writable_self = closure;
closure->native_address = exec_ptr;
atypes = g_callable_info_get_ffi_arg_types (callable_info, &n_args);
status = ffi_prep_cif (cif, FFI_DEFAULT_ABI, n_args,
@ -409,6 +411,21 @@ g_callable_info_prepare_closure (GICallableInfo *callable_info,
return &closure->ffi_closure;
}
/**
* g_callable_info_get_closure_native_address:
* @callable_info: a callable info from a typelib
* @closure: ffi closure
*
* Gets callable code from ffi_closure prepared by g_callable_info_prepare_closure()
*/
gpointer *
g_callable_info_get_closure_native_address (GICallableInfo *callable_info,
ffi_closure *closure)
{
GIClosureWrapper *wrapper = (GIClosureWrapper *)closure;
return wrapper->native_address;
}
/**
* g_callable_info_free_closure:
* @callable_info: a callable info from a typelib

@ -95,6 +95,11 @@ ffi_closure * g_callable_info_prepare_closure (GICallableInfo *callabl
ffi_cif *cif,
GIFFIClosureCallback callback,
gpointer user_data);
GI_AVAILABLE_IN_1_70
gpointer * g_callable_info_get_closure_native_address (GICallableInfo *callable_info,
ffi_closure *closure);
GI_AVAILABLE_IN_ALL
void g_callable_info_free_closure (GICallableInfo *callable_info,
ffi_closure *closure);