Possible to maintain/acquire/reuse stable pointers to marshaled Python callables?



hello,

this is again RE: https://bugs.webkit.org/show_bug.cgi?id=77835#c15

i've been working daily for a week trying to implement a
pygobject-based add/remove_event_handler mechanism for WebKit; is
there *any* existing implementation that requires an IDENTICAL pointer
for both add_ and remove_?  i have 120+ GIR files on my system and i
can't find a single one using this pattern ... the only working
example i can find for this pattern is GLib's `*_by_func` (signals),
but pygobject handles these manually, and maintains it's own closure
cache of python objects (pygtype.c:1434 `gclosure_from_pyfunc`).

i'd really like to maintain the existing API (specified by DOM/W3C),
but if all else fails i will try to get a patch accepted that relies
on opaque keys/ids being returned.

i rebuilt all components with debug symbols and have spent the last
two days tracing the code path for type `GCallable` (which btw, was
surprisingly straightforward, thanks :-).  i believe i've acquired a
good understanding of the process leading up to ffi_call() ... but
AFAICS there is no way to reuse a previously wrapped Python callable
for another invocation or function.

during the marshaling phase, specifically:

-----------------------------------------------------
--> [...]
    --> pygi-marshal-from-py.c:1218 `_pygi_marshal_from_py_interface_callback`
        --> pygi-closure.c:429 `_pygi_make_native_closure`

closure = g_slice_new0 (PyGICClosure);
[...]
fficlosure = g_callable_info_prepare_closure (info, &closure->cif,
_pygi_closure_handle, closure);
closure->closure = fficlosure;
[...]
return closure

    --> (return) pygi-marshal-from-py.c:1218
`_pygi_marshal_from_py_interface_callback`

arg->v_pointer = closure->closure;

-----------------------------------------------------

... per my understanding, a new object is unconditionally allocated
for every call, and thus the C-visible address [v_pointer] is updated
to reflect this.

so how does one maintain a stable pointer?  is the only way to
allocate/own the structure in C and marshal it too Python?  are there
any plans to key/reuse the FFI closure based on the py_args,
user_data, and GICallable? note this still would fail for add/remove
because the cache would be separate ... is there even a generic
solution?

would this a good use case for an add/remove scope?  where marshaled
objects sent to add_ must be *identical* to remove_?  i believe all
implementations of DOM listeners behave this way (eg, notably JS).
maybe some other scope ...

is there a way to construct a stable object from Python, and pass to
C? i also tried using GClosures, but they are also newly allocated per
invocation, and i cant figure out how to properly create from Python.
do i need different annotations, an override, or ... ?

apologies for the length -- i'm very interested/impressed in PyGI and
have done a considerable amount of work to reach this point -- i'm
more than willing to do the legwork, but i am in need of some
guidance.

thanks for your time,

-- 

C Anthony


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]