]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix bug with large structs passed by value on x86.64
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 9 Sep 2008 08:10:43 +0000 (03:10 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 9 Sep 2008 08:10:43 +0000 (03:10 -0500)
basis/compiler/generator/generator.factor
basis/compiler/tests/alien.factor
basis/cpu/architecture/architecture.factor
vm/ffi_test.c
vm/ffi_test.h

index 46be0d59625334c2b3ac34d60007abb84a0c2a3e..da120ce4320f0b4fd5d1d30fa6a8b693f8e56c40 100755 (executable)
@@ -325,12 +325,16 @@ M: single-float-regs reg-size drop 4 ;
 
 M: double-float-regs reg-size drop 8 ;
 
+M: stack-params reg-size drop "void*" heap-size ;
+
 GENERIC: reg-class-variable ( register-class -- symbol )
 
 M: reg-class reg-class-variable ;
 
 M: float-regs reg-class-variable drop float-regs ;
 
+M: stack-params reg-class-variable drop stack-params ;
+
 GENERIC: inc-reg-class ( register-class -- )
 
 M: reg-class inc-reg-class
index 18f7f67787794c6ac4cfc1e3d60d50a2a1add7e9..e44ae681ffed11f4dfec0b8fb0538335d7372be1 100755 (executable)
@@ -279,7 +279,7 @@ FUNCTION: double ffi_test_35 test-struct-11 x int y ;
 
 C-STRUCT: test-struct-12 { "int" "a" } { "double" "x" } ;
 
-: make-struct-12
+: make-struct-12 ( x -- alien )
     "test-struct-12" <c-object>
     [ set-test-struct-12-x ] keep ;
 
@@ -380,3 +380,24 @@ FUNCTION: int ffi_test_37 ( void* func ) ;
 [ 1 ] [ callback-9 ffi_test_37 ] unit-test
 
 [ 7 ] [ callback-9 ffi_test_37 ] unit-test
+
+C-STRUCT: test_struct_13
+{ "float" "x1" }
+{ "float" "x2" }
+{ "float" "x3" }
+{ "float" "x4" }
+{ "float" "x5" }
+{ "float" "x6" } ;
+
+: make-test-struct-13 ( -- alien )
+    "test_struct_13" <c-object>
+        1.0 over set-test_struct_13-x1
+        2.0 over set-test_struct_13-x2
+        3.0 over set-test_struct_13-x3
+        4.0 over set-test_struct_13-x4
+        5.0 over set-test_struct_13-x5
+        6.0 over set-test_struct_13-x6 ;
+
+FUNCTION: int ffi_test_39 ( long a, long b, test_struct_13 s ) ;
+
+[ 21 ] [ 12347 12347 make-test-struct-13 ffi_test_39 ] unit-test
index d15c5a30ab1fd2aef0111f0af4c55d788a23bd11..fc11e0a7317b89de4e15496efd51daa7d244552e 100755 (executable)
@@ -150,6 +150,8 @@ HOOK: %alien-indirect cpu ( -- )
 
 M: stack-params param-reg drop ;
 
+M: stack-params param-regs drop f ;
+
 GENERIC: v>operand ( obj -- operand )
 
 M: integer v>operand tag-fixnum ;
index 5cdfbb2a9e3e131a98b9875850c9c2be3ff5cccc..44a14f21f579f29bf72c7ff1544ce58a673c8262 100755 (executable)
@@ -274,4 +274,9 @@ unsigned long long ffi_test_38(unsigned long long x, unsigned long long y)
        return x * y;
 }
 
-
+int ffi_test_39(long a, long b, struct test_struct_13 s)
+{
+       printf("ffi_test_39(%ld,%ld,%f,%f,%f,%f,%f,%f)\n",a,b,s.x1,s.x2,s.x3,s.x4,s.x5,s.x6);
+       if(a != b) abort();
+       return s.x1 + s.x2 + s.x3 + s.x4 + s.x5 + s.x6;
+}
index 0f51092d25036b19fbc6d1cabfa4198c7d0b7a2e..779cb978570b1ca32bed4d05bcdd7f42f6c1ff8c 100755 (executable)
@@ -67,3 +67,7 @@ DLLEXPORT void ffi_test_36_point_5(void);
 DLLEXPORT int ffi_test_37(int (*f)(int, int, int));
 
 DLLEXPORT unsigned long long ffi_test_38(unsigned long long x, unsigned long long y);
+
+struct test_struct_13 { float x1, x2, x3, x4, x5, x6; };
+
+DLLEXPORT int ffi_test_39(long a, long b, struct test_struct_13 s);