コード例 #1
0
ファイル: StructLayout.java プロジェクト: techwhizbang/jruby
    public IRubyObject get(
        ThreadContext context, StructLayout.Storage cache, Member m, IRubyObject ptr) {
      IRubyObject s = cache.getCachedValue(m);
      if (s == null) {
        s =
            isCharArray()
                ? new StructLayout.CharArrayProxy(
                    context.getRuntime(), ptr, m.offset, arrayType, op)
                : new StructLayout.ArrayProxy(context.getRuntime(), ptr, m.offset, arrayType, op);
        cache.putCachedValue(m, s);
      }

      return s;
    }
コード例 #2
0
ファイル: StructLayout.java プロジェクト: techwhizbang/jruby
    public IRubyObject get(
        ThreadContext context, StructLayout.Storage cache, Member m, IRubyObject ptr) {
      DirectMemoryIO 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.getRuntime(), memory);
      cache.putCachedValue(m, retval);

      return retval;
    }
コード例 #3
0
ファイル: StructLayout.java プロジェクト: techwhizbang/jruby
    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);
    }
コード例 #4
0
ファイル: StructLayout.java プロジェクト: techwhizbang/jruby
    public IRubyObject get(
        ThreadContext context, StructLayout.Storage cache, Member m, IRubyObject ptr) {
      IRubyObject s = cache.getCachedValue(m);
      if (s == null) {
        s =
            sbv.getStructClass()
                .newInstance(
                    context,
                    new IRubyObject[] {
                      ((AbstractMemory) ptr).slice(context.getRuntime(), m.getOffset(ptr))
                    },
                    Block.NULL_BLOCK);
        cache.putCachedValue(m, s);
      }

      return s;
    }
コード例 #5
0
ファイル: StructLayout.java プロジェクト: techwhizbang/jruby
    public IRubyObject get(
        ThreadContext context, StructLayout.Storage cache, Member m, IRubyObject 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.getRuntime(),
                  ((Pointer) ptr).getPointer(context.getRuntime(), m.getOffset(ptr)),
                  (CallbackInfo) m.type);
      cache.putCachedValue(m, fptr);

      return fptr;
    }
コード例 #6
0
ファイル: StructLayout.java プロジェクト: techwhizbang/jruby
    public void put(
        ThreadContext context,
        StructLayout.Storage cache,
        Member m,
        IRubyObject ptr,
        IRubyObject value) {
      ByteList bl = value.convertToString().getByteList();

      MemoryPointer mem = MemoryPointer.allocate(context.getRuntime(), 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);

      m.getMemoryIO(ptr).putMemoryIO(m.getOffset(ptr), io);
    }