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 started:

```
from czmq_cffi import *

Zactor.test(True)

output = Zsock(0) # 0 == PAIR
output.connect(b"@inproc://zmsg.test")
assert(output)

input = Zsock(0) # 0 == PAIR
input.bind(b">inproc://zmsg.test")
assert (input);

msg = Zmsg()
assert (msg);
frame = Zframe(b"Hello", 5)
assert (frame);
msg.prepend(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>
    msg.prepend(frame);
File "/home/arnaud/src/libsphactor/bindings/py3test/lib/python3.7/site-packages/czmq_cffi-4.2.1-py3.7-linux-x86_64.egg/czmq_cffi/Zmsg.py", 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.

Rg,

Arnaud




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@lists.zeromq.org
https://lists.zeromq.org/mailman/listinfo/zeromq-dev
_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
https://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to