Merge branch 'issue-300' of github.com:twall/jna
Esse commit está contido em:
Arquivo binário não exibido.
@@ -305,6 +305,9 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
|
||||
|
||||
for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
|
||||
{
|
||||
#ifdef X86_WIN32
|
||||
if (cif->abi != FFI_STDCALL)
|
||||
#endif
|
||||
if (((*ptr)->alignment - 1) & cif->bytes)
|
||||
cif->bytes = ALIGN(cif->bytes, (*ptr)->alignment);
|
||||
cif->bytes += ALIGN((*ptr)->size, FFI_SIZEOF_ARG);
|
||||
|
||||
Arquivo executável
+42
@@ -0,0 +1,42 @@
|
||||
/* Area: ffi_call
|
||||
Purpose: Check stdcall for argument alignment (always 4) on X86_WIN32 systems.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: <twalljava@java.net> (from many_win32.c) */
|
||||
|
||||
/* { dg-do run { target i?86-*-cygwin* i?86-*-mingw* } } */
|
||||
|
||||
#include "ffitest.h"
|
||||
#include <float.h>
|
||||
|
||||
static float __attribute__((stdcall)) stdcall_align(int i1,
|
||||
double f2,
|
||||
int i3,
|
||||
double f4)
|
||||
{
|
||||
return i1+f2+i3+f4;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
ffi_type *args[4] = {&ffi_type_int, &ffi_type_double, &ffi_type_int, &ffi_type_double};
|
||||
float fa[2] = {1,2};
|
||||
int ia[2] = {1,2};
|
||||
void *values[4] = {&ia[0], &fa[0], &ia[1], &fa[1]};
|
||||
float f, ff;
|
||||
|
||||
/* Initialize the cif */
|
||||
CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 4,
|
||||
&ffi_type_float, args) == FFI_OK);
|
||||
|
||||
ff = stdcall_align(ia[0], fa[0], ia[1], fa[1]);
|
||||
|
||||
ffi_call(&cif, FFI_FN(stdcall_align), &f, values);
|
||||
|
||||
if (f - ff < FLT_EPSILON)
|
||||
printf("stdcall many arg tests ok!\n");
|
||||
else
|
||||
CHECK(0);
|
||||
exit(0);
|
||||
}
|
||||
+31
-1
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved
|
||||
/* Copyright (c) 2007-2013 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -941,6 +941,36 @@ callInt32StdCallCallback(int32_t (__stdcall *func)(int32_t arg, int32_t arg2),
|
||||
return value;
|
||||
}
|
||||
|
||||
EXPORT int32_t __stdcall
|
||||
callBugCallback(void (__stdcall *func)(long,int,double,
|
||||
const char*,const char*,
|
||||
double,long,
|
||||
double,long,long,long),
|
||||
long arg1, int arg2, double arg3,
|
||||
const char* arg4, const char* arg5,
|
||||
double arg6, long arg7,
|
||||
double arg8, long arg9,
|
||||
long arg10, long arg11) {
|
||||
void* sp1 = NULL;
|
||||
void* sp2 = NULL;
|
||||
int value = -1;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
__asm mov sp1, esp;
|
||||
(*func)(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11);
|
||||
__asm mov sp2, esp;
|
||||
#elif defined(__GNUC__)
|
||||
asm volatile (" movl %%esp,%0" : "=g" (sp1));
|
||||
(*func)(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11);
|
||||
asm volatile (" movl %%esp,%0" : "=g" (sp2));
|
||||
#endif
|
||||
|
||||
if (sp1 != sp2) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 && !_WIN64 */
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
/* Copyright (c) 2007-2014 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -23,6 +23,7 @@ import com.sun.jna.FunctionMapper;
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLibrary;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
/**
|
||||
@@ -54,6 +55,18 @@ public class W32StdCallTest extends TestCase {
|
||||
int callback(int arg, int arg2);
|
||||
}
|
||||
int callInt32StdCallCallback(Int32Callback c, int arg, int arg2);
|
||||
interface BugCallback extends StdCallCallback {
|
||||
void callback(NativeLong arg1, int arg2, double arg3,
|
||||
String arg4, String arg5,
|
||||
double arg6, NativeLong arg7,
|
||||
double arg8, NativeLong arg9,
|
||||
NativeLong arg10, NativeLong arg11);
|
||||
}
|
||||
int callBugCallback(BugCallback c, NativeLong arg1, int arg2,
|
||||
double arg3, String arg4, String arg5,
|
||||
double arg6, NativeLong arg7,
|
||||
double arg8, NativeLong arg9,
|
||||
NativeLong arg10, NativeLong arg11);
|
||||
}
|
||||
|
||||
public static void main(java.lang.String[] argList) {
|
||||
@@ -136,4 +149,27 @@ public class W32StdCallTest extends TestCase {
|
||||
}
|
||||
assertEquals("Wrong stdcall callback return", -3, value);
|
||||
}
|
||||
|
||||
public void testCallBugCallback() {
|
||||
final boolean[] called = { false };
|
||||
TestLibrary.BugCallback cb = new TestLibrary.BugCallback() {
|
||||
public void callback(NativeLong arg1, int arg2, double arg3,
|
||||
String arg4, String arg5,
|
||||
double arg6, NativeLong arg7,
|
||||
double arg8, NativeLong arg9,
|
||||
NativeLong arg10, NativeLong arg11) {
|
||||
called[0] = true;
|
||||
}
|
||||
};
|
||||
int value = testlib.callBugCallback(cb, new NativeLong(1),
|
||||
2, 3, "four", "five",
|
||||
6, new NativeLong(7),
|
||||
8, new NativeLong(9),
|
||||
new NativeLong(10),
|
||||
new NativeLong(11));
|
||||
assertTrue("stdcall callback not called", called[0]);
|
||||
if (value == -1) {
|
||||
fail("stdcall callback did not restore the stack pointer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário