@Override public boolean equals(Object obj) { return obj instanceof Member && ((Member) obj).offset == offset && type.equals(((Member) obj).type); }
/** * Initializes a new <tt>Type</tt> instance. */ protected Type(Ruby runtime, RubyClass klass, NativeType type) { super(runtime, klass); this.nativeType = type; this.size = getNativeSize(type); this.alignment = getNativeAlignment(type); }
public static final NativeType valueOf(IRubyObject type) { if (type instanceof Type) { return ((Type) type).getNativeType(); } else { return NativeType.VOID; } } }
/** * 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 ParameterMarshaller getEnumMarshaller(Type type, CallingConvention convention, IRubyObject enums) { if (!(enums instanceof RubyHash)) { throw type.getRuntime().newArgumentError("wrong argument type " + enums.getMetaClass().getName() + " (expected Hash)"); } NativeDataConverter converter = DataConverters.getParameterConverter(type, (RubyHash) enums); ParameterMarshaller marshaller = getMarshaller(type.getNativeType()); return converter != null ? new ConvertingMarshaller(marshaller, converter) : marshaller; }
private static com.kenai.jffi.Type cacheFFIType(Type type) { Object ffiType; synchronized (type) { if ((ffiType = type.getFFIHandle()) instanceof com.kenai.jffi.Type) { return (com.kenai.jffi.Type) ffiType; } if (type instanceof Type.Builtin || type instanceof CallbackInfo) { ffiType = FFIUtil.getFFIType(type.getNativeType()); } else if (type instanceof org.jruby.ext.ffi.StructLayout) { ffiType = FFIUtil.newStruct((org.jruby.ext.ffi.StructLayout) type); } else if (type instanceof org.jruby.ext.ffi.StructByValue) { ffiType = FFIUtil.newStruct(((org.jruby.ext.ffi.StructByValue) type).getStructLayout()); } else if (type instanceof org.jruby.ext.ffi.Type.Array) { ffiType = FFIUtil.newArray((org.jruby.ext.ffi.Type.Array) type); } else if (type instanceof org.jruby.ext.ffi.MappedType) { ffiType = FFIUtil.getFFIType(((org.jruby.ext.ffi.MappedType) type).getRealType()); } else { return null; } type.setFFIHandle(ffiType); } return (com.kenai.jffi.Type) ffiType; }
@Override public int hashCode() { return 53 * 5 + this.offset + 37 * type.hashCode(); }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { // Read an int from the native memory, then upcall to the ruby value // lookup code to convert it to the appropriate symbol return m.type.callMethod(context, "find", op.get(context, ptr, m.offset)); }
/** * Gets the native alignment of this <tt>Type</tt> in bytes * * @param context The Ruby thread context. * @return The native alignment of this Type. */ @JRubyMethod(name = "alignment") public IRubyObject alignment(ThreadContext context) { return context.runtime.newFixnum(getNativeAlignment()); }
/** * Gets the native size of this <tt>Type</tt> in bytes * * @param context The Ruby thread context. * @return The native size of this Type. */ @JRubyMethod(name = "size") public IRubyObject size(ThreadContext context) { return context.runtime.newFixnum(getNativeSize()); }
static final com.kenai.jffi.Type getFFIType(Type type) { Object jffiType; if ((jffiType = type.getFFIHandle()) instanceof com.kenai.jffi.Type) { return (com.kenai.jffi.Type) jffiType; } return cacheFFIType(type); }
defineBuiltinType(runtime, builtinClass, NativeType.CHAR, "char", "schar", "int8", "sint8"); defineBuiltinType(runtime, builtinClass, NativeType.UCHAR, "uchar", "uint8"); defineBuiltinType(runtime, builtinClass, NativeType.SHORT, "short", "sshort", "int16", "sint16"); defineBuiltinType(runtime, builtinClass, NativeType.USHORT, "ushort", "uint16"); defineBuiltinType(runtime, builtinClass, NativeType.INT, "int", "sint", "int32", "sint32"); defineBuiltinType(runtime, builtinClass, NativeType.UINT, "uint", "uint32"); defineBuiltinType(runtime, builtinClass, NativeType.LONG_LONG, "long_long", "slong_long", "int64", "sint64"); defineBuiltinType(runtime, builtinClass, NativeType.ULONG_LONG, "ulong_long", "uint64"); defineBuiltinType(runtime, builtinClass, NativeType.LONG, "long", "slong"); defineBuiltinType(runtime, builtinClass, NativeType.ULONG, "ulong"); defineBuiltinType(runtime, builtinClass, NativeType.FLOAT, "float", "float32"); defineBuiltinType(runtime, builtinClass, NativeType.DOUBLE, "double", "float64");
synchronized (ffi) { if (ffi.getClass("Type") == null) { Type.createTypeClass(runtime, ffi);
/** * 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 ParameterMarshaller getEnumMarshaller(Type type, CallingConvention convention, IRubyObject enums) { if (!(enums instanceof RubyHash)) { throw type.getRuntime().newArgumentError("wrong argument type " + enums.getMetaClass().getName() + " (expected Hash)"); } NativeDataConverter converter = DataConverters.getParameterConverter(type, (RubyHash) enums); ParameterMarshaller marshaller = getMarshaller(type.getNativeType()); return converter != null ? new ConvertingMarshaller(marshaller, converter) : marshaller; }
private static com.kenai.jffi.Type cacheFFIType(Type type) { Object ffiType; synchronized (type) { if ((ffiType = type.getFFIHandle()) instanceof com.kenai.jffi.Type) { return (com.kenai.jffi.Type) ffiType; } if (type instanceof Type.Builtin || type instanceof CallbackInfo) { ffiType = FFIUtil.getFFIType(type.getNativeType()); } else if (type instanceof org.jruby.ext.ffi.StructLayout) { ffiType = FFIUtil.newStruct((org.jruby.ext.ffi.StructLayout) type); } else if (type instanceof org.jruby.ext.ffi.StructByValue) { ffiType = FFIUtil.newStruct(((org.jruby.ext.ffi.StructByValue) type).getStructLayout()); } else if (type instanceof org.jruby.ext.ffi.Type.Array) { ffiType = FFIUtil.newArray((org.jruby.ext.ffi.Type.Array) type); } else if (type instanceof org.jruby.ext.ffi.MappedType) { ffiType = FFIUtil.getFFIType(((org.jruby.ext.ffi.MappedType) type).getRealType()); } else { return null; } type.setFFIHandle(ffiType); } return (com.kenai.jffi.Type) ffiType; }
@Override public int hashCode() { return 53 * 5 + (int) (this.offset ^ (this.offset >>> 32)) + 37 * type.hashCode(); }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { // Read an int from the native memory, then upcall to the ruby value // lookup code to convert it to the appropriate symbol return m.type.callMethod(context, "find", op.get(context, ptr, m.offset)); }
/** * Gets the native alignment of this <tt>Type</tt> in bytes * * @param context The Ruby thread context. * @return The native alignment of this Type. */ @JRubyMethod(name = "alignment") public IRubyObject alignment(ThreadContext context) { return context.runtime.newFixnum(getNativeAlignment()); }
/** * Gets the native size of this <tt>Type</tt> in bytes * * @param context The Ruby thread context. * @return The native size of this Type. */ @JRubyMethod(name = "size") public IRubyObject size(ThreadContext context) { return context.runtime.newFixnum(getNativeSize()); }
static final com.kenai.jffi.Type getFFIType(Type type) { Object jffiType; if ((jffiType = type.getFFIHandle()) instanceof com.kenai.jffi.Type) { return (com.kenai.jffi.Type) jffiType; } return cacheFFIType(type); }
defineBuiltinType(runtime, builtinClass, NativeType.CHAR, "char", "schar", "int8", "sint8"); defineBuiltinType(runtime, builtinClass, NativeType.UCHAR, "uchar", "uint8"); defineBuiltinType(runtime, builtinClass, NativeType.SHORT, "short", "sshort", "int16", "sint16"); defineBuiltinType(runtime, builtinClass, NativeType.USHORT, "ushort", "uint16"); defineBuiltinType(runtime, builtinClass, NativeType.INT, "int", "sint", "int32", "sint32"); defineBuiltinType(runtime, builtinClass, NativeType.UINT, "uint", "uint32"); defineBuiltinType(runtime, builtinClass, NativeType.LONG_LONG, "long_long", "slong_long", "int64", "sint64"); defineBuiltinType(runtime, builtinClass, NativeType.ULONG_LONG, "ulong_long", "uint64"); defineBuiltinType(runtime, builtinClass, NativeType.LONG, "long", "slong"); defineBuiltinType(runtime, builtinClass, NativeType.ULONG, "ulong"); defineBuiltinType(runtime, builtinClass, NativeType.FLOAT, "float", "float32"); defineBuiltinType(runtime, builtinClass, NativeType.DOUBLE, "double", "float64");