Package jnr.ffi

Examples of jnr.ffi.Pointer


        {
            String[] envp = getEnv(Daemon.class.getName() + "=daemon");
            List<String> argv = buildARGV(posix);

            jnr.ffi.Runtime runtime = jnr.ffi.Runtime.getSystemRuntime();
            Pointer NULL = Pointer.wrap(runtime, 0L);
            IntByReference child_pid = new IntByReference();

            int rs = posix.posix_spawnp(child_pid, argv.get(0), NULL, NULL,
                                        argv.toArray(new String[argv.size()]), envp);
            if (rs != 0) {
View Full Code Here


            throw new IllegalArgumentException("global variable type not supported: " + javaType);
        }

        set.start();
        set.aload(0);
        Pointer pointer = DirectMemoryIO.wrap(runtime, address);
        set.getfield(builder.getClassNamePath(), builder.getObjectFieldName(pointer, Pointer.class), ci(Pointer.class));
        set.lconst_0();

        set.aload(1);
        set.checkcast(javaType);
View Full Code Here

   
    @Test public void inOnlyReferenceSet() {
        TestLibInOnly lib = TstUtil.loadTestLib(TestLibInOnly.class);
        Runtime runtime = Runtime.getRuntime(lib);

        final Pointer MAGIC = Memory.allocateDirect(runtime, 123);
       
        PointerByReference ref = new PointerByReference(MAGIC);
        assertEquals("Wrong value passed", MAGIC, lib.ptr_ret_pointer(ref, 0));
    }
View Full Code Here

    @Test public void inOnlyIntReferenceNotWritten() {
        TestLibInOnly lib = TstUtil.loadTestLib(TestLibInOnly.class);
        Runtime runtime = Runtime.getRuntime(lib);

        final Pointer MAGIC = Memory.allocateDirect(runtime, 123);

        PointerByReference ref = new PointerByReference(MAGIC);

        lib.ptr_set_pointer(ref, 0, null);
        assertEquals("Int reference written when it should not be", MAGIC, ref.getValue());
View Full Code Here

    @Test public void outOnlyIntReferenceNotRead() {
        TestLibOutOnly lib = TstUtil.loadTestLib(TestLibOutOnly.class);
        Runtime runtime = Runtime.getRuntime(lib);

        final Pointer MAGIC = Memory.allocateDirect(runtime, 123);

        PointerByReference ref = new PointerByReference(MAGIC);
        assertNotSame("Reference value passed to native code when it should not be", MAGIC, lib.ptr_ret_pointer(ref, 0));
    }
View Full Code Here

    @Test public void outOnlyIntReferenceGet() {
        TestLibOutOnly lib = TstUtil.loadTestLib(TestLibOutOnly.class);
        Runtime runtime = Runtime.getRuntime(lib);

        final Pointer MAGIC = Memory.allocateDirect(runtime, 123);


        PointerByReference ref = new PointerByReference(Memory.allocateDirect(runtime, 1));
        lib.ptr_set_pointer(ref, 0, MAGIC);
        assertEquals("Reference value not set", MAGIC, ref.getValue());
View Full Code Here

    public Pointer toNative(ByReference value, ToNativeContext context) {
        if (value == null) {
            return null;
        }

        Pointer memory =  Memory.allocate(context.getRuntime(), value.nativeSize(context.getRuntime()));
        if (ParameterFlags.isIn(parameterFlags)) {
            value.toNative(context.getRuntime(), memory, 0);
        }

        return memory;
View Full Code Here

    @Override
    public Pointer toNative(Struct[] structs, ToNativeContext context) {
        if (structs == null) {
            return null;
        }
        Pointer memory = Struct.getMemory(structs[0], parameterFlags);
        if (!(memory instanceof DelegatingMemoryIO)) {
            throw new RuntimeException("Struct array must be backed by contiguous array");
        }
        return ((DelegatingMemoryIO) memory).getDelegatedMemoryIO();
    }
View Full Code Here

        Class boxedType = toNativeConverter != null ? toNativeConverter.nativeType() : javaType;
        NativeType nativeType = Types.getType(runtime, boxedType, annotations).getNativeType();
        jnr.ffi.provider.ToNativeType toNativeType = new jnr.ffi.provider.ToNativeType(javaType, nativeType, annotations, toNativeConverter, null);
        jnr.ffi.provider.FromNativeType fromNativeType = new jnr.ffi.provider.FromNativeType(javaType, nativeType, annotations, fromNativeConverter, null);
        Variable variable;
        Pointer memory = MemoryUtil.newPointer(runtime, symbolAddress);
        variable = getNativeVariableAccessor(memory, toNativeType, fromNativeType);
        return toNativeType.getToNativeConverter() != null
                ? getConvertingVariable(variable, toNativeType.getToNativeConverter(), fromNativeType.getFromNativeConverter())
                : variable;
    }
View Full Code Here

        return new BoundedMemoryIO(this, offset, size);
    }


    public void transferTo(long offset, Pointer other, long otherOffset, long count) {
        Pointer dst = other instanceof DelegatingMemoryIO ? ((DelegatingMemoryIO) other).getDelegatedMemoryIO() : other;

        dst.checkBounds(otherOffset, count);

        if (dst instanceof AbstractArrayMemoryIO) {
            AbstractArrayMemoryIO aio = (AbstractArrayMemoryIO) dst;
            get(offset, aio.array(), aio.offset() + (int) otherOffset, (int) count);
View Full Code Here

TOP

Related Classes of jnr.ffi.Pointer

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.