Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python_cffi we can't use automatic destructors? #1172

Open
sphaero opened this issue May 15, 2019 · 6 comments
Open

Python_cffi we can't use automatic destructors? #1172

sphaero opened this issue May 15, 2019 · 6 comments

Comments

@sphaero
Copy link
Contributor

sphaero commented May 15, 2019

Take Zmsg for example. If we construct a message and want to send it. The sender becomes the owner and will destroy the message. However if we use garbage collection it will also try to destroy the message resulting in an assert.

I think the only solution is, is to stop using GC and do manual destruction.

Parking this here so I can work on this later.

@sphaero
Copy link
Contributor Author

sphaero commented May 15, 2019

Either we remove garbage collection and only do manual cleanups or we add a method to remove cffi's gc() if we are passed to a method with "by_reference=1"

@sappo any thoughts on this?

@sappo
Copy link
Member

sappo commented May 15, 2019

Uff...this is tricky.

So here's one thought. I do build separate wrapper c-library which wraps the destroy calls so the signature is compatible to what ffi.gc expects as destructor. We could add some logic to these wrapper functions so that the actual destroy function is only called if we have something to destroy.

You can find the wrapper library in the build.py file.

@sappo
Copy link
Member

sappo commented May 15, 2019

But removing the gc function entirely would be the cleaner approach:
https://cffi.readthedocs.io/en/latest/ref.html#ffi-gc
ffi.gc(ptr, None, size=0)

@sappo
Copy link
Member

sappo commented May 15, 2019

IMO, the zmsg_send is defined wrongfully in the API file. It should be defined as destructor which will allow us to remove the cffi's gc function.

This might break some bindings though or at least remove the send function from those. Still I believe that's the correct solution here!

@sphaero
Copy link
Contributor Author

sphaero commented May 15, 2019

Ow, indeed that would be nicest. But it would also mean this issue needs to move czmq

@sappo
Copy link
Member

sappo commented May 16, 2019

Yes, this issue is also valid e.g. for the JNI binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants