Ejemplo n.º 1
0
 static FunctionInvoker getFunctionInvoker(Type returnType) {
   if (returnType instanceof Type.Builtin) {
     return getFunctionInvoker(returnType.getNativeType());
   } else if (returnType instanceof CallbackInfo) {
     return new CallbackInvoker((CallbackInfo) returnType);
   } else if (returnType instanceof org.jruby.ext.ffi.Enum) {
     return new EnumInvoker((org.jruby.ext.ffi.Enum) returnType);
   } else if (returnType instanceof StructByValue) {
     return new StructByValueInvoker((StructByValue) returnType);
   }
   throw returnType.getRuntime().newArgumentError("Cannot get FunctionInvoker for " + returnType);
 }
Ejemplo n.º 2
0
 /**
  * Gets a marshaller to convert from a ruby type to a native type.
  *
  * @param type The native type to convert to.
  * @return A new <tt>Marshaller</tt>
  */
 static final ParameterMarshaller getMarshaller(
     Type type, CallingConvention convention, IRubyObject enums) {
   if (type instanceof Type.Builtin) {
     return enums != null && !enums.isNil()
         ? getEnumMarshaller(type, enums)
         : getMarshaller(type.getNativeType());
   } else if (type instanceof org.jruby.ext.ffi.CallbackInfo) {
     return new CallbackMarshaller((org.jruby.ext.ffi.CallbackInfo) type, convention);
   } else if (type instanceof org.jruby.ext.ffi.Enum) {
     return getEnumMarshaller(
         type, type.callMethod(type.getRuntime().getCurrentContext(), "to_hash"));
   } else if (type instanceof org.jruby.ext.ffi.StructByValue) {
     return StructByValueMarshaller.INSTANCE;
   } else {
     return null;
   }
 }
Ejemplo n.º 3
0
 /**
  * Gets a marshaller to convert from a ruby type to a native type.
  *
  * @param type The native type to convert to.
  * @param enums The enum map
  * @return A new <tt>ParameterMarshaller</tt>
  */
 static final ParameterMarshaller getEnumMarshaller(Type type, IRubyObject enums) {
   switch (type.getNativeType()) {
     case INT8:
     case UINT8:
     case INT16:
     case UINT16:
     case INT32:
     case UINT32:
     case INT64:
     case UINT64:
       if (!(enums instanceof RubyHash)) {
         throw type.getRuntime()
             .newArgumentError(
                 "wrong argument type " + enums.getMetaClass().getName() + " (expected Hash)");
       }
       return new EnumMarshaller(getMarshaller(type.getNativeType()), (RubyHash) enums);
     default:
       return getMarshaller(type.getNativeType());
   }
 }
Ejemplo n.º 4
0
 final boolean isFastIntParam(Type paramType) {
   if (paramType instanceof Type.Builtin) {
     switch (paramType.getNativeType()) {
       case CHAR:
       case UCHAR:
       case SHORT:
       case USHORT:
       case INT:
       case UINT:
       case BOOL:
         //                case FLOAT:
         return true;
       case LONG:
       case ULONG:
         return Platform.getPlatform().longSize() == 32;
     }
   }
   return false;
 }
Ejemplo n.º 5
0
  static boolean isEnumConversionRequired(Type type, Enums enums) {
    if (type instanceof Type.Builtin && enums != null && !enums.isEmpty()) {
      switch (type.getNativeType()) {
        case CHAR:
        case UCHAR:
        case SHORT:
        case USHORT:
        case INT:
        case UINT:
        case LONG:
        case ULONG:
        case LONG_LONG:
        case ULONG_LONG:
          return true;

        default:
          return false;
      }
    }
    return false;
  }
Ejemplo n.º 6
0
 final boolean isFastIntResult(Type type) {
   if (type instanceof Type.Builtin) {
     switch (type.getNativeType()) {
       case VOID:
       case CHAR:
       case UCHAR:
       case SHORT:
       case USHORT:
       case INT:
       case UINT:
       case BOOL:
         return true;
       case POINTER:
       case STRING:
         return Platform.getPlatform().addressSize() == 32;
       case LONG:
       case ULONG:
         return Platform.getPlatform().longSize() == 32;
     }
   }
   return false;
 }
Ejemplo n.º 7
0
 final IntResultConverter getIntResultConverter(Type type) {
   return type instanceof Type.Builtin ? getIntResultConverter(type.getNativeType()) : null;
 }