summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/com/jogamp/gluegen/DebugEmitter.java3
-rw-r--r--src/java/com/jogamp/gluegen/GlueEmitter.java3
-rw-r--r--src/java/com/jogamp/gluegen/GlueGen.java2
-rw-r--r--src/java/com/jogamp/gluegen/JavaConfiguration.java7
-rw-r--r--src/java/com/jogamp/gluegen/JavaEmitter.java39
-rw-r--r--src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java5
6 files changed, 46 insertions, 13 deletions
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<Type, Type> canonMap) {
+ final Map<Type, Type> canonMap,
+ List<FunctionSymbol> cFunctions) {
final Set<String> 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<Type, Type> canonMap) throws Exception;
+ Map<Type, Type> canonMap,
+ List<FunctionSymbol> cFunctions) throws Exception;
/** Emit glue code for the list of FunctionSymbols. */
public Iterator<FunctionSymbol> emitFunctions(List<FunctionSymbol> 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/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java
index 870b708..82019f1 100644
--- a/src/java/com/jogamp/gluegen/JavaConfiguration.java
+++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java
@@ -2527,4 +2527,11 @@ public class JavaConfiguration {
/** Mapped binding name to {@link JavaCallbackInfo} */
/* pp */ final Map<String, JavaCallbackInfo> setFuncToJavaCallbackMap = new HashMap<String, JavaCallbackInfo>();
final Set<String> emittedJavaCallbackUserParamClasses = new HashSet<String>();
+
+ /** Returns true if a method binding requires specific java callback code */
+ final boolean requiresJavaCallbackCode(final String bindingName) {
+ final JavaCallbackInfo jcbi = setFuncToJavaCallbackMap.get(bindingName);
+ return null != jcbi && !jcbi.cbUserParamIsDefined;
+ }
+
}
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java
index 6e79b6c..8ed269e 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<Type, Type> canonMap) throws Exception {
+ final Map<Type, Type> canonMap,
+ final List<FunctionSymbol> 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<FunctionSymbol> 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);
}
@@ -465,9 +474,11 @@ public class JavaEmitter implements GlueEmitter {
final boolean isUnimplemented = cfg.isUnimplemented(cSymbol);
final List<String> prologue = cfg.javaPrologueForMethod(binding, false, false);
final List<String> epilogue = cfg.javaEpilogueForMethod(binding, false, false);
+ final boolean needsJavaCallbackCode = cfg.requiresJavaCallbackCode( binding.getName() );
final boolean needsBody = isUnimplemented ||
binding.needsNIOWrappingOrUnwrapping() ||
binding.signatureUsesJavaPrimitiveArrays() ||
+ needsJavaCallbackCode ||
null != prologue ||
null != epilogue;
@@ -531,6 +542,7 @@ public class JavaEmitter implements GlueEmitter {
final boolean hasPrologueOrEpilogue =
cfg.javaPrologueForMethod(binding, false, false) != null ||
cfg.javaEpilogueForMethod(binding, false, false) != null ;
+ final boolean needsJavaCallbackCode = cfg.requiresJavaCallbackCode( binding.getName() );
if ( !cfg.isUnimplemented( cSymbol ) ) {
// If we already generated a public native entry point for this
@@ -541,7 +553,7 @@ public class JavaEmitter implements GlueEmitter {
// the private native entry point for it along with the version
// taking only NIO buffers
if ( !binding.signatureUsesJavaPrimitiveArrays() &&
- ( binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue )
+ ( binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue || needsJavaCallbackCode )
)
{
final CodeUnit unit = (cfg.allStatic() ? javaUnit() : javaImplUnit());
@@ -588,7 +600,7 @@ public class JavaEmitter implements GlueEmitter {
cfg.implClassName(),
true, // NOTE: we always disambiguate with a suffix now, so this is optional
cfg.allStatic(),
- (binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue ),
+ (binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue || needsJavaCallbackCode),
!cfg.useNIODirectOnly(binding.getName()),
machDescJava, getConfig());
prepCEmitter(binding.getName(), binding.getJavaReturnType(), cEmitter);
@@ -1874,11 +1886,22 @@ public class JavaEmitter implements GlueEmitter {
if( !_constElemCount ) {
// check for const length field
if( elemCountExpr.startsWith("get") && elemCountExpr.endsWith("()") ) {
- final String lenFieldName = CodeGenUtils.decapitalizeString( elemCountExpr.substring(3, elemCountExpr.length()-2) );
- final Field lenField = structCType.getField(lenFieldName);
- if( null != lenField ) {
- _constElemCount = lenField.getType().isConst();
+ final String baseLenFieldName = elemCountExpr.substring(3, elemCountExpr.length()-2);
+ String lenFieldName = CodeGenUtils.decapitalizeString( baseLenFieldName );
+ Field lenField = structCType.getField(lenFieldName);
+ if( null == lenField ) {
+ lenFieldName = baseLenFieldName;
+ lenField = structCType.getField(lenFieldName);
+ }
+ if( null == lenField ) {
+ throw new GlueGenException("Unable to creating array accessors for field \"" +
+ fqStructFieldName + "\", because elemCountExpr specify following getter \"" +
+ elemCountExpr + "\" and host structure doesn't contain following field \"" +
+ CodeGenUtils.decapitalizeString( baseLenFieldName ) + "\" or \"" +
+ baseLenFieldName + "\"",
+ fieldType.getASTLocusTag());
}
+ _constElemCount = lenField.getType().isConst();
LOG.log(INFO, structCType.getASTLocusTag(),
unit.className+": elemCountExpr "+elemCountExpr+", lenFieldName "+lenFieldName+" -> "+lenField.toString()+", isConst "+_constElemCount);
}
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<Type, Type> canonMap) throws Exception {
+ public void beginFunctions(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary,
+ final Map<Type, Type> canonMap, final List<FunctionSymbol> cFunctions) throws Exception {
this.typedefDictionary = typedefDictionary;
if (getProcAddressConfig().emitProcAddressTable()) {
beginProcAddressTable();
}
- super.beginFunctions(typedefDictionary, structDictionary, canonMap);
+ super.beginFunctions(typedefDictionary, structDictionary, canonMap, cFunctions);
}
@Override