From b08c61935daa0191f4ec59c6998bc56dae18e54d Mon Sep 17 00:00:00 2001 From: Mathieu Féry Date: Fri, 4 Aug 2023 10:50:10 +0200 Subject: feat(callbackGenerator): Prevent generation of CallBack interface if setter related isn't present --- src/java/com/jogamp/gluegen/DebugEmitter.java | 3 ++- src/java/com/jogamp/gluegen/GlueEmitter.java | 3 ++- src/java/com/jogamp/gluegen/GlueGen.java | 2 +- src/java/com/jogamp/gluegen/JavaEmitter.java | 13 +++++++++++-- .../com/jogamp/gluegen/procaddress/ProcAddressEmitter.java | 5 +++-- 5 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src/java/com') diff --git a/src/java/com/jogamp/gluegen/DebugEmitter.java b/src/java/com/jogamp/gluegen/DebugEmitter.java index 9824462..8b53827 100644 --- a/src/java/com/jogamp/gluegen/DebugEmitter.java +++ b/src/java/com/jogamp/gluegen/DebugEmitter.java @@ -84,7 +84,8 @@ public class DebugEmitter implements GlueEmitter { @Override public void beginFunctions(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, - final Map canonMap) { + final Map canonMap, + List cFunctions) { final Set keys = typedefDictionary.keySet(); for (final String key: keys) { final Type value = typedefDictionary.get(key); diff --git a/src/java/com/jogamp/gluegen/GlueEmitter.java b/src/java/com/jogamp/gluegen/GlueEmitter.java index 8844a33..6b654f1 100644 --- a/src/java/com/jogamp/gluegen/GlueEmitter.java +++ b/src/java/com/jogamp/gluegen/GlueEmitter.java @@ -75,7 +75,8 @@ public interface GlueEmitter { public void beginFunctions(TypeDictionary typedefDictionary, TypeDictionary structDictionary, - Map canonMap) throws Exception; + Map canonMap, + List cFunctions) throws Exception; /** Emit glue code for the list of FunctionSymbols. */ public Iterator emitFunctions(List cFunctions) throws Exception; diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java index 872214d..5aa76f8 100644 --- a/src/java/com/jogamp/gluegen/GlueGen.java +++ b/src/java/com/jogamp/gluegen/GlueGen.java @@ -362,7 +362,7 @@ public class GlueGen implements GlueEmitterControls { if ( !cfg.structsOnly() ) { // emit java and C code to interface with the native functions - emit.beginFunctions(td, sd, headerParser.getCanonMap()); + emit.beginFunctions(td, sd, headerParser.getCanonMap(), allFunctions); emit.emitFunctions(allFunctions); emit.endFunctions(); } diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 576e9bc..a4260e7 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -66,6 +66,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import jogamp.common.os.MachineDataInfoRuntime; @@ -359,7 +360,8 @@ public class JavaEmitter implements GlueEmitter { @Override public void beginFunctions(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, - final Map canonMap) throws Exception { + final Map canonMap, + final List cFunctions) throws Exception { // this.typedefDictionary = typedefDictionary; this.canonMap = canonMap; @@ -371,7 +373,14 @@ public class JavaEmitter implements GlueEmitter { for(final JavaCallbackDef jcbd : javaCallbacks) { final Type funcPtr = typedefDictionary.get(jcbd.cbFuncTypeName); if( null != funcPtr && funcPtr.isFunctionPointer() ) { - generateJavaCallbackCode(jcbd, funcPtr.getTargetFunction()); + final Optional setter = cFunctions.stream() + .filter(cFunction -> jcbd.setFuncName.equals(cFunction.getName())) + .findFirst(); + if( setter.isPresent() ) { + generateJavaCallbackCode(jcbd, funcPtr.getTargetFunction()); + } else { + LOG.log(WARNING, "JavaCallback '{0}' setter not available", jcbd); + } } else { LOG.log(WARNING, "JavaCallback '{0}' function-pointer type not available", jcbd); } diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java index b812416..6fb8a10 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java @@ -78,13 +78,14 @@ public class ProcAddressEmitter extends JavaEmitter { protected String tableClassName; @Override - public void beginFunctions(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, final Map canonMap) throws Exception { + public void beginFunctions(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, + final Map canonMap, final List cFunctions) throws Exception { this.typedefDictionary = typedefDictionary; if (getProcAddressConfig().emitProcAddressTable()) { beginProcAddressTable(); } - super.beginFunctions(typedefDictionary, structDictionary, canonMap); + super.beginFunctions(typedefDictionary, structDictionary, canonMap, cFunctions); } @Override -- cgit v1.2.3