[util] Make exprctx hashlinks double pointer

The way I wound up using the field meant that exprctx should not "own"
the hashlinks chain, but rather just point to it. This fixes the nasty
access errors I had.
This commit is contained in:
Bill Currie 2021-01-05 19:55:17 +09:00
parent d8b389d2b6
commit a45f8f98b6
5 changed files with 16 additions and 16 deletions

View File

@ -94,7 +94,7 @@ typedef struct exprctx_s {
struct memsuper_s *memsuper;
const struct plitem_s *item;
struct plitem_s *messages;
struct hashlink_s *hashlinks;
struct hashlink_s **hashlinks;
int errors;
} exprctx_t;

View File

@ -128,7 +128,7 @@ void cexpr_init_symtab (exprtab_t *symtab, exprctx_t *ctx)
{
exprsym_t *sym;
symtab->tab = Hash_NewTable (61, expr_getkey, 0, 0, &ctx->hashlinks);
symtab->tab = Hash_NewTable (61, expr_getkey, 0, 0, ctx->hashlinks);
for (sym = symtab->symbols; sym->name; sym++) {
Hash_Add (symtab->tab, sym);
}

View File

@ -513,7 +513,7 @@ QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist)
exprctx.external_variables = &vars_tab;
exprctx.memsuper = new_memsuper ();
exprctx.messages = messages;
exprctx.hashlinks = ctx->hashlinks;
exprctx.hashlinks = &ctx->hashlinks;
cexpr_init_symtab (&vars_tab, &exprctx);
@ -526,7 +526,6 @@ QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist)
}
PL_Free (messages);
delete_memsuper (exprctx.memsuper);
ctx->hashlinks = exprctx.hashlinks;
renderpass = QFV_CreateRenderPass (device,
renderpass_data.attachments,
@ -556,17 +555,17 @@ QFV_ParseResources (vulkan_ctx_t *ctx, plitem_t *pipelinedef)
exprctx.memsuper = new_memsuper ();
exprctx.messages = messages;
exprctx.hashlinks = ctx->hashlinks;
exprctx.hashlinks = &ctx->hashlinks;
if (!ctx->setLayouts) {
ctx->shaderModules = Hash_NewTable (23, handleref_getkey,
shaderModule_free,
ctx, &exprctx.hashlinks);
ctx, &ctx->hashlinks);
ctx->setLayouts = Hash_NewTable (23, handleref_getkey, setLayout_free,
ctx, &exprctx.hashlinks);
ctx, &ctx->hashlinks);
ctx->pipelineLayouts = Hash_NewTable (23, handleref_getkey,
pipelineLayout_free,
ctx, &exprctx.hashlinks);
ctx, &ctx->hashlinks);
}
for (parseres_t *res = parse_resources; res->name; res++) {
@ -586,7 +585,6 @@ QFV_ParseResources (vulkan_ctx_t *ctx, plitem_t *pipelinedef)
PL_Free (messages);
delete_memsuper (exprctx.memsuper);
ctx->hashlinks = exprctx.hashlinks;
}
static const char *
@ -597,11 +595,12 @@ enum_symtab_getkey (const void *e, void *unused)
}
void
QFV_InitParse (void)
QFV_InitParse (vulkan_ctx_t *ctx)
{
exprctx_t context = {};
enum_symtab = Hash_NewTable (61, enum_symtab_getkey, 0, 0,
&context.hashlinks);
&ctx->hashlinks);
context.hashlinks = &ctx->hashlinks;
vkgen_init_symtabs (&context);
}

View File

@ -25,7 +25,7 @@ typedef struct handleref_s {
VkRenderPass QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist);
void QFV_ParseResources (vulkan_ctx_t *ctx, plitem_t *plist);
void QFV_InitParse (void);
void QFV_InitParse (vulkan_ctx_t *ctx);
exprenum_t *QFV_GetEnum (const char *name);
#endif//__vkparse_h

View File

@ -140,7 +140,7 @@ void
Vulkan_Init_Common (vulkan_ctx_t *ctx)
{
Sys_Printf ("Vulkan_Init_Common\n");
QFV_InitParse ();
QFV_InitParse (ctx);
Vulkan_Init_Cvars ();
ctx->instance = QFV_CreateInstance (ctx, PACKAGE_STRING, 0x000702ff, 0, instance_extensions);//FIXME version
}
@ -149,8 +149,9 @@ static void
clear_table (hashtab_t **table)
{
if (*table) {
Hash_DelTable (*table);
hashtab_t *tab = *table;
*table = 0;
Hash_DelTable (tab);
}
}
@ -166,11 +167,11 @@ Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
if (ctx->swapchain) {
QFV_DestroySwapchain (ctx->swapchain);
}
ctx->instance->funcs->vkDestroySurfaceKHR (ctx->instance->instance,
ctx->surface, 0);
clear_table (&ctx->pipelineLayouts);
clear_table (&ctx->setLayouts);
clear_table (&ctx->shaderModules);
ctx->instance->funcs->vkDestroySurfaceKHR (ctx->instance->instance,
ctx->surface, 0);
if (ctx->device) {
QFV_DestroyDevice (ctx->device);
}