[zeromq-dev] question about czmq zctx_destroy
Pieter Hintjens
ph at imatix.com
Thu Apr 18 07:40:57 CEST 2013
On Thu, Apr 18, 2013 at 7:17 AM, Michel Pelletier
<pelletier.michel at gmail.com> wrote:
> This is nagging me in a minor way:
>
> CZMQ_EXPORT zctx_t *
> zctx_new (void);
>
> // Destroy context and all sockets in it, replaces zmq_term
> CZMQ_EXPORT void
> zctx_destroy (zctx_t **self_p);
>
>
> Why does new return a pointer to a context, but destroy wants a pointer to
> that pointer? I'm trying to call this functions via an FFI interface, but I
> can't pass the result of new to destroy and I don't have the equivalent of
> the & operator in the FFI environment.
Hmm... the "destroy nullifies reference" pattern is one we've been
using for sometime in C with success. I'd not realized it might create
problems for bindings.
> I've got a workaround, but is there a particular reason for this?
The reason for the style is to clean up after destruction so that
further code can catch null references and either ignore them or
assert, but not try to access freed memory. That does work pretty
well. All the CZMQ modules work like this.
What are the limitations you have in FFI?
-Pieter
More information about the zeromq-dev
mailing list