aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/blob.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-10-11 09:52:07 -0700
committerJason Ekstrand <[email protected]>2017-10-12 21:47:06 -0700
commit26f6d4e5c7f38ab1f55d4cdef7013cc3c730f298 (patch)
treee311e7ef3c3fc4fd25fa84524e88af5a6b654663 /src/compiler/blob.c
parent49bb9f785af8349f3245bc223cb7e0e40b9fa243 (diff)
compiler/blob: Add a concept of a fixed-allocation blob
Reviewed-by: Nicolai Hähnle <[email protected]> Reviewed-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/compiler/blob.c')
-rw-r--r--src/compiler/blob.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/compiler/blob.c b/src/compiler/blob.c
index 2e20a11dc0c..a78fcd41a76 100644
--- a/src/compiler/blob.c
+++ b/src/compiler/blob.c
@@ -52,6 +52,11 @@ grow_to_fit(struct blob *blob, size_t additional)
if (blob->size + additional <= blob->allocated)
return true;
+ if (blob->fixed_allocation) {
+ blob->out_of_memory = true;
+ return false;
+ }
+
if (blob->allocated == 0)
to_allocate = BLOB_INITIAL_SIZE;
else
@@ -105,6 +110,17 @@ blob_init(struct blob *blob)
blob->data = NULL;
blob->allocated = 0;
blob->size = 0;
+ blob->fixed_allocation = false;
+ blob->out_of_memory = false;
+}
+
+void
+blob_init_fixed(struct blob *blob, void *data, size_t size)
+{
+ blob->data = data;
+ blob->allocated = size;
+ blob->size = 0;
+ blob->fixed_allocation = true;
blob->out_of_memory = false;
}