From 539af96b8e0ffdc067d4edfd94feb3b4a5b942ed Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Mar 2017 18:48:51 +0100 Subject: [PATCH] - fixed variable size mismatch and some warnings for 32 bit builds. --- src/p_sectors.cpp | 2 +- src/scripting/vm/vm.h | 12 +++++++++--- src/scripting/zscript/zcc_compile.cpp | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 6679e74d17..faf15af5fc 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -2417,7 +2417,7 @@ DEFINE_FIELD_X(Sector, sector_t, soundtraversed) DEFINE_FIELD_X(Sector, sector_t, stairlock) DEFINE_FIELD_X(Sector, sector_t, prevsec) DEFINE_FIELD_X(Sector, sector_t, nextsec) -DEFINE_FIELD_X(Sector, sector_t, Lines) +DEFINE_FIELD_UNSIZED(Sector, sector_t, Lines) DEFINE_FIELD_X(Sector, sector_t, heightsec) DEFINE_FIELD_X(Sector, sector_t, bottommap) DEFINE_FIELD_X(Sector, sector_t, midmap) diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index 4b1f406b18..c099a4cb50 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -1099,7 +1099,7 @@ struct FieldDesc { const char *ClassName; const char *FieldName; - intptr_t FieldOffset; + size_t FieldOffset; unsigned FieldSize; int BitValue; }; @@ -1144,6 +1144,12 @@ struct AFuncDesc extern FieldDesc const *const VMField_##icls##_##name##_HookPtr; \ MSVC_FSEG FieldDesc const *const VMField_##icls##_##name##_HookPtr GCC_FSEG = &VMField_##icls##_##name; +// This is for cases where the internal size does not match the part that gets exported. +#define DEFINE_FIELD_UNSIZED(cls, icls, name) \ + static const FieldDesc VMField_##icls##_##name = { "A" #cls, #name, (unsigned)myoffsetof(icls, name), ~0u, 0 }; \ + extern FieldDesc const *const VMField_##icls##_##name##_HookPtr; \ + MSVC_FSEG FieldDesc const *const VMField_##icls##_##name##_HookPtr GCC_FSEG = &VMField_##icls##_##name; + #define DEFINE_FIELD_NAMED_X(cls, icls, name, scriptname) \ static const FieldDesc VMField_##cls##_##scriptname = { "A" #cls, #scriptname, (unsigned)myoffsetof(icls, name), (unsigned)sizeof(icls::name), 0 }; \ extern FieldDesc const *const VMField_##cls##_##scriptname##_HookPtr; \ @@ -1170,12 +1176,12 @@ struct AFuncDesc MSVC_FSEG FieldDesc const *const VMField_##cls##_##scriptname##_HookPtr GCC_FSEG = &VMField_##cls##_##scriptname; #define DEFINE_GLOBAL(name) \ - static const FieldDesc VMGlobal_##name = { "", #name, (intptr_t)&name, (unsigned)sizeof(name), 0 }; \ + static const FieldDesc VMGlobal_##name = { "", #name, (size_t)&name, (unsigned)sizeof(name), 0 }; \ extern FieldDesc const *const VMGlobal_##name##_HookPtr; \ MSVC_FSEG FieldDesc const *const VMGlobal_##name##_HookPtr GCC_FSEG = &VMGlobal_##name; #define DEFINE_GLOBAL_NAMED(iname, name) \ - static const FieldDesc VMGlobal_##name = { "", #name, (intptr_t)&iname, (unsigned)sizeof(iname), 0 }; \ + static const FieldDesc VMGlobal_##name = { "", #name, (size_t)&iname, (unsigned)sizeof(iname), 0 }; \ extern FieldDesc const *const VMGlobal_##name##_HookPtr; \ MSVC_FSEG FieldDesc const *const VMGlobal_##name##_HookPtr GCC_FSEG = &VMGlobal_##name; diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 1d98b20cd4..11157a85bf 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1215,7 +1215,7 @@ bool ZCCCompiler::CompileFields(PStruct *type, TArray &Fiel Error(field, "The member variable '%s.%s' has not been exported from the executable.", type == nullptr? "" : type->TypeName.GetChars(), FName(name->Name).GetChars()); } // For native structs a size check cannot be done because they normally have no size. But for a native reference they are still fine. - else if (thisfieldtype->Size != ~0u && thisfieldtype->Size != fd->FieldSize && fd->BitValue == 0 && !thisfieldtype->IsA(RUNTIME_CLASS(PNativeStruct))) + else if (thisfieldtype->Size != ~0u && fd->FieldSize != ~0u && thisfieldtype->Size != fd->FieldSize && fd->BitValue == 0 && !thisfieldtype->IsA(RUNTIME_CLASS(PNativeStruct))) { Error(field, "The member variable '%s.%s' has mismatching sizes in internal and external declaration. (Internal = %d, External = %d)", type == nullptr ? "" : type->TypeName.GetChars(), FName(name->Name).GetChars(), fd->FieldSize, thisfieldtype->Size); }