[zeromq-dev] [PATCH] zmq::msg_t::const_data for const correctness?

Martin Sustrik sustrik at 250bpm.com
Fri May 27 13:14:58 CEST 2011


On 05/27/2011 10:26 AM, Ilja Golshtein wrote:
> The idea of the patch was to have something easily applicable.
>
> It does not break current interface, it is harmless, though not very useful.
> I hope it can slightly reduce chances of copy() misuse.

Well, I would say, let's fix the thing systematically. Now that 3.0 API 
is being devised we can even do it in core.

Here's how it can possibly look like:

void *zmq_msg_data (zmq_msg_t *msg);
void *zmq_msg_const_data (const zmq_msg_t *msg);
size_t zmq_msg_size (const zmq_msg_t *msg);

int zmq_msg_copy (const zmq_msg_t *src, const zmq_msg_t **dest1, const 
zmq_msg_t **dest2);

int zmq_msg_move (zmq_msg_t *src, zmq_msg_t *dest);
int zmq_msg_const_move (const zmq_msg_t *src, const zmq_msg_t *dest);

It's still not perfect though. The ugly thing is that src parameter in 
zmq_msg_copy and zmq_msg_const_move is marked as const (to mark that 
message content should be treated as const) while it's actually 
nullified inside of the function.

It's still the same problem: zmq_msg_t is a pointer pointing to data. 
There's no way to package information both about const-ness of the data 
and const-ness of the pointer into a single 'const' property.

Martin



More information about the zeromq-dev mailing list