Skip to content

Commit 38dab2c

Browse files
MeguminBOTtobil4sk
andauthored
[cppia] Fix reported field type for booleans (#1367)
* [cppia] Fix reported field type for booleans 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. * [cppia] Use sTypeSize for the member offset Every storage fieldStorageFromType returns maps onto an exprType with the same size, so the switch collapses to a table lookup and the offsets stay byte-identical. * [tests] Check cppia client bool fields --------- Co-authored-by: Tobiasz Laskowski <tobil4sk@outlook.com>
1 parent 2f6ccfa commit 38dab2c

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

‎src/hx/cppia/CppiaVars.cpp‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,9 @@ void CppiaVar::linkVarTypes(CppiaModule &cppia, int &ioOffset)
179179
exprType = typeId==0 ? etObject : type->expressionType;
180180
AlignOffset(exprType, ioOffset);
181181
offset = ioOffset;
182-
183-
switch(exprType)
184-
{
185-
case etInt: ioOffset += sizeof(int); storeType=fsInt; break;
186-
case etFloat: ioOffset += sizeof(Float);storeType=fsFloat; break;
187-
case etString: ioOffset += sizeof(String);storeType=fsString; break;
188-
case etObject: ioOffset += sizeof(hx::Object *);storeType=fsObject; break;
189-
case etVoid:
190-
case etNull:
191-
break;
192-
}
182+
183+
storeType = typeId==0 ? fsObject : fieldStorageFromType(type);
184+
ioOffset += sTypeSize[exprType];
193185
}
194186
}
195187

‎test/cppia/cases/client/TestClient.hx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class TestClient extends Test {
66
public static var clientBool2 = true;
77
public static var clientBool3 = false;
88

9+
var memberBool = true;
10+
911
function testThread() {
1012
// See if it compiles
1113
Assert.notNull(sys.thread.Thread.current());
@@ -55,6 +57,9 @@ class TestClient extends Test {
5557
var hostBools = HostBase.hostBool0 + "/" + HostBase.hostBool1 + "/" + HostBase.hostBool2 + "/" + HostBase.hostBool3;
5658
var clientBools = clientBool0 + "/" + clientBool1 + "/" + clientBool2 + "/" + clientBool3;
5759
Assert.equals(hostBools, clientBools);
60+
61+
Assert.same(Type.ValueType.TBool, Type.typeof(clientBool0));
62+
Assert.same(Type.ValueType.TBool, Type.typeof(memberBool));
5863
}
5964

6065
function testIssue926() {

0 commit comments

Comments
 (0)