aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/JavaEmitter.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-07-20 08:14:40 +0200
committerSven Gothel <[email protected]>2011-07-20 08:14:40 +0200
commit8b3057585930357bb16546f584d998953b084034 (patch)
tree5d7ffb74a36da6076d05657f2867c68c47068c7b /src/java/com/jogamp/gluegen/JavaEmitter.java
parent0a8e1566c766f3b5a5e71b5d80500034f1a614a8 (diff)
FIX StructAccessor / JavaEmitter's struct-emitter: Using byte offsets
Problem: typedef struct { int8_t bits1; // +1 - 0 // +3 (p32) int32_t id; // +4 - 4 int8_t bits2; // +1 - 8 // +3 (p32) - int64_t long0; // +8 - 12 "longBuffer.get(<type-sized index>)" is invalid, but "byteBuffer.getLong(<byte index>)" must be done. The actual impl. doesn't matter, hence dropping the other nio type mappings is good. FIXES 32bit unit test, works well (static) on 32/64 bit (unix). TODO: Respect diff alignment for OS/ARCH either by offset tables for all, or runtime computing.
Diffstat (limited to 'src/java/com/jogamp/gluegen/JavaEmitter.java')
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java41
1 files changed, 6 insertions, 35 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index 770db38..dfa7594 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -1062,10 +1062,7 @@ public class JavaEmitter implements GlueEmitter {
String paramType = typeToJavaType(baseElementType, false, extMachDesc).getName();
String capitalized = capitalizeString(fieldName);
- int slot = -1;
- if(!doBaseClass) {
- slot = slot(fieldType, (int) field.getOffset(intMachDesc), intMachDesc);
- }
+ final int byteOffset = doBaseClass ? -1 : (int) field.getOffset(intMachDesc);
// Setter
writer.println();
@@ -1074,7 +1071,7 @@ public class JavaEmitter implements GlueEmitter {
writer.println(";");
} else {
writer.println(" {");
- writer.print (" accessor.set" + capitalizeString(paramType) + "sAt(" + slot + ", ");
+ writer.print (" accessor.set" + capitalizeString(paramType) + "sAt(" + byteOffset + ", ");
writer.println("val);");
writer.println(" return this;");
writer.println(" }");
@@ -1087,7 +1084,7 @@ public class JavaEmitter implements GlueEmitter {
} else {
writer.println(" {");
writer.print (" return ");
- writer.println("accessor.get" + capitalizeString(paramType) + "sAt(" + slot + ", new " +paramType+"["+fieldType.asArray().getLength()+"]);");
+ writer.println("accessor.get" + capitalizeString(paramType) + "sAt(" + byteOffset + ", new " +paramType+"["+fieldType.asArray().getLength()+"]);");
writer.println(" }");
}
@@ -1123,10 +1120,7 @@ public class JavaEmitter implements GlueEmitter {
if (!doBaseClass) {
capitalized = capitalizeString(internalJavaTypeName);
}
- int slot = -1;
- if (!doBaseClass) {
- slot = slot(fieldType, (int) field.getOffset(intMachDesc), intMachDesc);
- }
+ final int byteOffset = doBaseClass ? -1 : (int) field.getOffset(intMachDesc);
writer.println();
String capitalizedFieldName = capitalizeString(fieldName);
// Setter
@@ -1135,7 +1129,7 @@ public class JavaEmitter implements GlueEmitter {
writer.println(";");
} else {
writer.println(" {");
- writer.print (" accessor.set" + capitalized + "At(" + slot + ", ");
+ writer.print (" accessor.set" + capitalized + "At(" + byteOffset + ", ");
if (!externalJavaTypeName.equals(internalJavaTypeName)) {
writer.print("(" + internalJavaTypeName + ") ");
}
@@ -1154,7 +1148,7 @@ public class JavaEmitter implements GlueEmitter {
if (!externalJavaTypeName.equals(internalJavaTypeName)) {
writer.print("(" + externalJavaTypeName + ") ");
}
- writer.println("accessor.get" + capitalized + "At(" + slot + ");");
+ writer.println("accessor.get" + capitalized + "At(" + byteOffset + ");");
writer.println(" }");
}
} else {
@@ -1408,29 +1402,6 @@ public class JavaEmitter implements GlueEmitter {
(c == Long.TYPE));
}
- private int slot(Type t, int byteOffset, MachineDescription curMachDesc) {
- if (t.isInt()) {
- final int tsz = (int) t.getSize(curMachDesc);
- switch (tsz) {
- case 1:
- case 2:
- case 4:
- case 8: return byteOffset / tsz;
- default: throw new RuntimeException("Illegal type");
- }
- } else if (t.isFloat()) {
- return byteOffset / 4;
- } else if (t.isDouble()) {
- return byteOffset / 8;
- } else if (t.isPointer()) {
- return byteOffset / curMachDesc.pointerSizeInBytes();
- } else if (t.isArray()) {
- return slot(t.asArray().getBaseElementType(), byteOffset, curMachDesc);
- } else {
- throw new RuntimeException("Illegal type " + t);
- }
- }
-
private StructLayout getLayout() {
if (layout == null) {
layout = StructLayout.create(0);