-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sgrekhov
committed
Feb 26, 2021
1 parent
975a228
commit 7c1b8d9
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
* for details. All rights reserved. Use of this source code is governed by a | ||
* BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
/** | ||
* @assertion Represents a native pointer-sized integer in C. | ||
* | ||
* @description Checks that this represents a native pointer-sized integer in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<IntPtr> p1 = calloc<IntPtr>(); | ||
try { | ||
Expect.equals(0, p1.value); | ||
p1.value = 42; | ||
Expect.equals(42, p1.value); | ||
p1.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p1.value = 256; | ||
Expect.equals(256, p1.value); | ||
p1.value = 32767; | ||
Expect.equals(32767, p1.value); | ||
if (sizeOf<IntPtr>() == 4) { | ||
p1.value = 32768; | ||
Expect.equals(-32768, p1.value); | ||
p1.value = -32768; | ||
Expect.equals(-32768, p1.value); | ||
p1.value = -32769; | ||
Expect.equals(32767, p1.value); | ||
} else { | ||
p1.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p1.value = -32769; | ||
Expect.equals(-32769, p1.value); | ||
} | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
* for details. All rights reserved. Use of this source code is governed by a | ||
* BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
/** | ||
* @assertion Represents a native pointer-sized integer in C. | ||
* | ||
* @description Checks that this represents a native pointer-sized integer in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<IntPtr> p1 = calloc<IntPtr>(); | ||
try { | ||
if (sizeOf<IntPtr>() == 4) { | ||
Pointer<Int32> p2 = new Pointer<Int32>.fromAddress(p1.address); | ||
p2.value = 42; | ||
Expect.equals(42, p1.value); | ||
p2.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p2.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p2.value = -32768; | ||
Expect.equals(-32768, p1.value); | ||
p2.value = 2147483647; | ||
Expect.equals(2147483647, p1.value); | ||
p2.value = 2147483648; | ||
Expect.equals(-2147483648, p1.value); | ||
p2.value = -2147483649; | ||
Expect.equals(2147483647, p1.value); | ||
} else { | ||
Pointer<Int64> p2 = new Pointer<Int64>.fromAddress(p1.address); | ||
Expect.equals(0, p1.value); | ||
p2.value = 42; | ||
Expect.equals(42, p1.value); | ||
p2.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p2.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p2.value = -32768; | ||
Expect.equals(-32768, p1.value); | ||
p2.value = 2147483648; | ||
Expect.equals(2147483648, p1.value); | ||
p2.value = -2147483649; | ||
Expect.equals(-2147483649, p1.value); | ||
p2.value = 0x7FFFFFFFFFFFFFFF; | ||
Expect.equals(9223372036854775807, p1.value); | ||
p2.value = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(-1, p1.value); | ||
p2.value = -9223372036854775808; | ||
Expect.equals(-9223372036854775808, p1.value); | ||
} | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
* for details. All rights reserved. Use of this source code is governed by a | ||
* BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
/** | ||
* @assertion Represents a native pointer-sized integer in C. | ||
* | ||
* @description Checks that this represents a native pointer-sized integer in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<IntPtr> p1 = calloc<IntPtr>(3); | ||
try { | ||
if (sizeOf<IntPtr>() == 4) { | ||
Expect.equals(4, p1.elementAt(1).address - p1.address); | ||
Expect.equals(4, p1.elementAt(2).address - p1.elementAt(1).address); | ||
} else { | ||
Expect.equals(8, p1.elementAt(1).address - p1.address); | ||
Expect.equals(8, p1.elementAt(2).address - p1.elementAt(1).address); | ||
} | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
* for details. All rights reserved. Use of this source code is governed by a | ||
* BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
/** | ||
* @assertion int sizeOf <T extends NativeType>() | ||
* Number of bytes used by native type T. | ||
* | ||
* Includes padding and alignment of structs. | ||
* | ||
* @description Checks that this function returns Number of bytes used by native | ||
* type T | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Expect.isTrue(sizeOf<IntPtr>() == 4 || sizeOf<IntPtr>() == 8); | ||
} |