public static DynamicMethod getConversionMethod(IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method; if (method.isUndefined()) { throw parameter.getRuntime().newTypeError("cannot convert parameter of type " + parameter.getMetaClass() + " to native pointer; does not respond to :" + callSite.getMethodName()); } return method; }
public static DynamicMethod getConversionMethod(IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method; if (method.isUndefined()) { throw parameter.getRuntime().newTypeError("cannot convert parameter of type " + parameter.getMetaClass() + " to native pointer; does not respond to :" + callSite.getMethodName()); } return method; }
public static DynamicMethod getConversionMethod(IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method; if (method.isUndefined()) { throw parameter.getRuntime().newTypeError("cannot convert parameter of type " + parameter.getMetaClass() + " to native pointer; does not respond to :" + callSite.getMethodName()); } return method; }
public static DynamicMethod getConversionMethod(IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method; if (method.isUndefined()) { throw parameter.getRuntime().newTypeError("cannot convert parameter of type " + parameter.getMetaClass() + " to native pointer; does not respond to :" + callSite.getMethodName()); } return method; }
NativeCallbackPointer newCallback(IRubyObject callable, CachingCallSite callSite) { if (callSite.retrieveCache(callable.getMetaClass(), callSite.getMethodName()).method.isUndefined()) { throw runtime.newArgumentError("callback does not respond to :" + callSite.getMethodName()); } return new NativeCallbackPointer(runtime, callbackClass, closurePool.newClosureHandle(new NativeClosureProxy(runtime, closureInfo, callable, callSite)), callbackInfo, closureInfo); }
public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = getConversionMethod(parameter, callSite); IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (ptr instanceof AbstractMemory) { return ((AbstractMemory) ptr).getMemoryIO(); } throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() + " should return " + context.runtime.getFFI().pointerClass); }
NativeCallbackPointer newCallback(IRubyObject callable, CachingCallSite callSite) { if (callSite.retrieveCache(callable.getMetaClass(), callSite.getMethodName()).method.isUndefined()) { throw runtime.newArgumentError("callback does not respond to :" + callSite.getMethodName()); } return new NativeCallbackPointer(runtime, callbackClass, closurePool.newClosureHandle(new NativeClosureProxy(runtime, closureInfo, callable, callSite)), callbackInfo, closureInfo); }
public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = getConversionMethod(parameter, callSite); IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (ptr instanceof AbstractMemory) { return ((AbstractMemory) ptr).getMemoryIO(); } throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() + " should return " + context.runtime.getFFI().pointerClass); }
NativeCallbackPointer newCallback(IRubyObject callable, CachingCallSite callSite) { if (callSite.retrieveCache(callable.getMetaClass(), callSite.getMethodName()).method.isUndefined()) { throw runtime.newArgumentError("callback does not respond to :" + callSite.getMethodName()); } return new NativeCallbackPointer(runtime, callbackClass, closurePool.newClosureHandle(new NativeClosureProxy(runtime, closureInfo, callable, callSite)), callbackInfo, closureInfo); }
public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = getConversionMethod(parameter, callSite); IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (ptr instanceof AbstractMemory) { return ((AbstractMemory) ptr).getMemoryIO(); } throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() + " should return " + context.runtime.getFFI().pointerClass); }
public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = getConversionMethod(parameter, callSite); IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (ptr instanceof AbstractMemory) { return ((AbstractMemory) ptr).getMemoryIO(); } throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() + " should return " + context.runtime.getFFI().pointerClass); }
NativeCallbackPointer newCallback(IRubyObject callable, CachingCallSite callSite) { if (callSite.retrieveCache(callable.getMetaClass(), callSite.getMethodName()).method.isUndefined()) { throw runtime.newArgumentError("callback does not respond to :" + callSite.getMethodName()); } return new NativeCallbackPointer(runtime, callbackClass, closurePool.newClosureHandle(new NativeClosureProxy(runtime, closureInfo, callable, callSite)), callbackInfo, closureInfo); }
private static MemoryIO convertToStringMemoryIO(IRubyObject parameter, ThreadContext context, CachingCallSite callSite, boolean isDirect, boolean checkStringSafety) { DynamicMethod conversionMethod; if (parameter instanceof RubyString) { return StringParameterStrategy.getMemoryIO((RubyString) parameter, isDirect, checkStringSafety); } else if (parameter instanceof RubyNil) { return NilPointerParameterStrategy.NullMemoryIO.INSTANCE; } else if (!(conversionMethod = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method).isUndefined()) { IRubyObject convertedParameter = conversionMethod.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (convertedParameter instanceof RubyString) { return StringParameterStrategy.getMemoryIO((RubyString) convertedParameter, isDirect, checkStringSafety); } // Fall through to the default conversion which will raise an error if the converted value is not of the correct type. } return StringParameterStrategy.getMemoryIO(parameter.convertToString(), isDirect, checkStringSafety); }
private static MemoryIO convertToStringMemoryIO(IRubyObject parameter, ThreadContext context, CachingCallSite callSite, boolean isDirect, boolean checkStringSafety) { DynamicMethod conversionMethod; if (parameter instanceof RubyString) { return StringParameterStrategy.getMemoryIO((RubyString) parameter, isDirect, checkStringSafety); } else if (parameter instanceof RubyNil) { return NilPointerParameterStrategy.NullMemoryIO.INSTANCE; } else if (!(conversionMethod = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method).isUndefined()) { IRubyObject convertedParameter = conversionMethod.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (convertedParameter instanceof RubyString) { return StringParameterStrategy.getMemoryIO((RubyString) convertedParameter, isDirect, checkStringSafety); } // Fall through to the default conversion which will raise an error if the converted value is not of the correct type. } return StringParameterStrategy.getMemoryIO(parameter.convertToString(), isDirect, checkStringSafety); }
private static MemoryIO convertToStringMemoryIO(IRubyObject parameter, ThreadContext context, CachingCallSite callSite, boolean isDirect, boolean checkStringSafety) { DynamicMethod conversionMethod; if (parameter instanceof RubyString) { return StringParameterStrategy.getMemoryIO((RubyString) parameter, isDirect, checkStringSafety); } else if (parameter instanceof RubyNil) { return NilPointerParameterStrategy.NullMemoryIO.INSTANCE; } else if (!(conversionMethod = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method).isUndefined()) { IRubyObject convertedParameter = conversionMethod.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (convertedParameter instanceof RubyString) { return StringParameterStrategy.getMemoryIO((RubyString) convertedParameter, isDirect, checkStringSafety); } // Fall through to the default conversion which will raise an error if the converted value is not of the correct type. } return StringParameterStrategy.getMemoryIO(parameter.convertToString(), isDirect, checkStringSafety); }
private static MemoryIO convertToStringMemoryIO(IRubyObject parameter, ThreadContext context, CachingCallSite callSite, boolean isDirect, boolean checkStringSafety) { DynamicMethod conversionMethod; if (parameter instanceof RubyString) { return StringParameterStrategy.getMemoryIO((RubyString) parameter, isDirect, checkStringSafety); } else if (parameter instanceof RubyNil) { return NilPointerParameterStrategy.NullMemoryIO.INSTANCE; } else if (!(conversionMethod = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method).isUndefined()) { IRubyObject convertedParameter = conversionMethod.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (convertedParameter instanceof RubyString) { return StringParameterStrategy.getMemoryIO((RubyString) convertedParameter, isDirect, checkStringSafety); } // Fall through to the default conversion which will raise an error if the converted value is not of the correct type. } return StringParameterStrategy.getMemoryIO(parameter.convertToString(), isDirect, checkStringSafety); }
@Override @JRubyMethod(name = "initialize", visibility = PRIVATE) public final IRubyObject initialize(ThreadContext context, IRubyObject pointerArg, IRubyObject releaser) { checkPointer(context.runtime, pointerArg); setMemoryIO(((Pointer) pointerArg).getMemoryIO()); this.pointer = (Pointer) pointerArg; this.size = pointer.size; this.typeSize = pointer.typeSize; Object ffiHandle = releaser.getMetaClass().getFFIHandleAccessorField().getVariableAccessorForRead().get(releaser); if (!(ffiHandle instanceof ReleaserData)) { getMetaClass().setFFIHandle(ffiHandle = new ReleaserData()); } ReleaserData releaserData = (ReleaserData) ffiHandle; DynamicMethod releaseMethod = releaserData.releaseCallSite.retrieveCache(releaser.getMetaClass(), releaserData.releaseCallSite.getMethodName()).method; // If no release method is defined, then memory leaks will result. if (releaseMethod.isUndefined()) { throw context.runtime.newRuntimeError("call method undefined"); } else if ((releaseMethod.getArity().isFixed() && releaseMethod.getArity().required() != 1) || releaseMethod.getArity().required() > 1) { throw context.runtime.newRuntimeError("wrong number of arguments to call method (" + 1 + " for " + releaseMethod.getArity().required() + ")"); } setReaper(new Reaper(pointer, releaser, releaserData.releaseCallSite)); return this; }
@Override @JRubyMethod(name = "initialize", visibility = PRIVATE) public final IRubyObject initialize(ThreadContext context, IRubyObject pointerArg) { Ruby runtime = context.runtime; checkPointer(runtime, pointerArg); Object ffiHandle = getMetaClass().getFFIHandle(); if (!(ffiHandle instanceof ClassData)) { getMetaClass().setFFIHandle(ffiHandle = new ClassData()); } ClassData classData = (ClassData) ffiHandle; // If no release method is defined, then memory leaks will result. DynamicMethod releaseMethod = classData.releaseCallSite.retrieveCache(getMetaClass().getMetaClass(), classData.releaseCallSite.getMethodName()).method; if (releaseMethod.isUndefined()) { throw runtime.newRuntimeError("release method undefined"); } else if ((releaseMethod.getArity().isFixed() && releaseMethod.getArity().required() != 1) || releaseMethod.getArity().required() > 1) { throw runtime.newRuntimeError("wrong number of arguments to release method (" + 1 + " for " + releaseMethod.getArity().required() + ")"); } setMemoryIO(((Pointer) pointerArg).getMemoryIO()); this.pointer = (Pointer) pointerArg; this.size = pointer.size; this.typeSize = pointer.typeSize; setReaper(new Reaper(pointer, getMetaClass(), classData.releaseCallSite)); return this; }
@Override @JRubyMethod(name = "initialize", visibility = PRIVATE) public final IRubyObject initialize(ThreadContext context, IRubyObject pointerArg) { Ruby runtime = context.runtime; checkPointer(runtime, pointerArg); Object ffiHandle = getMetaClass().getFFIHandle(); if (!(ffiHandle instanceof ClassData)) { getMetaClass().setFFIHandle(ffiHandle = new ClassData()); } ClassData classData = (ClassData) ffiHandle; // If no release method is defined, then memory leaks will result. DynamicMethod releaseMethod = classData.releaseCallSite.retrieveCache(getMetaClass().getMetaClass(), classData.releaseCallSite.getMethodName()).method; if (releaseMethod.isUndefined()) { throw runtime.newRuntimeError("release method undefined"); } else if ((releaseMethod.getArity().isFixed() && releaseMethod.getArity().required() != 1) || releaseMethod.getArity().required() > 1) { throw runtime.newRuntimeError("wrong number of arguments to release method (" + 1 + " for " + releaseMethod.getArity().required() + ")"); } setMemoryIO(((Pointer) pointerArg).getMemoryIO()); this.pointer = (Pointer) pointerArg; this.size = pointer.size; this.typeSize = pointer.typeSize; setReaper(new Reaper(pointer, getMetaClass(), classData.releaseCallSite)); return this; }
@Override @JRubyMethod(name = "initialize", visibility = PRIVATE) public final IRubyObject initialize(ThreadContext context, IRubyObject pointerArg) { Ruby runtime = context.runtime; checkPointer(runtime, pointerArg); Object ffiHandle = getMetaClass().getFFIHandle(); if (!(ffiHandle instanceof ClassData)) { getMetaClass().setFFIHandle(ffiHandle = new ClassData()); } ClassData classData = (ClassData) ffiHandle; // If no release method is defined, then memory leaks will result. DynamicMethod releaseMethod = classData.releaseCallSite.retrieveCache(getMetaClass().getMetaClass(), classData.releaseCallSite.getMethodName()).method; if (releaseMethod.isUndefined()) { throw runtime.newRuntimeError("release method undefined"); } else if ((releaseMethod.getArity().isFixed() && releaseMethod.getArity().required() != 1) || releaseMethod.getArity().required() > 1) { throw runtime.newRuntimeError("wrong number of arguments to release method (" + 1 + " for " + releaseMethod.getArity().required() + ")"); } setMemoryIO(((Pointer) pointerArg).getMemoryIO()); this.pointer = (Pointer) pointerArg; this.size = pointer.size; this.typeSize = pointer.typeSize; setReaper(new Reaper(pointer, getMetaClass(), classData.releaseCallSite)); return this; }