compiler.tests.alien: tests for varargs calls
parent
86274c895e
commit
00d15b66a6
|
@ -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 <struct>
|
||||
|
@ -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 } ;
|
||||
|
||||
: <double-rect> ( a b c d -- foo )
|
||||
double-rect <struct>
|
||||
|
@ -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 )
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
/* This file is linked into the runtime for the sole purpose
|
||||
* of testing FFI code. */
|
||||
#include "ffi_test.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue