NativeFunctionInfo.java

  1. package org.jruby.ext.ffi.jffi;

  2. import com.kenai.jffi.CallContextCache;
  3. import com.kenai.jffi.CallingConvention;
  4. import org.jruby.Ruby;

  5. /**
  6.  * Holds information for creating JFFI functions
  7.  */
  8. class NativeFunctionInfo {
  9.     final org.jruby.ext.ffi.Type returnType;
  10.     final org.jruby.ext.ffi.Type[] parameterTypes;
  11.     final com.kenai.jffi.Type jffiReturnType;
  12.     final com.kenai.jffi.Type[] jffiParameterTypes;
  13.     final com.kenai.jffi.CallingConvention convention;
  14.     final com.kenai.jffi.CallContext callContext;

  15.     public NativeFunctionInfo(Ruby runtime, org.jruby.ext.ffi.Type returnType,
  16.             org.jruby.ext.ffi.Type[] parameterTypes, CallingConvention convention) {
  17.         this.returnType = returnType;
  18.         this.parameterTypes = parameterTypes;
  19.         this.jffiReturnType = FFIUtil.getFFIType(returnType);
  20.         if (jffiReturnType == null) {
  21.             throw runtime.newTypeError("invalid FFI return type: " + returnType);
  22.         }

  23.         this.jffiParameterTypes = new com.kenai.jffi.Type[parameterTypes.length];
  24.         for (int i = 0; i < parameterTypes.length; ++i) {
  25.             jffiParameterTypes[i] = FFIUtil.getFFIType(parameterTypes[i]);
  26.             if (jffiParameterTypes[i] == null) {
  27.                 throw runtime.newTypeError("invalid FFI parameter type: " + parameterTypes[i]);
  28.             }
  29.         }

  30.         this.callContext = CallContextCache.getInstance().getCallContext(jffiReturnType, jffiParameterTypes, convention);
  31.         this.convention = convention;
  32.     }
  33. }