Mesa (master): compiler/blob: Allow for fixed-size blobs with a NULL data pointer
Jason Ekstrand
jekstrand at kemper.freedesktop.org
Fri Oct 13 04:47:33 UTC 2017
Module: Mesa
Branch: master
Commit: 8ae03af4ed1ca47a106e5fd7b2d11ce4003aad54
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8ae03af4ed1ca47a106e5fd7b2d11ce4003aad54
Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date: Thu Oct 12 21:02:48 2017 -0700
compiler/blob: Allow for fixed-size blobs with a NULL data pointer
These can be used to easily count up the number of bytes that will be
required by "writing" it into the NULL blob.
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>
---
src/compiler/blob.c | 9 ++++++---
src/compiler/blob.h | 4 ++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/compiler/blob.c b/src/compiler/blob.c
index a78fcd41a7..f3ff5d6862 100644
--- a/src/compiler/blob.c
+++ b/src/compiler/blob.c
@@ -91,7 +91,8 @@ align_blob(struct blob *blob, size_t alignment)
if (!grow_to_fit(blob, new_size - blob->size))
return false;
- memset(blob->data + blob->size, 0, new_size - blob->size);
+ if (blob->data)
+ memset(blob->data + blob->size, 0, new_size - blob->size);
blob->size = new_size;
}
@@ -136,7 +137,8 @@ blob_overwrite_bytes(struct blob *blob,
VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
- memcpy(blob->data + offset, bytes, to_write);
+ if (blob->data)
+ memcpy(blob->data + offset, bytes, to_write);
return true;
}
@@ -149,7 +151,8 @@ blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write)
VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
- memcpy(blob->data + blob->size, bytes, to_write);
+ if (blob->data)
+ memcpy(blob->data + blob->size, bytes, to_write);
blob->size += to_write;
return true;
diff --git a/src/compiler/blob.h b/src/compiler/blob.h
index e23e392eed..ec80b78284 100644
--- a/src/compiler/blob.h
+++ b/src/compiler/blob.h
@@ -96,6 +96,10 @@ blob_init(struct blob *blob);
* A fixed-size blob has a fixed block of data that will not be freed on
* blob_finish and will never be grown. If we hit the end, we simply start
* returning false from the write functions.
+ *
+ * If a fixed-size blob has a NULL data pointer then the data is written but
+ * it otherwise operates normally. This can be used to determine the size
+ * that will be required to write a given data structure.
*/
void
blob_init_fixed(struct blob *blob, void *data, size_t size);
More information about the mesa-commit
mailing list