Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
giuliomoro opened this issue Aug 10, 2022 · 0 comments
Open

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

giuliomoro opened this issue Aug 10, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers question Further information is requested

Comments

@giuliomoro
Copy link
Contributor

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;
}
@dromer dromer added documentation Improvements or additions to documentation question Further information is requested labels Sep 1, 2022
@dromer dromer added the good first issue Good for newcomers label Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants