[zeromq-dev] zproject api design and binding question

Arnaud Loonstra arnaud at sphaero.org
Tue May 7 16:51:27 CEST 2019

This indeed seems to a problem with at least Python's ctypes binding. 
Perhaps we could mention this somewhere?

I'm now trying the cffi binding. However you'd need to be some wizard to 
get this working without prior knowledge.

I got the binding to build and install. Now trying a simple test to get 

from czmq_cffi import *


output = Zsock(0) # 0 == PAIR

input = Zsock(0) # 0 == PAIR
assert (input);

msg = Zmsg()
assert (msg);
frame = Zframe(b"Hello", 5)
assert (frame);
assert (msg.size() == 1)
assert (msg.content_size () == 5);
rc = msg.send(output)
assert (rc == 0)

msg = input.recv(input);
assert (msg)
assert (msg.size() == 1)
assert (msg.content_size() == 5)

However it fails:
Traceback (most recent call last):
   File "test.py", line 20, in <module>
line 80, in prepend
     return utils.lib.zmsg_prepend(self._p, frame_p._p)
TypeError: initializer for ctype 'struct _zframe_t * *' must be a 
pointer to same type, not cdata 'struct _zframe_t *'
So how to do that? How to get the pointer from Zrame object?

@Kevin, you here? You wrote the cffi binding generator, not?
I think it would be helpful for others if we create a unittest.



On 5/2/19 4:20 PM, Arnaud Loonstra wrote:
> Hey all,
> I'm using zproject to design and build a library to extend zactor a bit. 
> However I'm now running into a design issue when using callbacks.
> For example I have in my api:
> https://github.com/sphaero/libsphactor/blob/master/api/sphactor.api
>      <callback_type name = "handler_fn">
>          Callback function for socket activity
>          <argument name = "msg" type = "zmsg" />
>          <argument name = "arg" type = "anything" />
>          <return type = "zmsg" />
>      </callback_type>
> So a callback which accepts a zmsg and returns a zmsg.
> Works perfectly in C. However when I bind to Python it doesn't work. It 
> seems Python(ctypes) only handles returning simple types from callbacks:
> https://bugs.python.org/issue5710
> I can see this doesn't apply to any api's I've found so for in czmq or 
> zyre.
> My question is whether it is bad api design from my side? Or are there 
> any workarounds or better approaches for this?
> Rg,
> Arnaud
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev

More information about the zeromq-dev mailing list