├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .travis.yml ├── LICENSE ├── README.md ├── docs ├── ComparisonToSimilarProjects.md ├── FAQ.md ├── GettingStarted.md ├── MemoryManagement.md ├── ProjectsUsingJNR.md ├── README.md ├── SqueezingPerformance.md ├── TypeMappings.md └── WhyUseJNR.md ├── libtest ├── Benchmark.c ├── BufferTest.c ├── ClosureTest.c ├── GNUmakefile ├── GlobalVariable.c ├── LastErrorTest.c ├── NumberTest.c ├── PointerNumericTest.c ├── PointerTest.c ├── ReferenceTest.c ├── StringTest.c ├── StructTest.c ├── struct │ ├── NestedStruct.c │ ├── NestedUnion.c │ ├── NumericStruct.c │ ├── NumericUnion.c │ └── StructTypes.h └── types.h ├── mvnw ├── pom.xml └── src ├── main └── java │ └── jnr │ └── ffi │ ├── Address.java │ ├── CallingConvention.java │ ├── LastError.java │ ├── Library.java │ ├── LibraryLoader.java │ ├── LibraryOption.java │ ├── Memory.java │ ├── NativeLong.java │ ├── NativeType.java │ ├── ObjectReferenceManager.java │ ├── Platform.java │ ├── Pointer.java │ ├── Runtime.java │ ├── Struct.java │ ├── StructLayout.java │ ├── Type.java │ ├── TypeAlias.java │ ├── Union.java │ ├── Variable.java │ ├── annotations │ ├── Clear.java │ ├── Delegate.java │ ├── Direct.java │ ├── Encoding.java │ ├── IgnoreError.java │ ├── In.java │ ├── LongLong.java │ ├── Meta.java │ ├── NulTerminate.java │ ├── Out.java │ ├── Pinned.java │ ├── SaveError.java │ ├── StdCall.java │ ├── Synchronized.java │ ├── Transient.java │ ├── TypeDefinition.java │ └── Variadic.java │ ├── byref │ ├── AbstractNumberReference.java │ ├── AbstractReference.java │ ├── AddressByReference.java │ ├── ByReference.java │ ├── ByteByReference.java │ ├── DoubleByReference.java │ ├── FloatByReference.java │ ├── IntByReference.java │ ├── LongLongByReference.java │ ├── NativeLongByReference.java │ ├── NumberByReference.java │ ├── PointerByReference.java │ └── ShortByReference.java │ ├── mapper │ ├── AbstractDataConverter.java │ ├── AbstractFromNativeType.java │ ├── AbstractSignatureTypeMapper.java │ ├── AbstractToNativeType.java │ ├── CachingTypeMapper.java │ ├── CompositeFunctionMapper.java │ ├── CompositeTypeMapper.java │ ├── DataConverter.java │ ├── DefaultSignatureType.java │ ├── DefaultTypeMapper.java │ ├── FromNativeContext.java │ ├── FromNativeConverter.java │ ├── FromNativeType.java │ ├── FromNativeTypes.java │ ├── FunctionMapper.java │ ├── MethodParameterContext.java │ ├── MethodResultContext.java │ ├── SignatureType.java │ ├── SignatureTypeMapper.java │ ├── SignatureTypeMapperAdapter.java │ ├── SimpleFunctionMapper.java │ ├── SimpleTypeMapper.java │ ├── ToNativeContext.java │ ├── ToNativeConverter.java │ ├── ToNativeType.java │ ├── ToNativeTypes.java │ ├── TypeMapper.java │ └── Util.java │ ├── provider │ ├── AbstractArrayMemoryIO.java │ ├── AbstractBufferMemoryIO.java │ ├── AbstractMemoryIO.java │ ├── AbstractRuntime.java │ ├── BadType.java │ ├── BoundedMemoryIO.java │ ├── ClosureManager.java │ ├── DefaultObjectReferenceManager.java │ ├── DelegatingMemoryIO.java │ ├── FFIProvider.java │ ├── FromNativeType.java │ ├── IdentityFunctionMapper.java │ ├── InAccessibleMemoryIO.java │ ├── IntPointer.java │ ├── InterfaceScanner.java │ ├── InvalidProvider.java │ ├── InvalidRuntime.java │ ├── InvocationSession.java │ ├── Invoker.java │ ├── LoadedLibrary.java │ ├── MemoryManager.java │ ├── NativeFunction.java │ ├── NativeInvocationHandler.java │ ├── NativeVariable.java │ ├── NullMemoryIO.java │ ├── NullTypeMapper.java │ ├── ParameterFlags.java │ ├── ParameterType.java │ ├── ResultType.java │ ├── ShareMemoryIO.java │ ├── SigType.java │ ├── ToNativeType.java │ ├── converters │ │ ├── BoxedBooleanArrayParameterConverter.java │ │ ├── BoxedByteArrayParameterConverter.java │ │ ├── BoxedDoubleArrayParameterConverter.java │ │ ├── BoxedFloatArrayParameterConverter.java │ │ ├── BoxedIntegerArrayParameterConverter.java │ │ ├── BoxedLong32ArrayParameterConverter.java │ │ ├── BoxedLong64ArrayParameterConverter.java │ │ ├── BoxedShortArrayParameterConverter.java │ │ ├── ByReferenceParameterConverter.java │ │ ├── CharSequenceArrayParameterConverter.java │ │ ├── CharSequenceParameterConverter.java │ │ ├── EnumConverter.java │ │ ├── EnumSetConverter.java │ │ ├── Long32ArrayParameterConverter.java │ │ ├── NativeLong32ArrayParameterConverter.java │ │ ├── NativeLong64ArrayParameterConverter.java │ │ ├── NativeLongConverter.java │ │ ├── Pointer32ArrayParameterConverter.java │ │ ├── Pointer64ArrayParameterConverter.java │ │ ├── StringBufferParameterConverter.java │ │ ├── StringBuilderParameterConverter.java │ │ ├── StringResultConverter.java │ │ ├── StringUtil.java │ │ ├── StructArrayParameterConverter.java │ │ ├── StructByReferenceFromNativeConverter.java │ │ └── StructByReferenceToNativeConverter.java │ └── jffi │ │ ├── ARM_64StubCompiler.java │ │ ├── AbstractA64StubCompiler.java │ │ ├── AbstractAsmLibraryInterface.java │ │ ├── AbstractFastNumericMethodGenerator.java │ │ ├── AbstractX86StubCompiler.java │ │ ├── AllocatedDirectMemoryIO.java │ │ ├── AnnotationTypeMapper.java │ │ ├── ArrayMemoryIO.java │ │ ├── AsmBuilder.java │ │ ├── AsmClassLoader.java │ │ ├── AsmLibraryLoader.java │ │ ├── AsmRuntime.java │ │ ├── AsmStructByReferenceFromNativeConverter.java │ │ ├── AsmUtil.java │ │ ├── BaseMethodGenerator.java │ │ ├── BufferMethodGenerator.java │ │ ├── BufferParameterStrategy.java │ │ ├── ByteBufferMemoryIO.java │ │ ├── ClosureFromNativeConverter.java │ │ ├── ClosureTypeMapper.java │ │ ├── ClosureUtil.java │ │ ├── CodegenUtils.java │ │ ├── ConverterMetaData.java │ │ ├── DefaultInvokerFactory.java │ │ ├── DirectMemoryIO.java │ │ ├── FastIntMethodGenerator.java │ │ ├── FastLongMethodGenerator.java │ │ ├── FastNumericMethodGenerator.java │ │ ├── HeapBufferParameterStrategy.java │ │ ├── InvokerTypeMapper.java │ │ ├── InvokerUtil.java │ │ ├── JNIInvokeInterface.java │ │ ├── JNINativeInterface.java │ │ ├── LibraryLoader.java │ │ ├── LocalVariable.java │ │ ├── LocalVariableAllocator.java │ │ ├── MemoryUtil.java │ │ ├── MethodGenerator.java │ │ ├── NativeClosureFactory.java │ │ ├── NativeClosureManager.java │ │ ├── NativeClosurePointer.java │ │ ├── NativeClosureProxy.java │ │ ├── NativeFinalizer.java │ │ ├── NativeFunctionMapperContext.java │ │ ├── NativeLibrary.java │ │ ├── NativeLibraryLoader.java │ │ ├── NativeMemoryManager.java │ │ ├── NativeRuntime.java │ │ ├── NoTrace.java │ │ ├── NoX86.java │ │ ├── NotImplMethodGenerator.java │ │ ├── NullObjectParameterStrategy.java │ │ ├── NumberUtil.java │ │ ├── ParameterStrategy.java │ │ ├── PointerParameterStrategy.java │ │ ├── PrimitiveArrayParameterStrategy.java │ │ ├── Provider.java │ │ ├── ReflectionLibraryLoader.java │ │ ├── ReflectionVariableAccessorGenerator.java │ │ ├── SimpleNativeContext.java │ │ ├── SkinnyMethodAdapter.java │ │ ├── StructByReferenceResultConverterFactory.java │ │ ├── StubCompiler.java │ │ ├── SymbolNotFoundError.java │ │ ├── ToNativeOp.java │ │ ├── TransientNativeMemory.java │ │ ├── Types.java │ │ ├── Util.java │ │ ├── VariableAccessorGenerator.java │ │ ├── X86Disassembler.java │ │ ├── X86MethodGenerator.java │ │ ├── X86_32StubCompiler.java │ │ ├── X86_64StubCompiler.java │ │ └── platform │ │ ├── aarch64 │ │ ├── darwin │ │ │ └── TypeAliases.java │ │ ├── freebsd │ │ │ └── TypeAliases.java │ │ ├── linux │ │ │ └── TypeAliases.java │ │ └── windows │ │ │ └── TypeAliases.java │ │ ├── arm │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── i386 │ │ ├── darwin │ │ │ └── TypeAliases.java │ │ ├── freebsd │ │ │ └── TypeAliases.java │ │ ├── linux │ │ │ └── TypeAliases.java │ │ ├── midnightbsd │ │ │ └── TypeAliases.java │ │ ├── openbsd │ │ │ └── TypeAliases.java │ │ ├── solaris │ │ │ └── TypeAliases.java │ │ └── windows │ │ │ └── TypeAliases.java │ │ ├── loongarch64 │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── mips │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── mips64 │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── mips64el │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── mipsel │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── ppc │ │ ├── aix │ │ │ └── TypeAliases.java │ │ ├── darwin │ │ │ └── TypeAliases.java │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── ppc64 │ │ ├── aix │ │ │ └── TypeAliases.java │ │ ├── freebsd │ │ │ └── TypeAliases.java │ │ ├── ibmi │ │ │ └── TypeAliases.java │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── ppc64le │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── riscv64 │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── s390 │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── s390x │ │ └── linux │ │ │ └── TypeAliases.java │ │ ├── sparc │ │ └── solaris │ │ │ └── TypeAliases.java │ │ ├── sparcv9 │ │ ├── linux │ │ │ └── TypeAliases.java │ │ └── solaris │ │ │ └── TypeAliases.java │ │ └── x86_64 │ │ ├── darwin │ │ └── TypeAliases.java │ │ ├── dragonfly │ │ └── TypeAliases.java │ │ ├── freebsd │ │ └── TypeAliases.java │ │ ├── linux │ │ └── TypeAliases.java │ │ ├── midnightbsd │ │ └── TypeAliases.java │ │ ├── openbsd │ │ └── TypeAliases.java │ │ ├── solaris │ │ └── TypeAliases.java │ │ └── windows │ │ └── TypeAliases.java │ ├── types │ ├── blkcnt_t.java │ ├── blksize_t.java │ ├── caddr_t.java │ ├── clock_t.java │ ├── dev_t.java │ ├── fsblkcnt_t.java │ ├── fsfilcnt_t.java │ ├── gid_t.java │ ├── id_t.java │ ├── in_addr_t.java │ ├── in_port_t.java │ ├── ino64_t.java │ ├── ino_t.java │ ├── int16_t.java │ ├── int32_t.java │ ├── int64_t.java │ ├── int8_t.java │ ├── intptr_t.java │ ├── key_t.java │ ├── mode_t.java │ ├── nlink_t.java │ ├── off_t.java │ ├── pid_t.java │ ├── rlim_t.java │ ├── sa_family_t.java │ ├── size_t.java │ ├── socklen_t.java │ ├── ssize_t.java │ ├── swblk_t.java │ ├── time_t.java │ ├── u_int16_t.java │ ├── u_int32_t.java │ ├── u_int64_t.java │ ├── u_int8_t.java │ ├── uid_t.java │ └── uintptr_t.java │ └── util │ ├── AnnotationNameComparator.java │ ├── AnnotationProperty.java │ ├── AnnotationProxy.java │ ├── Annotations.java │ ├── BufferUtil.java │ ├── EnumMapper.java │ └── ref │ ├── FinalizablePhantomReference.java │ ├── FinalizableReference.java │ ├── FinalizableReferenceQueue.java │ ├── FinalizableSoftReference.java │ ├── FinalizableWeakReference.java │ └── internal │ └── Finalizer.java └── test └── java └── jnr └── ffi ├── ArrayTest.java ├── BufferTest.java ├── DelegateTest.java ├── GetLoadedLibrariesTest.java ├── GlobalVariableTest.java ├── InvocationTest.java ├── LastErrorTest.java ├── LibraryLoaderTest.java ├── LibraryTest.java ├── MemoryIOTest.java ├── ObjectReferenceManagerTest.java ├── PlatformTest.java ├── PointerTest.java ├── ResultConverterTest.java ├── StringArrayTest.java ├── StringTest.java ├── TstUtil.java ├── TypeDefinitionTest.java ├── VarargsTest.java ├── byref ├── AddressByReferenceTest.java ├── ByteByReferenceTest.java ├── IntByReferenceTest.java └── PointerByReferenceTest.java ├── mapper ├── AnnotatedMappedTypeTest.java └── CachingTypeMapperTest.java ├── numeric ├── EnumTest.java ├── NativeLongTest.java ├── NumberTest.java └── utils │ ├── BooleanNumberTestLib.java │ ├── NumberOps.java │ ├── NumberRange.java │ ├── NumberTestLib.java │ └── NumberUtils.java ├── pointer └── PointerNumericTest.java ├── provider └── InterfaceScannerTest.java └── struct ├── AlignmentTest.java ├── ArrayTest.java ├── AsciiStringFieldTest.java ├── EnumTest.java ├── NestedStructTest.java ├── NestedUnionTest.java ├── NumericStructTest.java ├── NumericUnionTest.java ├── PaddingTest.java ├── StructLayoutTest.java ├── StructToStringTest.java ├── StructureTest.java └── UTF8StringFieldTest.java /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Java CI with Maven 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | 14 | mvn-test-x86: 15 | 16 | runs-on: ${{ matrix.os }} 17 | 18 | strategy: 19 | matrix: 20 | os: [ubuntu-latest, macos-latest, [self-hosted, macos, aarch64]] 21 | java-version: ['8', '11'] 22 | fail-fast: false 23 | 24 | steps: 25 | - uses: actions/checkout@v2 26 | - name: Cache dependencies 27 | uses: actions/cache@v2 28 | with: 29 | path: ~/.m2 30 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 31 | restore-keys: ${{ runner.os }}-m2 32 | - name: Set up JDK ${{ matrix.java-version }} 33 | uses: actions/setup-java@v1.4.3 34 | with: 35 | java-version: ${{ matrix.java-version }} 36 | - name: Build with Maven 37 | run: mvn -B package --file pom.xml 38 | 39 | mvn-test-macos-aarch64: 40 | 41 | runs-on: [self-hosted, macos, aarch64] 42 | 43 | name: mvn test on Apple M1 44 | 45 | strategy: 46 | fail-fast: false 47 | 48 | steps: 49 | - uses: actions/checkout@v2 50 | - name: Cache dependencies 51 | uses: actions/cache@v2 52 | with: 53 | path: ~/.m2 54 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 55 | restore-keys: ${{ runner.os }}-m2 56 | - name: Set up JDK 11 57 | uses: actions/setup-java@v2 58 | with: 59 | distribution: 'zulu' 60 | java-version: 11 61 | architecture: arm 62 | - name: Build with Maven 63 | run: mvn -B package --file pom.xml 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.orig$ 2 | *.rej$ 3 | *.class$ 4 | *~ 5 | .idea 6 | *.iml 7 | *.iws 8 | *.ipr 9 | *.log 10 | nbproject/private 11 | build 12 | dist 13 | target 14 | lib/nblibraries-private.properties 15 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jnr/jnr-ffi/683b8531776588b040cde17bb71a550ca19fc353/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | notifications: 3 | irc: 4 | channels: 5 | - "irc.freenode.org#jnr" 6 | on_success: change 7 | on_failure: always 8 | template: 9 | - "%{repository} (%{branch}:%{commit} by %{author}): %{message} (%{build_url})" 10 | matrix: 11 | include: 12 | - os: osx 13 | - os: linux 14 | jdk: oraclejdk8 15 | - os: linux 16 | jdk: openjdk7 17 | sudo: false 18 | cache: 19 | directories: 20 | - $HOME/.m2 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 (the "License"); 2 | you may not use this file except in compliance with the License. 3 | You may obtain a copy of the License at 4 | 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | 13 | 14 | Alternatively, you can redistribute it and/or modify it under 15 | the terms of the GNU Lesser General Public License as published by 16 | the Free Software Foundation, either version 3 of the License, or 17 | (at your option) any later version. 18 | 19 | This code is distributed in the hope that it will be useful, but WITHOUT 20 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 22 | version 3 for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public License 25 | version 3 along with this work. If not, see . 26 | -------------------------------------------------------------------------------- /docs/MemoryManagement.md: -------------------------------------------------------------------------------- 1 | # Memory Management 2 | 3 | ## Pointers 4 | A `Pointer` instance stores reference to a native memory address. As it can 5 | represent various data like struct, arrays, java objects, etc. it needs to 6 | be used with caution since any illegal access can cause segfaults and JVM crash. 7 | The `Pointer` class provides methods to return different representations of 8 | the stored data, for example: 9 | - `getInt(long offset)`: Reads 32-bit int value at given offset 10 | - `getPointer(long offset, int size)`: Reads a pointer at given offset 11 | - `array()`: Returns an array if it backs this pointer 12 | 13 | ## Runtime 14 | A `Runtime` instance for the loaded library can be obtained using 15 | the `Runtime.getRuntime()` method. It gives access to important 16 | services like `ObjectReferenceManager` and `MemoryManager`. 17 | 18 | ### MemoryManager 19 | As the name suggests, it provides various methods to allocate memory 20 | for use with native functions. 21 | - `allocate`: Allocates Java memory 22 | - `allocateDirect`: Allocates native memory 23 | - `allocateTemporary`: Allocates transient native memory 24 | 25 | The `Memory` class also provides utility methods to handle memory 26 | allocation for common use-cases. It uses `MemoryManager` internally. 27 | 28 | ### ObjectReferenceManager 29 | Any native memory associated with a Java object is released as soon as 30 | the object gets garbage-collected. An `ObjectReferenceManager` provides 31 | handy methods to keep objects strongly-referenced as long as its native 32 | memory is in use. This can be helpful while working with function pointers, 33 | which are associated with lambda functions on the Java side. Use `add` 34 | to register any object and use `remove` to dereference the registered object. -------------------------------------------------------------------------------- /docs/ProjectsUsingJNR.md: -------------------------------------------------------------------------------- 1 | # Projects Using JNR-FFI 2 | 3 | ## Our Projects 4 | 5 | These are projects developed and maintained by (generally) the same team that develops and maintains JNR-FFI. 6 | 7 | ### JRuby 8 | 9 | By far the largest, most substantial and most important project using JNR-FFI is JRuby, a JVM implementation of the Ruby 10 | programming language. In fact JNR-FFI started out as a library for JRuby to solve Ruby's need for native system calls 11 | and provide the same level of intractability with the native world as other Ruby implementations did. JRuby is JNR-FFI's 12 | largest *"client"* and indeed the lead maintainers of JNR-FFI and the JNR project in general are also the lead 13 | developers of JRuby currently employed by Red Hat. This is all to say that we are *"dogfooding"* JNR-FFI in our own 14 | major large-scale project JRuby. 15 | 16 | If you had doubts about whether this library or even the JNR project in general is professional or will survive the 17 | foreseeable future, JRuby's deep dependence on JNR-FFI (and the JNR project) should eliminate those doubts. 18 | 19 | ### JNR Projects 20 | 21 | The JNR Project has multiple libraries that use JNR-FFI to call to native libraries such as JNR-POSIX, JNR-Process and 22 | JNR-ENXIO. Many of these themselves used in JRuby to help increase ease (and performance) of native library calls for 23 | JRuby. 24 | 25 | ## Community Projects 26 | 27 | These are projects developed by the community. 28 | 29 | ### [JRtMidi](https://github.com/basshelal/JRtMidi) 30 | 31 | Java bindings to [RtMidi](https://github.com/thestk/rtmidi) written in Kotlin. 32 | 33 | -------------------------------------------------- 34 | 35 | If you're using JNR-FFI and want to add your project here, make a pull request! -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # User Documentation 2 | 3 | Here is where you will find documents that explain aspects about JNR-FFI such as how to quickly get started or whether 4 | to even use JNR-FFI. 5 | 6 | * [Getting Started](./GettingStarted.md) 7 | * [Type Mappings](./TypeMappings.md) 8 | * [Memory Management](./MemoryManagement.md) 9 | * [Why Use JNR-FFI](./WhyUseJNR.md) 10 | * [Comparison to Similar Projects](./ComparisonToSimilarProjects.md) 11 | * [Projects using JNR-FFI](./ProjectsUsingJNR.md) 12 | * [Squeezing Performance](./SqueezingPerformance.md) 13 | * [Frequently Asked Questions](./FAQ.md) -------------------------------------------------------------------------------- /libtest/Benchmark.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | void returnVoid() { 20 | 21 | } 22 | 23 | void returnVoidI(int arg) { 24 | (void)(arg); 25 | } 26 | int returnInt() { 27 | return 0; 28 | } 29 | 30 | int returnIntI(int arg) { 31 | return arg; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /libtest/BufferTest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | #define MEMSET(buf, value, size) do { \ 21 | int i; for (i = 0; i < size; ++i) buf[i] = value; \ 22 | } while(0) 23 | #define MEMCPY(dst, src, size) do { \ 24 | int i; for (i = 0; i < size; ++i) dst[i] = src[i]; \ 25 | } while(0) 26 | 27 | #define FILL(JTYPE, CTYPE) \ 28 | void fill##JTYPE##Buffer(CTYPE* buf, CTYPE value, int size) { MEMSET(buf, value, size); } 29 | 30 | #define COPY(JTYPE, CTYPE) \ 31 | void copy##JTYPE##Buffer(CTYPE* dst, CTYPE* src, int size) { MEMCPY(dst, src, size); } 32 | 33 | #define FUNC(JTYPE, CTYPE) \ 34 | FILL(JTYPE, CTYPE); \ 35 | COPY(JTYPE, CTYPE) 36 | 37 | FUNC(Byte, char); 38 | FUNC(Short, short); 39 | FUNC(Int, int); 40 | FUNC(Long, long long); 41 | FUNC(Float, float); 42 | FUNC(Double, double); 43 | 44 | -------------------------------------------------------------------------------- /libtest/GlobalVariable.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | typedef int8_t s8; 23 | typedef uint8_t u8; 24 | typedef int16_t s16; 25 | typedef uint16_t u16; 26 | typedef int32_t s32; 27 | typedef uint32_t u32; 28 | typedef int64_t s64; 29 | typedef uint64_t u64; 30 | typedef signed long sL; 31 | typedef unsigned long uL; 32 | typedef float f32; 33 | typedef double f64; 34 | #if !defined(__OpenBSD__) 35 | typedef unsigned long ulong; 36 | #endif 37 | typedef void* pointer; 38 | typedef void* P; 39 | 40 | #define GVAR(T) \ 41 | extern T gvar_##T; \ 42 | T gvar_##T = (T) -1; \ 43 | T gvar_##T##_get() { return gvar_##T; }; \ 44 | void gvar_##T##_set(T v) { gvar_##T = v; } 45 | 46 | GVAR(s8); 47 | GVAR(u8); 48 | GVAR(s16); 49 | GVAR(u16); 50 | GVAR(s32); 51 | GVAR(u32); 52 | GVAR(s64); 53 | GVAR(u64); 54 | GVAR(long); 55 | GVAR(ulong); 56 | GVAR(pointer); 57 | 58 | struct gstruct { 59 | long data; 60 | }; 61 | 62 | struct gstruct gvar_gstruct = { -1 }; 63 | 64 | struct gstruct* 65 | gvar_gstruct_get(void) 66 | { 67 | return &gvar_gstruct; 68 | } 69 | 70 | void 71 | gvar_gstruct_set(const struct gstruct* val) 72 | { 73 | gvar_gstruct = *val; 74 | } 75 | -------------------------------------------------------------------------------- /libtest/LastErrorTest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #include 19 | 20 | #ifdef _WIN32 21 | #include 22 | #endif 23 | 24 | int setLastError(int error) { 25 | #ifdef _WIN32 26 | SetLastError(error); 27 | #else 28 | errno = error; 29 | #endif 30 | 31 | return -1; 32 | } 33 | -------------------------------------------------------------------------------- /libtest/PointerNumericTest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef __mips__ 5 | # include 6 | #endif 7 | 8 | #if defined(__mips64) || defined(__PASE__) 9 | # include 10 | #endif 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // Let's define the stdint.h typedefs ourselves if they can't be found 18 | #if !defined(_STDINT_H_) && !defined(_STDINT_H) && !defined(_SYS__STDINT_H_) && !defined(_H_STDINT) 19 | typedef signed char int8_t; 20 | typedef signed short int16_t; 21 | typedef signed int int32_t; 22 | typedef signed long long int64_t; 23 | typedef unsigned char uint8_t; 24 | typedef unsigned short uint16_t; 25 | typedef unsigned int uint32_t; 26 | typedef unsigned long long uint64_t; 27 | #endif 28 | 29 | typedef long double ldouble; 30 | typedef unsigned long ulong; 31 | typedef void* pointer; 32 | typedef void* ptr; 33 | typedef enum Enum_t {e0, e1, e2, e3} Enum; 34 | typedef bool boolean; 35 | 36 | #define RET(T) T ptr_num_ret_##T(void *p, int offset) { \ 37 | T tmp; memcpy(&tmp, (ptr) (p + offset), sizeof(tmp)); return tmp; \ 38 | } 39 | #define SET(T) void ptr_num_set_##T(void *p, int offset, T value) { \ 40 | memcpy((ptr) (p + offset), &value, sizeof(value)); \ 41 | } 42 | 43 | #define TEST(T) SET(T) RET(T) 44 | 45 | TEST(int8_t); 46 | TEST(int16_t); 47 | TEST(int32_t); 48 | TEST(long); 49 | TEST(int64_t); 50 | 51 | TEST(uint8_t); 52 | TEST(uint16_t); 53 | TEST(uint32_t); 54 | TEST(ulong); 55 | TEST(uint64_t); 56 | 57 | TEST(float); 58 | TEST(double); 59 | TEST(ldouble); 60 | 61 | TEST(boolean); 62 | TEST(pointer); 63 | TEST(Enum); 64 | 65 | void *ptr_num_arr_get(void **array, int index) { 66 | return array[index]; 67 | } 68 | 69 | void ptr_num_arr_set(void **array, int index, void *value) { 70 | array[index] = value; 71 | } 72 | -------------------------------------------------------------------------------- /libtest/ReferenceTest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #if !defined(__mips__) || defined(__PASE__) 20 | # include 21 | #endif 22 | 23 | #if !defined(_STDINT_H_) && !defined(_STDINT_H) && !defined(_SYS__STDINT_H_) && !defined(_H_STDINT) 24 | typedef signed char int8_t; 25 | typedef signed short int16_t; 26 | typedef signed int int32_t; 27 | typedef signed long long int64_t; 28 | #endif 29 | 30 | #define REF(T) void ref_##T(T arg, T* result) { *result = arg; } 31 | #define ADD(T) void ref_add_##T(T arg1, T arg2, T* result) { *result = arg1 + arg2; } 32 | #define SUB(T) void ref_sub_##T(T arg1, T arg2, T* result) { *result = arg1 - arg2; } 33 | #define MUL(T) void ref_mul_##T(T arg1, T arg2, T* result) { *result = arg1 * arg2; } 34 | #define DIV(T) void ref_div_##T(T arg1, T arg2, T* result) { *result = arg1 / arg2; } 35 | #define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) REF(T) 36 | 37 | TEST(int8_t); 38 | TEST(int16_t); 39 | TEST(int32_t); 40 | TEST(int64_t); 41 | TEST(float); 42 | TEST(double); 43 | 44 | -------------------------------------------------------------------------------- /libtest/StringTest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | 21 | int 22 | string_equals(const char* s1, const char* s2) 23 | { 24 | return strcmp(s1, s2) == 0; 25 | } 26 | 27 | void 28 | string_set(char* s1, const char* s2) 29 | { 30 | strcpy(s1, s2); 31 | } 32 | 33 | void 34 | string_concat(char* dst, const char* src) 35 | { 36 | char* ep = dst; 37 | while (*ep) 38 | ep++; 39 | strcpy(ep, src); 40 | } 41 | 42 | char* 43 | string_duplicate(const char* s1) 44 | { 45 | return strdup(s1); 46 | } 47 | -------------------------------------------------------------------------------- /libtest/struct/NestedUnion.c: -------------------------------------------------------------------------------- 1 | #include "StructTypes.h" 2 | 3 | #define SET_VAL(TYPE) \ 4 | TYPE nested_union_inner_struct_get_##TYPE(NestedUnion *s) { \ 5 | return s->inner_NumericStruct.val_##TYPE; \ 6 | } \ 7 | TYPE nested_union_ptr_struct_get_##TYPE(NestedUnion *s) { \ 8 | return s->ptr_NumericStruct->val_##TYPE; \ 9 | } \ 10 | TYPE nested_union_inner_union_get_##TYPE(NestedUnion *s) { \ 11 | return s->inner_NumericUnion.val_##TYPE; \ 12 | } \ 13 | TYPE nested_union_ptr_union_get_##TYPE(NestedUnion *s) { \ 14 | return s->ptr_NumericUnion->val_##TYPE; \ 15 | } 16 | 17 | #define GET_VAL(TYPE) \ 18 | void nested_union_inner_struct_set_##TYPE(NestedUnion *s, TYPE v) { \ 19 | s->inner_NumericStruct.val_##TYPE = v; \ 20 | } \ 21 | void nested_union_ptr_struct_set_##TYPE(NestedUnion *s, TYPE v) { \ 22 | s->ptr_NumericStruct->val_##TYPE = v; \ 23 | } \ 24 | void nested_union_inner_union_set_##TYPE(NestedUnion *s, TYPE v) { \ 25 | s->inner_NumericUnion.val_##TYPE = v; \ 26 | } \ 27 | void nested_union_ptr_union_set_##TYPE(NestedUnion *s, TYPE v) { \ 28 | s->ptr_NumericUnion->val_##TYPE = v; \ 29 | } 30 | 31 | 32 | // ============================= Set Functions ====================== 33 | 34 | SET_VAL(int8_t); 35 | SET_VAL(int16_t); 36 | SET_VAL(int32_t); 37 | SET_VAL(long); 38 | SET_VAL(int64_t); 39 | 40 | SET_VAL(uint8_t); 41 | SET_VAL(uint16_t); 42 | SET_VAL(uint32_t); 43 | SET_VAL(ulong); 44 | SET_VAL(uint64_t); 45 | 46 | SET_VAL(float); 47 | SET_VAL(double); 48 | 49 | SET_VAL(bool); 50 | SET_VAL(Enum); 51 | SET_VAL(pointer); 52 | 53 | // ============================= Get Functions ====================== 54 | 55 | GET_VAL(int8_t); 56 | GET_VAL(int16_t); 57 | GET_VAL(int32_t); 58 | GET_VAL(long); 59 | GET_VAL(int64_t); 60 | 61 | GET_VAL(uint8_t); 62 | GET_VAL(uint16_t); 63 | GET_VAL(uint32_t); 64 | GET_VAL(ulong); 65 | GET_VAL(uint64_t); 66 | 67 | GET_VAL(float); 68 | GET_VAL(double); 69 | 70 | GET_VAL(bool); 71 | GET_VAL(Enum); 72 | GET_VAL(pointer); 73 | 74 | int nested_union_size() { 75 | return sizeof(NestedUnion); 76 | } 77 | -------------------------------------------------------------------------------- /libtest/struct/NumericStruct.c: -------------------------------------------------------------------------------- 1 | #include "StructTypes.h" 2 | 3 | #define SET_VAL(TYPE) \ 4 | TYPE struct_num_get_##TYPE(NumericStruct *s) { \ 5 | return s->val_##TYPE; \ 6 | } 7 | 8 | #define GET_VAL(TYPE) \ 9 | void struct_num_set_##TYPE(NumericStruct *s, TYPE v) { \ 10 | s->val_##TYPE = v; \ 11 | } 12 | 13 | // ============================= Set Functions ====================== 14 | 15 | SET_VAL(int8_t); 16 | SET_VAL(int16_t); 17 | SET_VAL(int32_t); 18 | SET_VAL(long); 19 | SET_VAL(int64_t); 20 | 21 | SET_VAL(uint8_t); 22 | SET_VAL(uint16_t); 23 | SET_VAL(uint32_t); 24 | SET_VAL(ulong); 25 | SET_VAL(uint64_t); 26 | 27 | SET_VAL(float); 28 | SET_VAL(double); 29 | 30 | SET_VAL(bool); 31 | SET_VAL(Enum); 32 | SET_VAL(pointer); 33 | 34 | // ============================= Get Functions ====================== 35 | 36 | GET_VAL(int8_t); 37 | GET_VAL(int16_t); 38 | GET_VAL(int32_t); 39 | GET_VAL(long); 40 | GET_VAL(int64_t); 41 | 42 | GET_VAL(uint8_t); 43 | GET_VAL(uint16_t); 44 | GET_VAL(uint32_t); 45 | GET_VAL(ulong); 46 | GET_VAL(uint64_t); 47 | 48 | GET_VAL(float); 49 | GET_VAL(double); 50 | 51 | GET_VAL(bool); 52 | GET_VAL(Enum); 53 | GET_VAL(pointer); 54 | 55 | int struct_num_size() { 56 | return sizeof(NumericStruct); 57 | } 58 | -------------------------------------------------------------------------------- /libtest/struct/NumericUnion.c: -------------------------------------------------------------------------------- 1 | #include "StructTypes.h" 2 | 3 | #define SET_VAL(TYPE) \ 4 | TYPE union_num_get_##TYPE(NumericUnion *s) { \ 5 | return s->val_##TYPE; \ 6 | } 7 | 8 | #define GET_VAL(TYPE) \ 9 | void union_num_set_##TYPE(NumericUnion *s, TYPE v) { \ 10 | s->val_##TYPE = v; \ 11 | } 12 | 13 | // ============================= Set Functions ====================== 14 | 15 | SET_VAL(int8_t); 16 | SET_VAL(int16_t); 17 | SET_VAL(int32_t); 18 | SET_VAL(long); 19 | SET_VAL(int64_t); 20 | 21 | SET_VAL(uint8_t); 22 | SET_VAL(uint16_t); 23 | SET_VAL(uint32_t); 24 | SET_VAL(ulong); 25 | SET_VAL(uint64_t); 26 | 27 | SET_VAL(float); 28 | SET_VAL(double); 29 | 30 | SET_VAL(bool); 31 | SET_VAL(Enum); 32 | SET_VAL(pointer); 33 | 34 | // ============================= Get Functions ====================== 35 | 36 | GET_VAL(int8_t); 37 | GET_VAL(int16_t); 38 | GET_VAL(int32_t); 39 | GET_VAL(long); 40 | GET_VAL(int64_t); 41 | 42 | GET_VAL(uint8_t); 43 | GET_VAL(uint16_t); 44 | GET_VAL(uint32_t); 45 | GET_VAL(ulong); 46 | GET_VAL(uint64_t); 47 | 48 | GET_VAL(float); 49 | GET_VAL(double); 50 | 51 | GET_VAL(bool); 52 | GET_VAL(Enum); 53 | GET_VAL(pointer); 54 | 55 | int union_num_size() { 56 | return sizeof(NumericUnion); 57 | } 58 | -------------------------------------------------------------------------------- /libtest/struct/StructTypes.h: -------------------------------------------------------------------------------- 1 | #include "../types.h" 2 | 3 | typedef struct NumericStruct_t { 4 | int8_t val_int8_t; 5 | int16_t val_int16_t; 6 | int32_t val_int32_t; 7 | long val_long; 8 | int64_t val_int64_t; 9 | 10 | uint8_t val_uint8_t; 11 | uint16_t val_uint16_t; 12 | uint32_t val_uint32_t; 13 | ulong val_ulong; 14 | uint64_t val_uint64_t; 15 | 16 | float val_float; 17 | double val_double; 18 | 19 | bool val_bool; 20 | Enum val_Enum; 21 | pointer val_pointer; 22 | } NumericStruct; 23 | 24 | typedef union NumericUnion_t { 25 | int8_t val_int8_t; 26 | int16_t val_int16_t; 27 | int32_t val_int32_t; 28 | long val_long; 29 | int64_t val_int64_t; 30 | 31 | uint8_t val_uint8_t; 32 | uint16_t val_uint16_t; 33 | uint32_t val_uint32_t; 34 | ulong val_ulong; 35 | uint64_t val_uint64_t; 36 | 37 | float val_float; 38 | double val_double; 39 | 40 | bool val_bool; 41 | Enum val_Enum; 42 | pointer val_pointer; 43 | } NumericUnion; 44 | 45 | typedef struct NestedStruct_t { 46 | NumericStruct inner_NumericStruct; 47 | NumericUnion inner_NumericUnion; 48 | 49 | NumericStruct *ptr_NumericStruct; 50 | NumericUnion *ptr_NumericUnion; 51 | } NestedStruct; 52 | 53 | typedef union NestedUnion_t { 54 | NumericStruct inner_NumericStruct; 55 | NumericUnion inner_NumericUnion; 56 | 57 | NumericStruct *ptr_NumericStruct; 58 | NumericUnion *ptr_NumericUnion; 59 | } NestedUnion; 60 | -------------------------------------------------------------------------------- /libtest/types.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #if !defined(__mips___) || defined(__PASE__) 4 | # include 5 | #endif 6 | 7 | // Let's define the stdint.h typedefs ourselves if they can't be found 8 | #if !defined (_STDINT_H_) && !defined(_STDINT_H) && !defined(_SYS__STDINT_H_) && !defined(_H_STDINT) 9 | typedef signed char int8_t; 10 | typedef signed short int16_t; 11 | typedef signed int int32_t; 12 | typedef signed long long int64_t; 13 | typedef unsigned char uint8_t; 14 | typedef unsigned short uint16_t; 15 | typedef unsigned int uint32_t; 16 | typedef unsigned long long uint64_t; 17 | #endif 18 | 19 | typedef unsigned long ulong; 20 | typedef long double ldouble; 21 | typedef void* pointer; 22 | typedef enum Enum_t {e0, e1, e2, e3} Enum; -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/CallingConvention.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi; 20 | 21 | /** 22 | * Native function calling conventions. 23 | * 24 | *

This is only needed on windows platforms - all platforms assume 25 | * {@link #DEFAULT} as the calling convention. 26 | */ 27 | public enum CallingConvention { 28 | /** 29 | * The default C calling convention 30 | */ 31 | DEFAULT, 32 | /** 33 | * Windows stdcall calling convention 34 | */ 35 | STDCALL 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/LastError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi; 20 | 21 | /** 22 | * Provides access to the unix errno and windows GetLastError() value. 23 | */ 24 | public final class LastError { 25 | private LastError() {} 26 | 27 | /** 28 | * Gets the value of errno from the last native call. 29 | * 30 | * @param runtime FFI runtime to get errno for. 31 | * @return An integer containing the errno value. 32 | */ 33 | public static int getLastError(Runtime runtime) { 34 | return runtime.getLastError(); 35 | } 36 | 37 | /** 38 | * Sets the native errno value. 39 | * 40 | * @param runtime FFI runtime to set errno for. 41 | * @param error The value to set errno to. 42 | */ 43 | public static void setLastError(Runtime runtime, int error) { 44 | runtime.setLastError(error); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/Type.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi; 20 | 21 | /** 22 | * Type is the superclass for all internal types used by jnr-ffi. 23 | * 24 | *

25 | * Use this type to access meta-data about a native type, such as its size or natural alignment. 26 | *

27 | * To obtain an instance of this class, use {@link jnr.ffi.Runtime#findType(NativeType)} or 28 | * {@link jnr.ffi.Runtime#findType(TypeAlias)}. 29 | *

30 | * Example 31 | *

32 |  * {@code
33 |  *
34 |  *    Type pointerType = runtime.findType(NativeType.ADDRESS);
35 |  *
36 |  *    System.out.println("The size of a pointer on this platform is " + pointerType.size());
37 |  * }
38 |  * 
39 | */ 40 | public abstract class Type { 41 | /** 42 | * The size in bytes of this type. 43 | * 44 | * @return An integer 45 | */ 46 | public abstract int size(); 47 | 48 | /** 49 | * The native alignment of this type, in bytes 50 | * 51 | * @return An integer 52 | */ 53 | public abstract int alignment(); 54 | 55 | /** 56 | * The native type of this type 57 | * 58 | * @return the native type of this type 59 | */ 60 | public abstract NativeType getNativeType(); 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/TypeAlias.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi; 20 | 21 | public enum TypeAlias { 22 | int8_t, 23 | u_int8_t, 24 | int16_t, 25 | u_int16_t, 26 | int32_t, 27 | u_int32_t, 28 | int64_t, 29 | u_int64_t, 30 | intptr_t, 31 | uintptr_t, 32 | caddr_t, 33 | dev_t, 34 | blkcnt_t, 35 | blksize_t, 36 | gid_t, 37 | in_addr_t, 38 | in_port_t, 39 | ino_t, 40 | ino64_t, 41 | key_t, 42 | mode_t, 43 | nlink_t, 44 | id_t, 45 | pid_t, 46 | off_t, 47 | swblk_t, 48 | uid_t, 49 | clock_t, 50 | size_t, 51 | ssize_t, 52 | time_t, 53 | fsblkcnt_t, 54 | fsfilcnt_t, 55 | sa_family_t, 56 | socklen_t, 57 | rlim_t, 58 | cc_t, 59 | speed_t, 60 | tcflag_t, 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/Union.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | /* 19 | * Some of the design and code of this class is from the javolution project. 20 | * 21 | * Copyright (C) 2006 - Javolution (http://javolution.org/) 22 | * All rights reserved. 23 | * 24 | * Permission to use, copy, modify, and distribute this software is 25 | * freely granted, provided that this notice is preserved. 26 | */ 27 | 28 | package jnr.ffi; 29 | 30 | /** 31 | * Represents a C union 32 | */ 33 | public abstract class Union extends Struct { 34 | protected Union(Runtime runtime) { 35 | super(runtime, true); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/Variable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi; 20 | 21 | /** 22 | * Access library global variables. 23 | * 24 | *

25 | * To access global variables, declare a method with a parameterized return type of this class. 26 | *

27 | * Example 28 | *

29 |  *     {@code
30 |  *
31 |  *     public interface MyLib {
32 |  *         public Variable my_int_var();
33 |  *     }
34 |  *
35 |  *     MyLib lib = LibraryLoader.create(MyLib.class).load("mylib"):
36 |  *     System.out.println("native value=" + lib.my_int_var().get())
37 |  *
38 |  *     lib.my_int_var().set(0xdeadbeef);
39 |  *     }
40 |  * 
41 | */ 42 | public interface Variable { 43 | /** 44 | * Gets the current value of the global variable 45 | * 46 | * @return The value of the variable 47 | */ 48 | public T get(); 49 | 50 | /** 51 | * Sets the global variable to a value 52 | * 53 | * @param value The value to set the global variable to. 54 | */ 55 | public void set(T value); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Clear.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * Indicates that the temporary native memory allocated for an {@code @Out} paramneter 29 | * should be cleared before passing to the native function. 30 | * 31 | *

By default, parameters that are annotated as {@code @Out} only do not clear 32 | * the data in the temporary native memory area allocated when a java heap object 33 | * is passed in as the parameter, so the memory passed to the native function is 34 | * full of garbage data. After the native method returns, the native memory is 35 | * copied back to java, which is usually not a problem, since the native function 36 | * will have updated the memory with valid data. However, if the native function 37 | * fails, the garbage data that was in the temporary native memory will be copied 38 | * back to java. 39 | * 40 | * @see In 41 | * @see Out 42 | */ 43 | @Retention(RetentionPolicy.RUNTIME) 44 | @Target({ ElementType.PARAMETER, ElementType.ANNOTATION_TYPE }) 45 | public @interface Clear { 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Delegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import jnr.ffi.CallingConvention; 22 | 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target(ElementType.METHOD) 33 | public @interface Delegate { 34 | CallingConvention convention() default CallingConvention.DEFAULT; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Direct.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * Indicates that a {@link jnr.ffi.Struct}} parameter should be 29 | * backed by a persistent native memory block. 30 | * 31 | *

Without the {@code @Direct} annotation, the native code will allocate a 32 | * temporary native memory block for the parameter, and free it immediately after 33 | * the call. 34 | * 35 | *

By using {@code @Direct}, the native memory block is permanently associated 36 | * with the {@link jnr.ffi.Struct} instance, and will remain allocated 37 | * for as long as the {@code Struct} instance remains strongly referenced by java code. 38 | * 39 | */ 40 | @Retention(RetentionPolicy.RUNTIME) 41 | @Target({ ElementType.PARAMETER, ElementType.ANNOTATION_TYPE }) 42 | public @interface Direct { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Encoding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package jnr.ffi.annotations; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Used to specify the {@link java.nio.charset.Charset} to use for encoding/decoding a {@link String} 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD, ElementType.TYPE, ElementType.ANNOTATION_TYPE }) 30 | public @interface Encoding { 31 | String value(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/IgnoreError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import jnr.ffi.LibraryLoader; 22 | 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.util.Map; 26 | 27 | /** 28 | * Indicates that the errno value for a native function need not be saved after 29 | * the function returns. 30 | * 31 | *

Due to the nature of the Java Virtual Machine, the errno value must be saved 32 | * immediately after the native function is called, otherwise internal jvm operations 33 | * may overwrite it before control is returned to java code. 34 | * 35 | *

Since it is not possible for jnr-ffi to infer in a generic way whether a native 36 | * function has succeeded or failed, the C errno value is saved after every native 37 | * function call - even for the ones that succeed. This can have a significant 38 | * performance impact, so for those functions which either don't fail, or for which 39 | * the errno value can be ignored, can be annotated with {@code @IgnoreError} to 40 | * avoid unneccessary saving of the errno value. 41 | * 42 | * @see SaveError 43 | * @see LibraryLoader#saveError(Map, boolean, boolean) 44 | */ 45 | @Retention(RetentionPolicy.RUNTIME) 46 | public @interface IgnoreError { 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/In.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Indicates that the parameter is an IN parameter. 28 | * 29 | *

When a java object is passed to a native function as a pointer 30 | * (for example {@link jnr.ffi.Pointer}, {@link jnr.ffi.Struct}, {@link java.nio.ByteBuffer}), 31 | * then a temporary native memory block is allocated, the java data is copied to 32 | * the temporary memory and the address of the temporary memory is passed to the function. 33 | * After the function returns, the java data is automatically updated from the 34 | * contents of the native memory. 35 | * 36 | *

As this extra copying can be expensive, parameters can be annotated with {@code @In} 37 | * so the data is only copied from java {@code IN} to native memory, but not copied 38 | * back {@code OUT} from native memory to java memory. 39 | * 40 | *

Parameters with neither a {@code @In} nor a {@code @Out} annotation will copy both ways. 41 | * 42 | */ 43 | @Retention(RetentionPolicy.RUNTIME) 44 | @Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 45 | public @interface In { 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/LongLong.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import jnr.ffi.TypeAlias; 22 | 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * Indicates that a long parameter should be treated as native long-long (64bit) 30 | * instead of the platform-dependent long size. 31 | */ 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 34 | @TypeDefinition(alias = TypeAlias.int64_t) 35 | public @interface LongLong { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Meta.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target(ElementType.ANNOTATION_TYPE) 28 | public @interface Meta { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/NulTerminate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Indicates that a byte array or ByteBuffer should be terminated with a zero byte 28 | * before passing it to a native function. 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 32 | public @interface NulTerminate { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Pinned.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Marks a method parameter as being pinnable. 28 | *

29 | * This means the data for the parameter is not copied to/from native memory. 30 | * Instead, the JVM memory is locked and passed directly to the native code. 31 | *

32 | *

33 | * Because the data is passed to native code unconverted, care must be taken to 34 | * ensure element widths align for types wider than byte. 35 | *

36 | *

37 | * IMPORTANT: This should not be used for functions that may block on 38 | * network or filesystem access such as read(2), write(2), stat(2). 39 | *

40 | */ 41 | @Retention(RetentionPolicy.RUNTIME) 42 | @Target({ ElementType.PARAMETER, ElementType.ANNOTATION_TYPE }) 43 | public @interface Pinned { 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/SaveError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import jnr.ffi.LibraryLoader; 22 | 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.util.Map; 26 | 27 | /** 28 | * Tags a library method as requiring any error codes as returned 29 | * by errno on unix, or GetLastError on windows be saved. 30 | * 31 | * @see IgnoreError 32 | * @see LibraryLoader#saveError(Map, boolean, boolean) 33 | */ 34 | @Retention(RetentionPolicy.RUNTIME) 35 | public @interface SaveError { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/StdCall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target(ElementType.METHOD) 28 | public @interface StdCall { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Synchronized.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | 24 | /** 25 | * Indicates that a library or a library method requires all calls to be 26 | * synchronized. 27 | * 28 | * i.e. calls from multiple threads will synchronize on a monitor object, 29 | * then call the native method. 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | public @interface Synchronized { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Transient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | /** 28 | * Indicates that the parameter is transient. 29 | * 30 | * This means it can be backed by a temporarily allocated native memory block, 31 | * and after the method call, the native memory can be freed again. 32 | */ 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Target({ ElementType.PARAMETER, ElementType.ANNOTATION_TYPE }) 35 | public @interface Transient { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/TypeDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.annotations; 20 | 21 | import jnr.ffi.TypeAlias; 22 | 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * This is used internally by jnr-ffi to define type aliases, e.g. {@code ssize_t => long}. 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target(value = { ElementType.ANNOTATION_TYPE }) 33 | public @interface TypeDefinition { 34 | TypeAlias alias(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/annotations/Variadic.java: -------------------------------------------------------------------------------- 1 | package jnr.ffi.annotations; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | /** 7 | * Specifies that a non-varargs function binding will call a variadic C function with the specified number of fixed 8 | * arguments. 9 | * 10 | * Platforms that pass variadic arguments differently than fixed arguments will need this annotation if the Java binding 11 | * does not itself use varargs. Without Java varargs or this annotation, there's no way for jnr-ffi to know where fixed 12 | * args end and variadic arguments begin, causing them all to be passed the way fixed arguments get passed on the given 13 | * platform. 14 | * 15 | * See https://github.com/jnr/jnr-ffi/pull/292 16 | */ 17 | @Retention(RetentionPolicy.RUNTIME) 18 | public @interface Variadic { 19 | int fixedCount(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/byref/AbstractReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.byref; 20 | 21 | /** 22 | * An abstract class for common PrimitiveReference functionality 23 | */ 24 | abstract public class AbstractReference implements ByReference { 25 | T value; 26 | 27 | protected AbstractReference(T value) { 28 | this.value = value; 29 | } 30 | 31 | protected static T checkNull(T value) { 32 | if (value == null) { 33 | throw new NullPointerException("reference value cannot be null"); 34 | } 35 | 36 | return value; 37 | } 38 | 39 | /** 40 | * Gets the current value the reference points to. 41 | * 42 | * @return the current value. 43 | */ 44 | public T getValue() { 45 | return value; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/AbstractDataConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | * 23 | */ 24 | abstract public class AbstractDataConverter implements DataConverter { 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/AbstractFromNativeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | * 23 | */ 24 | abstract public class AbstractFromNativeType implements FromNativeType { 25 | private final FromNativeConverter converter; 26 | 27 | AbstractFromNativeType(FromNativeConverter converter) { 28 | this.converter = converter; 29 | } 30 | 31 | @Override 32 | public FromNativeConverter getFromNativeConverter() { 33 | return converter; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/AbstractSignatureTypeMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | * 23 | */ 24 | abstract public class AbstractSignatureTypeMapper implements SignatureTypeMapper { 25 | 26 | @Override 27 | public FromNativeType getFromNativeType(SignatureType type, FromNativeContext context) { 28 | return null; 29 | } 30 | 31 | @Override 32 | public ToNativeType getToNativeType(SignatureType type, ToNativeContext context) { 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/AbstractToNativeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | * 23 | */ 24 | abstract public class AbstractToNativeType implements ToNativeType { 25 | private final ToNativeConverter converter; 26 | 27 | AbstractToNativeType(ToNativeConverter converter) { 28 | this.converter = converter; 29 | } 30 | 31 | @Override 32 | public ToNativeConverter getToNativeConverter() { 33 | return converter; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/CompositeFunctionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Collection; 23 | import java.util.Collections; 24 | 25 | /** 26 | * 27 | */ 28 | public final class CompositeFunctionMapper implements FunctionMapper { 29 | private final Collection functionMappers; 30 | 31 | public CompositeFunctionMapper(Collection functionMappers) { 32 | this.functionMappers = Collections.unmodifiableList(new ArrayList(functionMappers)); 33 | } 34 | 35 | @Override 36 | public String mapFunctionName(String functionName, Context context) { 37 | for (FunctionMapper functionMapper : functionMappers) { 38 | String mappedName = functionMapper.mapFunctionName(functionName, context); 39 | if (mappedName != functionName) { 40 | // A translation was explicit in this mapper. 41 | return mappedName; 42 | } 43 | } 44 | return functionName; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/DataConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | * 23 | */ 24 | public interface DataConverter extends ToNativeConverter, FromNativeConverter { 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/DefaultTypeMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.util.LinkedHashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * 26 | */ 27 | public final class DefaultTypeMapper implements TypeMapper { 28 | private final Map toNativeConverters; 29 | private final Map fromNativeConverters; 30 | 31 | public DefaultTypeMapper() { 32 | toNativeConverters = new LinkedHashMap(); 33 | fromNativeConverters = new LinkedHashMap(); 34 | } 35 | 36 | public final void put(Class javaClass, DataConverter converter) { 37 | toNativeConverters.put(javaClass, converter); 38 | fromNativeConverters.put(javaClass, converter); 39 | } 40 | 41 | public final void put(Class javaClass, ToNativeConverter converter) { 42 | toNativeConverters.put(javaClass, converter); 43 | } 44 | 45 | public final void put(Class javaClass, FromNativeConverter converter) { 46 | fromNativeConverters.put(javaClass, converter); 47 | } 48 | 49 | public FromNativeConverter getFromNativeConverter(Class type) { 50 | return fromNativeConverters.get(type); 51 | } 52 | 53 | public ToNativeConverter getToNativeConverter(Class type) { 54 | return toNativeConverters.get(type); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/FromNativeContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.lang.annotation.Annotation; 22 | import java.util.Collection; 23 | 24 | /** 25 | * Context for conversion from native to Java. 26 | */ 27 | public interface FromNativeContext { 28 | /** 29 | * Gets a sorted list of annotations 30 | * 31 | * @return a sorted list of annotations for this native type 32 | */ 33 | public abstract Collection getAnnotations(); 34 | 35 | /** 36 | * Gets the Runtime used for the conversion. 37 | * 38 | * @return The runtime used for the conversion. 39 | */ 40 | public jnr.ffi.Runtime getRuntime(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/FromNativeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Converts data from a native type to a java type 28 | */ 29 | public interface FromNativeConverter { 30 | public J fromNative(N nativeValue, FromNativeContext context); 31 | public Class nativeType(); 32 | 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Target({ElementType.TYPE, ElementType.METHOD}) 35 | public static @interface NoContext { 36 | } 37 | 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Target(ElementType.TYPE) 40 | public static @interface Cacheable { 41 | } 42 | 43 | @Retention(RetentionPolicy.RUNTIME) 44 | @Target(ElementType.METHOD) 45 | @interface FromNative { 46 | Class nativeType(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/FromNativeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 28 | */ 29 | public interface FromNativeType { 30 | public FromNativeConverter getFromNativeConverter(); 31 | 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.TYPE) 34 | public static @interface Cacheable { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/FromNativeTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | * 23 | */ 24 | public final class FromNativeTypes { 25 | 26 | public static FromNativeType create(FromNativeConverter converter) { 27 | if (converter == null) { 28 | return null; 29 | } 30 | return converter.getClass().isAnnotationPresent(FromNativeConverter.Cacheable.class) 31 | ? new Cacheable(converter) : new UnCacheable(converter); 32 | } 33 | 34 | @FromNativeType.Cacheable 35 | static class Cacheable extends AbstractFromNativeType { 36 | public Cacheable(FromNativeConverter converter) { 37 | super(converter); 38 | } 39 | } 40 | 41 | static class UnCacheable extends AbstractFromNativeType { 42 | public UnCacheable(FromNativeConverter converter) { 43 | super(converter); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/MethodResultContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.lang.annotation.Annotation; 22 | import java.lang.reflect.Method; 23 | import java.util.Collection; 24 | 25 | import static jnr.ffi.util.Annotations.sortedAnnotationCollection; 26 | 27 | /** 28 | * 29 | */ 30 | public class MethodResultContext implements FromNativeContext { 31 | private final jnr.ffi.Runtime runtime; 32 | private final Method method; 33 | private Collection annotations; 34 | 35 | public MethodResultContext(jnr.ffi.Runtime runtime, Method method) { 36 | this.runtime = runtime; 37 | this.method = method; 38 | } 39 | 40 | public Method getMethod() { 41 | return method; 42 | } 43 | 44 | public Collection getAnnotations() { 45 | return annotations != null ? annotations : (annotations = sortedAnnotationCollection(method.getAnnotations())); 46 | } 47 | 48 | public jnr.ffi.Runtime getRuntime() { 49 | return runtime; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/SignatureType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.lang.annotation.Annotation; 22 | import java.util.Collection; 23 | 24 | /** 25 | * 26 | */ 27 | public interface SignatureType { 28 | public Class getDeclaredType(); 29 | public Collection getAnnotations(); 30 | public java.lang.reflect.Type getGenericType(); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/SignatureTypeMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | 23 | */ 24 | public interface SignatureTypeMapper { 25 | public FromNativeType getFromNativeType(SignatureType type, FromNativeContext context); 26 | public ToNativeType getToNativeType(SignatureType type, ToNativeContext context); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/SignatureTypeMapperAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | * Adapts a {@link jnr.ffi.mapper.TypeMapper} to a SignatureTypeMapper 23 | */ 24 | public class SignatureTypeMapperAdapter implements SignatureTypeMapper { 25 | private final TypeMapper typeMapper; 26 | 27 | public SignatureTypeMapperAdapter(TypeMapper typeMapper) { 28 | this.typeMapper = typeMapper; 29 | } 30 | 31 | @Override 32 | public FromNativeType getFromNativeType(SignatureType type, FromNativeContext context) { 33 | return FromNativeTypes.create(typeMapper.getFromNativeConverter(type.getDeclaredType())); 34 | } 35 | 36 | @Override 37 | public ToNativeType getToNativeType(SignatureType type, ToNativeContext context) { 38 | return ToNativeTypes.create(typeMapper.getToNativeConverter(type.getDeclaredType())); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/SimpleFunctionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.util.Collections; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | class SimpleFunctionMapper implements FunctionMapper { 26 | private final Map functionNameMap; 27 | 28 | SimpleFunctionMapper(Map map) { 29 | functionNameMap = Collections.unmodifiableMap(new HashMap(map)); 30 | } 31 | 32 | public String mapFunctionName(String functionName, Context context) { 33 | String nativeFunction = functionNameMap.get(functionName); 34 | return nativeFunction != null ? nativeFunction : functionName; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/SimpleTypeMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.util.Collections; 22 | import java.util.IdentityHashMap; 23 | import java.util.Map; 24 | 25 | final class SimpleTypeMapper implements TypeMapper { 26 | private final Map> toNativeConverters; 27 | private final Map> fromNativeConverters; 28 | 29 | public SimpleTypeMapper(Map> toNativeConverters, Map> fromNativeConverters) { 30 | this.toNativeConverters = Collections.unmodifiableMap(new IdentityHashMap>(toNativeConverters)); 31 | this.fromNativeConverters = Collections.unmodifiableMap(new IdentityHashMap>(fromNativeConverters)); 32 | } 33 | 34 | @Override 35 | public FromNativeConverter getFromNativeConverter(Class type) { 36 | return fromNativeConverters.get(type); 37 | } 38 | 39 | @Override 40 | public ToNativeConverter getToNativeConverter(Class type) { 41 | return toNativeConverters.get(type); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/ToNativeContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.lang.annotation.Annotation; 22 | import java.util.Collection; 23 | 24 | public interface ToNativeContext { 25 | /** 26 | * Gets a sorted list of annotations 27 | * 28 | * @return a sorted list of annotations for this native type 29 | */ 30 | public abstract Collection getAnnotations(); 31 | 32 | /** 33 | * Gets the Runtime used for the conversion. 34 | * 35 | * @return The runtime used for the conversion. 36 | */ 37 | public jnr.ffi.Runtime getRuntime(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/ToNativeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | public interface ToNativeConverter { 27 | public N toNative(J value, ToNativeContext context); 28 | public Class nativeType(); 29 | 30 | /** 31 | * Used to reload a parameter converted to a native type via a custom {@link jnr.ffi.mapper.ToNativeConverter} 32 | */ 33 | public static interface PostInvocation extends ToNativeConverter { 34 | public void postInvoke(J j, N n, ToNativeContext context); 35 | } 36 | 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target({ElementType.TYPE, ElementType.METHOD}) 39 | public static @interface NoContext { 40 | } 41 | 42 | @Retention(RetentionPolicy.RUNTIME) 43 | @Target(ElementType.TYPE) 44 | public static @interface Cacheable { 45 | } 46 | 47 | @Retention(RetentionPolicy.RUNTIME) 48 | @Target(ElementType.METHOD) 49 | @interface ToNative { 50 | Class nativeType(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/ToNativeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 28 | */ 29 | public interface ToNativeType { 30 | public ToNativeConverter getToNativeConverter(); 31 | 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.TYPE) 34 | public static @interface Cacheable { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/ToNativeTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | /** 22 | * 23 | */ 24 | public final class ToNativeTypes { 25 | 26 | public static ToNativeType create(ToNativeConverter converter) { 27 | if (converter == null) { 28 | return null; 29 | } 30 | return converter.getClass().isAnnotationPresent(ToNativeConverter.Cacheable.class) 31 | ? new Cacheable(converter) : new UnCacheable(converter); 32 | } 33 | 34 | @ToNativeType.Cacheable 35 | static class Cacheable extends AbstractToNativeType { 36 | public Cacheable(ToNativeConverter converter) { 37 | super(converter); 38 | } 39 | } 40 | 41 | static class UnCacheable extends AbstractToNativeType { 42 | public UnCacheable(ToNativeConverter converter) { 43 | super(converter); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/mapper/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.mapper; 20 | 21 | class Util { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/BadType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.NativeType; 22 | 23 | /** 24 | * 25 | */ 26 | public final class BadType extends jnr.ffi.Type { 27 | 28 | private final String typeName; 29 | 30 | public BadType(String typeName) { 31 | this.typeName = typeName; 32 | } 33 | 34 | public final int alignment() { 35 | throw new RuntimeException("invalid type: " + typeName); 36 | } 37 | 38 | public final int size() { 39 | throw new RuntimeException("invalid type: " + typeName); 40 | } 41 | 42 | public NativeType getNativeType() { 43 | throw new RuntimeException("invalid type: " + typeName); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/ClosureManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | /** 22 | * 23 | */ 24 | public interface ClosureManager { 25 | public abstract T newClosure(Class closureClass, T instance); 26 | public abstract jnr.ffi.Pointer getClosurePointer(Class closureClass, T instance); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/DelegatingMemoryIO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.Pointer; 22 | 23 | public interface DelegatingMemoryIO { 24 | public Pointer getDelegatedMemoryIO(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/FromNativeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.NativeType; 22 | import jnr.ffi.mapper.FromNativeContext; 23 | import jnr.ffi.mapper.FromNativeConverter; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.Collection; 27 | 28 | /** 29 | * 30 | */ 31 | public class FromNativeType extends SigType implements jnr.ffi.mapper.FromNativeType { 32 | private final FromNativeConverter fromNativeConverter; 33 | private final FromNativeContext fromNativeContext; 34 | 35 | public FromNativeType(Class javaType, NativeType nativeType, Collection annotations, 36 | FromNativeConverter fromNativeConverter, FromNativeContext fromNativeContext) { 37 | super(javaType, nativeType, annotations, fromNativeConverter != null ? fromNativeConverter.nativeType() : javaType); 38 | this.fromNativeConverter = fromNativeConverter; 39 | this.fromNativeContext = fromNativeContext; 40 | } 41 | 42 | @Override 43 | public FromNativeConverter getFromNativeConverter() { 44 | return fromNativeConverter; 45 | } 46 | 47 | public FromNativeContext getFromNativeContext() { 48 | return fromNativeContext; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/IdentityFunctionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.mapper.FunctionMapper; 22 | 23 | /** 24 | * An implementation of {@link FunctionMapper} that just returns the same name as input 25 | */ 26 | public class IdentityFunctionMapper implements FunctionMapper { 27 | private static final class SingletonHolder { 28 | public static final FunctionMapper INSTANCE = new IdentityFunctionMapper(); 29 | } 30 | 31 | public static FunctionMapper getInstance() { 32 | return SingletonHolder.INSTANCE; 33 | } 34 | 35 | public String mapFunctionName(String functionName, Context context) { 36 | return functionName; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/IntPointer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.Pointer; 22 | 23 | /** 24 | * 25 | */ 26 | public final class IntPointer extends InAccessibleMemoryIO { 27 | public IntPointer(jnr.ffi.Runtime runtime, long address) { 28 | super(runtime, address, true); 29 | } 30 | 31 | public IntPointer(jnr.ffi.Runtime runtime, int address) { 32 | super(runtime, address & 0xffffffffL, true); 33 | } 34 | 35 | public long size() { 36 | return 0; 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | return (int) address(); 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | return obj instanceof Pointer && ((Pointer) obj).address() == address(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/InvalidProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.LibraryLoader; 22 | import jnr.ffi.LibraryOption; 23 | import jnr.ffi.Runtime; 24 | 25 | import java.util.Collection; 26 | import java.util.Map; 27 | 28 | final class InvalidProvider extends FFIProvider { 29 | private final String message; 30 | private final Throwable cause; 31 | private final jnr.ffi.Runtime runtime; 32 | 33 | InvalidProvider(String message, Throwable cause) { 34 | this.message = message; 35 | this.cause = cause; 36 | this.runtime = new InvalidRuntime(message, cause); 37 | } 38 | 39 | @Override 40 | public Runtime getRuntime() { 41 | return runtime; 42 | } 43 | 44 | @Override 45 | public LibraryLoader createLibraryLoader(Class interfaceClass) { 46 | return new LibraryLoader(interfaceClass) { 47 | @Override 48 | protected T loadLibrary(Class interfaceClass, Collection libraryNames, Collection searchPaths, Map options, boolean failImmediately) { 49 | UnsatisfiedLinkError error = new UnsatisfiedLinkError(message); 50 | error.initCause(cause); 51 | throw error; 52 | } 53 | }; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/InvocationSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import java.util.ArrayList; 22 | 23 | /** 24 | * Holds information for each invocation of a native function 25 | */ 26 | public class InvocationSession { 27 | private ArrayList list; 28 | private ArrayList liveObjects; 29 | public InvocationSession() { 30 | 31 | } 32 | public static interface PostInvoke { 33 | void postInvoke(); 34 | } 35 | public void finish() { 36 | if (list != null) for (PostInvoke p : list) { 37 | try { 38 | p.postInvoke(); 39 | } catch (Throwable t) {} 40 | } 41 | } 42 | public void addPostInvoke(PostInvoke postInvoke) { 43 | if (list == null) { 44 | list = new ArrayList(); 45 | } 46 | list.add(postInvoke); 47 | } 48 | 49 | public void keepAlive(Object obj) { 50 | if (liveObjects == null) { 51 | liveObjects = new ArrayList(); 52 | } 53 | liveObjects.add(obj); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/Invoker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | /** 22 | * Interface for any invocable function 23 | */ 24 | public interface Invoker { 25 | Object invoke(Object self, Object[] parameters); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/LoadedLibrary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | /** 22 | * All loaded libraries must implement this interface 23 | */ 24 | public interface LoadedLibrary { 25 | public jnr.ffi.Runtime getRuntime(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/MemoryManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.Pointer; 22 | 23 | import java.nio.ByteBuffer; 24 | 25 | /** 26 | * Manages access to various types of java and native memory. 27 | */ 28 | public interface MemoryManager { 29 | public abstract Pointer allocate(int size); 30 | public abstract Pointer allocateDirect(int size); 31 | public abstract Pointer allocateDirect(long size); 32 | public abstract Pointer allocateDirect(int size, boolean clear); 33 | public abstract Pointer allocateDirect(long size, boolean clear); 34 | public abstract Pointer allocateTemporary(int size, boolean clear); 35 | public abstract Pointer newPointer(ByteBuffer buffer); 36 | public abstract Pointer newPointer(long address); 37 | public abstract Pointer newPointer(long address, long size); 38 | public abstract Pointer newOpaquePointer(long address); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/NativeVariable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import java.lang.reflect.Method; 22 | 23 | public class NativeVariable { 24 | private final Method method; 25 | 26 | public NativeVariable(Method method) { 27 | this.method = method; 28 | } 29 | 30 | public Method getMethod() { 31 | return method; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/NullMemoryIO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.Runtime; 22 | 23 | public final class NullMemoryIO extends InAccessibleMemoryIO { 24 | private static final String msg = "attempted access to a NULL memory address"; 25 | 26 | public NullMemoryIO(Runtime runtime) { 27 | super(runtime, 0, true); 28 | } 29 | 30 | protected final NullPointerException error() { 31 | return new NullPointerException(msg); 32 | } 33 | 34 | public long size() { 35 | return Long.MAX_VALUE; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/NullTypeMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.mapper.AbstractSignatureTypeMapper; 22 | import jnr.ffi.mapper.FromNativeContext; 23 | import jnr.ffi.mapper.FromNativeConverter; 24 | import jnr.ffi.mapper.SignatureType; 25 | import jnr.ffi.mapper.SignatureTypeMapper; 26 | import jnr.ffi.mapper.ToNativeContext; 27 | import jnr.ffi.mapper.ToNativeConverter; 28 | import jnr.ffi.mapper.TypeMapper; 29 | 30 | /** 31 | * An instance of {@link TypeMapper} which always returns null 32 | */ 33 | public class NullTypeMapper extends AbstractSignatureTypeMapper implements TypeMapper, SignatureTypeMapper { 34 | 35 | public FromNativeConverter getFromNativeConverter(Class type) { 36 | return null; 37 | } 38 | 39 | public ToNativeConverter getToNativeConverter(Class type) { 40 | return null; 41 | } 42 | 43 | @Override 44 | public FromNativeType getFromNativeType(SignatureType type, FromNativeContext context) { 45 | return null; 46 | } 47 | 48 | @Override 49 | public ToNativeType getToNativeType(SignatureType type, ToNativeContext context) { 50 | return null; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/ParameterType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.NativeType; 22 | import jnr.ffi.mapper.ToNativeContext; 23 | import jnr.ffi.mapper.ToNativeConverter; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.Collection; 27 | 28 | /** 29 | * 30 | */ 31 | public class ParameterType extends ToNativeType { 32 | 33 | public ParameterType(Class javaType, NativeType nativeType, Collection annotations, 34 | ToNativeConverter toNativeConverter, ToNativeContext toNativeContext) { 35 | super(javaType, nativeType, annotations, toNativeConverter, toNativeContext); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/ResultType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.NativeType; 22 | import jnr.ffi.mapper.FromNativeContext; 23 | import jnr.ffi.mapper.FromNativeConverter; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.Collection; 27 | 28 | /** 29 | * 30 | */ 31 | public class ResultType extends FromNativeType { 32 | 33 | public ResultType(Class javaType, NativeType nativeType, Collection annotations, 34 | FromNativeConverter fromNativeConverter, FromNativeContext fromNativeContext) { 35 | super(javaType, nativeType, annotations, fromNativeConverter, fromNativeContext); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/ToNativeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider; 20 | 21 | import jnr.ffi.NativeType; 22 | import jnr.ffi.mapper.ToNativeContext; 23 | import jnr.ffi.mapper.ToNativeConverter; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.Collection; 27 | 28 | /** 29 | * 30 | */ 31 | public class ToNativeType extends SigType implements jnr.ffi.mapper.ToNativeType { 32 | private final ToNativeConverter toNativeConverter; 33 | private final ToNativeContext toNativeContext; 34 | 35 | public ToNativeType(Class javaType, NativeType nativeType, Collection annotations, 36 | ToNativeConverter toNativeConverter, ToNativeContext toNativeContext) { 37 | super(javaType, nativeType, annotations, toNativeConverter != null ? toNativeConverter.nativeType() : javaType); 38 | this.toNativeConverter = toNativeConverter; 39 | this.toNativeContext = toNativeContext; 40 | } 41 | 42 | @Override 43 | public final ToNativeConverter getToNativeConverter() { 44 | return toNativeConverter; 45 | } 46 | 47 | public ToNativeContext getToNativeContext() { 48 | return toNativeContext; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/converters/EnumConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.converters; 20 | 21 | import jnr.ffi.mapper.DataConverter; 22 | import jnr.ffi.mapper.FromNativeContext; 23 | import jnr.ffi.mapper.FromNativeConverter; 24 | import jnr.ffi.mapper.ToNativeContext; 25 | import jnr.ffi.mapper.ToNativeConverter; 26 | import jnr.ffi.util.EnumMapper; 27 | 28 | 29 | @ToNativeConverter.NoContext 30 | @FromNativeConverter.NoContext 31 | @ToNativeConverter.Cacheable 32 | @FromNativeConverter.Cacheable 33 | public final class EnumConverter implements DataConverter { 34 | private final EnumMapper mapper; 35 | 36 | public static EnumConverter getInstance(Class enumClass) { 37 | return new EnumConverter(enumClass); 38 | } 39 | 40 | private EnumConverter(Class enumClass) { 41 | this.mapper = EnumMapper.getInstance(enumClass); 42 | } 43 | 44 | public Enum fromNative(Integer nativeValue, FromNativeContext context) { 45 | return mapper.valueOf(nativeValue); 46 | } 47 | 48 | public Integer toNative(Enum value, ToNativeContext context) { 49 | return mapper.integerValue(value); 50 | } 51 | 52 | public Class nativeType() { 53 | return Integer.class; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/converters/NativeLongConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.converters; 20 | 21 | import jnr.ffi.NativeLong; 22 | import jnr.ffi.mapper.AbstractDataConverter; 23 | import jnr.ffi.mapper.DataConverter; 24 | import jnr.ffi.mapper.FromNativeContext; 25 | import jnr.ffi.mapper.FromNativeConverter; 26 | import jnr.ffi.mapper.ToNativeContext; 27 | import jnr.ffi.mapper.ToNativeConverter; 28 | 29 | /** 30 | * Parameter and return type support for the old NativeLong type 31 | */ 32 | 33 | @ToNativeConverter.NoContext 34 | @FromNativeConverter.NoContext 35 | @ToNativeConverter.Cacheable 36 | @FromNativeConverter.Cacheable 37 | public final class NativeLongConverter extends AbstractDataConverter { 38 | private static final DataConverter INSTANCE = new NativeLongConverter(); 39 | 40 | public static DataConverter getInstance() { 41 | return INSTANCE; 42 | } 43 | 44 | public Class nativeType() { 45 | return Long.class; 46 | } 47 | 48 | public Long toNative(NativeLong value, ToNativeContext toNativeContext) { 49 | return value.longValue(); 50 | } 51 | 52 | public NativeLong fromNative(Long value, FromNativeContext fromNativeContext) { 53 | return NativeLong.valueOf(value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/converters/StructByReferenceToNativeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.converters; 20 | 21 | import jnr.ffi.Pointer; 22 | import jnr.ffi.Struct; 23 | import jnr.ffi.mapper.ToNativeContext; 24 | import jnr.ffi.mapper.ToNativeConverter; 25 | import jnr.ffi.provider.ParameterFlags; 26 | 27 | @ToNativeConverter.NoContext 28 | @ToNativeConverter.Cacheable 29 | public final class StructByReferenceToNativeConverter implements ToNativeConverter { 30 | private final int flags; 31 | 32 | public static ToNativeConverter getInstance(ToNativeContext toNativeContext) { 33 | return new StructByReferenceToNativeConverter(ParameterFlags.parse(toNativeContext.getAnnotations())); 34 | } 35 | 36 | StructByReferenceToNativeConverter(int flags) { 37 | this.flags = flags; 38 | } 39 | 40 | public Class nativeType() { 41 | return Pointer.class; 42 | } 43 | 44 | public Pointer toNative(Struct value, ToNativeContext ctx) { 45 | return value != null ? Struct.getMemory(value, flags) : null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/AbstractAsmLibraryInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.provider.LoadedLibrary; 22 | 23 | /** 24 | * 25 | */ 26 | public abstract class AbstractAsmLibraryInterface implements LoadedLibrary { 27 | public static final com.kenai.jffi.Invoker ffi = com.kenai.jffi.Invoker.getInstance(); 28 | protected final jnr.ffi.Runtime runtime; 29 | 30 | // Strong ref to keep the library alive 31 | protected final NativeLibrary library; 32 | 33 | public AbstractAsmLibraryInterface(jnr.ffi.Runtime runtime, NativeLibrary library) { 34 | this.runtime = runtime; 35 | this.library = library; 36 | } 37 | 38 | public final jnr.ffi.Runtime getRuntime() { 39 | return runtime; 40 | } 41 | 42 | final NativeLibrary getLibrary() { 43 | return library; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/ArrayMemoryIO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.Pointer; 22 | import jnr.ffi.Runtime; 23 | import jnr.ffi.provider.AbstractArrayMemoryIO; 24 | 25 | 26 | public final class ArrayMemoryIO extends AbstractArrayMemoryIO { 27 | 28 | public ArrayMemoryIO(Runtime runtime, int size) { 29 | super(runtime, size); 30 | } 31 | 32 | public ArrayMemoryIO(Runtime runtime, byte[] bytes, int off, int len) { 33 | super(runtime, bytes, off, len); 34 | } 35 | 36 | public Pointer getPointer(long offset) { 37 | return MemoryUtil.newPointer(getRuntime(), getAddress(offset)); 38 | } 39 | 40 | @Override 41 | public Pointer getPointer(long offset, long size) { 42 | return MemoryUtil.newPointer(getRuntime(), getAddress(offset), size); 43 | } 44 | 45 | @Override 46 | public void putPointer(long offset, Pointer value) { 47 | putAddress(offset, value != null ? value.address() : 0L); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/AsmClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import java.util.concurrent.ConcurrentHashMap; 22 | import java.util.concurrent.ConcurrentMap; 23 | 24 | final class AsmClassLoader extends ClassLoader { 25 | private final ConcurrentMap definedClasses = new ConcurrentHashMap(); 26 | 27 | public AsmClassLoader() { 28 | } 29 | 30 | public AsmClassLoader(ClassLoader parent) { 31 | super(parent); 32 | } 33 | 34 | 35 | public Class defineClass(String name, byte[] b) { 36 | Class klass = defineClass(name, b, 0, b.length); 37 | definedClasses.putIfAbsent(name, klass); 38 | resolveClass(klass); 39 | return klass; 40 | } 41 | 42 | @Override 43 | protected Class findClass(String name) throws ClassNotFoundException { 44 | Class klass = definedClasses.get(name); 45 | if (klass != null) { 46 | return klass; 47 | } 48 | return super.findClass(name); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/ByteBufferMemoryIO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import com.kenai.jffi.MemoryIO; 22 | import jnr.ffi.Pointer; 23 | import jnr.ffi.provider.AbstractBufferMemoryIO; 24 | 25 | import java.nio.ByteBuffer; 26 | 27 | public class ByteBufferMemoryIO extends AbstractBufferMemoryIO { 28 | 29 | public ByteBufferMemoryIO(jnr.ffi.Runtime runtime, ByteBuffer buffer) { 30 | super(runtime, buffer, address(buffer)); 31 | } 32 | 33 | public Pointer getPointer(long offset) { 34 | return MemoryUtil.newPointer(getRuntime(), getAddress(offset)); 35 | } 36 | 37 | public Pointer getPointer(long offset, long size) { 38 | return MemoryUtil.newPointer(getRuntime(), getAddress(offset), size); 39 | } 40 | 41 | public void putPointer(long offset, Pointer value) { 42 | putAddress(offset, value != null ? value.address() : 0L); 43 | } 44 | 45 | private static long address(ByteBuffer buffer) { 46 | if (buffer.isDirect()) { 47 | long address = MemoryIO.getInstance().getDirectBufferAddress(buffer); 48 | return address != 0L ? address + buffer.position() : 0L; 49 | } 50 | 51 | return 0L; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/JNIInvokeInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | /** 22 | * Indexes of JavaVM methods 23 | */ 24 | public class JNIInvokeInterface { 25 | public static final int DestroyJavaVM = 3; 26 | public static final int AttachCurrentThread = 4; 27 | public static final int DetachCurrentThread = 5; 28 | public static final int GetEnv = 6; 29 | public static final int AttachCurrentThreadAsDaemon = 7; 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/LocalVariable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | /** 22 | * 23 | */ 24 | class LocalVariable { 25 | final Class type; 26 | final int idx; 27 | 28 | public LocalVariable(Class type, int idx) { 29 | this.type = type; 30 | this.idx = idx; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/LocalVariableAllocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.provider.SigType; 22 | 23 | /** 24 | * 25 | */ 26 | class LocalVariableAllocator { 27 | private int nextIndex; 28 | 29 | LocalVariableAllocator(SigType[] parameterTypes) { 30 | this.nextIndex = AsmUtil.calculateLocalVariableSpace(parameterTypes) + 1; 31 | } 32 | 33 | LocalVariableAllocator(Class... parameterTypes) { 34 | this.nextIndex = AsmUtil.calculateLocalVariableSpace(parameterTypes) + 1; 35 | } 36 | 37 | LocalVariableAllocator(int nextIndex) { 38 | this.nextIndex = nextIndex; 39 | } 40 | 41 | LocalVariable allocate(Class type) { 42 | LocalVariable var = new LocalVariable(type, nextIndex); 43 | this.nextIndex += AsmUtil.calculateLocalVariableSpace(type); 44 | return var; 45 | } 46 | 47 | int getSpaceUsed() { 48 | return nextIndex; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/MemoryUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.provider.BoundedMemoryIO; 22 | 23 | public final class MemoryUtil { 24 | private MemoryUtil() {} 25 | 26 | static jnr.ffi.Pointer newPointer(jnr.ffi.Runtime runtime, long ptr) { 27 | return ptr != 0 ? new DirectMemoryIO(runtime, ptr) : null; 28 | } 29 | 30 | static jnr.ffi.Pointer newPointer(jnr.ffi.Runtime runtime, int ptr) { 31 | return ptr != 0 ? new DirectMemoryIO(runtime, ptr) : null; 32 | } 33 | 34 | static jnr.ffi.Pointer newPointer(jnr.ffi.Runtime runtime, long ptr, long size) { 35 | return ptr != 0 ? new BoundedMemoryIO(new DirectMemoryIO(runtime, ptr), 0, size) : null; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/MethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import com.kenai.jffi.Function; 22 | import jnr.ffi.CallingConvention; 23 | import jnr.ffi.provider.ParameterType; 24 | import jnr.ffi.provider.ResultType; 25 | 26 | /** 27 | * 28 | */ 29 | public interface MethodGenerator { 30 | 31 | public boolean isSupported(ResultType resultType, ParameterType[] parameterTypes, CallingConvention callingConvention); 32 | public void generate(AsmBuilder builder, String functionName, Function function, 33 | ResultType resultType, ParameterType[] parameterTypes, boolean ignoreError); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/NativeClosurePointer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.provider.InAccessibleMemoryIO; 22 | 23 | /** 24 | * 25 | */ 26 | class NativeClosurePointer extends InAccessibleMemoryIO { 27 | private final com.kenai.jffi.Closure.Handle handle; 28 | final NativeClosureProxy proxy; 29 | 30 | 31 | public NativeClosurePointer(jnr.ffi.Runtime runtime, com.kenai.jffi.Closure.Handle handle, NativeClosureProxy proxy) { 32 | super(runtime, handle.getAddress(), true); 33 | this.handle = handle; 34 | this.proxy = proxy; 35 | } 36 | 37 | @Override 38 | public long size() { 39 | return 0; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/NativeFinalizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.util.ref.FinalizableReferenceQueue; 22 | 23 | /** 24 | * 25 | */ 26 | class NativeFinalizer { 27 | private final FinalizableReferenceQueue finalizerQueue = new FinalizableReferenceQueue(); 28 | 29 | private static final class SingletonHolder { 30 | private static final NativeFinalizer INSTANCE = new NativeFinalizer(); 31 | } 32 | 33 | public static NativeFinalizer getInstance() { 34 | return SingletonHolder.INSTANCE; 35 | } 36 | 37 | public FinalizableReferenceQueue getFinalizerQueue() { 38 | return finalizerQueue; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/NativeFunctionMapperContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.Library; 22 | import jnr.ffi.mapper.FunctionMapper; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.Collection; 26 | 27 | public final class NativeFunctionMapperContext implements FunctionMapper.Context { 28 | private final NativeLibrary library; 29 | 30 | private final Collection annotations; 31 | 32 | public NativeFunctionMapperContext(NativeLibrary library, Collection annotations) { 33 | this.library = library; 34 | this.annotations = annotations; 35 | } 36 | 37 | public Library getLibrary() { 38 | return null; 39 | } 40 | 41 | public boolean isSymbolPresent(String name) { 42 | return library.getSymbolAddress(name) != 0L; 43 | } 44 | 45 | public Collection getAnnotations() { 46 | return annotations; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/NativeLibraryLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.LibraryOption; 22 | 23 | import java.util.Collection; 24 | import java.util.Map; 25 | 26 | import static jnr.ffi.provider.jffi.Util.getBooleanProperty; 27 | 28 | /** 29 | * 30 | */ 31 | class NativeLibraryLoader extends jnr.ffi.LibraryLoader { 32 | static final boolean ASM_ENABLED = getBooleanProperty("jnr.ffi.asm.enabled", true); 33 | 34 | NativeLibraryLoader(Class interfaceClass) { 35 | super(interfaceClass); 36 | } 37 | 38 | public T loadLibrary(Class interfaceClass, Collection libraryNames, Collection searchPaths, 39 | Map options, boolean failImmediately) { 40 | NativeLibrary nativeLibrary = new NativeLibrary(libraryNames, searchPaths, options); 41 | 42 | try { 43 | return ASM_ENABLED 44 | ? new AsmLibraryLoader().loadLibrary(nativeLibrary, interfaceClass, options, failImmediately) 45 | : new ReflectionLibraryLoader().loadLibrary(nativeLibrary, interfaceClass, options, failImmediately); 46 | 47 | } catch (RuntimeException ex) { 48 | throw ex; 49 | 50 | } catch (Exception ex) { 51 | throw new RuntimeException(ex); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/NoTrace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Turns off debug tracing 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target({ElementType.TYPE, ElementType.METHOD}) 31 | public @interface NoTrace { 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/NoX86.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target({ElementType.TYPE, ElementType.METHOD}) 31 | public @interface NoX86 { 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/NotImplMethodGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import com.kenai.jffi.Function; 22 | import jnr.ffi.CallingConvention; 23 | import jnr.ffi.provider.ParameterType; 24 | import jnr.ffi.provider.ResultType; 25 | 26 | /** 27 | * 28 | */ 29 | class NotImplMethodGenerator implements MethodGenerator { 30 | public boolean isSupported(ResultType resultType, ParameterType[] parameterTypes, CallingConvention callingConvention) { 31 | return false; 32 | } 33 | 34 | public void generate(AsmBuilder builder, String functionName, Function function, ResultType resultType, ParameterType[] parameterTypes, boolean ignoreError) { 35 | throw new UnsupportedOperationException("not supported"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/NullObjectParameterStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | /** 22 | * 23 | */ 24 | public final class NullObjectParameterStrategy extends ParameterStrategy { 25 | public static final ParameterStrategy NULL = new NullObjectParameterStrategy(); 26 | 27 | public NullObjectParameterStrategy() { 28 | super(DIRECT); 29 | } 30 | 31 | @Override 32 | public long address(Object parameter) { 33 | return 0; 34 | } 35 | 36 | @Override 37 | public Object object(Object parameter) { 38 | throw new NullPointerException("null reference"); 39 | } 40 | 41 | @Override 42 | public int offset(Object parameter) { 43 | throw new NullPointerException("null reference"); 44 | } 45 | 46 | @Override 47 | public int length(Object parameter) { 48 | throw new NullPointerException("null reference"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/ParameterStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import com.kenai.jffi.ObjectParameterStrategy; 22 | import com.kenai.jffi.ObjectParameterType; 23 | 24 | /** 25 | * 26 | */ 27 | abstract public class ParameterStrategy extends ObjectParameterStrategy { 28 | /* objectCount is accessed directly from asm code - do not change */ 29 | public final int objectCount; 30 | 31 | protected ParameterStrategy(StrategyType type) { 32 | super(type); 33 | objectCount = type == HEAP ? 1 : 0; 34 | } 35 | 36 | protected ParameterStrategy(StrategyType type, ObjectParameterType parameterType) { 37 | super(type, parameterType); 38 | objectCount = type == HEAP ? 1 : 0; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/PointerParameterStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import com.kenai.jffi.ObjectParameterType; 22 | import jnr.ffi.Pointer; 23 | 24 | /** 25 | * 26 | */ 27 | public final class PointerParameterStrategy extends ParameterStrategy { 28 | public static final PointerParameterStrategy DIRECT = new PointerParameterStrategy(StrategyType.DIRECT); 29 | public static final PointerParameterStrategy HEAP = new PointerParameterStrategy(StrategyType.HEAP); 30 | 31 | PointerParameterStrategy(StrategyType type) { 32 | super(type, ObjectParameterType.create(ObjectParameterType.ARRAY, ObjectParameterType.BYTE)); 33 | } 34 | 35 | @Override 36 | public long address(Object o) { 37 | return address((Pointer) o); 38 | } 39 | 40 | public long address(Pointer pointer) { 41 | return pointer != null ? pointer.address() : 0L; 42 | } 43 | 44 | @Override 45 | public Object object(Object o) { 46 | return ((Pointer) o).array(); 47 | } 48 | 49 | @Override 50 | public int offset(Object o) { 51 | return ((Pointer) o).arrayOffset(); 52 | } 53 | 54 | @Override 55 | public int length(Object o) { 56 | return ((Pointer) o).arrayLength(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/Provider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.Runtime; 22 | import jnr.ffi.provider.FFIProvider; 23 | 24 | 25 | public final class Provider extends FFIProvider { 26 | private final NativeRuntime runtime; 27 | 28 | public Provider() { 29 | this.runtime = NativeRuntime.getInstance(); 30 | } 31 | 32 | public final Runtime getRuntime() { 33 | return runtime; 34 | } 35 | 36 | public jnr.ffi.LibraryLoader createLibraryLoader(Class interfaceClass) { 37 | return new NativeLibraryLoader(interfaceClass); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/SimpleNativeContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | import jnr.ffi.mapper.FromNativeContext; 22 | import jnr.ffi.mapper.ToNativeContext; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.Collection; 26 | 27 | public class SimpleNativeContext implements ToNativeContext, FromNativeContext { 28 | private final jnr.ffi.Runtime runtime; 29 | private final Collection annotations; 30 | 31 | SimpleNativeContext(jnr.ffi.Runtime runtime, Collection annotations) { 32 | this.runtime = runtime; 33 | this.annotations = annotations; 34 | } 35 | 36 | public Collection getAnnotations() { 37 | return annotations; 38 | } 39 | 40 | public final jnr.ffi.Runtime getRuntime() { 41 | return runtime; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/SymbolNotFoundError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | public class SymbolNotFoundError extends java.lang.UnsatisfiedLinkError { 22 | 23 | public SymbolNotFoundError(String msg) { 24 | super(msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/provider/jffi/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.provider.jffi; 20 | 21 | /** 22 | */ 23 | final class Util { 24 | static boolean getBooleanProperty(String propertyName, boolean defaultValue) { 25 | try { 26 | return Boolean.valueOf(System.getProperty(propertyName, Boolean.valueOf(defaultValue).toString())); 27 | } catch (SecurityException se) { 28 | return defaultValue; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/blkcnt_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.blkcnt_t) 32 | public @interface blkcnt_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/blksize_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.blksize_t) 32 | public @interface blksize_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/caddr_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.caddr_t) 32 | public @interface caddr_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/clock_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.clock_t) 32 | public @interface clock_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/dev_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.dev_t) 32 | public @interface dev_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/fsblkcnt_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.fsblkcnt_t) 32 | public @interface fsblkcnt_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/fsfilcnt_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.fsfilcnt_t) 32 | public @interface fsfilcnt_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/gid_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.gid_t) 32 | public @interface gid_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/id_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.id_t) 32 | public @interface id_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/in_addr_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.in_addr_t) 32 | public @interface in_addr_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/in_port_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.in_port_t) 32 | public @interface in_port_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/ino64_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.ino64_t) 32 | public @interface ino64_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/ino_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.ino_t) 32 | public @interface ino_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/int16_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.int16_t) 32 | public @interface int16_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/int32_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.int32_t) 32 | public @interface int32_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/int64_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.int64_t) 32 | public @interface int64_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/int8_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.int8_t) 32 | public @interface int8_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/intptr_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.intptr_t) 32 | public @interface intptr_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/key_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.key_t) 32 | public @interface key_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/mode_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.mode_t) 32 | public @interface mode_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/nlink_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.nlink_t) 32 | public @interface nlink_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/off_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.off_t) 32 | public @interface off_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/pid_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.pid_t) 32 | public @interface pid_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/rlim_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.rlim_t) 32 | public @interface rlim_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/sa_family_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.sa_family_t) 32 | public @interface sa_family_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/size_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.size_t) 32 | public @interface size_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/socklen_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.socklen_t) 32 | public @interface socklen_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/ssize_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.ssize_t) 32 | public @interface ssize_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/swblk_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.swblk_t) 32 | public @interface swblk_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/time_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.time_t) 32 | public @interface time_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/u_int16_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.u_int16_t) 32 | public @interface u_int16_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/u_int32_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.u_int32_t) 32 | public @interface u_int32_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/u_int64_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.u_int64_t) 32 | public @interface u_int64_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/u_int8_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.u_int8_t) 32 | public @interface u_int8_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/uid_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.uid_t) 32 | public @interface uid_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/types/uintptr_t.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.types; 20 | 21 | import jnr.ffi.TypeAlias; 22 | import jnr.ffi.annotations.TypeDefinition; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(value = { ElementType.PARAMETER, ElementType.METHOD }) 31 | @TypeDefinition(alias = TypeAlias.uintptr_t) 32 | public @interface uintptr_t { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/util/AnnotationNameComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi.util; 20 | 21 | import java.lang.annotation.Annotation; 22 | import java.util.Comparator; 23 | 24 | /** 25 | * Sorts annotations according to name 26 | */ 27 | final class AnnotationNameComparator implements Comparator { 28 | static final Comparator INSTANCE = new AnnotationNameComparator(); 29 | 30 | public static Comparator getInstance() { 31 | return INSTANCE; 32 | } 33 | 34 | public int compare(Annotation o1, Annotation o2) { 35 | return o1.annotationType().getName().compareTo(o2.annotationType().getName()); 36 | } 37 | 38 | public boolean equals(Object other) { 39 | return other != null && getClass().equals(other.getClass()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/util/ref/FinalizablePhantomReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package jnr.ffi.util.ref; 18 | 19 | import java.lang.ref.PhantomReference; 20 | 21 | /** 22 | * Phantom reference with a {@code finalizeReferent()} method which a background thread invokes 23 | * after the garbage collector reclaims the referent. This is a simpler alternative to using a 24 | * {@link java.lang.ref.ReferenceQueue}. 25 | * 26 | *

Unlike a normal phantom reference, this reference will be cleared automatically. 27 | * 28 | * @author Bob Lee 29 | * @since 2.0 (imported from Google Collections Library) 30 | */ 31 | public abstract class FinalizablePhantomReference extends PhantomReference 32 | implements FinalizableReference { 33 | /** 34 | * Constructs a new finalizable phantom reference. 35 | * 36 | * @param referent to phantom reference 37 | * @param queue that should finalize the referent 38 | */ 39 | protected FinalizablePhantomReference(T referent, FinalizableReferenceQueue queue) { 40 | super(referent, queue.queue); 41 | queue.cleanUp(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/util/ref/FinalizableReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package jnr.ffi.util.ref; 18 | 19 | /** 20 | * Implemented by references that have code to run after garbage collection of their referents. 21 | * 22 | * @see FinalizableReferenceQueue 23 | * @author Bob Lee 24 | * @since 2.0 (imported from Google Collections Library) 25 | */ 26 | public interface FinalizableReference { 27 | /** 28 | * Invoked on a background thread after the referent has been garbage collected unless security 29 | * restrictions prevented starting a background thread, in which case this method is invoked when 30 | * new references are created. 31 | */ 32 | void finalizeReferent(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/util/ref/FinalizableSoftReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package jnr.ffi.util.ref; 18 | 19 | import java.lang.ref.SoftReference; 20 | 21 | /** 22 | * Soft reference with a {@code finalizeReferent()} method which a background thread invokes after 23 | * the garbage collector reclaims the referent. This is a simpler alternative to using a {@link 24 | * java.lang.ref.ReferenceQueue}. 25 | * 26 | * @author Bob Lee 27 | * @since 2.0 (imported from Google Collections Library) 28 | */ 29 | public abstract class FinalizableSoftReference extends SoftReference 30 | implements FinalizableReference { 31 | /** 32 | * Constructs a new finalizable soft reference. 33 | * 34 | * @param referent to softly reference 35 | * @param queue that should finalize the referent 36 | */ 37 | protected FinalizableSoftReference(T referent, FinalizableReferenceQueue queue) { 38 | super(referent, queue.queue); 39 | queue.cleanUp(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/jnr/ffi/util/ref/FinalizableWeakReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package jnr.ffi.util.ref; 18 | 19 | import java.lang.ref.WeakReference; 20 | 21 | /** 22 | * Weak reference with a {@code finalizeReferent()} method which a background thread invokes after 23 | * the garbage collector reclaims the referent. This is a simpler alternative to using a {@link 24 | * java.lang.ref.ReferenceQueue}. 25 | * 26 | * @author Bob Lee 27 | * @since 2.0 (imported from Google Collections Library) 28 | */ 29 | public abstract class FinalizableWeakReference extends WeakReference 30 | implements FinalizableReference { 31 | /** 32 | * Constructs a new finalizable weak reference. 33 | * 34 | * @param referent to weakly reference 35 | * @param queue that should finalize the referent 36 | */ 37 | protected FinalizableWeakReference(T referent, FinalizableReferenceQueue queue) { 38 | super(referent, queue.queue); 39 | queue.cleanUp(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/jnr/ffi/InvocationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Wayne Meissner 3 | * 4 | * This file is part of the JNR project. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package jnr.ffi; 20 | 21 | import org.junit.jupiter.api.BeforeAll; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; 25 | 26 | public class InvocationTest { 27 | public static interface TestLib { 28 | int ret_int32_t(int i); 29 | } 30 | 31 | static TestLib testlib; 32 | 33 | @BeforeAll 34 | public static void setUpClass() throws Exception { 35 | testlib = TstUtil.loadTestLib(TestLib.class); 36 | } 37 | 38 | @Test 39 | public void hammer() throws Throwable { 40 | for (int i = 0; i < 1000000; i++) { 41 | assertEquals(i, testlib.ret_int32_t(i)); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/jnr/ffi/numeric/NativeLongTest.java: -------------------------------------------------------------------------------- 1 | package jnr.ffi.numeric; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import jnr.ffi.NativeLong; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | /** 10 | * Tests {@link jnr.ffi.NativeLong} 11 | */ 12 | public class NativeLongTest { 13 | 14 | @Test 15 | public void NativeLong_valueOf() { 16 | for (int i = -1000; i < 1000; ++i) { 17 | assertEquals(i, NativeLong.valueOf(i).intValue(), "Incorrect value from valueOf(" + i + ")"); 18 | } 19 | for (long i = -1000; i < 1000; ++i) { 20 | assertEquals(i, NativeLong.valueOf(i).longValue(), "Incorrect value from valueOf(" + i + ")"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/jnr/ffi/numeric/utils/BooleanNumberTestLib.java: -------------------------------------------------------------------------------- 1 | package jnr.ffi.numeric.utils; 2 | 3 | import jnr.ffi.annotations.LongLong; 4 | import jnr.ffi.types.u_int64_t; 5 | 6 | /** 7 | * Same as {@link NumberTestLib} but returns booleans to test boolean mapping. 8 | * Since return type doesn't change signature in Java, we need these this mapping separate 9 | * from {@link NumberTestLib} 10 | */ 11 | public interface BooleanNumberTestLib { 12 | 13 | public boolean ret_int8_t(byte i); 14 | public Boolean ret_int8_t(Byte i); 15 | 16 | public boolean ret_int16_t(short i); 17 | public Boolean ret_int16_t(Short i); 18 | 19 | public boolean ret_int32_t(int i); 20 | public Boolean ret_int32_t(Integer i); 21 | 22 | public boolean ret_long(long i); 23 | public Boolean ret_long(Long i); 24 | 25 | public boolean ret_int64_t(@LongLong long i); 26 | public Boolean ret_int64_t(@LongLong Long i); 27 | 28 | public boolean ret_uint8_t(byte i); 29 | public Boolean ret_uint8_t(Byte i); 30 | 31 | public boolean ret_uint16_t(short i); 32 | public Boolean ret_uint16_t(Short i); 33 | 34 | public boolean ret_uint32_t(int i); 35 | public Boolean ret_uint32_t(Integer i); 36 | 37 | public boolean ret_ulong(long i); 38 | public Boolean ret_ulong(Long i); 39 | 40 | public boolean ret_uint64_t(@u_int64_t long i); 41 | public Boolean ret_uint64_t(@LongLong Long i); 42 | 43 | public boolean ret_float(float f); 44 | public Boolean ret_float(Float f); 45 | 46 | public boolean ret_double(double f); 47 | public Boolean ret_double(Double f); 48 | 49 | public boolean ret_bool(boolean b); 50 | public Boolean ret_bool(Boolean b); 51 | 52 | public byte ret_bool(byte b); 53 | public Byte ret_bool(Byte b); 54 | 55 | public short ret_bool(short b); 56 | public Short ret_bool(Short b); 57 | 58 | public int ret_bool(int b); 59 | public Integer ret_bool(Integer b); 60 | 61 | public long ret_bool(long b); 62 | public Long ret_bool(Long b); 63 | 64 | } -------------------------------------------------------------------------------- /src/test/java/jnr/ffi/numeric/utils/NumberUtils.java: -------------------------------------------------------------------------------- 1 | package jnr.ffi.numeric.utils; 2 | 3 | import jnr.ffi.NativeLong; 4 | 5 | @SuppressWarnings("UnnecessaryBoxing") 6 | public class NumberUtils { 7 | public static Byte box(byte b) {return Byte.valueOf(b);} 8 | 9 | public static Short box(short s) {return Short.valueOf(s);} 10 | 11 | public static Integer box(int i) {return Integer.valueOf(i);} 12 | 13 | public static Long box(long l) {return Long.valueOf(l);} 14 | 15 | public static Float box(float f) {return Float.valueOf(f);} 16 | 17 | public static Double box(double f) {return Double.valueOf(f);} 18 | 19 | public static Boolean box(boolean b) {return Boolean.valueOf(b);} 20 | 21 | public static NativeLong nativeLong(long l) {return NativeLong.valueOf(l);} 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/jnr/ffi/provider/InterfaceScannerTest.java: -------------------------------------------------------------------------------- 1 | package jnr.ffi.provider; 2 | 3 | import jnr.ffi.TstUtil; 4 | import org.junit.jupiter.api.Test; 5 | import java.lang.reflect.Method; 6 | import java.util.Collection; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.api.Assertions.assertNotNull; 10 | import static org.junit.jupiter.api.Assumptions.assumeTrue; 11 | 12 | public class InterfaceScannerTest { 13 | private static final Method SPLITERATOR; 14 | 15 | static { 16 | Method s = null; 17 | try { 18 | Collection.class.getMethod("spliterator"); 19 | } catch (Exception e) { 20 | // leave null, tests will be skipped 21 | } 22 | SPLITERATOR = s; 23 | } 24 | 25 | @Test public void loadTestLib() throws Exception { 26 | // If we're on Java 8+, proceed 27 | assumeTrue(SPLITERATOR != null); 28 | 29 | Collection lib = TstUtil.loadTestLib(Collection.class); 30 | 31 | // spliterator function does not exist in the test lib, so this only works if we're skipping default methods 32 | Object spliterator = SPLITERATOR.invoke(lib); 33 | 34 | assertNotNull(spliterator); 35 | assertEquals("java.util.Spliterator", spliterator.getClass().getName()); 36 | } 37 | } 38 | --------------------------------------------------------------------------------