From 7220416bcef3140883d3966d921442feae3107c4 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 30 Mar 2010 01:53:58 +0200 Subject: http://www.jogamp.org/bugzilla/show_bug.cgi?id=389 32bit/64bit values and arrays are misrepresented - PointerBuffer is used to map 64bit integer values, which is illegal due to the latest PointerBuffer changes, where the underlying ByteBuffer is either 32bit wide or 64bit wide (in respect to the pointer size). The PointerBuffer semantic itself is correct, but no more suitable to represent 64bit values and arrays. A Int64Buffer (LongBuffer does not exist in CDC/CVM patch) should be used instead. - Determine use of Int64Buffer and PointerBuffer Assuming the 1st step being solved, it has to determined for which cases gluegen shall map a type to a PointerBuffer. All pointer pointer types, regardless of a Opaque mapping, ie: +++ typedef struct __MYAPIConfig * MYAPIConfig; Opaque long MYAPIConfig void foo(MYAPIConfig * ptrarray); +++ The argument 'ptrarray' must be represented as a PointerBuffer otherwise data is misrepresented in case: - 32bit machines _and_ - array semantics - more than one value is being used Impl: java/com/sun/gluegen/JavaEmitter.java: - Checks ptr-ptr for Opaque values - Returns PointerBuffer mapping for ptr-ptr types - Allow PointerBuffer being mapped as String[] Very elaborated tests .. :) ++++++++++++ Misc Changes: - Added .put(Buffer src) for Int64Buffer/PointerBuffer --- .../com/jogamp/gluegen/test/junit/BaseTest1.java | 115 ++++++++++++++++++++- .../com/jogamp/gluegen/test/junit/test1-common.cfg | 15 +++ src/junit/com/jogamp/gluegen/test/junit/test1.c | 55 +++++++++- src/junit/com/jogamp/gluegen/test/junit/test1.h | 19 +++- 4 files changed, 194 insertions(+), 10 deletions(-) (limited to 'src/junit/com') diff --git a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java index c53d142..420dc2b 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java +++ b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java @@ -35,6 +35,7 @@ package com.jogamp.gluegen.test.junit; import com.jogamp.gluegen.runtime.Buffers; import com.jogamp.gluegen.runtime.PointerBuffer; import com.jogamp.gluegen.runtime.Int64Buffer; +import com.jogamp.gluegen.runtime.Platform; import java.nio.*; import java.io.File; import java.lang.reflect.InvocationTargetException; @@ -89,6 +90,7 @@ public class BaseTest1 { long context = 0; ByteBuffer bb=null; Int64Buffer lb=null; + PointerBuffer pb=null; IntBuffer ib=null; long[] larray = null; int larray_offset = 0; @@ -103,10 +105,16 @@ public class BaseTest1 { result = binding.arrayTestInt64(context, lb); result = binding.arrayTestInt64(context, larray, larray_offset); - result = binding.arrayTestFoo(context, lb); - result = binding.arrayTestFoo(context, larray, larray_offset); + result = binding.arrayTestFoo1(context, lb); + result = binding.arrayTestFoo1(context, larray, larray_offset); result = binding.arrayTestFooNioOnly(context, lb); + lb = binding.arrayTestFoo2(lb); + lb = binding.arrayTestFoo2(larray, larray_offset); + + pb = binding.arrayTestFoo3ArrayToPtrPtr(lb); + pb = binding.arrayTestFoo3PtrPtr(pb); + result = binding.bufferTest(bb); result = binding.bufferTestNioOnly(bb); @@ -128,6 +136,9 @@ public class BaseTest1 { i = binding.intArrayRead(ib, i); i = binding.intArrayRead(iarray, iarray_offset, i); + long cfg=0; + cfg = binding.typeTestAnonSingle(cfg); + pb = binding.typeTestAnonPointer(pb); } /** @@ -192,15 +203,84 @@ public class BaseTest1 { result = binding.arrayTestInt64(context, larray1, larray1_offset); Assert.assertTrue("Wrong result: "+result, 1+8000==result); - result = binding.arrayTestFoo(context, lb1); + result = binding.arrayTestFoo1(context, lb1); Assert.assertTrue("Wrong result: "+result, 1+8000==result); - result = binding.arrayTestFoo(context, larray1, larray1_offset); + result = binding.arrayTestFoo1(context, larray1, larray1_offset); Assert.assertTrue("Wrong result: "+result, 1+8000==result); result = binding.arrayTestFooNioOnly(context, lb1); Assert.assertTrue("Wrong result: "+result, 1+8000==result); + { + lb2.rewind(); + Int64Buffer lb3 = Int64Buffer.allocateDirect(BindingTest1.ARRAY_SIZE); + lb3.put(lb2); + lb3.rewind(); + lb2.rewind(); + + // System.out.println("lb3: "+lb3); + Assert.assertTrue("Wrong result: "+lb3.capacity(), BindingTest1.ARRAY_SIZE == lb3.capacity()); + Assert.assertTrue("Wrong result: "+lb3.remaining(), BindingTest1.ARRAY_SIZE == lb3.remaining()); + + Int64Buffer lbR = binding.arrayTestFoo2(lb3); + // System.out.println("lbR: "+lbR); + + Assert.assertNotNull(lbR); + Assert.assertTrue("Wrong result: "+lb3.capacity(), BindingTest1.ARRAY_SIZE == lb3.capacity()); + Assert.assertTrue("Wrong result: "+lb3.remaining(), BindingTest1.ARRAY_SIZE == lb3.remaining()); + Assert.assertTrue("Wrong result: "+lbR.capacity(), BindingTest1.ARRAY_SIZE == lbR.capacity()); + Assert.assertTrue("Wrong result: "+lbR.remaining(), BindingTest1.ARRAY_SIZE == lbR.remaining()); + int j=0; + for(j=0; j #include #include +#include foo nopTest() { return 42; @@ -31,7 +32,38 @@ int64_t arrayTestInt64(int64_t context, int64_t * array) { return r+context; } -foo arrayTestFoo(int64_t context, foo * array) { +foo * arrayTestFoo2( foo * array ) { + int i; + foo * result = calloc(ARRAY_SIZE, sizeof(foo)); + assert(NULL!=array); + for(i=0; i %d\n", i, (int)array[i], (int)result[i]); + } + return result; +} + +foo * * arrayTestFoo3ArrayToPtrPtr(foo * array) { + int j; + foo * * result = calloc(ARRAY_SIZE, sizeof(foo *)); + for(j=0; j