From 3ad38748d7ef50a3631506eabcd3ae3417faa84d Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Fri, 4 Aug 2023 11:13:33 +0200
Subject: JavaCallbackEmitter.emitJavaKeyClass(): Use directBufferAddress for
 compound types in equals and hashCode, i.e. use memory identity

Use case is having a compound-type as userParam, which also acts as key, see MessageCallback13, Test4JavaCallback.chapter13().

The Java compound instance is re-created using the actual identical native memory (address),
which has been stored or passed in the native toolkit.
---
 src/java/com/jogamp/gluegen/JavaCallbackEmitter.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'src/java/com/jogamp/gluegen')

diff --git a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java
index 5e83016..01ffe8f 100644
--- a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java
@@ -386,7 +386,9 @@ public final class JavaCallbackEmitter {
                         unit.emitln(" &&");
                         unit.emit  ("             ");
                     }
-                    if( jType.isPrimitive() || idx == info.setFuncUserParamIdx ) {
+                    if( jType.isCompoundTypeWrapper() ) {
+                        unit.emit(name+".getDirectBufferAddress() == o2."+name+".getDirectBufferAddress()");
+                    } else if( jType.isPrimitive() || idx == info.setFuncUserParamIdx ) {
                         unit.emit(name+" == o2."+name);
                     } else {
                         unit.emit(name+".equals( o2."+name+" )");
@@ -419,6 +421,8 @@ public final class JavaCallbackEmitter {
                         } else {
                             unit.emitln(name+";");
                         }
+                    } else if( jType.isCompoundTypeWrapper() ) {
+                            unit.emitln("HashUtil.getAddrHash32_EqualDist( "+name+".getDirectBufferAddress() );");
                     } else {
                         if( idx == info.setFuncUserParamIdx ) {
                             unit.emitln("System.identityHashCode( "+name+" );");
-- 
cgit v1.2.3