public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { MemoryIO memory = ((AbstractMemory) ptr).getMemoryIO().getMemoryIO(m.getOffset(ptr)); IRubyObject old = cache.getCachedValue(m); if (old instanceof Pointer) { MemoryIO oldMemory = ((Pointer) old).getMemoryIO(); if (memory.equals(oldMemory)) { return old; } } Pointer retval = new Pointer(context.runtime, memory); cache.putCachedValue(m, retval); return retval; }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { DynamicMethod conversionMethod; if (value instanceof Pointer) { ptr.getMemoryIO().putMemoryIO(m.offset, ((Pointer) value).getMemoryIO()); } else if (value instanceof Struct) { MemoryIO mem = ((Struct) value).getMemoryIO(); if (!mem.isDirect()) { throw context.runtime.newArgumentError("Struct memory not backed by a native pointer"); } ptr.getMemoryIO().putMemoryIO(m.offset, mem); } else if (value instanceof RubyInteger) { ptr.getMemoryIO().putAddress(m.offset, Util.int64Value(ptr)); } else if (value.isNil()) { ptr.getMemoryIO().putAddress(m.offset, 0L); } else if (!(conversionMethod = value.getMetaClass().searchMethod("to_ptr")).isUndefined()) { IRubyObject addr = conversionMethod.call(context, value, value.getMetaClass(), "to_ptr"); if (addr instanceof Pointer) { ptr.getMemoryIO().putMemoryIO(m.offset, ((Pointer) addr).getMemoryIO()); } else { throw context.runtime.newArgumentError("Invalid pointer value"); } } else { throw context.runtime.newArgumentError("Invalid pointer value"); } cache.putReference(m, value); }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { DynamicMethod conversionMethod; if (value instanceof Pointer) { ptr.getMemoryIO().putMemoryIO(m.offset, ((Pointer) value).getMemoryIO()); } else if (value instanceof Struct) { MemoryIO mem = ((Struct) value).getMemoryIO(); if (!mem.isDirect()) { throw context.runtime.newArgumentError("Struct memory not backed by a native pointer"); } ptr.getMemoryIO().putMemoryIO(m.offset, mem); } else if (value instanceof RubyInteger) { ptr.getMemoryIO().putAddress(m.offset, Util.int64Value(ptr)); } else if (value.isNil()) { ptr.getMemoryIO().putAddress(m.offset, 0L); } else if (!(conversionMethod = value.getMetaClass().searchMethod("to_ptr")).isUndefined()) { IRubyObject addr = conversionMethod.call(context, value, value.getMetaClass(), "to_ptr"); if (addr instanceof Pointer) { ptr.getMemoryIO().putMemoryIO(m.offset, ((Pointer) addr).getMemoryIO()); } else { throw context.runtime.newArgumentError("Invalid pointer value"); } } else { throw context.runtime.newArgumentError("Invalid pointer value"); } cache.putReference(m, value); }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { DynamicMethod conversionMethod; if (value instanceof Pointer) { ptr.getMemoryIO().putMemoryIO(m.offset, ((Pointer) value).getMemoryIO()); } else if (value instanceof Struct) { MemoryIO mem = ((Struct) value).getMemoryIO(); if (!mem.isDirect()) { throw context.runtime.newArgumentError("Struct memory not backed by a native pointer"); } ptr.getMemoryIO().putMemoryIO(m.offset, mem); } else if (value instanceof RubyInteger) { ptr.getMemoryIO().putAddress(m.offset, Util.int64Value(value)); } else if (value.isNil()) { ptr.getMemoryIO().putAddress(m.offset, 0L); } else if (!(conversionMethod = value.getMetaClass().searchMethod("to_ptr")).isUndefined()) { IRubyObject addr = conversionMethod.call(context, value, value.getMetaClass(), "to_ptr"); if (addr instanceof Pointer) { ptr.getMemoryIO().putMemoryIO(m.offset, ((Pointer) addr).getMemoryIO()); } else { throw context.runtime.newArgumentError("Invalid pointer value"); } } else { throw context.runtime.newArgumentError("Invalid pointer value"); } cache.putReference(m, value); }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { DynamicMethod conversionMethod; if (value instanceof Pointer) { ptr.getMemoryIO().putMemoryIO(m.offset, ((Pointer) value).getMemoryIO()); } else if (value instanceof Struct) { MemoryIO mem = ((Struct) value).getMemoryIO(); if (!mem.isDirect()) { throw context.runtime.newArgumentError("Struct memory not backed by a native pointer"); } ptr.getMemoryIO().putMemoryIO(m.offset, mem); } else if (value instanceof RubyInteger) { ptr.getMemoryIO().putAddress(m.offset, Util.int64Value(value)); } else if (value.isNil()) { ptr.getMemoryIO().putAddress(m.offset, 0L); } else if (!(conversionMethod = value.getMetaClass().searchMethod("to_ptr")).isUndefined()) { IRubyObject addr = conversionMethod.call(context, value, value.getMetaClass(), "to_ptr"); if (addr instanceof Pointer) { ptr.getMemoryIO().putMemoryIO(m.offset, ((Pointer) addr).getMemoryIO()); } else { throw context.runtime.newArgumentError("Invalid pointer value"); } } else { throw context.runtime.newArgumentError("Invalid pointer value"); } cache.putReference(m, value); }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { ByteList bl = value.convertToString().getByteList(); MemoryPointer mem = MemoryPointer.allocate(context.runtime, 1, bl.length() + 1, false); // // Keep a reference to the temporary memory in the cache so it does // not get freed by the GC until the struct is freed // cache.putReference(m, mem); MemoryIO io = mem.getMemoryIO(); io.put(0, bl.getUnsafeBytes(), bl.begin(), bl.length()); io.putByte(bl.length(), (byte) 0); ptr.getMemoryIO().putMemoryIO(m.getOffset(ptr), io); }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { ByteList bl = value.convertToString().getByteList(); MemoryPointer mem = MemoryPointer.allocate(context.runtime, 1, bl.length() + 1, false); // // Keep a reference to the temporary memory in the cache so it does // not get freed by the GC until the struct is freed // cache.putReference(m, mem); MemoryIO io = mem.getMemoryIO(); io.put(0, bl.getUnsafeBytes(), bl.begin(), bl.length()); io.putByte(bl.length(), (byte) 0); ptr.getMemoryIO().putMemoryIO(m.getOffset(ptr), io); }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { MemoryIO memory = ((AbstractMemory) ptr).getMemoryIO().getMemoryIO(m.getOffset(ptr)); IRubyObject old = cache.getCachedValue(m); if (old instanceof Pointer) { MemoryIO oldMemory = ((Pointer) old).getMemoryIO(); if (memory.equals(oldMemory)) { return old; } } Pointer retval = new Pointer(context.runtime, memory); cache.putCachedValue(m, retval); return retval; }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { MemoryIO memory = ((AbstractMemory) ptr).getMemoryIO().getMemoryIO(m.getOffset(ptr)); IRubyObject old = cache.getCachedValue(m); if (old instanceof Pointer) { MemoryIO oldMemory = ((Pointer) old).getMemoryIO(); if (memory.equals(oldMemory)) { return old; } } Pointer retval = new Pointer(context.runtime, memory); cache.putCachedValue(m, retval); return retval; }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { ByteList bl = value.convertToString().getByteList(); MemoryPointer mem = MemoryPointer.allocate(context.runtime, 1, bl.length() + 1, false); // // Keep a reference to the temporary memory in the cache so it does // not get freed by the GC until the struct is freed // cache.putReference(m, mem); MemoryIO io = mem.getMemoryIO(); io.put(0, bl.getUnsafeBytes(), bl.begin(), bl.length()); io.putByte(bl.length(), (byte) 0); ptr.getMemoryIO().putMemoryIO(m.getOffset(ptr), io); }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { MemoryIO memory = ((AbstractMemory) ptr).getMemoryIO().getMemoryIO(m.getOffset(ptr)); IRubyObject old = cache.getCachedValue(m); if (old instanceof Pointer) { MemoryIO oldMemory = ((Pointer) old).getMemoryIO(); if (memory.equals(oldMemory)) { return old; } } Pointer retval = new Pointer(context.runtime, memory); cache.putCachedValue(m, retval); return retval; }
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) { final IRubyObject nativeValue = mappedType.toNative(context, value); nativeFieldIO.put(context, cache, m, ptr, nativeValue); if (isValueReferenceNeeded()) { // keep references to both the ruby and native values to preserve // reference chains cache.putReference(m, new Object[] { value, nativeValue }); } } }
public void put(ThreadContext context, Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { final IRubyObject nativeValue = mappedType.toNative(context, value); nativeFieldIO.put(context, cache, m, ptr, nativeValue); if (isValueReferenceNeeded()) { // keep references to both the ruby and native values to preserve // reference chains cache.putReference(m, new Object[] { value, nativeValue }); } } }
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 IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { IRubyObject s = cache.getCachedValue(m); if (s == null) { s = isCharArray() ? new StructLayout.CharArrayProxy(context.runtime, ptr, m.offset, arrayType, op) : new StructLayout.ArrayProxy(context.runtime, ptr, m.offset, arrayType, op); cache.putCachedValue(m, s); } return s; }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { IRubyObject s = cache.getCachedValue(m); if (s == null) { s = sbv.getStructClass().newInstance(context, ptr.slice(context.runtime, m.getOffset(ptr)), Block.NULL_BLOCK); cache.putCachedValue(m, s); } return s; }
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) { IRubyObject s = cache.getCachedValue(m); if (s == null) { s = isCharArray() ? new StructLayout.CharArrayProxy(context.runtime, ptr, m.offset, arrayType, op) : new StructLayout.ArrayProxy(context.runtime, ptr, m.offset, arrayType, op); cache.putCachedValue(m, s); } return s; }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { IRubyObject s = cache.getCachedValue(m); if (s == null) { s = sbv.getStructClass().newInstance(context, ptr.slice(context.runtime, m.getOffset(ptr)), Block.NULL_BLOCK); cache.putCachedValue(m, s); } return s; }