Package org.jruby.ext.ffi

Examples of org.jruby.ext.ffi.MemoryIO


            final AbstractMemory memory = ((Struct) parameter).getMemory();
            if (memory.getSize() < layout.getSize()) {
                throw context.getRuntime().newArgumentError("struct memory too small for parameter");
            }

            final MemoryIO io = memory.getMemoryIO();
            if (io instanceof DirectMemoryIO) {
                if (io.isNull()) {
                    throw context.getRuntime().newRuntimeError("Cannot use a NULL pointer as a struct by value argument");
                }
                buffer.putStruct(((DirectMemoryIO) io).getAddress());

            } else if (io instanceof ArrayMemoryIO) {
View Full Code Here


        } else if (type instanceof StructByValue) {

            if (value instanceof Struct) {
                Struct s = (Struct) value;
                MemoryIO memory = s.getMemory().getMemoryIO();

                if (memory instanceof DirectMemoryIO) {
                    long address = ((DirectMemoryIO) memory).getAddress();
                    if (address != 0) {
                        buffer.setStructReturn(address);
View Full Code Here

            this.cbInfo = cbInfo;
            this.closureInfo = closureInfo;
        }

        void dispose() {
            MemoryIO mem = getMemoryIO();
            if (mem instanceof CallbackMemoryIO) {
                ((CallbackMemoryIO) mem).free();
            }
        }
View Full Code Here

            final AbstractMemory memory = ((Struct) parameter).getMemory();
            if (memory.getSize() < layout.getSize()) {
                throw context.runtime.newArgumentError("struct memory too small for parameter");
            }

            final MemoryIO io = memory.getMemoryIO();
            if (io instanceof DirectMemoryIO) {
                if (io.isNull()) {
                    throw context.runtime.newRuntimeError("Cannot use a NULL pointer as a struct by value argument");
                }
                buffer.putStruct(((DirectMemoryIO) io).getAddress());

            } else if (io instanceof ArrayMemoryIO) {
View Full Code Here

        this.closureInfo = closureInfo;
    }


    void dispose() {
        MemoryIO mem = getMemoryIO();
        if (mem instanceof CallbackMemoryIO) {
            ((CallbackMemoryIO) mem).free();
        }
    }
View Full Code Here

        }

        public final IRubyObject invoke(ThreadContext context, Function function, HeapInvocationBuffer args) {
            int size = info.getStructLayout().getSize();
            Buffer buf = new Buffer(context.runtime, size);
            MemoryIO mem = buf.getMemoryIO();
            byte[] array;
            int arrayOffset;
            if (mem instanceof ArrayMemoryIO) {
                ArrayMemoryIO arrayMemoryIO = (ArrayMemoryIO) mem;
                array = arrayMemoryIO.array();
                arrayOffset = arrayMemoryIO.arrayOffset();
            } else {
                array = new byte[size];
                arrayOffset = 0;
            }

            invoker.invokeStruct(function, args, array, arrayOffset);

            if (!(mem instanceof ArrayMemoryIO)) {
                mem.put(0, array, 0, array.length);
            }

            return info.getStructClass().newInstance(context, buf, Block.NULL_BLOCK);
        }
View Full Code Here

        }

        public final IRubyObject invoke(ThreadContext context, Function function, HeapInvocationBuffer args) {
            int size = info.getStructLayout().getSize();
            Buffer buf = new Buffer(context.runtime, size);
            MemoryIO mem = buf.getMemoryIO();
            byte[] array;
            int arrayOffset;
            if (mem instanceof ArrayMemoryIO) {
                ArrayMemoryIO arrayMemoryIO = (ArrayMemoryIO) mem;
                array = arrayMemoryIO.array();
                arrayOffset = arrayMemoryIO.arrayOffset();
            } else {
                array = new byte[size];
                arrayOffset = 0;
            }

            invoker.invokeStruct(function, args, array, arrayOffset);

            if (!(mem instanceof ArrayMemoryIO)) {
                mem.put(0, array, 0, array.length);
            }

            return info.getStructClass().newInstance(context, buf, Block.NULL_BLOCK);
        }
View Full Code Here

        this.closureInfo = closureInfo;
    }


    void dispose() {
        MemoryIO mem = getMemoryIO();
        if (mem instanceof CallbackMemoryIO) {
            ((CallbackMemoryIO) mem).free();
        }
    }
View Full Code Here

            final AbstractMemory memory = ((Struct) parameter).getMemory();
            if (memory.getSize() < layout.getSize()) {
                throw context.runtime.newArgumentError("struct memory too small for parameter");
            }

            final MemoryIO io = memory.getMemoryIO();
            if (io.isDirect()) {
                if (io.isNull()) {
                    throw context.runtime.newRuntimeError("Cannot use a NULL pointer as a struct by value argument");
                }
                buffer.putStruct(io.address());

            } else if (io instanceof ArrayMemoryIO) {
                ArrayMemoryIO aio = (ArrayMemoryIO) io;
                buffer.putStruct(aio.array(), aio.arrayOffset());
View Full Code Here

            }
        }

        ByteList bl = s.getByteList();
        if (checkStringSafety) StringSupport.checkStringSafety(s.getRuntime(), s);
        MemoryIO memory;
        if (isDirect) {
            memory = TransientNativeMemoryIO.allocateAligned(s.getRuntime(), bl.length() + 1, 1, false);
            memory.putZeroTerminatedByteArray(0, bl.unsafeBytes(), bl.begin(), bl.length());
        } else {
            memory = new ArrayMemoryIO(s.getRuntime(), bl.unsafeBytes(), bl.begin(), bl.length());
        }

        s.setByteListShared();
View Full Code Here

TOP

Related Classes of org.jruby.ext.ffi.MemoryIO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.