summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-12-18 04:17:47 +0100
committerSven Gothel <[email protected]>2011-12-18 04:17:47 +0100
commitf20389b3f59c5d8c6d9afe0df16282dd09115640 (patch)
tree142ade0593db5b2a602be5aaff0c9756859f7d14 /src
parent53bcf1366374a2005003088b02d6019ca402843c (diff)
JavaEmitter: Fix primitive StructEmitter for non-fixed-sized (size conversion, ie. 32/64 bits)
An opaque type still needs to be converted to the right size (32/64 bit). In case of a conversion, respect the pointer type. This fixes bug 536 .
Diffstat (limited to 'src')
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java23
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java28
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.c3
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h5
4 files changed, 49 insertions, 10 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index d768858..7ab3aca 100644
--- a/src/java/com/jogamp/gluegen/JavaEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaEmitter.java
@@ -1061,22 +1061,31 @@ public class JavaEmitter implements GlueEmitter {
}
if (javaType.isPrimitive()) {
// Primitive type
- final boolean fieldTypeNativeSizeFixed = fieldType.getSize().hasFixedNativeSize() || isOpaque(fieldType) ;
- String javaTypeName = javaType.getName();
- if (isOpaque(fieldType)) {
+ final boolean fieldTypeNativeSizeFixed = fieldType.getSize().hasFixedNativeSize();
+ final String javaTypeName;
+ if ( isOpaque(fieldType) ) {
javaTypeName = compatiblePrimitiveJavaTypeName(fieldType, javaType, machDescJava);
+ } else {
+ javaTypeName = javaType.getName();
+ }
+ final String capJavaTypeName = capitalizeString(javaTypeName);
+ final String capFieldName = capitalizeString(fieldName);
+ final String sizeDenominator = fieldType.isPointer() ? "pointer" : javaTypeName ;
+
+ if(GlueGen.debug()) {
+ System.err.println("Java.StructEmitter.Primitive: "+field.getName()+", "+fieldType.getName(true)+", "+javaTypeName+", "+
+ ", fixedSize "+fieldTypeNativeSizeFixed+", opaque "+isOpaque(fieldType)+", isPointer "+fieldType.isPointer()+", isCompound "+fieldType.isCompound()+
+ ", sizeDenominator "+sizeDenominator);
}
- String capJavaTypeName = capitalizeString(javaTypeName);
writer.println();
- String capFieldName = capitalizeString(fieldName);
// Setter
generateSetterSignature(writer, false, containingTypeName, capFieldName, javaTypeName);
writer.println(" {");
if( fieldTypeNativeSizeFixed ) {
writer.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val);");
} else {
- writer.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md."+javaTypeName+"SizeInBytes());");
+ writer.println(" accessor.set" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md."+sizeDenominator+"SizeInBytes());");
}
writer.println(" return this;");
writer.println(" }");
@@ -1089,7 +1098,7 @@ public class JavaEmitter implements GlueEmitter {
if( fieldTypeNativeSizeFixed ) {
writer.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx]);");
} else {
- writer.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], MachineDescriptionRuntime.getStatic().md."+javaTypeName+"SizeInBytes());");
+ writer.println("accessor.get" + capJavaTypeName + "At(" + fieldName+"_offset[mdIdx], MachineDescriptionRuntime.getStatic().md."+sizeDenominator+"SizeInBytes());");
}
writer.println(" }");
}
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
index 4673805..8d9c73a 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java
@@ -685,10 +685,34 @@ public class BaseClass extends JunitTracer {
TK_Surface surface = binding.createSurface();
- assertAPTR(0x123456789abcdef0L, surface.getCtx());
+ final long surfaceContext = surface.getCtx();
+ assertAPTR(0x123456789abcdef0L, surfaceContext);
+
+ TK_ContextWrapper ctxWrapper = surface.getCtxWrapper();
+ final long wrapperContext = ctxWrapper.getCtx();
+ assertAPTR(0xA23456781abcdef0L, wrapperContext);
TK_Engine engine = surface.getEngine();
- assertAPTR(0x123456789abcdef0L, engine.getCtx());
+ final long engineContext = engine.getCtx();
+ assertAPTR(0xB23456782abcdef0L, engineContext);
+ Assert.assertEquals(0x0111, engine.render(0x0100, 0x0010, 0x0001));
+
+ surface.setCtx(surfaceContext);
+ assertAPTR(surfaceContext, surface.getCtx());
+ assertAPTR(wrapperContext, ctxWrapper.getCtx());
+ assertAPTR(engineContext, engine.getCtx());
+ Assert.assertEquals(0x0111, engine.render(0x0100, 0x0010, 0x0001));
+
+ ctxWrapper.setCtx(wrapperContext);
+ assertAPTR(surfaceContext, surface.getCtx());
+ assertAPTR(wrapperContext, ctxWrapper.getCtx());
+ assertAPTR(engineContext, engine.getCtx());
+ Assert.assertEquals(0x0111, engine.render(0x0100, 0x0010, 0x0001));
+
+ engine.setCtx(engineContext);
+ assertAPTR(surfaceContext, surface.getCtx());
+ assertAPTR(wrapperContext, ctxWrapper.getCtx());
+ assertAPTR(engineContext, engine.getCtx());
Assert.assertEquals(0x0111, engine.render(0x0100, 0x0010, 0x0001));
TK_Dimension dimension = surface.getBounds();
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
index ae3c8a5..ebb1e08 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c
@@ -259,10 +259,11 @@ MYAPI TK_Surface * MYAPIENTRY createSurface() {
s->getClip = _TK_getClip;
s->ctx = (void *) 0x123456789abcdef0UL;
+ s->ctxWrapper.ctx = (void *) 0xA23456781abcdef0UL;
//s->engine = (TK_Engine *) calloc(1, sizeof(TK_Engine));
//s->engine->ctx = (void *) 0x123456789abcdef0UL;
//s->engine->render = _TK_render;
- s->engine.ctx = (void *) 0x123456789abcdef0UL;
+ s->engine.ctx = (void *) 0xB23456782abcdef0UL;
s->engine.render = _TK_render;
s->bounds.x = 0x11111111U;
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
index 6c38a03..76a15f2 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -143,8 +143,13 @@ typedef struct {
int32_t (MYAPIENTRY *render) (int x, int y, int ps);
} TK_Engine;
+typedef struct {
+ TK_Context ctx;
+} TK_ContextWrapper;
+
typedef struct tk_Surface {
TK_Context ctx;
+ TK_ContextWrapper ctxWrapper;
// const TK_Engine * engine;
TK_Engine engine;
TK_Dimension bounds;