Skip to content

Commit 566f531

Browse files
MeguminBOTdimensionscape
authored andcommitted
Report a cppia boolean constant as a boolean to the JIT
DataVal never overrode isBoolInt, so ArrayDef::genCode stored a constant true in an Array<Any> through varraySetInt and it read back as 1. The interpreter was never affected. HaxeFoundation/hxcpp#1371 Fixes #23
1 parent 06f7c67 commit 566f531

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎Changes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ The first libhxcpp version. It is based on hxcpp 4.3 (the changes listed under 4
195195
* Fixed cppia with HXCPP_GC_GENERATIONAL freeing young objects that an old script still used: a field set by name had no write barrier, and literals, JIT-embedded boxes and statics held by a loaded module were not traced by a generational collection (hxcpp #1408, #1406)
196196
* Fixed the cppia JIT allocating unaligned objects in the nursery, which a conservative scan could misread (hxcpp #1411)
197197
* Fixed the cppia JIT failing to load a module that converts an Int subtraction to a String, with Bad move target (hxcpp #1369)
198+
* Fixed the cppia JIT storing a Bool constant in an Array<Any> as a number (hxcpp #1371)
198199
* Added the libhxcpp define: a build that uses the library gets -D libhxcpp=<version>. Compare it with version("x.y.z"); a plain string comparison compares text
199200
* Added separate Linux ARMv7 and ARM64 build architectures (hxcpp #1355)
200201
* Fixed AndroidCompat.cpp closing its extern "C" section in the wrong place (hxcpp #1404)

‎src/hx/cppia/Cppia.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4839,6 +4839,8 @@ struct DataVal : public CppiaExprWithValue
48394839
}
48404840
const char *getName() HXCPP_OVERRIDE { return "DataVal"; }
48414841

4842+
bool isBoolInt() HXCPP_OVERRIDE { return ExprTypeIsBool<T>::value; }
4843+
48424844
ExprType getType() HXCPP_OVERRIDE { return (ExprType)ExprTypeOf<T>::value; }
48434845

48444846
bool getConstantInt(int &outValue) HXCPP_OVERRIDE

‎test/cppia/Client.hx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ class ClientJitConvert {
117117
}
118118
}
119119

120+
class ClientBoolConst {
121+
122+
public static function constToDynamic():String {
123+
var d:Dynamic = true;
124+
125+
return Std.string(d);
126+
}
127+
128+
public static function anyArrayWithConsts():Array<Any> {
129+
return [true, false];
130+
}
131+
132+
public static function anyArrayWithComparison(i:Int):Array<Any> {
133+
return [i > 1];
134+
}
135+
}
136+
120137
class Client
121138
{
122139
public static var clientBool0 = true;

‎test/cppia/cases/TestCommon.hx‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,43 @@ class TestCommon extends Test {
174174
Assert.floatEquals(3.0, callConvert('dynamicToFloatInRegister'), 'Dynamic into a float register did not answer');
175175
}
176176

177+
function callBoolConst(name:String, args:Array<Dynamic>):Dynamic {
178+
final cls = Type.resolveClass('ClientBoolConst');
179+
180+
if (!Assert.notNull(cls, 'Unable to resolve ClientBoolConst')) {
181+
return null;
182+
}
183+
184+
return Reflect.callMethod(null, Reflect.field(cls, name), args);
185+
}
186+
187+
@:depends(testStatus)
188+
function testBoolConstToDynamic() {
189+
Assert.equals('true', callBoolConst('constToDynamic', []),
190+
'Bool constant boxed as a number');
191+
}
192+
193+
@:depends(testStatus)
194+
function testBoolConstInAnyArray() {
195+
final arr:Array<Any> = callBoolConst('anyArrayWithConsts', []);
196+
197+
if (Assert.notNull(arr, 'No array returned')) {
198+
Assert.isTrue(Std.isOfType(arr[0], Bool), 'Bool constant did not store as a Bool');
199+
Assert.isTrue(Std.isOfType(arr[1], Bool), 'Bool constant did not store as a Bool');
200+
Assert.equals('true', Std.string(arr[0]), 'Bool constant stored in an Any array as a number');
201+
Assert.equals('false', Std.string(arr[1]), 'Bool constant stored in an Any array as a number');
202+
}
203+
}
204+
205+
@:depends(testStatus)
206+
function testBoolComparisonInAnyArray() {
207+
final arr:Array<Any> = callBoolConst('anyArrayWithComparison', [3]);
208+
209+
if (Assert.notNull(arr, 'No array returned')) {
210+
Assert.equals('true', Std.string(arr[0]), 'Bool comparison stored in an Any array as a number');
211+
}
212+
}
213+
177214
@:depends(testStatus)
178215
function testInterfaceCalling() {
179216
final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []);

0 commit comments

Comments
 (0)