protected AbstractMemory slice(Ruby runtime, long offset, long size) { return new Buffer(runtime, getMetaClass(), getMemoryIO().slice(offset, size), size, this.typeSize, this.inout); }
private IRubyObject init(ThreadContext context, IRubyObject rbTypeSize, int count, int flags) { this.typeSize = calculateTypeSize(context, rbTypeSize); this.size = this.typeSize * count; this.inout = flags; setMemoryIO(allocateMemoryIO(context.runtime, (int) this.size)); return this; }
private static Buffer allocate(ThreadContext context, IRubyObject recv, IRubyObject sizeArg, int count, int flags) { final int typeSize = calculateTypeSize(context, sizeArg); final int total = typeSize * count; return new Buffer(context.runtime, recv, allocateMemoryIO(context.runtime, total), total, typeSize, flags); }
@JRubyMethod(name = { "alloc_inout", "__alloc_inout" }, meta = true) public static Buffer allocateInOut(ThreadContext context, IRubyObject recv, IRubyObject sizeArg) { return allocate(context, recv, sizeArg, 1, IN | OUT); }
/** * */ @JRubyMethod(required = 1, visibility=PRIVATE) public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) { if (this == other) { return this; } Buffer orig = (Buffer) other; this.typeSize = orig.typeSize; this.size = orig.size; this.inout = orig.inout; setMemoryIO(orig.getMemoryIO().dup()); return this; }
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 IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new Buffer(runtime, klazz); } }
public Buffer(Ruby runtime, int size, int flags) { this(runtime, runtime.getFFI().bufferClass, allocateMemoryIO(runtime, size), size, 1, flags); }
protected Pointer getPointer(Ruby runtime, long offset) { return new Pointer(runtime, getMemoryIO().getMemoryIO(offset)); } public int getInOutFlags() {
Buffer.createBufferClass(runtime, ffi);
private static Buffer allocate(ThreadContext context, IRubyObject recv, IRubyObject sizeArg, int count, int flags) { final int typeSize = calculateTypeSize(context, sizeArg); final int total = typeSize * count; return new Buffer(context.runtime, recv, allocateMemoryIO(context.runtime, total), total, typeSize, flags); }
@JRubyMethod(name = { "new_out", "alloc_out", "__alloc_out" }, meta = true) public static Buffer allocateOutput(ThreadContext context, IRubyObject recv, IRubyObject sizeArg) { return allocate(context, recv, sizeArg, 1, OUT); }
/** * */ @JRubyMethod(required = 1, visibility=PRIVATE) public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) { if (this == other) { return this; } Buffer orig = (Buffer) other; this.typeSize = orig.typeSize; this.size = orig.size; this.inout = orig.inout; setMemoryIO(orig.getMemoryIO().dup()); return this; }
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); } }
@JRubyMethod(name = "initialize", visibility = PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject sizeArg, Block block) { return sizeArg instanceof RubyFixnum ? init(context, RubyFixnum.one(context.runtime), RubyFixnum.fix2int(sizeArg), (IN | OUT), block) : init(context, sizeArg, 1, (IN | OUT), block); }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new Buffer(runtime, klazz); } }