jna unsupported datatypes but jnaerator converts them anyways #289

Closed
johnny-tc opened this Issue Mar 14, 2012 · 1 comment

Projects

None yet

2 participants

@johnny-tc

On windows, there are data types that seem to get mapped strangely (well legacy crap). Perhaps JNAerator should reject
trying to convert them with some error message (or use some sort of intrinsic knowledge if ran on a windows platform to convert them over to an int or byte respectively). The APIs that have these somewhat weird data types seem not to
work properly unless the types match up.

e.g:

typedef BOOL int; // http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx

void foo(BOOL); // maybe map to void foo(int int1);
void foo2(bool); // maybe map to void foo (byte byte1);

gets converted to this:

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.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);
    /
    *
    • Original signature : void foo(BOOL)
    • native declaration : line 4
      _/
      @Mangling({"Z3foo4BOOL", "?foo@@YAX4BOOL@Z"})
      void foo(boolean BOOL1);
      /
      *
    • Original signature : void foo2(bool)
    • native declaration : line 5
      */
      @Mangling({"_Z4foo2b", "?foo2@@YAX_N@Z"})
      void foo2(boolean bool1);
      }
@ochafik
Member
ochafik commented Mar 20, 2012

Hi @johnny-tc ,

Thanks for your report.

I've fixed the mapping of C++ bool type to byte for JNA target runtime, although this will obviously only work for functions in extern "C" blocks (or with the exact Mangling annotation).

https://github.com/twall/jna/blob/master/www/Mappings.md

Cheers

@ochafik ochafik closed this Mar 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment