Permalink
Browse files

Synchronize changes between libtest and spec/ffi/fixtures directories.

  • Loading branch information...
1 parent 7c509bb commit 71687cb91e4174307c087ed6ffac938a974f6f4f @larskanis larskanis committed with larskanis Aug 5, 2015
Showing with 66 additions and 2 deletions.
  1. +37 −0 libtest/VariadicTest.c
  2. +15 −0 spec/ffi/fixtures/ClosureTest.c
  3. +14 −2 spec/ffi/fixtures/FunctionTest.c
@@ -60,3 +60,40 @@ void pack_varargs(s64* buf, const char* fmt, ...)
va_end(ap);
}
+int pack_varargs2(s64* buf, int retval, const char* fmt, ...)
+{
+ va_list ap;
+ int c;
+ double d;
+ va_start(ap, fmt);
+ while ((c = *fmt++)) {
+ switch (c) {
+ case 'c':
+ case 's':
+ case 'i':
+ *buf++ = va_arg(ap, s32);
+ break;
+ case 'l':
+ *buf++ = va_arg(ap, long);
+ break;
+ case 'j':
+ *buf++ = va_arg(ap, s64);
+ break;
+ case 'f':
+ case 'd':
+ d = va_arg(ap, double);
+ memcpy(buf++, &d, sizeof(d));
+ break;
+ case 'C':
+ case 'S':
+ case 'I':
+ *buf++ = va_arg(ap, u32);
+ break;
+ case 'L':
+ *buf++ = va_arg(ap, unsigned long);
+ break;
+ }
+ }
+ va_end(ap);
+ return retval + 1;
+}
@@ -50,6 +50,21 @@ P(D, double);
P(P, const void*);
P(UL, unsigned long);
+#if defined(_WIN32) && !defined(_WIN64)
+bool __stdcall testClosureStdcall(long *a1, void __stdcall(*closure)(void *, long), long a2) { \
+ void* sp_pre;
+ void* sp_post;
+
+ asm volatile (" movl %%esp,%0" : "=g" (sp_pre));
+ (*closure)(a1, a2);
+ asm volatile (" movl %%esp,%0" : "=g" (sp_post));
+
+ /* %esp before pushing parameters on the stack and after the call returns
+ * should be equal, if both sides respects the stdcall convention */
+ return sp_pre == sp_post;
+}
+#endif
+
void testOptionalClosureBrV(void (*closure)(char), char a1)
{
if (closure) {
@@ -6,7 +6,7 @@
#ifdef _WIN32
#include <windows.h>
-#define sleep(x) Sleep(x)
+#define sleep(x) Sleep((x)*1000)
#endif
#ifndef _WIN32
@@ -55,4 +55,16 @@ void testAsyncCallback(void (*fn)(int), int value)
#else
(*fn)(value);
#endif
-}
+}
+
+#if defined(_WIN32) && !defined(_WIN64)
+struct StructUCDP {
+ unsigned char a1;
+ double a2;
+ void *a3;
+};
+
+void __stdcall testStdcallManyParams(long *a1, char a2, short int a3, int a4, __int64 a5,
+ struct StructUCDP a6, struct StructUCDP *a7, float a8, double a9) {
+}
+#endif

0 comments on commit 71687cb

Please sign in to comment.