public ArrayMemoryIO slice(long offset, long size) { checkBounds(offset, size); return offset == 0 && size == this.length ? this : new ArrayMemoryIO(runtime, array(), arrayOffset() + (int) offset, (int) size); }
public final void putByte(long offset, byte value) { checkBounds(offset, 1); buffer[index(offset)] = value; }
public ArrayMemoryIO dup() { ArrayMemoryIO tmp = new ArrayMemoryIO(runtime, length); System.arraycopy(array(), arrayOffset(), tmp.array(), tmp.arrayOffset(), length); return tmp; }
public final byte[] getZeroTerminatedByteArray(long offset) { checkBounds(offset, 1); int len = indexOf(offset, (byte) 0); byte[] bytes = new byte[len != -1 ? len : length - (int) offset]; System.arraycopy(buffer, index(offset), bytes, 0, bytes.length); return bytes; }
if (arrayMemory.arrayLength() < type.getNativeSize()) { throw runtime.newRuntimeError("size of struct returned from callback too small"); buffer.setStructReturn(arrayMemory.array(), arrayMemory.arrayOffset());
public final IRubyObject invoke(ThreadContext context, Function function, HeapInvocationBuffer args) { int size = info.getStructLayout().getSize(); Buffer buf = new Buffer(context.runtime, size); MemoryIO mem = buf.getMemoryIO(); byte[] array; int arrayOffset; if (mem instanceof ArrayMemoryIO) { ArrayMemoryIO arrayMemoryIO = (ArrayMemoryIO) mem; array = arrayMemoryIO.array(); arrayOffset = arrayMemoryIO.arrayOffset(); } else { array = new byte[size]; arrayOffset = 0; } invoker.invokeStruct(function, args, array, arrayOffset); if (!(mem instanceof ArrayMemoryIO)) { mem.put(0, array, 0, array.length); } return info.getStructClass().newInstance(context, buf, Block.NULL_BLOCK); } }
public final MemoryIO getMemoryIO(long offset) { checkBounds(offset, ADDRESS_SIZE >> 3); return Factory.getInstance().wrapDirectMemory(runtime, getAddress(offset)); }
public final void putMemoryIO(long offset, MemoryIO value) { checkBounds(offset, ADDRESS_SIZE >> 3); putAddress(offset, value.address()); } public final byte getByte(long offset) {
public final int indexOf(long offset, byte value) { int off = index(offset); for (int i = 0; i < length; ++i) { if (buffer[off + i] == value) { return i; } } return -1; }
private final void checkBounds(long off, long len) { Util.checkBounds(runtime, arrayLength(), off, len); }
static MemoryIO getMemoryIO(RubyString s, boolean isDirect, boolean checkStringSafety) { Object existingHandle = s.getFFIHandle(); if (existingHandle instanceof NativeStringHandle) { NativeStringHandle sh = (NativeStringHandle) existingHandle; if (s.getByteList() == sh.bl && sh.memory.isDirect() == isDirect) { return sh.memory; } } ByteList bl = s.getByteList(); if (checkStringSafety) StringSupport.checkStringSafety(s.getRuntime(), s); MemoryIO memory; if (isDirect) { memory = TransientNativeMemoryIO.allocateAligned(s.getRuntime(), bl.length() + 1, 1, false); memory.putZeroTerminatedByteArray(0, bl.unsafeBytes(), bl.begin(), bl.length()); } else { memory = new ArrayMemoryIO(s.getRuntime(), bl.unsafeBytes(), bl.begin(), bl.length()); } s.setByteListShared(); s.setFFIHandle(new NativeStringHandle(memory, s.getByteList())); return memory; }
public final byte[] getZeroTerminatedByteArray(long offset) { checkBounds(offset, 1); int len = indexOf(offset, (byte) 0); byte[] bytes = new byte[len != -1 ? len : length - (int) offset]; System.arraycopy(buffer, index(offset), bytes, 0, bytes.length); return bytes; }
public ArrayMemoryIO dup() { ArrayMemoryIO tmp = new ArrayMemoryIO(runtime, length); System.arraycopy(array(), arrayOffset(), tmp.array(), tmp.arrayOffset(), length); return tmp; }
if (arrayMemory.arrayLength() < type.getNativeSize()) { throw runtime.newRuntimeError("size of struct returned from callback too small"); buffer.setStructReturn(arrayMemory.array(), arrayMemory.arrayOffset());
public final IRubyObject invoke(ThreadContext context, Function function, HeapInvocationBuffer args) { int size = info.getStructLayout().getSize(); Buffer buf = new Buffer(context.runtime, size); MemoryIO mem = buf.getMemoryIO(); byte[] array; int arrayOffset; if (mem instanceof ArrayMemoryIO) { ArrayMemoryIO arrayMemoryIO = (ArrayMemoryIO) mem; array = arrayMemoryIO.array(); arrayOffset = arrayMemoryIO.arrayOffset(); } else { array = new byte[size]; arrayOffset = 0; } invoker.invokeStruct(function, args, array, arrayOffset); if (!(mem instanceof ArrayMemoryIO)) { mem.put(0, array, 0, array.length); } return info.getStructClass().newInstance(context, buf, Block.NULL_BLOCK); } }
public final MemoryIO getMemoryIO(long offset) { checkBounds(offset, ADDRESS_SIZE >> 3); return Factory.getInstance().wrapDirectMemory(runtime, getAddress(offset)); }
public final void putMemoryIO(long offset, MemoryIO value) { checkBounds(offset, ADDRESS_SIZE >> 3); putAddress(offset, value.address()); } public final byte getByte(long offset) {
public final int indexOf(long offset, byte value) { int off = index(offset); for (int i = 0; i < length; ++i) { if (buffer[off + i] == value) { return i; } } return -1; }
private final void checkBounds(long off, long len) { Util.checkBounds(runtime, arrayLength(), off, len); }