ochafik/nativelibs4java — Issue #282: jnaerator seems to generate invalid stubs for the callback / library under the following code:
Author: johnny-tc
Created: 2012-03-08 00:50:55+00:00
State: open

Actual Behavior:
JNAerator takes the following when running the jnlp (or the jar directly)

void __stdcall hello();
typedef void ( __stdcall *func)(int);

and generates:

package test;
import com.ochafik.lang.jnaerator.runtime.LibraryExtractor;
import com.ochafik.lang.jnaerator.runtime.MangledFunctionMapper;
import com.ochafik.lang.jnaerator.runtime.Mangling;
import com.sun.jna.Callback;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
/**
* JNA Wrapper for library test

* This file was autogenerated by JNAerator,

* a tool written by Olivier Chafik that uses a few opensource projects..

* For help, please visit NativeLibs4Java , Rococoa, or JNA.
*/
public interface TestLibrary extends Library {
public static final String JNA_LIBRARY_NAME = LibraryExtractor.getLibraryPath("test", true, TestLibrary.class);
public static final NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance(TestLibrary.JNA_LIBRARY_NAME, MangledFunctionMapper.DEFAULT_OPTIONS);
public static final TestLibrary INSTANCE = (TestLibrary)Native.loadLibrary(TestLibrary.JNA_LIBRARY_NAME, TestLibrary.class, MangledFunctionMapper.DEFAULT_OPTIONS);
public interface func extends Callback {
void apply(int int1);
};
/**
* Original signature : __stdcall void hello()

* native declaration : line 2
*/
@Mangling({"_Z5hellov", "?hello@@YAXXZ"})
void hello();
}
}

Expected Behavior:
The interface func should probably extend StdCallLibrary.StdCallCallback and the library itself should extend StdCallLibrary.

Notes:
MSDN says this (in practice, the compiler seems to lenient with respect to the order of the return type and the extension so my hope is jnaerator would be as lenient or at least take the standard syntax):
http://msdn.microsoft.com/en-us/library/zxk0tw93%28v=vs.80%29.aspx

The impact would probably mean some really odd behavior when the stack is unwound when the callback is utilized or when the direct call is performed.
Reversing the order of the function prototype, __stdcall void hello() seems to extends the StdCallLibrary, but reversing it in the typedef does not help.