Give a cppia member field declared Bool its boolean storage - #1367
Open
MeguminBOT wants to merge 1 commit into
Open
Give a cppia member field declared Bool its boolean storage#1367MeguminBOT wants to merge 1 commit into
MeguminBOT wants to merge 1 commit into
Conversation
CppiaVar::linkVarTypes has two forms. The static form asks fieldStorageFromType, which answers fsBool for Bool. The member form switches on exprType instead, and TypeData::link has already mapped Bool onto etInt by the time it runs, so the field is laid out as fsInt and reads back through reflection as 1 rather than true. The member form now asks fieldStorageFromType as well. The slot stays the size of an int, leaving the layout and the AlignOffset call above it unchanged. The cppia test suite covers it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
A class member declared
Boolin a cppia module gets an integer slot, so reading it back throughreflection gives you
1instead oftrue. A static field of the same declared type, in the samemodule, gives you
true:Conditions and comparisons still work, since they are happy with the integer. Anything that looks at
the value itself does not.
Why
CppiaVar::linkVarTypeshas two forms:fieldStorageFromType, which has a case forBooland returnsfsBool.exprTypeinstead. By the time it runs,TypeData::linkhasalready mapped the
Booltype name toetInt, so the field ends up asfsInt.That is why the two fields above disagree.
The fix
In
src/hx/cppia/CppiaVars.cpp, the member form now callsfieldStorageFromTypetoo:The slot is still int sized, so the layout and the
AlignOffsetcall above it do not change.Test
test/cppiacovers it.ClientBoolFieldinClient.hxholds aBoolmember and aBoolstatic,and
testBoolMemberStorageincases/TestCommon.hxreads both back throughReflect.field.Without the fix that test fails with
Member Bool did not read back as a boolean, and the staticassertion beside it still passes, which is the pair that shows the two forms disagreeing. Same result
with or without
-jit.Reproducing by hand
Script.hx, built withhaxe -m Script --cppia script.cppia:Load it from a host built with
-D scriptable, usingcpp.cppia.Module.fromData(bytes).boot(), and callScript.runthrough reflection.member 1, static truemember true, static trueSame result with the JIT on or off, since the storage is decided at link time.
Let me know if I got anything wrong!