[jffi-next] 32/49: Store parameter offsets in Function
Tim Potter
tpot-guest at moszumanska.debian.org
Wed Mar 4 04:51:13 UTC 2015
This is an automated email from the git hooks/post-receive script.
tpot-guest pushed a commit to annotated tag upstream/1.0.10
in repository jffi-next.
commit 7f6b6920237bac698470c4fe113dab2f5de0cf58
Author: Wayne Meissner <wmeissner at gmail.com>
Date: Sat Apr 23 15:25:18 2011 +1000
Store parameter offsets in Function
---
src/com/kenai/jffi/Function.java | 19 +++++++++++++++++++
src/com/kenai/jffi/HeapInvocationBuffer.java | 22 +++++++++++++++++-----
2 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/src/com/kenai/jffi/Function.java b/src/com/kenai/jffi/Function.java
index 21429bc..bb5ee09 100644
--- a/src/com/kenai/jffi/Function.java
+++ b/src/com/kenai/jffi/Function.java
@@ -59,6 +59,9 @@ public final class Function implements CallInfo {
/** The parameter types of this function */
private final Type[] paramTypes;
+
+ /* offset within encoding buffer of a parameter */
+ private final int[] parameterOffsets;
/** Whether the native context has been freed yet */
private volatile boolean disposed = false;
@@ -124,6 +127,12 @@ public final class Function implements CallInfo {
this.parameterCount = paramTypes.length;
this.rawParameterSize = foreign.getFunctionRawParameterSize(h);
+ this.parameterOffsets = new int[parameterCount];
+ int rawOffset = 0;
+ for (int i = 0; i < parameterCount; i++) {
+ rawOffset += HeapInvocationBuffer.FFI_ALIGN(paramTypes[i].size(), HeapInvocationBuffer.FFI_SIZEOF_ARG);
+ parameterOffsets[i] = rawOffset;
+ }
}
/**
@@ -181,6 +190,16 @@ public final class Function implements CallInfo {
public final Type getParameterType(int index) {
return paramTypes[index];
}
+
+ /**
+ * Gets the encoding buffer offset of a parameter.
+ *
+ * @param index The index of the parameter in the function signature
+ * @return the offset of the parameter.
+ */
+ final int getParameterOffset(int index) {
+ return parameterOffsets[index];
+ }
public synchronized final void dispose() {
if (disposed) {
diff --git a/src/com/kenai/jffi/HeapInvocationBuffer.java b/src/com/kenai/jffi/HeapInvocationBuffer.java
index f1a4255..b043031 100644
--- a/src/com/kenai/jffi/HeapInvocationBuffer.java
+++ b/src/com/kenai/jffi/HeapInvocationBuffer.java
@@ -39,9 +39,9 @@ import java.nio.ByteOrder;
* a java heap allocated buffer.
*/
public final class HeapInvocationBuffer implements InvocationBuffer {
- private static final int FFI_SIZEOF_ARG = Platform.getPlatform().addressSize() / 8;
+ static final int FFI_SIZEOF_ARG = Platform.getPlatform().addressSize() / 8;
private static final int PARAM_SIZE = 8;
- private static final Encoder encoder = getEncoder();
+ static final Encoder encoder = getEncoder();
private final CallInfo info;
private final byte[] buffer;
private ObjectBuffer objectBuffer = null;
@@ -196,7 +196,7 @@ public final class HeapInvocationBuffer implements InvocationBuffer {
getObjectBuffer().putJNI(paramIndex++, ObjectBuffer.JNIENV);
}
- private static final Encoder getEncoder() {
+ static final Encoder getEncoder() {
if (Platform.getPlatform().getCPU() == Platform.CPU.I386) {
return Foreign.getInstance().isRawParameterPackingEnabled()
? newI386RawEncoder()
@@ -228,13 +228,16 @@ public final class HeapInvocationBuffer implements InvocationBuffer {
/**
* Encodes java data types into native parameter frames
*/
- private static abstract class Encoder {
+ static abstract class Encoder {
/** Returns true if this <tt>Encoder</tt> is a raw encoder */
public abstract boolean isRaw();
/** Gets the size in bytes of the buffer required for the function */
public abstract int getBufferSize(CallInfo info);
+ /* Gets the buffer offset of a parameter */
+ public abstract int getBufferOffset(Function function, int parameterIndex);
+
/**
* Encodes a byte value into the byte array.
*
@@ -321,6 +324,11 @@ public final class HeapInvocationBuffer implements InvocationBuffer {
public final int getBufferSize(CallInfo info) {
return info.getRawParameterSize();
}
+
+ public final int getBufferOffset(Function function, int parameterIndex) {
+ return function.getParameterOffset(parameterIndex);
+ }
+
public final int putByte(byte[] buffer, int offset, int value) {
IO.putByte(buffer, offset, value); return offset + 4;
}
@@ -354,6 +362,10 @@ public final class HeapInvocationBuffer implements InvocationBuffer {
return false;
}
+ public final int getBufferOffset(Function function, int parameterIndex) {
+ return parameterIndex * PARAM_SIZE;
+ }
+
public final int getBufferSize(CallInfo info) {
return info.getParameterCount() * PARAM_SIZE;
}
@@ -511,7 +523,7 @@ public final class HeapInvocationBuffer implements InvocationBuffer {
* @param a The boundary to align to.
* @return The aligned address.
*/
- private static final int FFI_ALIGN(int v, int a) {
+ static final int FFI_ALIGN(int v, int a) {
return ((v - 1) | (a - 1)) + 1;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jffi-next.git
More information about the pkg-java-commits
mailing list