Example #1
0
    public void put(
        ThreadContext context,
        StructLayout.Storage cache,
        Member m,
        IRubyObject ptr,
        IRubyObject value) {
      if (value instanceof Pointer) {
        m.getMemoryIO(ptr).putMemoryIO(m.offset, ((Pointer) value).getMemoryIO());
      } else if (value instanceof Struct) {
        MemoryIO mem = ((Struct) value).getMemoryIO();

        if (!(mem instanceof DirectMemoryIO)) {
          throw context
              .getRuntime()
              .newArgumentError("Struct memory not backed by a native pointer");
        }
        m.getMemoryIO(ptr).putMemoryIO(m.offset, mem);

      } else if (value instanceof RubyInteger) {
        m.getMemoryIO(ptr).putAddress(m.offset, Util.int64Value(ptr));
      } else if (value.respondsTo("to_ptr")) {
        IRubyObject addr = value.callMethod(context, "to_ptr");
        if (addr instanceof Pointer) {
          m.getMemoryIO(ptr).putMemoryIO(m.offset, ((Pointer) addr).getMemoryIO());
        } else {
          throw context.getRuntime().newArgumentError("Invalid pointer value");
        }
      } else if (value.isNil()) {
        m.getMemoryIO(ptr).putAddress(m.offset, 0L);
      } else {
        throw context.getRuntime().newArgumentError("Invalid pointer value");
      }
      cache.putReference(m, value);
    }
Example #2
0
 public final void marshal(
     Invocation invocation, InvocationBuffer buffer, IRubyObject parameter) {
   buffer.putLong(Util.int64Value(parameter));
 }
Example #3
0
 public final void marshal(
     ThreadContext context, InvocationBuffer buffer, IRubyObject parameter) {
   buffer.putLong(Util.int64Value(parameter));
 }