@Override protected AbstractMemory slice(Ruby runtime, long offset) { return new Pointer(runtime, getPointerClass(runtime), getMemoryIO().slice(offset), size == Long.MAX_VALUE ? Long.MAX_VALUE : size - offset, typeSize); }
public CodeMemoryIO(Ruby runtime, Pointer pointer) { super(runtime, true, pointer.getAddress(), "code region is inaccessible"); this.pointer = pointer; } }
@Override @JRubyMethod(name = { "to_s", "inspect" }, optional = 1) public IRubyObject to_s(ThreadContext context, IRubyObject[] args) { String s = size != Long.MAX_VALUE ? String.format("#<%s address=0x%x size=%s>", getMetaClass().getName(), getAddress(), size) : String.format("#<%s address=0x%x>", getMetaClass().getName(), getAddress()); return RubyString.newString(context.runtime, s); }
public final AbstractMemory order(Ruby runtime, ByteOrder order) { return new Pointer(runtime, order.equals(getMemoryIO().order()) ? getMemoryIO() : new SwappedMemoryIO(runtime, getMemoryIO()), size, typeSize); }
@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(required = 1, visibility=PRIVATE) public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) { if (this == other) { return this; } Pointer orig = (Pointer) other; this.typeSize = orig.typeSize; this.size = orig.size; setMemoryIO(orig.getMemoryIO().dup()); 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 allocate(Ruby runtime, RubyClass klazz) { return new Pointer(runtime, klazz); } }
@JRubyMethod(name = "to_native") public IRubyObject to_native(ThreadContext context, IRubyObject value, IRubyObject ctx) { if (value instanceof Struct && structClass.isInstance(value)) { return ((Struct) value).getMemory(); } else if (value.isNil()) { return Pointer.getNull(context.runtime); } else { throw context.runtime.newTypeError(value, structClass); } }
public Pointer(Ruby runtime, MemoryIO io) { this(runtime, getPointerClass(runtime), io); } public Pointer(Ruby runtime, MemoryIO io, long size, int typeSize) {
/** * Gets the native memory address of this pointer. * * @return A long containing the native memory address. */ public final long getAddress() { return getMemoryIO().address(); }
Pointer.createPointerClass(runtime, ffi);
@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(required = 1, visibility=PRIVATE) public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) { if (this == other) { return this; } Pointer orig = (Pointer) other; this.typeSize = orig.typeSize; this.size = orig.size; setMemoryIO(orig.getMemoryIO().dup()); return this; }
public final AbstractMemory order(Ruby runtime, ByteOrder order) { return new Pointer(runtime, order.equals(getMemoryIO().order()) ? getMemoryIO() : new SwappedMemoryIO(runtime, getMemoryIO()), size, typeSize); }
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 allocate(Ruby runtime, RubyClass klazz) { return new Pointer(runtime, klazz); } }
@JRubyMethod(name = "to_native") public IRubyObject to_native(ThreadContext context, IRubyObject value, IRubyObject ctx) { if (value instanceof Struct && structClass.isInstance(value)) { return ((Struct) value).getMemory(); } else if (value.isNil()) { return Pointer.getNull(context.runtime); } else { throw context.runtime.newTypeError(value, structClass); } }
public Pointer(Ruby runtime, MemoryIO io, long size, int typeSize) { this(runtime, getPointerClass(runtime), io, size, typeSize); } protected Pointer(Ruby runtime, RubyClass klass, MemoryIO io) {
/** * Tests if this <tt>Pointer</tt> represents the C <tt>NULL</tt> value. * * @return true if the address is NULL. */ @JRubyMethod(name = "null?") public IRubyObject null_p(ThreadContext context) { return context.runtime.newBoolean(getMemoryIO().isNull()); }