hvcc icon indicating copy to clipboard operation
hvcc copied to clipboard

msg_copy: "Copy a message onto the stack" wrong?

Open giuliomoro opened this issue 2 years ago • 0 comments

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;
}

giuliomoro avatar Aug 10 '22 11:08 giuliomoro