/** * Registers FFI ruby classes/modules * * @param module the module to register the classes under */ public void init(Ruby runtime, RubyModule ffi) { synchronized (ffi) { if (ffi.getClass("Type") == null) { Type.createTypeClass(runtime, ffi); } DataConverter.createDataConverterModule(runtime, ffi); if (ffi.getClass(AbstractMemory.ABSTRACT_MEMORY_RUBY_CLASS) == null) { AbstractMemory.createAbstractMemoryClass(runtime, ffi); } if (ffi.getClass("Buffer") == null) { Buffer.createBufferClass(runtime, ffi); } if (ffi.getClass("Pointer") == null) { Pointer.createPointerClass(runtime, ffi); } if (ffi.getClass("AutoPointer") == null) { AutoPointer.createAutoPointerClass(runtime, ffi); } if (ffi.getClass("MemoryPointer") == null) { MemoryPointer.createMemoryPointerClass(runtime, ffi); } if (ffi.getClass("Struct") == null) { Struct.createStructClass(runtime, ffi); } if (ffi.getClass(StructLayout.CLASS_NAME) == null) { StructLayout.createStructLayoutClass(runtime, ffi); } if (ffi.getClass("StructByValue") == null) { StructByValue.createStructByValueClass(runtime, ffi); } if (ffi.getClass(AbstractInvoker.CLASS_NAME) == null) { AbstractInvoker.createAbstractInvokerClass(runtime, ffi); } if (ffi.getClass(CallbackInfo.CLASS_NAME) == null) { CallbackInfo.createCallbackInfoClass(runtime, ffi); } if (ffi.getClass("Enum") == null) { Enum.createEnumClass(runtime, ffi); } if (ffi.getClass("Type").getClass("Mapped") == null) { MappedType.createConverterTypeClass(runtime, ffi); } if (ffi.getClass(FileDescriptorIO.CLASS_NAME) == null) { FileDescriptorIO.createFileDescriptorIOClass(runtime, ffi); } ffi.setConstant("TypeDefs", RubyHash.newHash(runtime)); Platform.createPlatformModule(runtime, ffi); IOModule.createIOModule(runtime, ffi); StructByReference.createStructByReferenceClass(runtime, ffi); } }
public void put( ThreadContext context, Storage cache, Member m, IRubyObject ptr, IRubyObject value) { final IRubyObject nativeValue = mappedType.toNative(context, value); nativeFieldIO.put(context, cache, m, ptr, nativeValue); if (isValueReferenceNeeded()) { // keep references to both the ruby and native values to preserve // reference chains cache.putReference(m, new Object[] {value, nativeValue}); } }
public final IRubyObject get(ThreadContext context, Storage cache, Member m, IRubyObject ptr) { return mappedType.fromNative(context, nativeFieldIO.get(context, nullStorage, m, ptr)); }
public final boolean isValueReferenceNeeded() { return nativeFieldIO.isValueReferenceNeeded() || mappedType.isReferenceRequired(); }
public IRubyObject toNative(ThreadContext context, IRubyObject obj) { return converter.toNative(context, obj); }
public NativeType nativeType() { return converter.getRealType().getNativeType(); }
public MappedDataConverter(MappedType converter) { super(converter.isReferenceRequired(), converter.isPostInvokeRequired()); this.converter = converter; }