diff options
author | Sven Gothel <[email protected]> | 2023-07-05 10:21:48 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-07-05 10:21:48 +0200 |
commit | 5ceca8550b82591a6a2661a26d3e0d5e6e3e15ff (patch) | |
tree | 95768138afdb5ee4c6d3b705e803ad497241f756 /src/java/com/jogamp/gluegen/JavaEmitter.java | |
parent | ae4c2c3e59ed92caa6f0e18360b7236e50899bf6 (diff) |
GlueGen: Add 'PascalString' string semantics (length + value-ptr), added prelim code for JavaCallback use-case emitBodyMapCToJNIType()
It is common in toolkit APIs that a string might not be passed as a 'nul' terminated (EOS) C string,
but as a Pascal string with a given length argument.
A C string is specied as
ArgumentIsString alEventCallbackInject 3
while allowing multiple indices ..
A Pascal string can be specified as
ArgumentIsPascalString ALEVENTPROCSOFT 3 4
while allowing multiple indice-tuples for length and value ..
The tuple consist of the length agrument-index first (usually an int)
followed by the value argument-index (usually a 'char*').
+++
CMethodBindingEmitter.emitBodyMapCToJNIType(), where PascalString is implemented,
is currently being used for
- JNI return statement (no PascalString impact possible)
- JavaCallback C type -> JNI type, PascalString impacting
Diffstat (limited to 'src/java/com/jogamp/gluegen/JavaEmitter.java')
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 96202bf..8af79e4 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -78,6 +78,7 @@ import com.jogamp.common.util.HashUtil; import com.jogamp.gluegen.ASTLocusTag.ASTLocusTagProvider; import com.jogamp.gluegen.JavaConfiguration.JavaCallbackDef; import com.jogamp.gluegen.JavaConfiguration.JavaCallbackInfo; +import com.jogamp.gluegen.JavaConfiguration.PascalStringIdx; import com.jogamp.gluegen.Logging.LoggerIf; import com.jogamp.gluegen.cgram.types.AliasedSymbol; import com.jogamp.gluegen.cgram.types.ArrayType; @@ -3049,6 +3050,9 @@ public class JavaEmitter implements GlueEmitter { private JavaType javaType(final Class<?> c) { return JavaType.createForClass(c); } + private JavaType javaStringType(final Class<?> c, final boolean pascalString) { + return JavaType.createForStringClass(c, pascalString); + } /** Maps the C types in the specified function to Java types through the MethodBinding interface. Note that the JavaTypes in the @@ -3081,7 +3085,7 @@ public class JavaEmitter implements GlueEmitter { "\". ReturnsString requires native method to have return type \"char *\"", sym.getASTLocusTag()); } - javaReturnType = javaType(java.lang.String.class); + javaReturnType = javaStringType(java.lang.String.class, false); } else { final JavaType r = cfg.getOpaqueReturnType(sym); if( null != r ) { @@ -3094,7 +3098,11 @@ public class JavaEmitter implements GlueEmitter { // List of the indices of the arguments in this function that should be // converted from byte[] or short[] to String final List<JavaType> javaArgumentTypes = new ArrayList<JavaType>(); - final List<Integer> stringArgIndices = cfg.stringArguments(sym); + List<Integer> stringArgIndices = cfg.stringArguments(sym); + final List<PascalStringIdx> pascalStringArgs = cfg.pascalStringArgument(sym); + if( null != pascalStringArgs ) { + stringArgIndices = PascalStringIdx.pushValueIndex(pascalStringArgs, stringArgIndices); + } final JavaCallbackInfo jcbi = cfg.setFuncToJavaCallbackMap.get( sym.getName() ); int jcbiSetFuncCBParamIdx=-1, jcbiSetFuncUserParamIdx=-1; @@ -3134,7 +3142,7 @@ public class JavaEmitter implements GlueEmitter { mappedType = JavaType.forObjectClass(); } } - } else if (stringArgIndices != null && stringArgIndices.contains(i)) { + } else if ( stringArgIndices != null && stringArgIndices.contains(i) ) { // Take into account any ArgumentIsString configuration directives that apply // System.out.println("Forcing conversion of " + binding.getName() + " arg #" + i + " from byte[] to String "); if (mappedType.isCVoidPointerType() || @@ -3147,10 +3155,11 @@ public class JavaEmitter implements GlueEmitter { // convert mapped type from: // void*, byte[], and short[] to String // ByteBuffer[] and ShortBuffer[] to String[] + final boolean pascalString = cfg.pascalStringLengthIndex(sym, i) >= 0; if (mappedType.isArray() || mappedType.isNIOPointerBuffer()) { - mappedType = javaType(ArrayTypes.stringArrayClass); + mappedType = javaStringType(ArrayTypes.stringArrayClass, pascalString); } else { - mappedType = javaType(String.class); + mappedType = javaStringType(String.class, pascalString); } } else { |