<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 22, 2017 at 7:18 AM, Connor Abbott <span dir="ltr"><<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I like the version I wrote a little better. The main difference is<br>
that instead of the alignment parameter, I added a<br>
blob_reserve_intptr() function to match blob_read_intptr() and<br>
blob_write_intptr(). I also updated the doxygen comment for the<br>
function, and had a little more descriptive commit message:<br>
<a href="https://cgit.freedesktop.org/~cwabbott0/mesa/commit/?h=nir-serialize&id=f2e1e0df8d0d24afc072bcd47d86338436b3fdc2" rel="noreferrer" target="_blank">https://cgit.freedesktop.org/~<wbr>cwabbott0/mesa/commit/?h=nir-<wbr>serialize&id=<wbr>f2e1e0df8d0d24afc072bcd47d8633<wbr>8436b3fdc2</a><br>
</blockquote><div><br></div><div>I think I like that better too<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
On Fri, Sep 15, 2017 at 9:39 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> This commit primarily makes two changes. First, blob_reserve_bytes now<br>
> takes an alignment parameter. Second, we now return an offset into the<br>
> blob instead of a pointer and leave the pointer arithmetic to the<br>
> caller. This way you can call blob_reserve_bytes, emit a bunch more<br>
> stuff, and then come back and fill in the reserved data.<br>
> ---<br>
> src/compiler/blob.c | 14 ++++++++------<br>
> src/compiler/blob.h | 8 ++++----<br>
> src/compiler/glsl/tests/blob_<wbr>test.c | 7 ++++---<br>
> 3 files changed, 16 insertions(+), 13 deletions(-)<br>
><br>
> diff --git a/src/compiler/blob.c b/src/compiler/blob.c<br>
> index 3c4aed8..7324a6b 100644<br>
> --- a/src/compiler/blob.c<br>
> +++ b/src/compiler/blob.c<br>
> @@ -139,18 +139,20 @@ blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write)<br>
> return true;<br>
> }<br>
><br>
> -uint8_t *<br>
> -blob_reserve_bytes(struct blob *blob, size_t to_write)<br>
> +size_t<br>
> +blob_reserve_bytes(struct blob *blob, size_t to_write, size_t align)<br>
> {<br>
> - uint8_t *ret;<br>
> + size_t offset;<br>
> +<br>
> + align_blob(blob, align);<br>
><br>
> if (! grow_to_fit (blob, to_write))<br>
> - return NULL;<br>
> + return (size_t)-1;<br>
><br>
> - ret = blob->data + blob->size;<br>
> + offset = blob->size;<br>
> blob->size += to_write;<br>
><br>
> - return ret;<br>
> + return offset;<br>
> }<br>
><br>
> bool<br>
> diff --git a/src/compiler/blob.h b/src/compiler/blob.h<br>
> index 940c81e..e1f7fe7 100644<br>
> --- a/src/compiler/blob.h<br>
> +++ b/src/compiler/blob.h<br>
> @@ -113,11 +113,11 @@ blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write);<br>
> * that is not aware of the blob API, (so that blob_write_bytes cannot be<br>
> * called).<br>
> *<br>
> - * \return A pointer to space allocated within \blob to which \to_write bytes<br>
> - * can be written, (or NULL in case of any allocation error).<br>
> + * \return The offset into \blob at which \to_write bytes can be written, (or<br>
> + * NULL in case of any allocation error).<br>
> */<br>
> -uint8_t *<br>
> -blob_reserve_bytes(struct blob *blob, size_t to_write);<br>
> +size_t<br>
> +blob_reserve_bytes(struct blob *blob, size_t to_write, size_t align);<br>
><br>
> /**<br>
> * Overwrite some data previously written to the blob.<br>
> diff --git a/src/compiler/glsl/tests/<wbr>blob_test.c b/src/compiler/glsl/tests/<wbr>blob_test.c<br>
> index df0e91a..e82ceb1 100644<br>
> --- a/src/compiler/glsl/tests/<wbr>blob_test.c<br>
> +++ b/src/compiler/glsl/tests/<wbr>blob_test.c<br>
> @@ -120,7 +120,7 @@ test_write_and_read_functions (void)<br>
> {<br>
> struct blob *blob;<br>
> struct blob_reader reader;<br>
> - uint8_t *reserved;<br>
> + size_t reserved_offset;<br>
> size_t str_offset, uint_offset;<br>
> uint8_t reserve_buf[sizeof(reserve_<wbr>test_str)];<br>
><br>
> @@ -130,8 +130,9 @@ test_write_and_read_functions (void)<br>
><br>
> blob_write_bytes(blob, bytes_test_str, sizeof(bytes_test_str));<br>
><br>
> - reserved = blob_reserve_bytes(blob, sizeof(reserve_test_str));<br>
> - memcpy(reserved, reserve_test_str, sizeof(reserve_test_str));<br>
> + reserved_offset = blob_reserve_bytes(blob, sizeof(reserve_test_str), 1);<br>
> + memcpy(blob->data + reserved_offset,<br>
> + reserve_test_str, sizeof(reserve_test_str));<br>
><br>
> /* Write a placeholder, (to be replaced later via overwrite_bytes) */<br>
> str_offset = blob->size;<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div>