private static MemoryIO allocateMemoryIO(Ruby runtime, int size) { return Factory.getInstance().allocateTransientDirectMemory(runtime, size, 8, true); } }
public final MemoryIO getMemoryIO(long offset) { checkBounds(offset, ADDRESS_SIZE >> 3); return Factory.getInstance().wrapDirectMemory(runtime, getAddress(offset)); }
static MemoryPointer allocate(Ruby runtime, int typeSize, int count, boolean clear) { final int total = typeSize * count; MemoryIO io = Factory.getInstance().allocateDirectMemory(runtime, total > 0 ? total : 1, clear); if (io == null) { throw RaiseException.from(runtime, runtime.getNoMemoryError(), String.format("Failed to allocate %d objects of %d bytes", count, typeSize)); } return new MemoryPointer(runtime, runtime.getFFI().memptrClass, io, total, typeSize); }
static MemoryPointer allocate(Ruby runtime, int typeSize, int count, boolean clear) { final int total = typeSize * count; MemoryIO io = Factory.getInstance().allocateDirectMemory(runtime, total > 0 ? total : 1, clear); if (io == null) { throw new RaiseException(runtime, runtime.getNoMemoryError(), String.format("Failed to allocate %d objects of %d bytes", count, typeSize), true); } return new MemoryPointer(runtime, runtime.getFFI().memptrClass, io, total, typeSize); }
static MemoryPointer allocate(Ruby runtime, int typeSize, int count, boolean clear) { final int total = typeSize * count; MemoryIO io = Factory.getInstance().allocateDirectMemory(runtime, total > 0 ? total : 1, clear); if (io == null) { throw new RaiseException(runtime, runtime.getNoMemoryError(), String.format("Failed to allocate %d objects of %d bytes", count, typeSize), true); } return new MemoryPointer(runtime, runtime.getFFI().memptrClass, io, total, typeSize); }
static MemoryPointer allocate(Ruby runtime, int typeSize, int count, boolean clear) { final int total = typeSize * count; MemoryIO io = Factory.getInstance().allocateDirectMemory(runtime, total > 0 ? total : 1, clear); if (io == null) { throw RaiseException.from(runtime, runtime.getNoMemoryError(), String.format("Failed to allocate %d objects of %d bytes", count, typeSize)); } return new MemoryPointer(runtime, runtime.getFFI().memptrClass, io, total, typeSize); }
@JRubyMethod(name = { "initialize" }, visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject address) { setMemoryIO(address instanceof Pointer ? ((Pointer) address).getMemoryIO() : Factory.getInstance().wrapDirectMemory(context.runtime, RubyFixnum.num2long(address))); size = Long.MAX_VALUE; typeSize = 1; return this; }
@JRubyMethod(name = { "initialize" }, visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject address) { setMemoryIO(address instanceof Pointer ? ((Pointer) address).getMemoryIO() : Factory.getInstance().wrapDirectMemory(context.runtime, RubyFixnum.num2long(address))); size = Long.MAX_VALUE; typeSize = 1; return this; }
@JRubyMethod(name = { "initialize" }, visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject address) { setMemoryIO(address instanceof Pointer ? ((Pointer) address).getMemoryIO() : Factory.getInstance().wrapDirectMemory(context.runtime, RubyFixnum.num2long(address))); size = Long.MAX_VALUE; typeSize = 1; return this; }
@JRubyMethod(name = { "initialize" }, visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject type, IRubyObject address) { setMemoryIO(address instanceof Pointer ? ((Pointer) address).getMemoryIO() : Factory.getInstance().wrapDirectMemory(context.runtime, RubyFixnum.num2long(address))); size = Long.MAX_VALUE; typeSize = calculateTypeSize(context, type); return this; }
@JRubyMethod(name = { "initialize" }, visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject type, IRubyObject address) { setMemoryIO(address instanceof Pointer ? ((Pointer) address).getMemoryIO() : Factory.getInstance().wrapDirectMemory(context.runtime, RubyFixnum.num2long(address))); size = Long.MAX_VALUE; typeSize = calculateTypeSize(context, type); return this; }
@JRubyMethod(name = "put_callback", required = 3) public IRubyObject put_callback(ThreadContext context, IRubyObject offset, IRubyObject proc, IRubyObject cbInfo) { if (!(cbInfo instanceof CallbackInfo)) { throw context.runtime.newArgumentError("invalid CallbackInfo"); } Pointer ptr = Factory.getInstance().getCallbackManager().getCallback(context.runtime, (CallbackInfo) cbInfo, proc); getMemoryIO().putMemoryIO(getOffset(offset), ((AbstractMemory) ptr).getMemoryIO()); return this; }
@JRubyMethod(name = "put_callback", required = 3) public IRubyObject put_callback(ThreadContext context, IRubyObject offset, IRubyObject proc, IRubyObject cbInfo) { if (!(cbInfo instanceof CallbackInfo)) { throw context.runtime.newArgumentError("invalid CallbackInfo"); } Pointer ptr = Factory.getInstance().getCallbackManager().getCallback(context.runtime, (CallbackInfo) cbInfo, proc); getMemoryIO().putMemoryIO(getOffset(offset), ((AbstractMemory) ptr).getMemoryIO()); return this; }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { final long address = ((Pointer) ptr).getMemoryIO().getAddress(m.getOffset(ptr)); AbstractInvoker fptr = (AbstractInvoker) cache.getCachedValue(m); if (fptr != null && fptr.getAddress() == address) { return fptr; } fptr = Factory.getInstance().newFunction(context.runtime, ((Pointer) ptr).getPointer(context.runtime, m.getOffset(ptr)), (CallbackInfo) m.type); cache.putCachedValue(m, fptr); return fptr; }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { final long address = ((Pointer) ptr).getMemoryIO().getAddress(m.getOffset(ptr)); AbstractInvoker fptr = (AbstractInvoker) cache.getCachedValue(m); if (fptr != null && fptr.getAddress() == address) { return fptr; } fptr = Factory.getInstance().newFunction(context.runtime, ((Pointer) ptr).getPointer(context.runtime, m.getOffset(ptr)), (CallbackInfo) m.type); cache.putCachedValue(m, fptr); return fptr; }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { final long address = ((Pointer) ptr).getMemoryIO().getAddress(m.getOffset(ptr)); AbstractInvoker fptr = (AbstractInvoker) cache.getCachedValue(m); if (fptr != null && fptr.getAddress() == address) { return fptr; } fptr = Factory.getInstance().newFunction(context.runtime, ((Pointer) ptr).getPointer(context.runtime, m.getOffset(ptr)), (CallbackInfo) m.type); cache.putCachedValue(m, fptr); return fptr; }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { final long address = ((Pointer) ptr).getMemoryIO().getAddress(m.getOffset(ptr)); AbstractInvoker fptr = (AbstractInvoker) cache.getCachedValue(m); if (fptr != null && fptr.getAddress() == address) { return fptr; } fptr = Factory.getInstance().newFunction(context.runtime, ((Pointer) ptr).getPointer(context.runtime, m.getOffset(ptr)), (CallbackInfo) m.type); cache.putCachedValue(m, fptr); return fptr; }
public void put(ThreadContext context, Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { if (value.isNil()) { ptr.getMemoryIO().putAddress(m.getOffset(ptr), 0L); cache.putReference(m, value); } else { Pointer cb = Factory.getInstance().getCallbackManager().getCallback(context.runtime, (CallbackInfo) m.type, value); ptr.getMemoryIO().putMemoryIO(m.getOffset(ptr), cb.getMemoryIO()); cache.putReference(m, cb); } }
public void put(ThreadContext context, Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { if (value.isNil()) { ptr.getMemoryIO().putAddress(m.getOffset(ptr), 0L); cache.putReference(m, value); } else { Pointer cb = Factory.getInstance().getCallbackManager().getCallback(context.runtime, (CallbackInfo) m.type, value); ptr.getMemoryIO().putMemoryIO(m.getOffset(ptr), cb.getMemoryIO()); cache.putReference(m, cb); } }
public void put(ThreadContext context, Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { if (value.isNil()) { ptr.getMemoryIO().putAddress(m.getOffset(ptr), 0L); cache.putReference(m, value); } else { Pointer cb = Factory.getInstance().getCallbackManager().getCallback(context.runtime, (CallbackInfo) m.type, value); ptr.getMemoryIO().putMemoryIO(m.getOffset(ptr), cb.getMemoryIO()); cache.putReference(m, cb); } }