From cba9387c361c3d33dcf1b21ff0e5beb4b0a81ade Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 16 May 2023 22:12:57 +0100 Subject: Do some pedantic spring cleaning - Use const in more places where it makes sense - not absolutely everywhere because it can get a bit annoying - Make all the instruction search loops a bit more readable by casting the function pointer into a temporary variable to loop over - Add a few more doc comments and fix a typo or two - Make that RTTI thing flexibly-sized, finally - Don't include gamedata.h in vcall.h for no reason; consequently include gamedata.h in a bunch of places where it was implictly pulled in before - Fix dbg_toghidra() and ent_getedict() having mismatched return types between their headers and respective source files - Remove that one broken, hacky, secret Portal non-feature that probably nobody even ended up using; it can be implemented properly later if required --- src/abi.h | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'src/abi.h') diff --git a/src/abi.h b/src/abi.h index 81b97e5..f9b5b7c 100644 --- a/src/abi.h +++ b/src/abi.h @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Michael Smith + * Copyright © 2023 Michael Smith * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -20,8 +20,8 @@ #include "intdefs.h" /* - * This file defines miscellaneous C++ ABI stuff. Looking at it may cause - * brain damage and/or emotional trauma. + * This file defines miscellaneous C++ ABI stuff. Looking at it may cause brain + * damage and/or emotional trauma. */ #ifdef _WIN32 // Windows RTTI stuff, obviously only used on Windows. @@ -37,19 +37,20 @@ // should be a small lookup table is an absolute nutcase. I hope that individual // has gotten some help by now, mostly for the sake of others. -struct msvc_rtti_descriptor { - void *vtab; +struct msvc_rtti_descriptor_head { + void **vtab; void *unknown; // ??? - // XXX: pretty sure this is supposed to be flexible, but too lazy to write - // the stupid union init macros to make that fully portable - char classname[80]; + // descriptor includes this, but constant flexible arrays are annoying, so + // this structure is just the header part and the string is tacked on in the + // DEF_MSVC_BASIC_RTTI macro below + //char classname[]; }; // "pointer to member displacement" struct msvc_pmd { int mdisp, pdisp, vdisp; }; struct msvc_basedesc { - struct msvc_rtti_descriptor *desc; + const struct msvc_rtti_descriptor_head *desc; uint nbases; struct msvc_pmd where; uint attr; @@ -59,7 +60,7 @@ struct msvc_rtti_hierarchy { uint sig; uint attrs; uint nbaseclasses; - struct msvc_basedesc **baseclasses; + const struct msvc_basedesc **baseclasses; }; struct msvc_rtti_locator { @@ -67,20 +68,26 @@ struct msvc_rtti_locator { int baseoff; // ctor offset, or some flags; reactos and rust pelite say different things? int unknown; - struct msvc_rtti_descriptor *desc; - struct msvc_rtti_hierarchy *hier; + const struct msvc_rtti_descriptor_head *desc; + const struct msvc_rtti_hierarchy *hier; }; // I mean seriously look at this crap! #define DEF_MSVC_BASIC_RTTI(mod, name, vtab, typestr) \ -mod struct msvc_rtti_locator name; \ -static struct msvc_rtti_descriptor _desc_##name = {(vtab), 0, typestr}; \ -static struct msvc_basedesc _basedesc_##name = {&_desc_##name, 0, {0, 0, 0}, 0}; \ -mod struct msvc_rtti_locator name = { \ +const mod struct msvc_rtti_locator name; \ +static const struct { \ + struct msvc_rtti_descriptor_head d; \ + char classname[sizeof("" typestr)]; \ +} _desc_##name = {(vtab), 0, .classname = "" typestr}; \ +static const struct msvc_basedesc _basedesc_##name = { \ + &_desc_##name.d, 0, {0, 0, 0}, 0 \ +}; \ +mod const struct msvc_rtti_locator name = { \ 0, 0, 0, \ - &_desc_##name, \ + &_desc_##name.d, \ &(struct msvc_rtti_hierarchy){ \ - 0, 1 /* per engine */, 1, (struct msvc_basedesc *[]){&_basedesc_##name} \ + 0, 1 /* match engine */, 1, \ + (const struct msvc_basedesc *[]){&_basedesc_##name} \ } \ }; -- cgit v1.2.3