@JRubyMethod(
     name = {"create_invoker", "createInvoker"},
     required = 5)
 public IRubyObject createInvoker(ThreadContext context, IRubyObject[] args) {
   RubyArray paramTypes = (RubyArray) args[3];
   NativeParam[] nativeParamTypes = new NativeParam[paramTypes.size()];
   for (int i = 0; i < paramTypes.size(); ++i) {
     IRubyObject obj = (IRubyObject) paramTypes.entry(i);
     if (obj instanceof NativeParam) {
       nativeParamTypes[i] = (NativeParam) obj;
     } else if (obj instanceof RubyInteger) {
       nativeParamTypes[i] = NativeType.valueOf(Util.int32Value(obj));
     } else {
       context.getRuntime().newArgumentError("Invalid parameter type");
     }
   }
   try {
     return createInvoker(
         context.getRuntime(),
         args[0].isNil() ? null : args[0].toString(),
         args[1].toString(),
         NativeType.valueOf(Util.int32Value(args[2])),
         nativeParamTypes,
         args[4].toString());
   } catch (UnsatisfiedLinkError ex) {
     return context.getRuntime().getNil();
   }
 }
Exemple #2
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);
    }
 public final void marshal(
     ThreadContext context, InvocationBuffer buffer, IRubyObject parameter) {
   if (parameter instanceof RubyString) {
     Util.checkStringSafety(context.getRuntime(), parameter);
     ByteList bl = ((RubyString) parameter).getByteList();
     buffer.putArray(
         bl.unsafeBytes(), bl.begin(), bl.length(), ArrayFlags.IN | ArrayFlags.NULTERMINATE);
   } else if (parameter.isNil()) {
     buffer.putAddress(0);
   } else {
     throw context.getRuntime().newArgumentError("Invalid string parameter");
   }
 }
 public final void marshal(
     Invocation invocation, InvocationBuffer buffer, IRubyObject parameter) {
   buffer.putLong(Util.uint64Value(parameter));
 }
 public final void marshal(
     ThreadContext context, InvocationBuffer buffer, IRubyObject parameter) {
   buffer.putLong(Util.uint64Value(parameter));
 }
 public final void marshal(
     Invocation invocation, InvocationBuffer buffer, IRubyObject parameter) {
   buffer.putInt((int) Util.uint32Value(parameter));
 }
 public final void marshal(
     Invocation invocation, InvocationBuffer buffer, IRubyObject parameter) {
   buffer.putShort(Util.int16Value(parameter));
 }
 public final void marshal(
     ThreadContext context, InvocationBuffer buffer, IRubyObject parameter) {
   buffer.putShort(Util.int16Value(parameter));
 }
 public final IRubyObject invoke(Ruby runtime, Function function, HeapInvocationBuffer args) {
   return Util.newSigned32(runtime, invoker.invokeInt(function, args));
 }
Exemple #10
0
 public final IRubyObject invoke(
     ThreadContext context, Function function, HeapInvocationBuffer args) {
   return Util.newUnsigned64(context.getRuntime(), invoker.invokeLong(function, args));
 }
Exemple #11
0
 public final IRubyObject invoke(
     ThreadContext context, Function function, HeapInvocationBuffer args) {
   return Util.newSigned16(context.getRuntime(), (short) invoker.invokeInt(function, args));
 }
 public final int intValue(ThreadContext context, IRubyObject obj) {
   return (int) Util.uint32Value(obj);
 }
 public final int intValue(ThreadContext context, IRubyObject obj) {
   return Util.int16Value(obj);
 }
 public final IRubyObject fromNative(ThreadContext context, int value) {
   return Util.newUnsigned32(context.getRuntime(), value);
 }
 public final IRubyObject fromNative(ThreadContext context, int value) {
   return Util.newSigned16(context.getRuntime(), (short) value);
 }
 public final IRubyObject invoke(Ruby runtime, Function function, HeapInvocationBuffer args) {
   return Util.newUnsigned64(runtime, invoker.invokeLong(function, args));
 }
 private final void checkBounds(long off, long len) {
   Util.checkBounds(runtime, size, off, len);
 }
 public void marshal(Invocation invocation, InvocationBuffer buffer, IRubyObject parameter) {
   buffer.putByte(Util.int8Value(parameter));
 }
Exemple #19
0
 private final long getOffset(IRubyObject index) {
   return getOffset(Util.int32Value(index));
 }
 @JRubyMethod(name = {"error=", "last_error="})
 public IRubyObject getLastError(ThreadContext context, IRubyObject error) {
   setLastError(Util.int32Value(error));
   return context.getRuntime().getNil();
 }