Function(Ruby runtime, RubyClass klass, MemoryIO address, NativeFunctionInfo functionInfo, IRubyObject enums) { super(runtime, klass, functionInfo.parameterTypes.length, address); this.functionInfo = functionInfo; function = new com.kenai.jffi.Function(address.address(), functionInfo.jffiReturnType, functionInfo.jffiParameterTypes, functionInfo.convention); this.enums = enums; this.saveError = true; // Wire up Function#call(*args) to use the super-fast native invokers getSingletonClass().addMethod("call", createDynamicMethod(getSingletonClass())); }
@JRubyMethod(name = "free") public final IRubyObject free(ThreadContext context) { if (getMemoryIO() instanceof AllocatedDirectMemoryIO) { ((AllocatedDirectMemoryIO) getMemoryIO()).free(); } else { throw context.runtime.newRuntimeError("cannot free non-allocated function"); } // Replace memory object with one that throws an exception on any access setMemoryIO(new FreedMemoryIO(context.runtime)); return context.nil; }
@Override public DynamicMethod createDynamicMethod(RubyModule module) { return MethodFactory.createDynamicMethod(getRuntime(), module, function, functionInfo.returnType, functionInfo.parameterTypes, functionInfo.convention, enums, !saveError); }
@Override public Function newFunction(Ruby runtime, Pointer address, CallbackInfo cbInfo) { CodeMemoryIO mem = new CodeMemoryIO(runtime, address); RubyClass klass = runtime.getModule("FFI").getClass("Function"); return new Function(runtime, klass, mem, cbInfo.getReturnType(), cbInfo.getParameterTypes(), cbInfo.isStdcall() ? CallingConvention.STDCALL : CallingConvention.DEFAULT, null, false); }
@JRubyMethod(name = "autorelease=", required = 1) public final IRubyObject autorelease(ThreadContext context, IRubyObject release) { if (autorelease != release.isTrue() && getMemoryIO() instanceof AllocatedDirectMemoryIO) { ((AllocatedDirectMemoryIO) getMemoryIO()).setAutoRelease(autorelease = release.isTrue()); } return context.nil; }
@Override public void init(Ruby runtime, RubyModule ffi) { super.init(runtime, ffi); synchronized (ffi) { if (ffi.getClass("DynamicLibrary") == null) { DynamicLibrary.createDynamicLibraryClass(runtime, ffi); } if (ffi.getClass("Invoker") == null) { JFFIInvoker.createInvokerClass(runtime, ffi); } if (ffi.getClass("VariadicInvoker") == null) { VariadicInvoker.createVariadicInvokerClass(runtime, ffi); } if (ffi.getClass("Callback") == null) { CallbackManager.createCallbackClass(runtime, ffi); } if (ffi.getClass("Function") == null) { Function.createFunctionClass(runtime, ffi); } if (ffi.getClass("LastError") == null) { ffi.defineModuleUnder("LastError").defineAnnotatedMethods(LastError.class); } } runtime.setFFI(new FFI(ffi)); }
public IRubyObject fromNative(ThreadContext context, IRubyObject obj) { if (!(obj instanceof Pointer)) { throw context.runtime.newTypeError("internal error: non-pointer"); } Pointer ptr = (Pointer) obj; if (ptr.getAddress() == 0) { return context.nil; } return new org.jruby.ext.ffi.jffi.Function(context.runtime, context.runtime.getModule("FFI").getClass("Function"), new CodeMemoryIO(context.runtime, ptr), functionInfo, null); }
@JRubyMethod(name = "autorelease=", required = 1) public final IRubyObject autorelease(ThreadContext context, IRubyObject release) { if (autorelease != release.isTrue() && getMemoryIO() instanceof AllocatedDirectMemoryIO) { ((AllocatedDirectMemoryIO) getMemoryIO()).setAutoRelease(autorelease = release.isTrue()); } return context.nil; }
@Override public void init(Ruby runtime, RubyModule ffi) { super.init(runtime, ffi); synchronized (ffi) { if (ffi.getClass("DynamicLibrary") == null) { DynamicLibrary.createDynamicLibraryClass(runtime, ffi); } if (ffi.getClass("Invoker") == null) { JFFIInvoker.createInvokerClass(runtime, ffi); } if (ffi.getClass("VariadicInvoker") == null) { VariadicInvoker.createVariadicInvokerClass(runtime, ffi); } if (ffi.getClass("Callback") == null) { CallbackManager.createCallbackClass(runtime, ffi); } if (ffi.getClass("Function") == null) { Function.createFunctionClass(runtime, ffi); } if (ffi.getClass("LastError") == null) { ffi.defineModuleUnder("LastError").defineAnnotatedMethods(LastError.class); } } runtime.setFFI(new FFI(ffi)); }
Function(Ruby runtime, RubyClass klass, MemoryIO address, NativeFunctionInfo functionInfo, IRubyObject enums) { super(runtime, klass, functionInfo.parameterTypes.length, address); this.functionInfo = functionInfo; function = new com.kenai.jffi.Function(address.address(), functionInfo.jffiReturnType, functionInfo.jffiParameterTypes, functionInfo.convention); this.enums = enums; this.saveError = true; // Wire up Function#call(*args) to use the super-fast native invokers getSingletonClass().addMethod("call", createDynamicMethod(getSingletonClass())); }
public IRubyObject fromNative(ThreadContext context, IRubyObject obj) { if (!(obj instanceof Pointer)) { throw context.runtime.newTypeError("internal error: non-pointer"); } Pointer ptr = (Pointer) obj; if (ptr.getAddress() == 0) { return context.nil; } return new org.jruby.ext.ffi.jffi.Function(context.runtime, context.runtime.getModule("FFI").getClass("Function"), new CodeMemoryIO(context.runtime, ptr), functionInfo, null); }
@JRubyMethod(name = "free") public final IRubyObject free(ThreadContext context) { if (getMemoryIO() instanceof AllocatedDirectMemoryIO) { ((AllocatedDirectMemoryIO) getMemoryIO()).free(); } else { throw context.runtime.newRuntimeError("cannot free non-allocated function"); } // Replace memory object with one that throws an exception on any access setMemoryIO(new FreedMemoryIO(context.runtime)); return context.nil; }
@Override public DynamicMethod createDynamicMethod(RubyModule module) { return MethodFactory.createDynamicMethod(getRuntime(), module, function, functionInfo.returnType, functionInfo.parameterTypes, functionInfo.convention, enums, !saveError); }
@JRubyMethod(name = "autorelease=", required = 1) public final IRubyObject autorelease(ThreadContext context, IRubyObject release) { if (autorelease != release.isTrue() && getMemoryIO() instanceof AllocatedDirectMemoryIO) { ((AllocatedDirectMemoryIO) getMemoryIO()).setAutoRelease(autorelease = release.isTrue()); } return context.runtime.getNil(); }
@Override public void init(Ruby runtime, RubyModule ffi) { super.init(runtime, ffi); synchronized (ffi) { if (ffi.getClass("DynamicLibrary") == null) { DynamicLibrary.createDynamicLibraryClass(runtime, ffi); } if (ffi.getClass("Invoker") == null) { JFFIInvoker.createInvokerClass(runtime, ffi); } if (ffi.getClass("VariadicInvoker") == null) { VariadicInvoker.createVariadicInvokerClass(runtime, ffi); } if (ffi.getClass("Callback") == null) { CallbackManager.createCallbackClass(runtime, ffi); } if (ffi.getClass("Function") == null) { Function.createFunctionClass(runtime, ffi); } if (ffi.getClass("LastError") == null) { ffi.defineModuleUnder("LastError").defineAnnotatedMethods(LastError.class); } } runtime.setFFI(new FFI(ffi)); }
Function(Ruby runtime, RubyClass klass, MemoryIO address, NativeFunctionInfo functionInfo, IRubyObject enums) { super(runtime, klass, functionInfo.parameterTypes.length, address); this.functionInfo = functionInfo; function = new com.kenai.jffi.Function(address.address(), functionInfo.jffiReturnType, functionInfo.jffiParameterTypes, functionInfo.convention); this.enums = enums; this.saveError = true; // Wire up Function#call(*args) to use the super-fast native invokers getSingletonClass().addMethod("call", createDynamicMethod(getSingletonClass())); }
@Override public Function newFunction(Ruby runtime, Pointer address, CallbackInfo cbInfo) { CodeMemoryIO mem = new CodeMemoryIO(runtime, address); RubyClass klass = runtime.getModule("FFI").getClass("Function"); return new Function(runtime, klass, mem, cbInfo.getReturnType(), cbInfo.getParameterTypes(), cbInfo.isStdcall() ? CallingConvention.STDCALL : CallingConvention.DEFAULT, null, false); }
@JRubyMethod(name = "free") public final IRubyObject free(ThreadContext context) { if (getMemoryIO() instanceof AllocatedDirectMemoryIO) { ((AllocatedDirectMemoryIO) getMemoryIO()).free(); } else { throw context.runtime.newRuntimeError("cannot free non-allocated function"); } // Replace memory object with one that throws an exception on any access setMemoryIO(new FreedMemoryIO(context.runtime)); return context.runtime.getNil(); }
@Override public DynamicMethod createDynamicMethod(RubyModule module) { return MethodFactory.createDynamicMethod(getRuntime(), module, function, functionInfo.returnType, functionInfo.parameterTypes, functionInfo.convention, enums, !saveError); }
@JRubyMethod(name = "autorelease=", required = 1) public final IRubyObject autorelease(ThreadContext context, IRubyObject release) { if (autorelease != release.isTrue() && getMemoryIO() instanceof AllocatedDirectMemoryIO) { ((AllocatedDirectMemoryIO) getMemoryIO()).setAutoRelease(autorelease = release.isTrue()); } return context.runtime.getNil(); }