Generic (void *)int

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Feb 18 14:27:19 UTC 2019


Uhm - the code snippet for converting long into pointer is correct; I 
checked this on my machine:

class Test {
     public static void main(String[] args) throws Throwable {
          try (Scope sc = Scope.globalScope().fork()) {
               var ptr1 = sc.allocate(NativeTypes.LONG);
               ptr1.set(42L);
               var p1 = 
ptr1.cast(NativeTypes.VOID).cast(NativeTypes.VOID.pointer()).get();
               System.err.println(p1.addr());
         }
   }
}


And this prints 42 as expected.

Are you sure the problem is coming from that pointer, and not from 
somewhere else?

Maurizio

On 18/02/2019 14:16, Giuseppe Barbieri wrote:
> I just had a chance to try, but that, unfortunately, doesnt seem to work..
> https://github.com/elect86/panama/blob/master/src/test/kotlin/hello-triangle.kt#L100-L102
>
> I get a black triangle (I shall get a colored one instead)
>
> I guess I get at least the vertex positions (the triangle, although black,
> is there) because in my case `semantic.attr.POSITION` is luckily zero,
> which is the same index where the attributes start from.
>
> Other ideas?
>
> Il giorno lun 18 feb 2019 alle ore 10:56 Jorn Vernee <jbvernee at xs4all.nl>
> ha scritto:
>
>> Hi Giuseppe,
>>
>> You should be able to use this trick:
>>
>>       long pointerValue = 12L; // e.g.
>>       Scope scope = Scope.newNativeScope; // or Scope.globalScope().fork()
>> depending on which version you are
>>       Pointer<Long> ptr = scope.allocate(NativeTypes.UINT64);
>>       ptr.set(pointerValue);
>>       Pointer<?> result =
>> ptr.cast(NativeTypes.VOID).cast(NativeTypes.VOID.pointer()).get();
>>       // use 'result'
>>
>> Be aware that this does do an allocation of a 64 bit int, so you might
>> want to reuse the allocated space if you create a lot of pointers from
>> literals.
>>
>> Maybe in the future we can add an API for creating pointers from long
>> literals directly.
>>
>> Jorn
>>
>> Giuseppe Barbieri schreef op 2019-02-18 10:44:
>>> Thanks Sundar,
>>>
>>> that works flawless for `(void *)0`
>>>
>>> But now I also would need a generic solution, for example:
>>>
>>> (void *)12
>>>
>>> There is a sill opengl call ( glVertexPointer ) requesting explicitely
>>> that: https://stackoverflow.com/a/8283855/1047713
>>>
>>> Signature:
>>>
>>> void glVertexAttribPointer(int index, int size, int type, byte
>>> normalized, int stride, Pointer<?> pointer);
>>>
>>>
>>> is there actually a way?
>>>
>>>
>>>
>>>
>>>
>>>
>>> You can use Pointer.nullPointer() method.
>>>
>>> -Sundar
>>>
>>> On 18/02/19, 8:09 AM, Giuseppe Barbieri wrote:
>>>> Hi,
>>>>
>>>> I'm looking for a way to convert this:
>>>>
>>>> (void*)0
>>>>
>>>> in Java.
>>>>
>>>> I tried to allocate a pointer and set its value to 0, but it didnt
>>>> work
>>>>
>>>> Any ideas, guys?
>>>>
>>>> Thanks in advance


More information about the panama-dev mailing list