Thread (63 messages) 63 messages, 5 authors, 2024-10-18

Re: [PATCH v2 03/10] reftable/basics: provide new `reftable_buf` interface

From: Eric Sunshine <hidden>
Date: 2024-10-15 05:11:11

On Tue, Oct 15, 2024 at 12:38 AM Patrick Steinhardt [off-list ref] wrote:
On Mon, Oct 14, 2024 at 06:34:55PM -0400, Taylor Blau wrote:
quoted
On Mon, Oct 14, 2024 at 03:02:24PM +0200, Patrick Steinhardt wrote:
quoted
+/*
+ * Add the given bytes to the buffer. Returns 0 on success,
+ * REFTABLE_OUT_OF_MEMORY_ERROR on allocation failure.
+ */
+int reftable_buf_add(struct reftable_buf *buf, const void *data, size_t len);
Is there a reason that data is a void-pointer here and not a const char
*?
Only that it emulates `strbuf_add()`, which also uses a void pointer.
The reason for that is because strbuf is a generic byte-array which
may contain embedded NULs, and the `const void *` plus `len`
emphasizes this property, whereas `const char *` would imply a
C-string with no embedded NULs.

(strbuf also happens to ensure that the contained byte-array ends with
NUL so that the .buf member can be used safely with any function
accepting a C-string, but that is a convenience for the common case
when it does not contain embedded NULs, not a promise that there won't
be embedded NULs, hence `const void *` rather than `cont char *`.)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help