Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ef0c7f1

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[vm/ffi] Do not use int in tests
sizeof(int) on iOS arm64 in Flutter test projects returns 4. Issue: dart-lang/sdk#36140 Issue: dart-lang/sdk#39637 Change-Id: I7b471fa1da653e9bee169c34d1bd36a96fa6a704 Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132607 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
1 parent f910a75 commit ef0c7f1

File tree

3 files changed

+88
-88
lines changed

3 files changed

+88
-88
lines changed

runtime/bin/ffi_test/ffi_test_dynamic_library.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
extern "C" __attribute__((visibility("default"))) __attribute((used))
1414
#endif
1515

16-
DART_EXPORT int return42() {
16+
DART_EXPORT intptr_t return42() {
1717
return 42;
1818
}
1919

runtime/bin/ffi_test/ffi_test_functions.cc

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ DART_EXPORT int64_t UintComputation(uint8_t a,
199199
return retval;
200200
}
201201

202-
// Multiplies pointer sized int by three.
202+
// Multiplies pointer sized intptr_t by three.
203203
// Used for testing pointer sized parameter and return value.
204204
DART_EXPORT intptr_t Times3(intptr_t a) {
205205
std::cout << "Times3(" << a << ")\n";
@@ -317,25 +317,25 @@ DART_EXPORT double SumManyDoubles(double a,
317317
// Sums many numbers.
318318
// Used for testing calling conventions. With so many parameters we are using
319319
// both registers and stack slots.
320-
DART_EXPORT double SumManyNumbers(int a,
320+
DART_EXPORT double SumManyNumbers(intptr_t a,
321321
float b,
322-
int c,
322+
intptr_t c,
323323
double d,
324-
int e,
324+
intptr_t e,
325325
float f,
326-
int g,
326+
intptr_t g,
327327
double h,
328-
int i,
328+
intptr_t i,
329329
float j,
330-
int k,
330+
intptr_t k,
331331
double l,
332-
int m,
332+
intptr_t m,
333333
float n,
334-
int o,
334+
intptr_t o,
335335
double p,
336-
int q,
336+
intptr_t q,
337337
float r,
338-
int s,
338+
intptr_t s,
339339
double t) {
340340
std::cout << "SumManyNumbers(" << a << ", " << b << ", " << c << ", " << d
341341
<< ", " << e << ", " << f << ", " << g << ", " << h << ", " << i
@@ -532,7 +532,7 @@ DART_EXPORT int64_t SumVeryLargeStruct(VeryLargeStruct* vls) {
532532
retval += vls->parent->a;
533533
}
534534
std::cout << "has " << vls->numChildren << " children\n";
535-
for (int i = 0; i < vls->numChildren; i++) {
535+
for (intptr_t i = 0; i < vls->numChildren; i++) {
536536
retval += vls->children[i].a;
537537
}
538538
std::cout << "returning " << retval << "\n";
@@ -577,7 +577,7 @@ DART_EXPORT void DevNullFloat(float a) {
577577
std::cout << "returning nothing\n";
578578
}
579579

580-
// Invents an elite floating point number.
580+
// Invents an elite floating pointptr_t number.
581581
// Used for testing functions that do not take any arguments.
582582
DART_EXPORT float InventFloatValue() {
583583
std::cout << "InventFloatValue()\n";
@@ -590,95 +590,95 @@ DART_EXPORT float InventFloatValue() {
590590
// Tests for callbacks.
591591

592592
// Sanity test.
593-
DART_EXPORT int TestSimpleAddition(int (*add)(int, int)) {
593+
DART_EXPORT intptr_t TestSimpleAddition(intptr_t (*add)(int, int)) {
594594
CHECK_EQ(add(10, 20), 30);
595595
return 0;
596596
}
597597

598598
//// Following tests are copied from above, with the role of Dart and C++ code
599599
//// reversed.
600600

601-
DART_EXPORT int TestIntComputation(
602-
int64_t (*fn)(int8_t, int16_t, int32_t, int64_t)) {
601+
DART_EXPORT intptr_t
602+
TestIntComputation(int64_t (*fn)(int8_t, int16_t, int32_t, int64_t)) {
603603
CHECK_EQ(fn(125, 250, 500, 1000), 625);
604604
CHECK_EQ(0x7FFFFFFFFFFFFFFFLL, fn(0, 0, 0, 0x7FFFFFFFFFFFFFFFLL));
605605
CHECK_EQ(((int64_t)-0x8000000000000000LL),
606606
fn(0, 0, 0, -0x8000000000000000LL));
607607
return 0;
608608
}
609609

610-
DART_EXPORT int TestUintComputation(
611-
uint64_t (*fn)(uint8_t, uint16_t, uint32_t, uint64_t)) {
610+
DART_EXPORT intptr_t
611+
TestUintComputation(uint64_t (*fn)(uint8_t, uint16_t, uint32_t, uint64_t)) {
612612
CHECK_EQ(0x7FFFFFFFFFFFFFFFLL, fn(0, 0, 0, 0x7FFFFFFFFFFFFFFFLL));
613613
CHECK_EQ(-0x8000000000000000LL, fn(0, 0, 0, -0x8000000000000000LL));
614614
CHECK_EQ(-1, (int64_t)fn(0, 0, 0, -1));
615615
return 0;
616616
}
617617

618-
DART_EXPORT int TestSimpleMultiply(double (*fn)(double)) {
618+
DART_EXPORT intptr_t TestSimpleMultiply(double (*fn)(double)) {
619619
CHECK_EQ(fn(2.0), 2.0 * 1.337);
620620
return 0;
621621
}
622622

623-
DART_EXPORT int TestSimpleMultiplyFloat(float (*fn)(float)) {
623+
DART_EXPORT intptr_t TestSimpleMultiplyFloat(float (*fn)(float)) {
624624
CHECK(::std::abs(fn(2.0) - 2.0 * 1.337) < 0.001);
625625
return 0;
626626
}
627627

628-
DART_EXPORT int TestManyInts(intptr_t (*fn)(intptr_t,
629-
intptr_t,
630-
intptr_t,
631-
intptr_t,
632-
intptr_t,
633-
intptr_t,
634-
intptr_t,
635-
intptr_t,
636-
intptr_t,
637-
intptr_t)) {
628+
DART_EXPORT intptr_t TestManyInts(intptr_t (*fn)(intptr_t,
629+
intptr_t,
630+
intptr_t,
631+
intptr_t,
632+
intptr_t,
633+
intptr_t,
634+
intptr_t,
635+
intptr_t,
636+
intptr_t,
637+
intptr_t)) {
638638
CHECK_EQ(55, fn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
639639
return 0;
640640
}
641641

642-
DART_EXPORT int TestManyDoubles(double (*fn)(double,
643-
double,
644-
double,
645-
double,
646-
double,
647-
double,
648-
double,
649-
double,
650-
double,
651-
double)) {
642+
DART_EXPORT intptr_t TestManyDoubles(double (*fn)(double,
643+
double,
644+
double,
645+
double,
646+
double,
647+
double,
648+
double,
649+
double,
650+
double,
651+
double)) {
652652
CHECK_EQ(55, fn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
653653
return 0;
654654
}
655655

656-
DART_EXPORT int TestManyArgs(double (*fn)(intptr_t a,
657-
float b,
658-
intptr_t c,
659-
double d,
660-
intptr_t e,
661-
float f,
662-
intptr_t g,
663-
double h,
664-
intptr_t i,
665-
float j,
666-
intptr_t k,
667-
double l,
668-
intptr_t m,
669-
float n,
670-
intptr_t o,
671-
double p,
672-
intptr_t q,
673-
float r,
674-
intptr_t s,
675-
double t)) {
656+
DART_EXPORT intptr_t TestManyArgs(double (*fn)(intptr_t a,
657+
float b,
658+
intptr_t c,
659+
double d,
660+
intptr_t e,
661+
float f,
662+
intptr_t g,
663+
double h,
664+
intptr_t i,
665+
float j,
666+
intptr_t k,
667+
double l,
668+
intptr_t m,
669+
float n,
670+
intptr_t o,
671+
double p,
672+
intptr_t q,
673+
float r,
674+
intptr_t s,
675+
double t)) {
676676
CHECK(210.0 == fn(1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9, 10.0, 11, 12.0, 13, 14.0,
677677
15, 16.0, 17, 18.0, 19, 20.0));
678678
return 0;
679679
}
680680

681-
DART_EXPORT int TestStore(int64_t* (*fn)(int64_t* a)) {
681+
DART_EXPORT intptr_t TestStore(int64_t* (*fn)(int64_t* a)) {
682682
int64_t p[2] = {42, 1000};
683683
int64_t* result = fn(p);
684684
CHECK_EQ(*result, 1337);
@@ -687,56 +687,56 @@ DART_EXPORT int TestStore(int64_t* (*fn)(int64_t* a)) {
687687
return 0;
688688
}
689689

690-
DART_EXPORT int TestReturnNull(int32_t (*fn)()) {
690+
DART_EXPORT intptr_t TestReturnNull(int32_t (*fn)()) {
691691
CHECK_EQ(fn(), 42);
692692
return 0;
693693
}
694694

695-
DART_EXPORT int TestNullPointers(int64_t* (*fn)(int64_t* ptr)) {
695+
DART_EXPORT intptr_t TestNullPointers(int64_t* (*fn)(int64_t* ptr)) {
696696
CHECK_EQ(fn(nullptr), reinterpret_cast<void*>(sizeof(int64_t)));
697697
int64_t p[2] = {0};
698698
CHECK_EQ(fn(p), p + 1);
699699
return 0;
700700
}
701701

702-
DART_EXPORT int TestReturnVoid(int (*return_void)()) {
702+
DART_EXPORT intptr_t TestReturnVoid(intptr_t (*return_void)()) {
703703
CHECK_EQ(return_void(), 0);
704704
return 0;
705705
}
706706

707-
DART_EXPORT int TestThrowExceptionDouble(double (*fn)()) {
707+
DART_EXPORT intptr_t TestThrowExceptionDouble(double (*fn)()) {
708708
CHECK_EQ(fn(), 42.0);
709709
return 0;
710710
}
711711

712-
DART_EXPORT int TestThrowExceptionPointer(void* (*fn)()) {
712+
DART_EXPORT intptr_t TestThrowExceptionPointer(void* (*fn)()) {
713713
CHECK_EQ(fn(), nullptr);
714714
return 0;
715715
}
716716

717-
DART_EXPORT int TestThrowException(int (*fn)()) {
717+
DART_EXPORT intptr_t TestThrowException(intptr_t (*fn)()) {
718718
CHECK_EQ(fn(), 42);
719719
return 0;
720720
}
721721

722-
DART_EXPORT int TestTakeMaxUint8x10(intptr_t (*fn)(uint8_t,
723-
uint8_t,
724-
uint8_t,
725-
uint8_t,
726-
uint8_t,
727-
uint8_t,
728-
uint8_t,
729-
uint8_t,
730-
uint8_t,
731-
uint8_t)) {
722+
DART_EXPORT intptr_t TestTakeMaxUint8x10(intptr_t (*fn)(uint8_t,
723+
uint8_t,
724+
uint8_t,
725+
uint8_t,
726+
uint8_t,
727+
uint8_t,
728+
uint8_t,
729+
uint8_t,
730+
uint8_t,
731+
uint8_t)) {
732732
CHECK_EQ(1, fn(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF));
733733
// Check the argument values are properly truncated.
734734
uint64_t v = 0xabcFF;
735735
CHECK_EQ(1, fn(v, v, v, v, v, v, v, v, v, v));
736736
return 0;
737737
}
738738

739-
DART_EXPORT int TestReturnMaxUint8(uint8_t (*fn)()) {
739+
DART_EXPORT intptr_t TestReturnMaxUint8(uint8_t (*fn)()) {
740740
std::cout << "TestReturnMaxUint8(fn): " << static_cast<int>(fn()) << "\n";
741741
CHECK_EQ(0xFF, fn());
742742
return 0;

runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ void ClobberAndCall(void (*fn)()) {
172172
extern "C" void ClobberAndCall(void (*fn)());
173173
#endif
174174

175-
DART_EXPORT int TestGC(void (*do_gc)()) {
175+
DART_EXPORT intptr_t TestGC(void (*do_gc)()) {
176176
ClobberAndCall(do_gc);
177177
return 0;
178178
}
179179

180180
struct CallbackTestData {
181-
int success;
181+
intptr_t success;
182182
void (*callback)();
183183
};
184184

@@ -189,11 +189,11 @@ void CallbackTestSignalHandler(int) {
189189
siglongjmp(buf, 1);
190190
}
191191

192-
int ExpectAbort(void (*fn)()) {
192+
intptr_t ExpectAbort(void (*fn)()) {
193193
fprintf(stderr, "**** EXPECT STACKTRACE TO FOLLOW. THIS IS OK. ****\n");
194194

195195
struct sigaction old_action = {};
196-
int result = __sigsetjmp(buf, /*savesigs=*/1);
196+
intptr_t result = __sigsetjmp(buf, /*savesigs=*/1);
197197
if (result == 0) {
198198
// Install signal handler.
199199
struct sigaction handler = {};
@@ -219,10 +219,10 @@ void* TestCallbackOnThreadOutsideIsolate(void* parameter) {
219219
return NULL;
220220
}
221221

222-
int TestCallbackOtherThreadHelper(void* (*tester)(void*), void (*fn)()) {
222+
intptr_t TestCallbackOtherThreadHelper(void* (*tester)(void*), void (*fn)()) {
223223
CallbackTestData data = {1, fn};
224224
pthread_attr_t attr;
225-
int result = pthread_attr_init(&attr);
225+
intptr_t result = pthread_attr_init(&attr);
226226
CHECK_EQ(result, 0);
227227

228228
pthread_t tid;
@@ -241,13 +241,13 @@ int TestCallbackOtherThreadHelper(void* (*tester)(void*), void (*fn)()) {
241241
}
242242

243243
// Run a callback on another thread and verify that it triggers SIGABRT.
244-
DART_EXPORT int TestCallbackWrongThread(void (*fn)()) {
244+
DART_EXPORT intptr_t TestCallbackWrongThread(void (*fn)()) {
245245
return TestCallbackOtherThreadHelper(&TestCallbackOnThreadOutsideIsolate, fn);
246246
}
247247

248248
// Verify that we get SIGABRT when invoking a native callback outside an
249249
// isolate.
250-
DART_EXPORT int TestCallbackOutsideIsolate(void (*fn)()) {
250+
DART_EXPORT intptr_t TestCallbackOutsideIsolate(void (*fn)()) {
251251
Dart_Isolate current = Dart_CurrentIsolate();
252252

253253
Dart_ExitIsolate();
@@ -258,7 +258,7 @@ DART_EXPORT int TestCallbackOutsideIsolate(void (*fn)()) {
258258
return data.success;
259259
}
260260

261-
DART_EXPORT int TestCallbackWrongIsolate(void (*fn)()) {
261+
DART_EXPORT intptr_t TestCallbackWrongIsolate(void (*fn)()) {
262262
return ExpectAbort(fn);
263263
}
264264

0 commit comments

Comments
 (0)