[cffi-devel] Support for cleanup actions on arguments performed when callback returns
I am trying to create a binding for gobject library with CFFI. CFFI works extremely well, however I have a use case that is not covered by CFFI. Basically, I want to define foreign types that should "clean up" after themselves when they are used as types for callback arguments. I have following use cases for this: 1) I want to have a structure created when callback is entered and have its contents copied to foreign structure when callback returns. 2) I want to have wrappers that contain a pointer to foreign structure. However, I want to ensure that operations on wrapper signal errors when callback returns (because pointer points to a stack-allocated structure). This is needed to ensure that no operations are done on invalid pointer. The attached patch provides suggested change: foreign types may specify that additional actions should be performed when the callback returns. This is achieved by adding new generic function CLEANUP-TRANSLATED-OBJECT-FOR- CALLBACK. Additional generic function HAS-CALLBACK-CLEANUP is called at macroexpansion time as an optimization to remove unnecessary calls to CLEANUP- TRANSLATED-OBJECT-FOR-CALLBACK. Attached is a test case that demonstrates the usage and checks for correctness of behavior. If there are obstacles for adding this patch, I would be happy to work on them.
participants (1)
-
Kalyanov Dmitry