org.jruby.Ruby.getFFI()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(87)

本文整理了Java中org.jruby.Ruby.getFFI方法的一些代码示例,展示了Ruby.getFFI的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getFFI方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getFFI

Ruby.getFFI介绍

暂无

代码示例

代码示例来源:origin: org.jruby/jruby-core

/**
 * Creates a new <tt>StructLayout</tt> instance using defaults.
 *
 * @param runtime The runtime for the <tt>StructLayout</tt>
 */
Struct(Ruby runtime) {
  this(runtime, runtime.getFFI().structClass);
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * Creates a new <tt>StructLayout</tt> instance using defaults.
 *
 * @param runtime The runtime for the <tt>StructLayout</tt>
 */
Struct(Ruby runtime) {
  this(runtime, runtime.getFFI().structClass);
}

代码示例来源:origin: org.jruby/jruby-complete

static final MemoryIO wrap(Ruby runtime, long address) {
  return address != 0
      ? new NativeMemoryIO(runtime, address)
      : runtime.getFFI().getNullMemoryIO();
}

代码示例来源:origin: org.jruby/jruby-complete

private static final void checkPointer(Ruby runtime, IRubyObject ptr) {
  if (!(ptr instanceof Pointer)) {
    throw runtime.newTypeError(ptr, runtime.getFFI().pointerClass);
  }
  if (ptr instanceof MemoryPointer || ptr instanceof AutoPointer) {
    throw runtime.newTypeError("Cannot use AutoPointer with MemoryPointer or AutoPointer instances");
  }
}

代码示例来源:origin: org.jruby/jruby-core

static final MemoryIO wrap(Ruby runtime, long address) {
  return address != 0
      ? new NativeMemoryIO(runtime, address)
      : runtime.getFFI().getNullMemoryIO();
}

代码示例来源:origin: org.jruby/jruby-complete

final IRubyObject getValue(ThreadContext context, IRubyObject name, Storage cache, IRubyObject ptr) {
  if (!(ptr instanceof AbstractMemory)) {
    throw context.runtime.newTypeError(ptr, context.runtime.getFFI().memoryClass);
  }
  return getMember(context.runtime, name).get(context, cache, (AbstractMemory) ptr);
}

代码示例来源:origin: org.jruby/jruby-complete

final void putValue(ThreadContext context, IRubyObject name, Storage cache, IRubyObject ptr, IRubyObject value) {
  if (!(ptr instanceof AbstractMemory)) {
    throw context.runtime.newTypeError(ptr, context.runtime.getFFI().memoryClass);
  }
  getMember(context.runtime, name).put(context, cache, (AbstractMemory) ptr, value);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

final IRubyObject getValue(ThreadContext context, IRubyObject name, Storage cache, IRubyObject ptr) {
  if (!(ptr instanceof AbstractMemory)) {
    throw context.runtime.newTypeError(ptr, context.runtime.getFFI().memoryClass);
  }
  return getMember(context.runtime, name).get(context, cache, (AbstractMemory) ptr);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

final void putValue(ThreadContext context, IRubyObject name, Storage cache, IRubyObject ptr, IRubyObject value) {
  if (!(ptr instanceof AbstractMemory)) {
    throw context.runtime.newTypeError(ptr, context.runtime.getFFI().memoryClass);
  }
  getMember(context.runtime, name).put(context, cache, (AbstractMemory) ptr, value);
}

代码示例来源:origin: org.jruby/jruby-complete

static MemoryPointer allocate(Ruby runtime, int typeSize, int count, boolean clear) {
  final int total = typeSize * count;
  MemoryIO io = Factory.getInstance().allocateDirectMemory(runtime, total > 0 ? total : 1, clear);
  if (io == null) {
    throw RaiseException.from(runtime, runtime.getNoMemoryError(),
        String.format("Failed to allocate %d objects of %d bytes", count, typeSize));
  }
  return new MemoryPointer(runtime, runtime.getFFI().memptrClass, io, total, typeSize);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(name = "from_native")
public IRubyObject from_native(ThreadContext context, IRubyObject value, IRubyObject ctx) {
  if (value instanceof AbstractMemory) {
    return getStructClass().newInstance(context, value, Block.NULL_BLOCK);
  } else if (value.isNil()) {
    return getStructClass().newInstance(context, Pointer.getNull(context.runtime), Block.NULL_BLOCK);
  } else {
    throw context.runtime.newTypeError(value, context.runtime.getFFI().pointerClass);
  }
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(name = "from_native")
public IRubyObject from_native(ThreadContext context, IRubyObject value, IRubyObject ctx) {
  if (value instanceof AbstractMemory) {
    return getStructClass().newInstance(context, value, Block.NULL_BLOCK);
  } else if (value.isNil()) {
    return getStructClass().newInstance(context, Pointer.getNull(context.runtime), Block.NULL_BLOCK);
  } else {
    throw context.runtime.newTypeError(value, context.runtime.getFFI().pointerClass);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) {
  DynamicMethod method = getConversionMethod(parameter, callSite);
  IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK);
  if (ptr instanceof AbstractMemory) {
    return ((AbstractMemory) ptr).getMemoryIO();
  }
  throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() 
      + " should return " + context.runtime.getFFI().pointerClass);
}

代码示例来源:origin: org.jruby/jruby-core

public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) {
  DynamicMethod method = getConversionMethod(parameter, callSite);
  IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK);
  if (ptr instanceof AbstractMemory) {
    return ((AbstractMemory) ptr).getMemoryIO();
  }
  throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() 
      + " should return " + context.runtime.getFFI().pointerClass);
}

代码示例来源:origin: org.jruby/jruby-complete

private void putPointer(ThreadContext context, long offset, IRubyObject value) {
  DynamicMethod conversionMethod;
  
  if (value instanceof Pointer) {
    putPointer(context, offset, (Pointer) value);
  
  } else if (value.isNil()) {
    getMemoryIO().putAddress(offset, 0L);
  
  } else if (!(conversionMethod = value.getMetaClass().searchMethod("to_ptr")).isUndefined()) {
    putPointer(context, offset, conversionMethod.call(context, value, value.getMetaClass(), "to_ptr"));
  
  } else {
    throw context.runtime.newTypeError(value, context.runtime.getFFI().pointerClass);
  }
}

代码示例来源:origin: org.jruby/jruby-core

private void putPointer(ThreadContext context, long offset, IRubyObject value) {
  DynamicMethod conversionMethod;
  
  if (value instanceof Pointer) {
    putPointer(context, offset, (Pointer) value);
  
  } else if (value.isNil()) {
    getMemoryIO().putAddress(offset, 0L);
  
  } else if (!(conversionMethod = value.getMetaClass().searchMethod("to_ptr")).isUndefined()) {
    putPointer(context, offset, conversionMethod.call(context, value, value.getMetaClass(), "to_ptr"));
  
  } else {
    throw context.runtime.newTypeError(value, context.runtime.getFFI().pointerClass);
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private void putPointer(ThreadContext context, long offset, IRubyObject value) {
  DynamicMethod conversionMethod;
  
  if (value instanceof Pointer) {
    putPointer(context, offset, (Pointer) value);
  
  } else if (value.isNil()) {
    getMemoryIO().putAddress(offset, 0L);
  
  } else if (!(conversionMethod = value.getMetaClass().searchMethod("to_ptr")).isUndefined()) {
    putPointer(context, offset, conversionMethod.call(context, value, value.getMetaClass(), "to_ptr"));
  
  } else {
    throw context.runtime.newTypeError(value, context.runtime.getFFI().pointerClass);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(name = { "write_array_of_type" }, required = 3)
public IRubyObject write_array_of_type(ThreadContext context, IRubyObject typeArg, IRubyObject writer, IRubyObject aryArg) {
  Type type = context.runtime.getFFI().getTypeResolver().findType(context.runtime, typeArg);
  DynamicMethod method = getMetaClass().searchMethod(writer.asJavaString());
  RubyArray arr = aryArg.convertToArray();
  int len = arr.size();
  for (int i = 0, off = 0; i < len; i++, off += type.size) {
    method.call(context, this.slice(context.runtime, off, type.size), this.getMetaClass(), writer.asJavaString(), arr.entry(i));
  }
  return this;
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(name = { "read_array_of_type" }, required = 3)
public IRubyObject read_array_of_type(ThreadContext context, IRubyObject typeArg, IRubyObject reader, IRubyObject lenArg) {
  Type type = context.runtime.getFFI().getTypeResolver().findType(context.runtime, typeArg);
  DynamicMethod method = getMetaClass().searchMethod(reader.asJavaString());
  
  int len = checkArrayLength(lenArg);
  RubyArray arr = RubyArray.newArray(context.runtime, len);
  for (int i = 0, off = 0; i < len; i++, off += type.size) {
    arr.add(method.call(context, this.slice(context.runtime, off, type.size), this.getMetaClass(), reader.asJavaString()));
  }
  return arr;
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(name = { "write_array_of_type" }, required = 3)
public IRubyObject write_array_of_type(ThreadContext context, IRubyObject typeArg, IRubyObject writer, IRubyObject aryArg) {
  Type type = context.runtime.getFFI().getTypeResolver().findType(context.runtime, typeArg);
  DynamicMethod method = getMetaClass().searchMethod(writer.asJavaString());
  RubyArray arr = aryArg.convertToArray();
  int len = arr.size();
  for (int i = 0, off = 0; i < len; i++, off += type.size) {
    method.call(context, this.slice(context.runtime, off, type.size), this.getMetaClass(), writer.asJavaString(), arr.entry(i));
  }
  return this;
}

相关文章

微信公众号

最新文章

更多

Ruby类方法