diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index 0e388f2407..1d40f87336 100755 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -414,12 +414,12 @@ FUNCTION: int ffi_test_37 ( void* func ) [ 7 ] [ callback-9 [ ffi_test_37 ] with-callback ] unit-test STRUCT: test_struct_13 -{ x1 float } -{ x2 float } -{ x3 float } -{ x4 float } -{ x5 float } -{ x6 float } ; + { x1 float } + { x2 float } + { x3 float } + { x4 float } + { x5 float } + { x6 float } ; : make-test-struct-13 ( -- alien ) test_struct_13 @@ -436,10 +436,10 @@ FUNCTION: int ffi_test_39 ( long a, long b, test_struct_13 s ) ! Joe Groff found this problem STRUCT: double-rect -{ a double } -{ b double } -{ c double } -{ d double } ; + { a double } + { b double } + { c double } + { d double } ; : ( a b c d -- foo ) double-rect @@ -934,6 +934,26 @@ FUNCTION: void* bug1021_test_1 ( void* s, int x ) ] times ] unit-test +! Varargs with non-float parameters works. +FUNCTION-ALIAS: do-sum-ints2 int ffi_test_64 ( int n, int a, int b ) +FUNCTION-ALIAS: do-sum-ints3 int ffi_test_64 ( int n, int a, int b, int c ) + +{ 30 60 } [ + 2 10 20 do-sum-ints2 + 3 10 20 30 do-sum-ints3 +] unit-test + +! Varargs with non-floats doesn't work on windows +FUNCTION-ALIAS: do-sum-doubles2 double ffi_test_65 ( int n, double a, double b ) +FUNCTION-ALIAS: do-sum-doubles3 double ffi_test_65 ( int n, double a, double b, double c ) + +os windows? [ + { 27.0 22.0 } [ + 2 7 20 do-sum-doubles2 + 3 5 10 7 do-sum-doubles3 + ] unit-test +] unless + FUNCTION: int bug1021_test_2 ( int a, char* b, void* c ) FUNCTION: void* bug1021_test_3 ( c-string a ) diff --git a/vm/ffi_test.c b/vm/ffi_test.c index 5bf0280e00..4bf5e70f3e 100644 --- a/vm/ffi_test.c +++ b/vm/ffi_test.c @@ -1,8 +1,7 @@ -/* This file is linked into the runtime for the sole purpose - * of testing FFI code. */ #include "ffi_test.h" #include +#include #include void ffi_test_0(void) {} @@ -333,6 +332,29 @@ struct ulonglong_pair ffi_test_63() { return ullp; } +int ffi_test_64(int n, ...) { + va_list ap; + va_start(ap, n); + int sum = 0; + for (int i = 0; i < n; i++) { + sum += va_arg(ap, int); + } + va_end(ap); + return sum; +} + +double ffi_test_65(int n, ...) { + va_list ap; + va_start(ap, n); + double sum = 0.0; + for (int i = 0; i < n; i++) { + sum += va_arg(ap, double); + } + va_end(ap); + return sum; +} + + void* bug1021_test_1(void* x, int y) { return (void*)(y * y + (size_t)x); } diff --git a/vm/ffi_test.h b/vm/ffi_test.h index c76cb4134c..c359811e65 100644 --- a/vm/ffi_test.h +++ b/vm/ffi_test.h @@ -229,6 +229,9 @@ struct ulonglong_pair { FACTOR_EXPORT struct ulonglong_pair ffi_test_63(); +FACTOR_EXPORT int ffi_test_64(int n, ...); +FACTOR_EXPORT double ffi_test_65(int n, ...); + FACTOR_EXPORT void* bug1021_test_1(void* x, int y); FACTOR_EXPORT int bug1021_test_2(int x, char* y, void *z); FACTOR_EXPORT void* bug1021_test_3(int x);