Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  
  package org.jruby.ext.ffi.jffi;
  
  import org.jruby.Ruby;
 
 public class Factory extends org.jruby.ext.ffi.Factory {
 
     public Factory() {
         if (!com.kenai.jffi.Platform.getPlatform().isSupported()) {
             throw new UnsatisfiedLinkError("JFFI backend not available");
         }
     }
 
     @Override
     public void init(Ruby runtimeRubyModule ffi) {
         super.init(runtimeffi);
 
         synchronized (ffi) {
             if (ffi.getClass("DynamicLibrary") == null) {
                 DynamicLibrary.createDynamicLibraryClass(runtimeffi);
             }
             if (ffi.getClass("Invoker") == null) {
                 JFFIInvoker.createInvokerClass(runtimeffi);
             }
             if (ffi.getClass("VariadicInvoker") == null) {
                 VariadicInvoker.createVariadicInvokerClass(runtimeffi);
             }
             if (ffi.getClass("Callback") == null) {
                 CallbackManager.createCallbackClass(runtimeffi);
             }
             if (ffi.getClass("Function") == null) {
                 Function.createFunctionClass(runtimeffi);
             }
             if (ffi.getClass("LastError") == null) {
                 ffi.defineModuleUnder("LastError").defineAnnotatedMethods(LastError.class);
             }
         }
 
         runtime.setFFI(new FFI(ffi));
     }

    
Allocates memory on the native C heap and wraps it in a MemoryIO accessor.

Parameters:
size The number of bytes to allocate.
clear If the memory should be cleared.
Returns:
A new MemoryIO.
 
     public MemoryIO allocateDirectMemory(Ruby runtimeint sizeboolean clear) {
         return CachingNativeMemoryAllocator.allocateAligned(runtimesize, 8, clear);
     }

    
Allocates memory on the native C heap and wraps it in a MemoryIO accessor.

Parameters:
size The number of bytes to allocate.
align The minimum alignment of the memory
clear If the memory should be cleared.
Returns:
A new MemoryIO.
 
     public MemoryIO allocateDirectMemory(Ruby runtimeint sizeint alignboolean clear) {
         return CachingNativeMemoryAllocator.allocateAligned(runtimesizealignclear);
     }
 
     public MemoryIO allocateTransientDirectMemory(Ruby runtimeint sizeint alignboolean clear) {
         return TransientNativeMemoryIO.allocateAligned(runtimesizealignclear);
     }
 
     public MemoryIO wrapDirectMemory(Ruby runtimelong address) {
         return NativeMemoryIO.wrap(runtimeaddress);
     }
 
     @Override
     public Function newFunction(Ruby runtimePointer addressCallbackInfo cbInfo) {
         CodeMemoryIO mem = new CodeMemoryIO(runtimeaddress);
         RubyClass klass = runtime.getModule("FFI").getClass("Function");
         return new Function(runtimeklassmem
                 cbInfo.getReturnType(), cbInfo.getParameterTypes(),
                 cbInfo.isStdcall() ? . : .nullfalse);
     }
 
 
     @Override
     public CallbackManager getCallbackManager() {
         return CallbackManager.getInstance();
     }
 
     private static final com.kenai.jffi.Type getType(NativeType type) {
         com.kenai.jffi.Type jffiType = FFIUtil.getFFIType(type);
         if (jffiType == null) {
             throw new UnsupportedOperationException("Cannot determine native type for " + type);
         }
        return jffiType;
    }
    public int sizeOf(NativeType type) {
        return getType(type).size();
    }
    public int alignmentOf(NativeType type) {
        return getType(type).alignment();
    }
    public static final class LastError {
        @JRubyMethod(name = {  "error" }, module = true)
        public static final  IRubyObject error(ThreadContext contextIRubyObject recv) {
            return context.runtime.newFixnum(com.kenai.jffi.LastError.getInstance().get());
        }
        @JRubyMethod(name = {  "error=" }, module = true)
        public static final  IRubyObject error_set(ThreadContext contextIRubyObject recvIRubyObject value) {
            com.kenai.jffi.LastError.getInstance().set((int)value.convertToInteger().getLongValue());
            return value;
        }
    }
New to GrepCode? Check out our FAQ X