Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/Vulkan-Loader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2022-05-21 04:40:53 +0300
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2022-05-24 23:18:26 +0300
commit9b355f194844ad4414816f283664f8b28819451a (patch)
treebc7e0666579f289fe3f384838fe334a956134e0c
parent0a2395df92309cb0a4bf20ca3a7185ab658b0f31 (diff)
Use VkAllocationCallback in cJSON
Make cJSON pass the VkAllocationCallbacks instead of the loader_instance. This removes and unecessary dependency between cJSON and the loader headers. It also somewhat simplifies the interface by not requiring the inst parameter everywhere, just in the creation of cJSON pointers and freeing.
-rw-r--r--loader/cJSON.c369
-rw-r--r--loader/cJSON.h66
-rw-r--r--loader/loader.c106
3 files changed, 265 insertions, 276 deletions
diff --git a/loader/cJSON.c b/loader/cJSON.c
index a75959efe..40adcb464 100644
--- a/loader/cJSON.c
+++ b/loader/cJSON.c
@@ -38,49 +38,50 @@
#include "allocation.h"
-void *cJSON_malloc(const struct loader_instance *instance, size_t size) {
- return loader_instance_heap_alloc(instance, size, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
+void *cJSON_malloc(const VkAllocationCallbacks *pAllocator, size_t size) {
+ return loader_alloc(pAllocator, size, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
}
-void cJSON_free(const struct loader_instance *instance, void *pMemory) { loader_instance_heap_free(instance, pMemory); }
+void cJSON_Free(const VkAllocationCallbacks *pAllocator, void *pMemory) { loader_free(pAllocator, pMemory); }
static const char *ep;
const char *cJSON_GetErrorPtr(void) { return ep; }
-char *cJSON_strdup(const struct loader_instance *instance, const char *str) {
+char *cJSON_strdup(const VkAllocationCallbacks *pAllocator, const char *str) {
size_t len;
char *copy;
len = strlen(str) + 1;
- copy = (char *)cJSON_malloc(instance, len);
+ copy = (char *)cJSON_malloc(pAllocator, len);
if (!copy) return 0;
memcpy(copy, str, len);
return copy;
}
/* Internal constructor. */
-cJSON *cJSON_New_Item(const struct loader_instance *instance) {
- cJSON *node = (cJSON *)cJSON_malloc(instance, sizeof(cJSON));
- if (node) memset(node, 0, sizeof(cJSON));
+cJSON *cJSON_New_Item(const VkAllocationCallbacks *pAllocator) {
+ cJSON *node = (cJSON *)cJSON_malloc(pAllocator, sizeof(cJSON));
+ if (node) {
+ memset(node, 0, sizeof(cJSON));
+ node->pAllocator = (VkAllocationCallbacks *)pAllocator;
+ }
return node;
}
/* Delete a cJSON structure. */
-void cJSON_Delete(const struct loader_instance *instance, cJSON *c) {
+void cJSON_Delete(cJSON *c) {
cJSON *next;
while (c) {
next = c->next;
- if (!(c->type & cJSON_IsReference) && c->child) cJSON_Delete(instance, c->child);
- if (!(c->type & cJSON_IsReference) && c->valuestring) cJSON_free(instance, c->valuestring);
- if (!(c->type & cJSON_StringIsConst) && c->string) cJSON_free(instance, c->string);
- cJSON_free(instance, c);
+ if (!(c->type & cJSON_IsReference) && c->child) cJSON_Delete(c->child);
+ if (!(c->type & cJSON_IsReference) && c->valuestring) cJSON_Free(c->pAllocator, c->valuestring);
+ if (!(c->type & cJSON_StringIsConst) && c->string) cJSON_Free(c->pAllocator, c->string);
+ cJSON_Free(c->pAllocator, c);
c = next;
}
}
-void cJSON_Free(const struct loader_instance *instance, void *p) { cJSON_free(instance, p); }
-
/* Parse the input text to generate a number, and populate the result into item.
*/
const char *parse_number(cJSON *item, const char *num) {
@@ -133,7 +134,7 @@ typedef struct {
size_t offset;
} printbuffer;
-char *ensure(const struct loader_instance *instance, printbuffer *p, size_t needed) {
+char *ensure(const VkAllocationCallbacks *pAllocator, printbuffer *p, size_t needed) {
char *newbuffer;
size_t newsize;
if (!p || !p->buffer) return 0;
@@ -141,14 +142,14 @@ char *ensure(const struct loader_instance *instance, printbuffer *p, size_t need
if (needed <= p->length) return p->buffer + p->offset;
newsize = pow2gt(needed);
- newbuffer = (char *)cJSON_malloc(instance, newsize);
+ newbuffer = (char *)cJSON_malloc(pAllocator, newsize);
if (!newbuffer) {
- cJSON_free(instance, p->buffer);
+ cJSON_Free(pAllocator, p->buffer);
p->length = 0, p->buffer = 0;
return 0;
}
if (newbuffer) memcpy(newbuffer, p->buffer, p->length);
- cJSON_free(instance, p->buffer);
+ cJSON_Free(pAllocator, p->buffer);
p->length = newsize;
p->buffer = newbuffer;
return newbuffer + p->offset;
@@ -162,26 +163,26 @@ size_t cJSON_update(printbuffer *p) {
}
/* Render the number nicely from the given item into a string. */
-char *print_number(const struct loader_instance *instance, cJSON *item, printbuffer *p) {
+char *print_number(cJSON *item, printbuffer *p) {
char *str = 0;
double d = item->valuedouble;
if (d == 0) {
if (p)
- str = ensure(instance, p, 2);
+ str = ensure(item->pAllocator, p, 2);
else
- str = (char *)cJSON_malloc(instance, 2); /* special case for 0. */
+ str = (char *)cJSON_malloc(item->pAllocator, 2); /* special case for 0. */
if (str) strcpy(str, "0");
} else if (fabs(((double)item->valueint) - d) <= DBL_EPSILON && d <= INT_MAX && d >= INT_MIN) {
if (p)
- str = ensure(instance, p, 21);
+ str = ensure(item->pAllocator, p, 21);
else
- str = (char *)cJSON_malloc(instance, 21); /* 2^64+1 can be represented in 21 chars. */
+ str = (char *)cJSON_malloc(item->pAllocator, 21); /* 2^64+1 can be represented in 21 chars. */
if (str) sprintf(str, "%d", item->valueint);
} else {
if (p)
- str = ensure(instance, p, 64);
+ str = ensure(item->pAllocator, p, 64);
else
- str = (char *)cJSON_malloc(instance, 64); /* This is a nice tradeoff. */
+ str = (char *)cJSON_malloc(item->pAllocator, 64); /* This is a nice tradeoff. */
if (str) {
if (fabs(floor(d) - d) <= DBL_EPSILON && fabs(d) < 1.0e60)
sprintf(str, "%.0f", d);
@@ -239,7 +240,7 @@ unsigned parse_hex4(const char *str) {
/* Parse the input text into an unescaped cstring, and populate item. */
static const unsigned char firstByteMark[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
-const char *parse_string(const struct loader_instance *instance, cJSON *item, const char *str) {
+const char *parse_string(cJSON *item, const char *str) {
const char *ptr = str + 1;
char *ptr2;
char *out;
@@ -253,7 +254,7 @@ const char *parse_string(const struct loader_instance *instance, cJSON *item, co
while (*ptr != '\"' && *ptr && ++len)
if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
- out = (char *)cJSON_malloc(instance, len + 1); /* This is how long we need for the string, roughly. */
+ out = (char *)cJSON_malloc(item->pAllocator, len + 1); /* This is how long we need for the string, roughly. */
if (!out) return 0;
ptr = str + 1;
@@ -336,7 +337,7 @@ const char *parse_string(const struct loader_instance *instance, cJSON *item, co
}
/* Render the cstring provided to an escaped version that can be printed. */
-char *print_string_ptr(const struct loader_instance *instance, const char *str, printbuffer *p) {
+char *print_string_ptr(const VkAllocationCallbacks *pAllocator, const char *str, printbuffer *p) {
const char *ptr;
char *ptr2;
char *out;
@@ -347,9 +348,9 @@ char *print_string_ptr(const struct loader_instance *instance, const char *str,
if (!flag) {
len = ptr - str;
if (p)
- out = ensure(instance, p, len + 3);
+ out = ensure(pAllocator, p, len + 3);
else
- out = (char *)cJSON_malloc(instance, len + 3);
+ out = (char *)cJSON_malloc(pAllocator, len + 3);
if (!out) return 0;
ptr2 = out;
*ptr2++ = '\"';
@@ -361,9 +362,9 @@ char *print_string_ptr(const struct loader_instance *instance, const char *str,
if (!str) {
if (p)
- out = ensure(instance, p, 3);
+ out = ensure(pAllocator, p, 3);
else
- out = (char *)cJSON_malloc(instance, 3);
+ out = (char *)cJSON_malloc(pAllocator, 3);
if (!out) return 0;
strcpy(out, "\"\"");
return out;
@@ -380,9 +381,9 @@ char *print_string_ptr(const struct loader_instance *instance, const char *str,
}
if (p)
- out = ensure(instance, p, len + 3);
+ out = ensure(pAllocator, p, len + 3);
else
- out = (char *)cJSON_malloc(instance, len + 3);
+ out = (char *)cJSON_malloc(pAllocator, len + 3);
if (!out) return 0;
ptr2 = out;
@@ -426,17 +427,15 @@ char *print_string_ptr(const struct loader_instance *instance, const char *str,
return out;
}
/* Invoke print_string_ptr (which is useful) on an item. */
-char *print_string(const struct loader_instance *instance, cJSON *item, printbuffer *p) {
- return print_string_ptr(instance, item->valuestring, p);
-}
+char *print_string(cJSON *item, printbuffer *p) { return print_string_ptr(item->pAllocator, item->valuestring, p); }
/* Predeclare these prototypes. */
-const char *parse_value(const struct loader_instance *instance, cJSON *item, const char *value);
-char *print_value(const struct loader_instance *instance, cJSON *item, int depth, int fmt, printbuffer *p);
-const char *parse_array(const struct loader_instance *instance, cJSON *item, const char *value);
-char *print_array(const struct loader_instance *instance, cJSON *item, int depth, int fmt, printbuffer *p);
-const char *parse_object(const struct loader_instance *instance, cJSON *item, const char *value);
-char *print_object(const struct loader_instance *instance, cJSON *item, int depth, int fmt, printbuffer *p);
+const char *parse_value(cJSON *item, const char *value);
+char *print_value(cJSON *item, int depth, int fmt, printbuffer *p);
+const char *parse_array(cJSON *item, const char *value);
+char *print_array(cJSON *item, int depth, int fmt, printbuffer *p);
+const char *parse_object(cJSON *item, const char *value);
+char *print_object(cJSON *item, int depth, int fmt, printbuffer *p);
/* Utility to jump whitespace and cr/lf */
const char *skip(const char *in) {
@@ -445,16 +444,16 @@ const char *skip(const char *in) {
}
/* Parse an object - create a new root, and populate. */
-cJSON *cJSON_ParseWithOpts(const struct loader_instance *instance, const char *value, const char **return_parse_end,
+cJSON *cJSON_ParseWithOpts(const VkAllocationCallbacks *pAllocator, const char *value, const char **return_parse_end,
int require_null_terminated) {
const char *end = 0;
- cJSON *c = cJSON_New_Item(instance);
+ cJSON *c = cJSON_New_Item(pAllocator);
ep = 0;
if (!c) return 0; /* memory fail */
- end = parse_value(instance, c, skip(value));
+ end = parse_value(c, skip(value));
if (!end) {
- cJSON_Delete(instance, c);
+ cJSON_Delete(c);
return 0;
} /* parse failure. ep is set. */
@@ -463,7 +462,7 @@ cJSON *cJSON_ParseWithOpts(const struct loader_instance *instance, const char *v
if (require_null_terminated) {
end = skip(end);
if (*end) {
- cJSON_Delete(instance, c);
+ cJSON_Delete(c);
ep = end;
return 0;
}
@@ -472,22 +471,24 @@ cJSON *cJSON_ParseWithOpts(const struct loader_instance *instance, const char *v
return c;
}
/* Default options for cJSON_Parse */
-cJSON *cJSON_Parse(const struct loader_instance *instance, const char *value) { return cJSON_ParseWithOpts(instance, value, 0, 0); }
+cJSON *cJSON_Parse(const VkAllocationCallbacks *pAllocator, const char *value) {
+ return cJSON_ParseWithOpts(pAllocator, value, 0, 0);
+}
/* Render a cJSON item/entity/structure to text. */
-char *cJSON_Print(const struct loader_instance *instance, cJSON *item) { return print_value(instance, item, 0, 1, 0); }
-char *cJSON_PrintUnformatted(const struct loader_instance *instance, cJSON *item) { return print_value(instance, item, 0, 0, 0); }
+char *cJSON_Print(cJSON *item) { return print_value(item, 0, 1, 0); }
+char *cJSON_PrintUnformatted(cJSON *item) { return print_value(item, 0, 0, 0); }
-char *cJSON_PrintBuffered(const struct loader_instance *instance, cJSON *item, int prebuffer, int fmt) {
+char *cJSON_PrintBuffered(cJSON *item, int prebuffer, int fmt) {
printbuffer p;
- p.buffer = (char *)cJSON_malloc(instance, prebuffer);
+ p.buffer = (char *)cJSON_malloc(item->pAllocator, prebuffer);
p.length = prebuffer;
p.offset = 0;
- return print_value(instance, item, 0, fmt, &p);
+ return print_value(item, 0, fmt, &p);
}
/* Parser core - when encountering text, process appropriately. */
-const char *parse_value(const struct loader_instance *instance, cJSON *item, const char *value) {
+const char *parse_value(cJSON *item, const char *value) {
if (!value) return 0; /* Fail on null. */
if (!strncmp(value, "null", 4)) {
item->type = cJSON_NULL;
@@ -503,16 +504,16 @@ const char *parse_value(const struct loader_instance *instance, cJSON *item, con
return value + 4;
}
if (*value == '\"') {
- return parse_string(instance, item, value);
+ return parse_string(item, value);
}
if (*value == '-' || (*value >= '0' && *value <= '9')) {
return parse_number(item, value);
}
if (*value == '[') {
- return parse_array(instance, item, value);
+ return parse_array(item, value);
}
if (*value == '{') {
- return parse_object(instance, item, value);
+ return parse_object(item, value);
}
ep = value;
@@ -520,61 +521,61 @@ const char *parse_value(const struct loader_instance *instance, cJSON *item, con
}
/* Render a value to text. */
-char *print_value(const struct loader_instance *instance, cJSON *item, int depth, int fmt, printbuffer *p) {
+char *print_value(cJSON *item, int depth, int fmt, printbuffer *p) {
char *out = 0;
if (!item) return 0;
if (p) {
switch ((item->type) & 255) {
case cJSON_NULL: {
- out = ensure(instance, p, 5);
+ out = ensure(item->pAllocator, p, 5);
if (out) strcpy(out, "null");
break;
}
case cJSON_False: {
- out = ensure(instance, p, 6);
+ out = ensure(item->pAllocator, p, 6);
if (out) strcpy(out, "false");
break;
}
case cJSON_True: {
- out = ensure(instance, p, 5);
+ out = ensure(item->pAllocator, p, 5);
if (out) strcpy(out, "true");
break;
}
case cJSON_Number:
- out = print_number(instance, item, p);
+ out = print_number(item, p);
break;
case cJSON_String:
- out = print_string(instance, item, p);
+ out = print_string(item, p);
break;
case cJSON_Array:
- out = print_array(instance, item, depth, fmt, p);
+ out = print_array(item, depth, fmt, p);
break;
case cJSON_Object:
- out = print_object(instance, item, depth, fmt, p);
+ out = print_object(item, depth, fmt, p);
break;
}
} else {
switch ((item->type) & 255) {
case cJSON_NULL:
- out = cJSON_strdup(instance, "null");
+ out = cJSON_strdup(item->pAllocator, "null");
break;
case cJSON_False:
- out = cJSON_strdup(instance, "false");
+ out = cJSON_strdup(item->pAllocator, "false");
break;
case cJSON_True:
- out = cJSON_strdup(instance, "true");
+ out = cJSON_strdup(item->pAllocator, "true");
break;
case cJSON_Number:
- out = print_number(instance, item, 0);
+ out = print_number(item, 0);
break;
case cJSON_String:
- out = print_string(instance, item, 0);
+ out = print_string(item, 0);
break;
case cJSON_Array:
- out = print_array(instance, item, depth, fmt, 0);
+ out = print_array(item, depth, fmt, 0);
break;
case cJSON_Object:
- out = print_object(instance, item, depth, fmt, 0);
+ out = print_object(item, depth, fmt, 0);
break;
}
}
@@ -582,7 +583,7 @@ char *print_value(const struct loader_instance *instance, cJSON *item, int depth
}
/* Build an array from input text. */
-const char *parse_array(const struct loader_instance *instance, cJSON *item, const char *value) {
+const char *parse_array(cJSON *item, const char *value) {
cJSON *child;
if (*value != '[') {
ep = value;
@@ -593,19 +594,19 @@ const char *parse_array(const struct loader_instance *instance, cJSON *item, con
value = skip(value + 1);
if (*value == ']') return value + 1; /* empty array. */
- item->child = child = cJSON_New_Item(instance);
- if (!item->child) return 0; /* memory fail */
- value = skip(parse_value(instance, child, skip(value))); /* skip any spacing, get the value. */
+ item->child = child = cJSON_New_Item(item->pAllocator);
+ if (!item->child) return 0; /* memory fail */
+ value = skip(parse_value(child, skip(value))); /* skip any spacing, get the value. */
if (!value) return 0;
while (*value == ',') {
cJSON *new_item;
- new_item = cJSON_New_Item(instance);
+ new_item = cJSON_New_Item(item->pAllocator);
if (!new_item) return 0; /* memory fail */
child->next = new_item;
new_item->prev = child;
child = new_item;
- value = skip(parse_value(instance, child, skip(value + 1)));
+ value = skip(parse_value(child, skip(value + 1)));
if (!value) return 0; /* memory fail */
}
@@ -615,7 +616,7 @@ const char *parse_array(const struct loader_instance *instance, cJSON *item, con
}
/* Render an array to text */
-char *print_array(const struct loader_instance *instance, cJSON *item, int depth, int fmt, printbuffer *p) {
+char *print_array(cJSON *item, int depth, int fmt, printbuffer *p) {
char **entries;
char *out = 0, *ptr, *ret;
size_t len = 5;
@@ -628,9 +629,9 @@ char *print_array(const struct loader_instance *instance, cJSON *item, int depth
/* Explicitly handle numentries==0 */
if (!numentries) {
if (p)
- out = ensure(instance, p, 3);
+ out = ensure(item->pAllocator, p, 3);
else
- out = (char *)cJSON_malloc(instance, 3);
+ out = (char *)cJSON_malloc(item->pAllocator, 3);
if (out) strcpy(out, "[]");
return out;
}
@@ -638,17 +639,17 @@ char *print_array(const struct loader_instance *instance, cJSON *item, int depth
if (p) {
/* Compose the output array. */
i = p->offset;
- ptr = ensure(instance, p, 1);
+ ptr = ensure(item->pAllocator, p, 1);
if (!ptr) return 0;
*ptr = '[';
p->offset++;
child = item->child;
while (child && !fail) {
- print_value(instance, child, depth + 1, fmt, p);
+ print_value(child, depth + 1, fmt, p);
p->offset = cJSON_update(p);
if (child->next) {
len = fmt ? 2 : 1;
- ptr = ensure(instance, p, len + 1);
+ ptr = ensure(item->pAllocator, p, len + 1);
if (!ptr) return 0;
*ptr++ = ',';
if (fmt) *ptr++ = ' ';
@@ -657,20 +658,20 @@ char *print_array(const struct loader_instance *instance, cJSON *item, int depth
}
child = child->next;
}
- ptr = ensure(instance, p, 2);
+ ptr = ensure(item->pAllocator, p, 2);
if (!ptr) return 0;
*ptr++ = ']';
*ptr = 0;
out = (p->buffer) + i;
} else {
/* Allocate an array to hold the values for each */
- entries = (char **)cJSON_malloc(instance, numentries * sizeof(char *));
+ entries = (char **)cJSON_malloc(item->pAllocator, numentries * sizeof(char *));
if (!entries) return 0;
memset(entries, 0, numentries * sizeof(char *));
/* Retrieve all the results: */
child = item->child;
while (child && !fail) {
- ret = print_value(instance, child, depth + 1, fmt, 0);
+ ret = print_value(child, depth + 1, fmt, 0);
entries[i++] = ret;
if (ret)
len += strlen(ret) + 2 + (fmt ? 1 : 0);
@@ -680,15 +681,15 @@ char *print_array(const struct loader_instance *instance, cJSON *item, int depth
}
/* If we didn't fail, try to malloc the output string */
- if (!fail) out = (char *)cJSON_malloc(instance, len);
+ if (!fail) out = (char *)cJSON_malloc(item->pAllocator, len);
/* If that fails, we fail. */
if (!out) fail = 1;
/* Handle failure. */
if (fail) {
for (j = 0; j < numentries; j++)
- if (entries[j]) cJSON_free(instance, entries[j]);
- cJSON_free(instance, entries);
+ if (entries[j]) cJSON_Free(item->pAllocator, entries[j]);
+ cJSON_Free(item->pAllocator, entries);
return 0;
}
@@ -705,9 +706,9 @@ char *print_array(const struct loader_instance *instance, cJSON *item, int depth
if (fmt) *ptr++ = ' ';
*ptr = 0;
}
- cJSON_free(instance, entries[j]);
+ cJSON_Free(item->pAllocator, entries[j]);
}
- cJSON_free(instance, entries);
+ cJSON_Free(item->pAllocator, entries);
*ptr++ = ']';
*ptr++ = 0;
}
@@ -715,7 +716,7 @@ char *print_array(const struct loader_instance *instance, cJSON *item, int depth
}
/* Build an object from the text. */
-const char *parse_object(const struct loader_instance *instance, cJSON *item, const char *value) {
+const char *parse_object(cJSON *item, const char *value) {
cJSON *child;
if (*value != '{') {
ep = value;
@@ -726,35 +727,35 @@ const char *parse_object(const struct loader_instance *instance, cJSON *item, co
value = skip(value + 1);
if (*value == '}') return value + 1; /* empty array. */
- item->child = child = cJSON_New_Item(instance);
+ item->child = child = cJSON_New_Item(item->pAllocator);
if (!item->child) return 0;
- value = skip(parse_string(instance, child, skip(value)));
+ value = skip(parse_string(child, skip(value)));
if (!value) return 0;
child->string = child->valuestring;
child->valuestring = 0;
if (*value != ':') {
ep = value;
return 0;
- } /* fail! */
- value = skip(parse_value(instance, child, skip(value + 1))); /* skip any spacing, get the value. */
+ } /* fail! */
+ value = skip(parse_value(child, skip(value + 1))); /* skip any spacing, get the value. */
if (!value) return 0;
while (*value == ',') {
cJSON *new_item;
- new_item = cJSON_New_Item(instance);
+ new_item = cJSON_New_Item(item->pAllocator);
if (!new_item) return 0; /* memory fail */
child->next = new_item;
new_item->prev = child;
child = new_item;
- value = skip(parse_string(instance, child, skip(value + 1)));
+ value = skip(parse_string(child, skip(value + 1)));
if (!value) return 0;
child->string = child->valuestring;
child->valuestring = 0;
if (*value != ':') {
ep = value;
return 0;
- } /* fail! */
- value = skip(parse_value(instance, child, skip(value + 1))); /* skip any spacing, get the value. */
+ } /* fail! */
+ value = skip(parse_value(child, skip(value + 1))); /* skip any spacing, get the value. */
if (!value) return 0;
}
@@ -764,7 +765,7 @@ const char *parse_object(const struct loader_instance *instance, cJSON *item, co
}
/* Render an object to text. */
-char *print_object(const struct loader_instance *instance, cJSON *item, int depth, int fmt, printbuffer *p) {
+char *print_object(cJSON *item, int depth, int fmt, printbuffer *p) {
char **entries = 0, **names = 0;
char *out = 0, *ptr, *ret, *str;
int j;
@@ -776,9 +777,9 @@ char *print_object(const struct loader_instance *instance, cJSON *item, int dept
/* Explicitly handle empty object case */
if (!numentries) {
if (p)
- out = ensure(instance, p, fmt ? depth + 4 : 3);
+ out = ensure(item->pAllocator, p, fmt ? depth + 4 : 3);
else
- out = (char *)cJSON_malloc(instance, fmt ? depth + 4 : 3);
+ out = (char *)cJSON_malloc(item->pAllocator, fmt ? depth + 4 : 3);
if (!out) return 0;
ptr = out;
*ptr++ = '{';
@@ -794,7 +795,7 @@ char *print_object(const struct loader_instance *instance, cJSON *item, int dept
/* Compose the output: */
i = p->offset;
len = fmt ? 2 : 1;
- ptr = ensure(instance, p, len + 1);
+ ptr = ensure(item->pAllocator, p, len + 1);
if (!ptr) return 0;
*ptr++ = '{';
if (fmt) *ptr++ = '\n';
@@ -804,26 +805,26 @@ char *print_object(const struct loader_instance *instance, cJSON *item, int dept
depth++;
while (child) {
if (fmt) {
- ptr = ensure(instance, p, depth);
+ ptr = ensure(item->pAllocator, p, depth);
if (!ptr) return 0;
for (j = 0; j < depth; j++) *ptr++ = '\t';
p->offset += depth;
}
- print_string_ptr(instance, child->string, p);
+ print_string_ptr(item->pAllocator, child->string, p);
p->offset = cJSON_update(p);
len = fmt ? 2 : 1;
- ptr = ensure(instance, p, len);
+ ptr = ensure(item->pAllocator, p, len);
if (!ptr) return 0;
*ptr++ = ':';
if (fmt) *ptr++ = '\t';
p->offset += len;
- print_value(instance, child, depth, fmt, p);
+ print_value(child, depth, fmt, p);
p->offset = cJSON_update(p);
len = (fmt ? 1 : 0) + (child->next ? 1 : 0);
- ptr = ensure(instance, p, len + 1);
+ ptr = ensure(item->pAllocator, p, len + 1);
if (!ptr) return 0;
if (child->next) *ptr++ = ',';
if (fmt) *ptr++ = '\n';
@@ -831,7 +832,7 @@ char *print_object(const struct loader_instance *instance, cJSON *item, int dept
p->offset += len;
child = child->next;
}
- ptr = ensure(instance, p, fmt ? (depth + 1) : 2);
+ ptr = ensure(item->pAllocator, p, fmt ? (depth + 1) : 2);
if (!ptr) return 0;
if (fmt)
for (j = 0; j < depth - 1; j++) *ptr++ = '\t';
@@ -840,11 +841,11 @@ char *print_object(const struct loader_instance *instance, cJSON *item, int dept
out = (p->buffer) + i;
} else {
/* Allocate space for the names and the objects */
- entries = (char **)cJSON_malloc(instance, numentries * sizeof(char *));
+ entries = (char **)cJSON_malloc(item->pAllocator, numentries * sizeof(char *));
if (!entries) return 0;
- names = (char **)cJSON_malloc(instance, numentries * sizeof(char *));
+ names = (char **)cJSON_malloc(item->pAllocator, numentries * sizeof(char *));
if (!names) {
- cJSON_free(instance, entries);
+ cJSON_Free(item->pAllocator, entries);
return 0;
}
memset(entries, 0, sizeof(char *) * numentries);
@@ -855,8 +856,8 @@ char *print_object(const struct loader_instance *instance, cJSON *item, int dept
depth++;
if (fmt) len += depth;
while (child) {
- names[i] = str = print_string_ptr(instance, child->string, 0);
- entries[i++] = ret = print_value(instance, child, depth, fmt, 0);
+ names[i] = str = print_string_ptr(item->pAllocator, child->string, 0);
+ entries[i++] = ret = print_value(child, depth, fmt, 0);
if (str && ret)
len += strlen(ret) + strlen(str) + 2 + (fmt ? 2 + depth : 0);
else
@@ -865,17 +866,17 @@ char *print_object(const struct loader_instance *instance, cJSON *item, int dept
}
/* Try to allocate the output string */
- if (!fail) out = (char *)cJSON_malloc(instance, len);
+ if (!fail) out = (char *)cJSON_malloc(item->pAllocator, len);
if (!out) fail = 1;
/* Handle failure */
if (fail) {
for (j = 0; j < numentries; j++) {
- if (names[i]) cJSON_free(instance, names[j]);
- if (entries[j]) cJSON_free(instance, entries[j]);
+ if (names[i]) cJSON_Free(item->pAllocator, names[j]);
+ if (entries[j]) cJSON_Free(item->pAllocator, entries[j]);
}
- cJSON_free(instance, names);
- cJSON_free(instance, entries);
+ cJSON_Free(item->pAllocator, names);
+ cJSON_Free(item->pAllocator, entries);
return 0;
}
@@ -897,12 +898,12 @@ char *print_object(const struct loader_instance *instance, cJSON *item, int dept
if (j != numentries - 1) *ptr++ = ',';
if (fmt) *ptr++ = '\n';
*ptr = 0;
- cJSON_free(instance, names[j]);
- cJSON_free(instance, entries[j]);
+ cJSON_Free(item->pAllocator, names[j]);
+ cJSON_Free(item->pAllocator, entries[j]);
}
- cJSON_free(instance, names);
- cJSON_free(instance, entries);
+ cJSON_Free(item->pAllocator, names);
+ cJSON_Free(item->pAllocator, entries);
if (fmt)
for (j = 0; j < depth - 1; j++) *ptr++ = '\t';
*ptr++ = '}';
@@ -935,8 +936,8 @@ void suffix_object(cJSON *prev, cJSON *item) {
item->prev = prev;
}
/* Utility for handling references. */
-cJSON *create_reference(const struct loader_instance *instance, cJSON *item) {
- cJSON *ref = cJSON_New_Item(instance);
+cJSON *create_reference(cJSON *item) {
+ cJSON *ref = cJSON_New_Item(item->pAllocator);
if (!ref) return 0;
memcpy(ref, item, sizeof(cJSON));
ref->string = 0;
@@ -956,24 +957,22 @@ void cJSON_AddItemToArray(cJSON *array, cJSON *item) {
suffix_object(c, item);
}
}
-void cJSON_AddItemToObject(const struct loader_instance *instance, cJSON *object, const char *string, cJSON *item) {
+void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) {
if (!item) return;
- if (item->string) cJSON_free(instance, item->string);
- item->string = cJSON_strdup(instance, string);
+ if (item->string) cJSON_Free(object->pAllocator, item->string);
+ item->string = cJSON_strdup(object->pAllocator, string);
cJSON_AddItemToArray(object, item);
}
-void cJSON_AddItemToObjectCS(const struct loader_instance *instance, cJSON *object, const char *string, cJSON *item) {
+void cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) {
if (!item) return;
- if (!(item->type & cJSON_StringIsConst) && item->string) cJSON_free(instance, item->string);
+ if (!(item->type & cJSON_StringIsConst) && item->string) cJSON_Free(object->pAllocator, item->string);
item->string = (char *)string;
item->type |= cJSON_StringIsConst;
cJSON_AddItemToArray(object, item);
}
-void cJSON_AddItemReferenceToArray(const struct loader_instance *instance, cJSON *array, cJSON *item) {
- cJSON_AddItemToArray(array, create_reference(instance, item));
-}
-void cJSON_AddItemReferenceToObject(const struct loader_instance *instance, cJSON *object, const char *string, cJSON *item) {
- cJSON_AddItemToObject(instance, object, string, create_reference(instance, item));
+void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) { cJSON_AddItemToArray(array, create_reference(item)); }
+void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) {
+ cJSON_AddItemToObject(object, string, create_reference(item));
}
cJSON *cJSON_DetachItemFromArray(cJSON *array, int which) {
@@ -986,9 +985,7 @@ cJSON *cJSON_DetachItemFromArray(cJSON *array, int which) {
c->prev = c->next = 0;
return c;
}
-void cJSON_DeleteItemFromArray(const struct loader_instance *instance, cJSON *array, int which) {
- cJSON_Delete(instance, cJSON_DetachItemFromArray(array, which));
-}
+void cJSON_DeleteItemFromArray(cJSON *array, int which) { cJSON_Delete(cJSON_DetachItemFromArray(array, which)); }
cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string) {
int i = 0;
cJSON *c = object->child;
@@ -996,9 +993,7 @@ cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string) {
if (c) return cJSON_DetachItemFromArray(object, i);
return 0;
}
-void cJSON_DeleteItemFromObject(const struct loader_instance *instance, cJSON *object, const char *string) {
- cJSON_Delete(instance, cJSON_DetachItemFromObject(object, string));
-}
+void cJSON_DeleteItemFromObject(cJSON *object, const char *string) { cJSON_Delete(cJSON_DetachItemFromObject(object, string)); }
/* Replace array/object items with new ones. */
void cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) {
@@ -1016,7 +1011,7 @@ void cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) {
else
newitem->prev->next = newitem;
}
-void cJSON_ReplaceItemInArray(const struct loader_instance *instance, cJSON *array, int which, cJSON *newitem) {
+void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) {
cJSON *c = array->child;
while (c && which > 0) c = c->next, which--;
if (!c) return;
@@ -1028,41 +1023,41 @@ void cJSON_ReplaceItemInArray(const struct loader_instance *instance, cJSON *arr
else
newitem->prev->next = newitem;
c->next = c->prev = 0;
- cJSON_Delete(instance, c);
+ cJSON_Delete(c);
}
-void cJSON_ReplaceItemInObject(const struct loader_instance *instance, cJSON *object, const char *string, cJSON *newitem) {
+void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) {
int i = 0;
cJSON *c = object->child;
while (c && strcmp(c->string, string)) i++, c = c->next;
if (c) {
- newitem->string = cJSON_strdup(instance, string);
- cJSON_ReplaceItemInArray(instance, object, i, newitem);
+ newitem->string = cJSON_strdup(object->pAllocator, string);
+ cJSON_ReplaceItemInArray(object, i, newitem);
}
}
/* Create basic types: */
-cJSON *cJSON_CreateNull(const struct loader_instance *instance) {
- cJSON *item = cJSON_New_Item(instance);
+cJSON *cJSON_CreateNull(const VkAllocationCallbacks *pAllocator) {
+ cJSON *item = cJSON_New_Item(pAllocator);
if (item) item->type = cJSON_NULL;
return item;
}
-cJSON *cJSON_CreateTrue(const struct loader_instance *instance) {
- cJSON *item = cJSON_New_Item(instance);
+cJSON *cJSON_CreateTrue(const VkAllocationCallbacks *pAllocator) {
+ cJSON *item = cJSON_New_Item(pAllocator);
if (item) item->type = cJSON_True;
return item;
}
-cJSON *cJSON_CreateFalse(const struct loader_instance *instance) {
- cJSON *item = cJSON_New_Item(instance);
+cJSON *cJSON_CreateFalse(const VkAllocationCallbacks *pAllocator) {
+ cJSON *item = cJSON_New_Item(pAllocator);
if (item) item->type = cJSON_False;
return item;
}
-cJSON *cJSON_CreateBool(const struct loader_instance *instance, int b) {
- cJSON *item = cJSON_New_Item(instance);
+cJSON *cJSON_CreateBool(const VkAllocationCallbacks *pAllocator, int b) {
+ cJSON *item = cJSON_New_Item(pAllocator);
if (item) item->type = b ? cJSON_True : cJSON_False;
return item;
}
-cJSON *cJSON_CreateNumber(const struct loader_instance *instance, double num) {
- cJSON *item = cJSON_New_Item(instance);
+cJSON *cJSON_CreateNumber(const VkAllocationCallbacks *pAllocator, double num) {
+ cJSON *item = cJSON_New_Item(pAllocator);
if (item) {
item->type = cJSON_Number;
item->valuedouble = num;
@@ -1070,31 +1065,31 @@ cJSON *cJSON_CreateNumber(const struct loader_instance *instance, double num) {
}
return item;
}
-cJSON *cJSON_CreateString(const struct loader_instance *instance, const char *string) {
- cJSON *item = cJSON_New_Item(instance);
+cJSON *cJSON_CreateString(const VkAllocationCallbacks *pAllocator, const char *string) {
+ cJSON *item = cJSON_New_Item(pAllocator);
if (item) {
item->type = cJSON_String;
- item->valuestring = cJSON_strdup(instance, string);
+ item->valuestring = cJSON_strdup(pAllocator, string);
}
return item;
}
-cJSON *cJSON_CreateArray(const struct loader_instance *instance) {
- cJSON *item = cJSON_New_Item(instance);
+cJSON *cJSON_CreateArray(const VkAllocationCallbacks *pAllocator) {
+ cJSON *item = cJSON_New_Item(pAllocator);
if (item) item->type = cJSON_Array;
return item;
}
-cJSON *cJSON_CreateObject(const struct loader_instance *instance) {
- cJSON *item = cJSON_New_Item(instance);
+cJSON *cJSON_CreateObject(const VkAllocationCallbacks *pAllocator) {
+ cJSON *item = cJSON_New_Item(pAllocator);
if (item) item->type = cJSON_Object;
return item;
}
/* Create Arrays: */
-cJSON *cJSON_CreateIntArray(const struct loader_instance *instance, const int *numbers, int count) {
+cJSON *cJSON_CreateIntArray(const VkAllocationCallbacks *pAllocator, const int *numbers, int count) {
int i;
- cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(instance);
+ cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(pAllocator);
for (i = 0; a && i < count; i++) {
- n = cJSON_CreateNumber(instance, numbers[i]);
+ n = cJSON_CreateNumber(pAllocator, numbers[i]);
if (!i)
a->child = n;
else
@@ -1103,11 +1098,11 @@ cJSON *cJSON_CreateIntArray(const struct loader_instance *instance, const int *n
}
return a;
}
-cJSON *cJSON_CreateFloatArray(const struct loader_instance *instance, const float *numbers, int count) {
+cJSON *cJSON_CreateFloatArray(const VkAllocationCallbacks *pAllocator, const float *numbers, int count) {
int i;
- cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(instance);
+ cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(pAllocator);
for (i = 0; a && i < count; i++) {
- n = cJSON_CreateNumber(instance, numbers[i]);
+ n = cJSON_CreateNumber(pAllocator, numbers[i]);
if (!i)
a->child = n;
else
@@ -1116,11 +1111,11 @@ cJSON *cJSON_CreateFloatArray(const struct loader_instance *instance, const floa
}
return a;
}
-cJSON *cJSON_CreateDoubleArray(const struct loader_instance *instance, const double *numbers, int count) {
+cJSON *cJSON_CreateDoubleArray(const VkAllocationCallbacks *pAllocator, const double *numbers, int count) {
int i;
- cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(instance);
+ cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(pAllocator);
for (i = 0; a && i < count; i++) {
- n = cJSON_CreateNumber(instance, numbers[i]);
+ n = cJSON_CreateNumber(pAllocator, numbers[i]);
if (!i)
a->child = n;
else
@@ -1129,11 +1124,11 @@ cJSON *cJSON_CreateDoubleArray(const struct loader_instance *instance, const dou
}
return a;
}
-cJSON *cJSON_CreateStringArray(const struct loader_instance *instance, const char **strings, int count) {
+cJSON *cJSON_CreateStringArray(const VkAllocationCallbacks *pAllocator, const char **strings, int count) {
int i;
- cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(instance);
+ cJSON *n = 0, *p = 0, *a = cJSON_CreateArray(pAllocator);
for (i = 0; a && i < count; i++) {
- n = cJSON_CreateString(instance, strings[i]);
+ n = cJSON_CreateString(pAllocator, strings[i]);
if (!i)
a->child = n;
else
@@ -1144,26 +1139,26 @@ cJSON *cJSON_CreateStringArray(const struct loader_instance *instance, const cha
}
/* Duplication */
-cJSON *cJSON_Duplicate(const struct loader_instance *instance, cJSON *item, int recurse) {
+cJSON *cJSON_Duplicate(cJSON *item, int recurse) {
cJSON *newitem, *cptr, *nptr = 0, *newchild;
/* Bail on bad ptr */
if (!item) return 0;
/* Create new item */
- newitem = cJSON_New_Item(instance);
+ newitem = cJSON_New_Item(item->pAllocator);
if (!newitem) return 0;
/* Copy over all vars */
newitem->type = item->type & (~cJSON_IsReference), newitem->valueint = item->valueint, newitem->valuedouble = item->valuedouble;
if (item->valuestring) {
- newitem->valuestring = cJSON_strdup(instance, item->valuestring);
+ newitem->valuestring = cJSON_strdup(item->pAllocator, item->valuestring);
if (!newitem->valuestring) {
- cJSON_Delete(instance, newitem);
+ cJSON_Delete(newitem);
return 0;
}
}
if (item->string) {
- newitem->string = cJSON_strdup(instance, item->string);
+ newitem->string = cJSON_strdup(item->pAllocator, item->string);
if (!newitem->string) {
- cJSON_Delete(instance, newitem);
+ cJSON_Delete(newitem);
return 0;
}
}
@@ -1172,9 +1167,9 @@ cJSON *cJSON_Duplicate(const struct loader_instance *instance, cJSON *item, int
/* Walk the ->next chain for the child. */
cptr = item->child;
while (cptr) {
- newchild = cJSON_Duplicate(instance, cptr, 1); /* Duplicate (with recurse) each item in the ->next chain */
+ newchild = cJSON_Duplicate(cptr, 1); /* Duplicate (with recurse) each item in the ->next chain */
if (!newchild) {
- cJSON_Delete(instance, newitem);
+ cJSON_Delete(newitem);
return 0;
}
if (nptr) {
diff --git a/loader/cJSON.h b/loader/cJSON.h
index 8714c4e80..9379cf84f 100644
--- a/loader/cJSON.h
+++ b/loader/cJSON.h
@@ -60,25 +60,27 @@ typedef struct cJSON {
char *string; /* The item's name string, if this item is the child of, or is
in the list of subitems of an object. */
+ /* pointer to the allocation callbacks to use */
+ VkAllocationCallbacks *pAllocator;
} cJSON;
/* Supply a block of JSON, and this returns a cJSON object you can interrogate.
* Call cJSON_Delete when finished. */
-cJSON *cJSON_Parse(const struct loader_instance *instance, const char *value);
+cJSON *cJSON_Parse(const VkAllocationCallbacks *pAllocator, const char *value);
/* Render a cJSON entity to text for transfer/storage. Free the char* when
* finished. */
-char *cJSON_Print(const struct loader_instance *instance, cJSON *item);
+char *cJSON_Print(cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting.
* Free the char* when finished. */
-char *cJSON_PrintUnformatted(const struct loader_instance *instance, cJSON *item);
+char *cJSON_PrintUnformatted(cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess
* at the final size. guessing well reduces reallocation. fmt=0 gives
* unformatted, =1 gives formatted */
-char *cJSON_PrintBuffered(const struct loader_instance *instance, cJSON *item, int prebuffer, int fmt);
+char *cJSON_PrintBuffered(cJSON *item, int prebuffer, int fmt);
/* Delete a cJSON entity and all subentities. */
-void cJSON_Delete(const struct loader_instance *instance, cJSON *c);
+void cJSON_Delete(cJSON *c);
/* Delete an item allocated inside the JSON parser*/
-void cJSON_Free(const struct loader_instance *instance, void *p);
+void cJSON_Free(const VkAllocationCallbacks *pAllocator, void *p);
/* Returns the number of items in an array (or object). */
int cJSON_GetArraySize(cJSON *array);
@@ -94,46 +96,46 @@ cJSON *cJSON_GetObjectItem(cJSON *object, const char *string);
const char *cJSON_GetErrorPtr(void);
/* These calls create a cJSON item of the appropriate type. */
-cJSON *cJSON_CreateNull(const struct loader_instance *instance);
-cJSON *cJSON_CreateTrue(const struct loader_instance *instance);
-cJSON *cJSON_CreateFalse(const struct loader_instance *instance);
-cJSON *cJSON_CreateBool(const struct loader_instance *instance, int b);
-cJSON *cJSON_CreateNumber(const struct loader_instance *instance, double num);
-cJSON *cJSON_CreateString(const struct loader_instance *instance, const char *string);
-cJSON *cJSON_CreateArray(const struct loader_instance *instance);
-cJSON *cJSON_CreateObject(const struct loader_instance *instance);
+cJSON *cJSON_CreateNull(const VkAllocationCallbacks *pAllocator);
+cJSON *cJSON_CreateTrue(const VkAllocationCallbacks *pAllocator);
+cJSON *cJSON_CreateFalse(const VkAllocationCallbacks *pAllocator);
+cJSON *cJSON_CreateBool(const VkAllocationCallbacks *pAllocator, int b);
+cJSON *cJSON_CreateNumber(const VkAllocationCallbacks *pAllocator, double num);
+cJSON *cJSON_CreateString(const VkAllocationCallbacks *pAllocator, const char *string);
+cJSON *cJSON_CreateArray(const VkAllocationCallbacks *pAllocator);
+cJSON *cJSON_CreateObject(const VkAllocationCallbacks *pAllocator);
/* These utilities create an Array of count items. */
-cJSON *cJSON_CreateIntArray(const struct loader_instance *instance, const int *numbers, int count);
-cJSON *cJSON_CreateFloatArray(const struct loader_instance *instance, const float *numbers, int count);
-cJSON *cJSON_CreateDoubleArray(const struct loader_instance *instance, const double *numbers, int count);
-cJSON *cJSON_CreateStringArray(const struct loader_instance *instance, const char **strings, int count);
+cJSON *cJSON_CreateIntArray(const VkAllocationCallbacks *pAllocator, const int *numbers, int count);
+cJSON *cJSON_CreateFloatArray(const VkAllocationCallbacks *pAllocator, const float *numbers, int count);
+cJSON *cJSON_CreateDoubleArray(const VkAllocationCallbacks *pAllocator, const double *numbers, int count);
+cJSON *cJSON_CreateStringArray(const VkAllocationCallbacks *pAllocator, const char **strings, int count);
/* Append item to the specified array/object. */
void cJSON_AddItemToArray(cJSON *array, cJSON *item);
-void cJSON_AddItemToObject(const struct loader_instance *instance, cJSON *object, const char *string, cJSON *item);
+void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and
* will definitely survive the cJSON object */
-void cJSON_AddItemToObjectCS(const struct loader_instance *instance, cJSON *object, const char *string, cJSON *item);
+void cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you
* want to add an existing cJSON to a new cJSON, but don't want to corrupt your
* existing cJSON. */
-void cJSON_AddItemReferenceToArray(const struct loader_instance *instance, cJSON *array, cJSON *item);
-void cJSON_AddItemReferenceToObject(const struct loader_instance *instance, cJSON *object, const char *string, cJSON *item);
+void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
+void cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
cJSON *cJSON_DetachItemFromArray(cJSON *array, int which);
-void cJSON_DeleteItemFromArray(const struct loader_instance *instance, cJSON *array, int which);
+void cJSON_DeleteItemFromArray(cJSON *array, int which);
cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string);
-void cJSON_DeleteItemFromObject(const struct loader_instance *instance, cJSON *object, const char *string);
+void cJSON_DeleteItemFromObject(cJSON *object, const char *string);
/* Update array items. */
void cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
-void cJSON_ReplaceItemInArray(const struct loader_instance *instance, cJSON *array, int which, cJSON *newitem);
-void cJSON_ReplaceItemInObject(const struct loader_instance *instance, cJSON *object, const char *string, cJSON *newitem);
+void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
+void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
/* Duplicate a cJSON item */
-cJSON *cJSON_Duplicate(const struct loader_instance *instance, cJSON *item, int recurse);
+cJSON *cJSON_Duplicate(cJSON *item, int recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new
memory that will
need to be released. With recurse!=0, it will duplicate any children connected
@@ -142,19 +144,11 @@ The item->next and ->prev pointers are always zero on return from Duplicate. */
/* ParseWithOpts allows you to require (and check) that the JSON is null
* terminated, and to retrieve the pointer to the final byte parsed. */
-cJSON *cJSON_ParseWithOpts(const struct loader_instance *instance, const char *value, const char **return_parse_end,
+cJSON *cJSON_ParseWithOpts(const VkAllocationCallbacks *pAllocator, const char *value, const char **return_parse_end,
int require_null_terminated);
void cJSON_Minify(char *json);
-/* Macros for creating things quickly. */
-#define cJSON_AddNullToObject(object, name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
-#define cJSON_AddTrueToObject(object, name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
-#define cJSON_AddFalseToObject(object, name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
-#define cJSON_AddBoolToObject(object, name, b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
-#define cJSON_AddNumberToObject(object, name, n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
-#define cJSON_AddStringToObject(object, name, s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
-
/* When assigning an integer value, it needs to be propagated to valuedouble
* too. */
#define cJSON_SetIntValue(object, val) ((object) ? (object)->valueint = (object)->valuedouble = (val) : (val))
diff --git a/loader/loader.c b/loader/loader.c
index c494c22a1..98c5ff2e8 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -132,7 +132,7 @@ bool loader_check_version_meets_required(loader_api_version required, loader_api
DIR *loader_opendir(const struct loader_instance *instance, const char *name) {
#if defined(_WIN32)
return opendir(instance ? &instance->alloc_callbacks : NULL, name);
-#else // _WIN32
+#else // _WIN32
return opendir(name);
#endif // _WIN32
}
@@ -1693,7 +1693,7 @@ static VkResult loader_get_json(const struct loader_instance *inst, const char *
goto out;
}
// Parse text from file
- *json = cJSON_Parse(inst, json_buf);
+ *json = cJSON_Parse(inst ? &inst->alloc_callbacks : NULL, json_buf);
if (*json == NULL) {
loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
"loader_get_json: Failed to parse JSON file %s, this is usually because something ran out of memory.", filename);
@@ -1950,7 +1950,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
#var); \
goto out; \
} \
- temp = cJSON_Print(inst, item); \
+ temp = cJSON_Print(item); \
if (temp == NULL) { \
loader_log(inst, VULKAN_LOADER_WARN_BIT, 0, \
"Problem accessing layer value %s in manifest JSON " \
@@ -1962,7 +1962,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
temp[strlen(temp) - 1] = '\0'; \
var = loader_stack_alloc(strlen(temp) + 1); \
strcpy(var, &temp[1]); \
- cJSON_Free(inst, temp); \
+ loader_instance_heap_free(inst, temp); \
}
GET_JSON_ITEM(inst, layer_node, name)
GET_JSON_ITEM(inst, layer_node, type)
@@ -2014,7 +2014,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
uint8_t cur_item = 0;
// Get the string for the current item
- temp = cJSON_Print(inst, expiration);
+ temp = cJSON_Print(expiration);
if (temp == NULL) {
loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
"Problem accessing layer value 'expiration_date' in manifest JSON file, skipping this layer");
@@ -2023,7 +2023,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
}
temp[strlen(temp) - 1] = '\0';
strcpy(date_copy, &temp[1]);
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
if (strlen(date_copy) == 16) {
char *cur_start = &date_copy[0];
@@ -2077,7 +2077,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
props->num_component_layers = 0;
props->component_layer_names = NULL;
- temp = cJSON_Print(inst, library_path);
+ temp = cJSON_Print(library_path);
if (NULL == temp) {
loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
"Problem accessing layer value library_path in manifest JSON file, skipping this layer");
@@ -2087,7 +2087,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
temp[strlen(temp) - 1] = '\0';
library_path_str = loader_stack_alloc(strlen(temp) + 1);
strcpy(library_path_str, &temp[1]);
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
strncpy(props->manifest_file_name, filename, MAX_STRING_SIZE);
char *fullpath = props->lib_name;
@@ -2128,7 +2128,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
for (i = 0; i < count; i++) {
cJSON *comp_layer = cJSON_GetArrayItem(component_layers, i);
if (NULL != comp_layer) {
- temp = cJSON_Print(inst, comp_layer);
+ temp = cJSON_Print(comp_layer);
if (NULL == temp) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
@@ -2136,7 +2136,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
temp[strlen(temp) - 1] = '\0';
strncpy(props->component_layer_names[i], temp + 1, MAX_STRING_SIZE - 1);
props->component_layer_names[i][MAX_STRING_SIZE - 1] = '\0';
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
}
}
@@ -2179,7 +2179,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
if (black_layer == NULL) {
continue;
}
- temp = cJSON_Print(inst, black_layer);
+ temp = cJSON_Print(black_layer);
if (temp == NULL) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
@@ -2187,7 +2187,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
temp[strlen(temp) - 1] = '\0';
strncpy(props->blacklist_layer_names[i], temp + 1, MAX_STRING_SIZE - 1);
props->blacklist_layer_names[i][MAX_STRING_SIZE - 1] = '\0';
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
}
}
}
@@ -2214,7 +2214,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
for (i = 0; i < count; i++) {
cJSON *override_path = cJSON_GetArrayItem(override_paths, i);
if (NULL != override_path) {
- temp = cJSON_Print(inst, override_path);
+ temp = cJSON_Print(override_path);
if (NULL == temp) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
@@ -2222,7 +2222,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
temp[strlen(temp) - 1] = '\0';
strncpy(props->override_paths[i], temp + 1, MAX_STRING_SIZE - 1);
props->override_paths[i][MAX_STRING_SIZE - 1] = '\0';
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
}
}
}
@@ -2277,12 +2277,12 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
{ \
item = cJSON_GetObjectItem(node, #var); \
if (item != NULL) { \
- temp = cJSON_Print(inst, item); \
+ temp = cJSON_Print(item); \
if (temp != NULL) { \
temp[strlen(temp) - 1] = '\0'; \
var = loader_stack_alloc(strlen(temp) + 1); \
strcpy(var, &temp[1]); \
- cJSON_Free(inst, temp); \
+ loader_instance_heap_free(inst, temp); \
} else { \
result = VK_ERROR_OUT_OF_HOST_MEMORY; \
goto out; \
@@ -2404,7 +2404,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
for (j = 0; j < entry_count; j++) {
ext_item = cJSON_GetArrayItem(entrypoints, j);
if (ext_item != NULL) {
- temp = cJSON_Print(inst, ext_item);
+ temp = cJSON_Print(ext_item);
if (NULL == temp) {
entry_array[j] = NULL;
result = VK_ERROR_OUT_OF_HOST_MEMORY;
@@ -2413,7 +2413,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
temp[strlen(temp) - 1] = '\0';
entry_array[j] = loader_stack_alloc(strlen(temp) + 1);
strcpy(entry_array[j], &temp[1]);
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
}
}
loader_add_to_dev_ext_list(inst, &props->device_extension_list, &ext_prop, entry_count, entry_array);
@@ -2448,7 +2448,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
} else {
cJSON *inst_ext_json = cJSON_GetObjectItem(pre_instance, "vkEnumerateInstanceExtensionProperties");
if (NULL != inst_ext_json) {
- char *inst_ext_name = cJSON_Print(inst, inst_ext_json);
+ char *inst_ext_name = cJSON_Print(inst_ext_json);
if (NULL == inst_ext_name) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
@@ -2456,12 +2456,12 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
size_t len = strlen(inst_ext_name) >= MAX_STRING_SIZE ? MAX_STRING_SIZE - 3 : strlen(inst_ext_name) - 2;
strncpy(props->pre_instance_functions.enumerate_instance_extension_properties, inst_ext_name + 1, len);
props->pre_instance_functions.enumerate_instance_extension_properties[len] = '\0';
- cJSON_Free(inst, inst_ext_name);
+ loader_instance_heap_free(inst, inst_ext_name);
}
cJSON *inst_layer_json = cJSON_GetObjectItem(pre_instance, "vkEnumerateInstanceLayerProperties");
if (NULL != inst_layer_json) {
- char *inst_layer_name = cJSON_Print(inst, inst_layer_json);
+ char *inst_layer_name = cJSON_Print(inst_layer_json);
if (NULL == inst_layer_name) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
@@ -2469,12 +2469,12 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
size_t len = strlen(inst_layer_name) >= MAX_STRING_SIZE ? MAX_STRING_SIZE - 3 : strlen(inst_layer_name) - 2;
strncpy(props->pre_instance_functions.enumerate_instance_layer_properties, inst_layer_name + 1, len);
props->pre_instance_functions.enumerate_instance_layer_properties[len] = '\0';
- cJSON_Free(inst, inst_layer_name);
+ loader_instance_heap_free(inst, inst_layer_name);
}
cJSON *inst_version_json = cJSON_GetObjectItem(pre_instance, "vkEnumerateInstanceVersion");
if (NULL != inst_version_json) {
- char *inst_version_name = cJSON_Print(inst, inst_version_json);
+ char *inst_version_name = cJSON_Print(inst_version_json);
if (NULL == inst_version_name) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
@@ -2482,7 +2482,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
size_t len = strlen(inst_version_name) >= MAX_STRING_SIZE ? MAX_STRING_SIZE - 3 : strlen(inst_version_name) - 2;
strncpy(props->pre_instance_functions.enumerate_instance_version, inst_version_name + 1, len);
props->pre_instance_functions.enumerate_instance_version[len] = '\0';
- cJSON_Free(inst, inst_version_name);
+ loader_instance_heap_free(inst, inst_version_name);
}
}
}
@@ -2513,7 +2513,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
if (app_key_path == NULL) {
continue;
}
- temp = cJSON_Print(inst, app_key_path);
+ temp = cJSON_Print(app_key_path);
if (temp == NULL) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
@@ -2521,7 +2521,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
temp[strlen(temp) - 1] = '\0';
strncpy(props->app_key_paths[i], temp + 1, MAX_STRING_SIZE - 1);
props->app_key_paths[i][MAX_STRING_SIZE - 1] = '\0';
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
}
}
}
@@ -2576,7 +2576,7 @@ static VkResult loader_add_layer_properties(const struct loader_instance *inst,
if (item == NULL) {
goto out;
}
- char *file_vers = cJSON_PrintUnformatted(inst, item);
+ char *file_vers = cJSON_PrintUnformatted(item);
if (NULL == file_vers) {
goto out;
}
@@ -2589,7 +2589,7 @@ static VkResult loader_add_layer_properties(const struct loader_instance *inst,
"loader_add_layer_properties: %s has unknown layer manifest file version %d.%d.%d. May cause errors.", filename,
json_version.major, json_version.minor, json_version.patch);
}
- cJSON_Free(inst, file_vers);
+ loader_instance_heap_free(inst, file_vers);
// If "layers" is present, read in the array of layer objects
layers_node = cJSON_GetObjectItem(json, "layers");
@@ -3389,7 +3389,7 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
VkResult temp_res = loader_get_json(inst, file_str, &json);
if (NULL == json || temp_res != VK_SUCCESS) {
if (NULL != json) {
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
json = NULL;
}
// If we haven't already found an ICD, copy this result to
@@ -3414,12 +3414,12 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
}
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
"loader_icd_scan: ICD JSON %s does not have a \'file_format_version\' field. Skipping ICD JSON.", file_str);
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
json = NULL;
continue;
}
- char *file_vers = cJSON_Print(inst, item);
+ char *file_vers = cJSON_Print(item);
if (NULL == file_vers) {
// Only reason the print can fail is if there was an allocation issue
if (num_good_icds == 0) {
@@ -3428,7 +3428,7 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
"loader_icd_scan: Failed retrieving ICD JSON %s \'file_format_version\' field. Skipping ICD JSON",
file_str);
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
json = NULL;
continue;
}
@@ -3443,13 +3443,13 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
"loader_icd_scan: %s has unknown icd manifest file version %d.%d.%d. May cause errors.", file_str,
json_file_version.major, json_file_version.minor, json_file_version.patch);
}
- cJSON_Free(inst, file_vers);
+ loader_instance_heap_free(inst, file_vers);
itemICD = cJSON_GetObjectItem(json, "ICD");
if (itemICD != NULL) {
item = cJSON_GetObjectItem(itemICD, "library_path");
if (item != NULL) {
- char *temp = cJSON_Print(inst, item);
+ char *temp = cJSON_Print(item);
if (!temp || strlen(temp) == 0) {
if (num_good_icds == 0) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
@@ -3457,8 +3457,8 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
"loader_icd_scan: Failed retrieving ICD JSON %s \'library_path\' field. Skipping ICD JSON.",
file_str);
- cJSON_Free(inst, temp);
- cJSON_Delete(inst, json);
+ loader_instance_heap_free(inst, temp);
+ cJSON_Delete(json);
json = NULL;
continue;
}
@@ -3471,17 +3471,17 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
"loader_icd_scan: Failed to allocate space for ICD JSON %s \'library_path\' value. Skipping ICD JSON.",
file_str);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
- cJSON_Free(inst, temp);
- cJSON_Delete(inst, json);
+ loader_instance_heap_free(inst, temp);
+ cJSON_Delete(json);
json = NULL;
goto out;
}
strcpy(library_path, &temp[1]);
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
if (strlen(library_path) == 0) {
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
"loader_icd_scan: ICD JSON %s \'library_path\' field is empty. Skipping ICD JSON.", file_str);
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
json = NULL;
continue;
}
@@ -3507,7 +3507,7 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
uint32_t vers = 0;
item = cJSON_GetObjectItem(itemICD, "api_version");
if (item != NULL) {
- temp = cJSON_Print(inst, item);
+ temp = cJSON_Print(item);
if (NULL == temp) {
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
"loader_icd_scan: Failed retrieving ICD JSON %s \'api_version\' field. Skipping ICD JSON.",
@@ -3519,13 +3519,13 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
res = VK_ERROR_OUT_OF_HOST_MEMORY;
}
- cJSON_Free(inst, temp);
- cJSON_Delete(inst, json);
+ loader_instance_heap_free(inst, temp);
+ cJSON_Delete(json);
json = NULL;
continue;
}
vers = loader_parse_version_string(temp);
- cJSON_Free(inst, temp);
+ loader_instance_heap_free(inst, temp);
} else {
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
"loader_icd_scan: ICD JSON %s does not have an \'api_version\' field.", file_str);
@@ -3536,7 +3536,7 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
"loader_icd_scan: Driver's ICD JSON %s \'api_version\' field contains a non-zero variant value of %d. "
" Skipping ICD JSON.",
file_str, VK_API_VERSION_VARIANT(vers));
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
json = NULL;
continue;
}
@@ -3545,7 +3545,7 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
item = cJSON_GetObjectItem(itemICD, "is_portability_driver");
if (item != NULL && item->type == cJSON_True && !inst->portability_enumeration_enabled) {
if (skipped_portability_drivers) *skipped_portability_drivers = true;
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
json = NULL;
continue;
}
@@ -3577,7 +3577,7 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
fullpath);
break;
}
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
json = NULL;
continue;
}
@@ -3592,14 +3592,14 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
"loader_icd_scan: Can not find \'ICD\' object in ICD JSON file %s. Skipping ICD JSON", file_str);
}
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
json = NULL;
}
out:
if (NULL != json) {
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
}
if (NULL != manifest_files.filename_list) {
@@ -3654,7 +3654,7 @@ void loader_scan_for_layers(struct loader_instance *inst, struct loader_layer_li
}
VkResult local_res = loader_add_layer_properties(inst, instance_layers, json, true, file_str);
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
// If the error is anything other than out of memory we still want to try to load the other layers
if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
@@ -3716,7 +3716,7 @@ void loader_scan_for_layers(struct loader_instance *inst, struct loader_layer_li
}
VkResult local_res = loader_add_layer_properties(inst, instance_layers, json, false, file_str);
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
// If the error is anything other than out of memory we still want to try to load the other layers
if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
@@ -3794,7 +3794,7 @@ void loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader
loader_instance_heap_free(inst, file_str);
manifest_files.filename_list[i] = NULL;
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
goto out;
@@ -3862,7 +3862,7 @@ void loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader
loader_instance_heap_free(inst, file_str);
manifest_files.filename_list[i] = NULL;
- cJSON_Delete(inst, json);
+ cJSON_Delete(json);
if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
goto out;