hvcc
hvcc copied to clipboard
msg_copy: "Copy a message onto the stack" wrong?
The source and documentation say:
/** Copy a message onto the stack. The message persists. */
HvMessage *hv_msg_copy(const HvMessage *const m);
However, that's not "copied onto the stack". I'd suggest a new description:
Copy a message, allocating memory for it
The returned pointer MUST be deallocated by the caller via hv_msg_free().
The implementation (after one indirection), for reference:
// the message is serialised such that all symbol elements are placed in order at the end of the buffer
HvMessage *msg_copy(const HvMessage *m) {
const hv_uint32_t heapSize = msg_getSize(m);
char *r = (char *) hv_malloc(heapSize);
hv_assert(r != NULL);
msg_copyToBuffer(m, r, heapSize);
return (HvMessage *) r;
}