mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-21 19:21:47 +00:00
[util] Pass context to the plist array/symtab parser allocator
This commit is contained in:
parent
a408fd40da
commit
14e4fd9f6a
3 changed files with 19 additions and 13 deletions
|
@ -109,7 +109,7 @@ typedef struct plfield_s {
|
||||||
typedef struct plelement_s {
|
typedef struct plelement_s {
|
||||||
pltype_t type; ///< the required type of the array elements
|
pltype_t type; ///< the required type of the array elements
|
||||||
size_t stride; ///< the size of each element
|
size_t stride; ///< the size of each element
|
||||||
void *(*alloc) (size_t size); ///< allocator for array memory
|
void *(*alloc) (void *ctx, size_t size);///< allocator for array memory
|
||||||
plparser_t parser; ///< custom parser function
|
plparser_t parser; ///< custom parser function
|
||||||
void *data; ///< additional data for \a parser
|
void *data; ///< additional data for \a parser
|
||||||
} plelement_t;
|
} plelement_t;
|
||||||
|
@ -360,7 +360,7 @@ void PL_TypeMismatch (plitem_t *messages, const plitem_t *item,
|
||||||
int PL_ParseStruct (const plfield_t *fields, const plitem_t *dict,
|
int PL_ParseStruct (const plfield_t *fields, const plitem_t *dict,
|
||||||
void *data, plitem_t *messages, void *context);
|
void *data, plitem_t *messages, void *context);
|
||||||
|
|
||||||
/** Parse an array object into a dynamic arrah (see darray.h).
|
/** Parse an array object into a dynamic array (see darray.h).
|
||||||
|
|
||||||
For each object in the array, the field item is used to determine how to
|
For each object in the array, the field item is used to determine how to
|
||||||
parse the object. If the array is empty, the destination will be
|
parse the object. If the array is empty, the destination will be
|
||||||
|
@ -378,7 +378,7 @@ int PL_ParseStruct (const plfield_t *fields, const plitem_t *dict,
|
||||||
\param array The array object to parse
|
\param array The array object to parse
|
||||||
\param data Pointer to the pointer to which the dynamic array will
|
\param data Pointer to the pointer to which the dynamic array will
|
||||||
be written. The dynamic array is allocated using
|
be written. The dynamic array is allocated using
|
||||||
DARRAY_ALLOCFIXED().
|
DARRAY_ALLOCFIXED_OBJ().
|
||||||
\param messages Array object supplied by the caller used for storing
|
\param messages Array object supplied by the caller used for storing
|
||||||
messages. The messages may or may not indicate errors (its
|
messages. The messages may or may not indicate errors (its
|
||||||
contents are not checked). This function itself will add
|
contents are not checked). This function itself will add
|
||||||
|
@ -390,7 +390,7 @@ int PL_ParseStruct (const plfield_t *fields, const plitem_t *dict,
|
||||||
message format is "[line number]: [message]". If the line
|
message format is "[line number]: [message]". If the line
|
||||||
number is 0, then the actual line is unknown (due to the
|
number is 0, then the actual line is unknown (due to the
|
||||||
source item not being parsed from a file or string).
|
source item not being parsed from a file or string).
|
||||||
\param context Additional context data passed to the parser.
|
\param context Additional context data passed to the parser and allocator.
|
||||||
\return 0 if there are any errors, 1 if there are no errors.
|
\return 0 if there are any errors, 1 if there are no errors.
|
||||||
*/
|
*/
|
||||||
int PL_ParseArray (const plfield_t *field, const plitem_t *array,
|
int PL_ParseArray (const plfield_t *field, const plitem_t *array,
|
||||||
|
@ -438,7 +438,7 @@ int PL_ParseArray (const plfield_t *field, const plitem_t *array,
|
||||||
message format is "[line number]: [message]". If the line
|
message format is "[line number]: [message]". If the line
|
||||||
number is 0, then the actual line is unknown (due to the
|
number is 0, then the actual line is unknown (due to the
|
||||||
source item not being parsed from a file or string).
|
source item not being parsed from a file or string).
|
||||||
\param context Additional context data passed to the parser.
|
\param context Additional context data passed to the parser and allocator.
|
||||||
\return 0 if there are any errors, 1 if there are no errors.
|
\return 0 if there are any errors, 1 if there are no errors.
|
||||||
*/
|
*/
|
||||||
int PL_ParseSymtab (const plfield_t *field, const plitem_t *dict,
|
int PL_ParseSymtab (const plfield_t *field, const plitem_t *dict,
|
||||||
|
|
|
@ -1272,8 +1272,8 @@ PL_ParseArray (const plfield_t *field, const plitem_t *array, void *data,
|
||||||
parser = pl_default_parser;
|
parser = pl_default_parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
arr = DARRAY_ALLOCFIXED (arr_t, plarray->numvals * element->stride,
|
arr = DARRAY_ALLOCFIXED_OBJ (arr_t, plarray->numvals * element->stride,
|
||||||
element->alloc);
|
element->alloc, context);
|
||||||
memset (arr->a, 0, arr->size);
|
memset (arr->a, 0, arr->size);
|
||||||
// the array is allocated using bytes, but need the actual number of
|
// the array is allocated using bytes, but need the actual number of
|
||||||
// elements in the array
|
// elements in the array
|
||||||
|
@ -1329,7 +1329,7 @@ PL_ParseSymtab (const plfield_t *field, const plitem_t *dict, void *data,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *obj = element->alloc (element->stride);
|
void *obj = element->alloc (context, element->stride);
|
||||||
memset (obj, 0, element->stride);
|
memset (obj, 0, element->stride);
|
||||||
while ((current = (dictkey_t *) *l++)) {
|
while ((current = (dictkey_t *) *l++)) {
|
||||||
const char *key = current->key;
|
const char *key = current->key;
|
||||||
|
@ -1349,7 +1349,7 @@ PL_ParseSymtab (const plfield_t *field, const plitem_t *dict, void *data,
|
||||||
result = 0;
|
result = 0;
|
||||||
} else {
|
} else {
|
||||||
Hash_Add (tab, obj);
|
Hash_Add (tab, obj);
|
||||||
obj = element->alloc (element->stride);
|
obj = element->alloc (context, element->stride);
|
||||||
memset (obj, 0, element->stride);
|
memset (obj, 0, element->stride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,6 +259,12 @@ parse_single (const plfield_t *field, const plitem_t *item,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
array_alloc (void *context, size_t size)
|
||||||
|
{
|
||||||
|
return malloc (size);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
parse_array (const plfield_t *field, const plitem_t *item,
|
parse_array (const plfield_t *field, const plitem_t *item,
|
||||||
void *data, plitem_t *messages, void *context)
|
void *data, plitem_t *messages, void *context)
|
||||||
|
@ -270,7 +276,7 @@ parse_array (const plfield_t *field, const plitem_t *item,
|
||||||
plelement_t element = {
|
plelement_t element = {
|
||||||
array->type,
|
array->type,
|
||||||
array->stride,
|
array->stride,
|
||||||
malloc,
|
array_alloc,
|
||||||
array->parser,
|
array->parser,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
@ -630,7 +636,7 @@ typedef struct qfv_renderpass_s {
|
||||||
static plelement_t parse_qfv_renderpass_attachments_data = {
|
static plelement_t parse_qfv_renderpass_attachments_data = {
|
||||||
QFDictionary,
|
QFDictionary,
|
||||||
sizeof (VkAttachmentDescription),
|
sizeof (VkAttachmentDescription),
|
||||||
malloc,
|
array_alloc,
|
||||||
parse_VkAttachmentDescription,
|
parse_VkAttachmentDescription,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
@ -638,7 +644,7 @@ static plelement_t parse_qfv_renderpass_attachments_data = {
|
||||||
static plelement_t parse_qfv_renderpass_subpasses_data = {
|
static plelement_t parse_qfv_renderpass_subpasses_data = {
|
||||||
QFDictionary,
|
QFDictionary,
|
||||||
sizeof (VkSubpassDescription),
|
sizeof (VkSubpassDescription),
|
||||||
malloc,
|
array_alloc,
|
||||||
parse_VkSubpassDescription,
|
parse_VkSubpassDescription,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
@ -646,7 +652,7 @@ static plelement_t parse_qfv_renderpass_subpasses_data = {
|
||||||
static plelement_t parse_qfv_renderpass_dependencies_data = {
|
static plelement_t parse_qfv_renderpass_dependencies_data = {
|
||||||
QFDictionary,
|
QFDictionary,
|
||||||
sizeof (VkSubpassDependency),
|
sizeof (VkSubpassDependency),
|
||||||
malloc,
|
array_alloc,
|
||||||
parse_VkSubpassDependency,
|
parse_VkSubpassDependency,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue