Browse Source

Fix cpp.Int64 <-> haxe.Int64 roundtrip (#10101)

* [cpp] support cpp.Int64 -> haxe.Int64 round-trip. Closes #10100

* [test] add regression test for Int64 roundtrip #10100

* try not using @:structAccess and cast instead

* Guard with #if cpp || cppia

* remove #if cppia

* Disable test on cppia
George Corney 4 years ago
parent
commit
dc1fbacbb2
2 changed files with 34 additions and 1 deletions
  1. 10 1
      std/cpp/_std/haxe/Int64.hx
  2. 24 0
      tests/unit/src/unit/hxcpp_issues/Issue10100.hx

+ 10 - 1
std/cpp/_std/haxe/Int64.hx

@@ -28,7 +28,6 @@ import haxe.Int64Helper;
 @:include("cpp/Int64.h")
 @:native("cpp::Int64Struct")
 private extern class ___Int64 {
-	function get():cpp.Int64;
 
 	@:native("_hx_int64_make")
 	static function make(high:Int32, low:Int32):__Int64;
@@ -145,6 +144,16 @@ abstract Int64(__Int64) from __Int64 to __Int64 {
 		return __Int64.make(high, low);
 	}
 
+	@:to
+	#if !cppia inline #end function toInt64():cpp.Int64 {
+		return cast this;
+	}
+
+	@:from
+	static #if !cppia inline #end function ofInt64(x:cpp.Int64):Int64 {
+		return cast x;
+	}
+
 	@:from
 	public static #if !cppia inline #end function ofInt(x:Int):Int64 {
 		return __Int64.ofInt(x);

+ 24 - 0
tests/unit/src/unit/hxcpp_issues/Issue10100.hx

@@ -0,0 +1,24 @@
+package unit.hxcpp_issues;
+
+class Issue10100 extends Test {
+	#if (cpp && !cppia)
+	@:analyzer(no_optimize)
+	function test() {
+		var cpp64:cpp.Int64 = untyped __cpp__('12345678944444');
+		// https://repl.it/join/wtqnxkxc-haxiomic
+		// low 1942935740
+		// high 2874
+		var hx64:haxe.Int64 = cpp64;
+		eq(hx64.low, 1942935740);
+		eq(hx64.high, 2874);
+
+		// there and back again
+		var cpp64:cpp.Int64 = hx64;
+		eq(Std.string(cpp64), '12345678944444');
+
+		var hx64:haxe.Int64 = cpp64;
+		eq(hx64.low, 1942935740);
+		eq(hx64.high, 2874);
+	}
+	#end
+}