diff options
author | Sven Gothel <[email protected]> | 2023-07-02 14:26:04 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-07-02 14:26:04 +0200 |
commit | 6d53b4b1dd07006e7af0e540b2c2e6ee6e1746d5 (patch) | |
tree | 74a17394d340da857266f51ddfa5fe44724242f5 /src/java/com/jogamp/gluegen/CMethodBindingEmitter.java | |
parent | 9b9aa128d92e9512cb00559e99dce9c8de726ed7 (diff) |
GlueGen JavaCallback: Unify native 'T_JavaCallbackGlueData' typedef structcallback_jniuserparamproxy
Diffstat (limited to 'src/java/com/jogamp/gluegen/CMethodBindingEmitter.java')
-rw-r--r-- | src/java/com/jogamp/gluegen/CMethodBindingEmitter.java | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index c1b175f..00cae13 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -113,6 +113,8 @@ public class CMethodBindingEmitter extends FunctionEmitter { protected static final String STRING_CHARS_PREFIX = "_strchars_"; + protected static final String T_JavaCallbackGlueData = "T_JavaCallbackGlueData"; + // We need this in order to compute sizes of certain types protected MachineDataInfo machDesc; @@ -338,12 +340,6 @@ public class CMethodBindingEmitter extends FunctionEmitter { final String userParamArgName = javaCallback.cbFuncBinding.getArgumentName(javaCallback.cbFuncUserParamIdx); final Type cReturnType = javaCallback.cbFuncBinding.getCReturnType(); final JavaType jretType = javaCallback.cbFuncBinding.getJavaReturnType(); - unit.emitln("typedef struct {"); - unit.emitln(" jobject lockObj;"); - unit.emitln(" jobject cbFunc;"); - unit.emitln(" jmethodID cbMethodID;"); - unit.emitln(" jobject userParam;"); - unit.emitln("} T_"+jcbNativeBasename+";"); unit.emitln(); // javaCallback.cbFuncCEmitter.emitSignature(); unit.emit("static "+cReturnType.getCName()+" "+staticCallbackName+"("); @@ -366,7 +362,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { jcbCMethodEmitter.emitJavaCallbackBodyCToJavaPreCall(javaCallback); // javaCallback.cbFuncCEmitter.emitBodyCallCFunction(); - unit.emitln(" T_"+jcbNativeBasename+"* cb = (T_"+jcbNativeBasename+"*) "+userParamArgName+";"); + unit.emitln(" "+T_JavaCallbackGlueData+"* cb = ("+T_JavaCallbackGlueData+"*) "+userParamArgName+";"); unit.emitln(" // C Params: "+javaCallback.cbFuncBinding.getCParameterList(new StringBuilder(), false, null).toString()); unit.emitln(" // J Params: "+javaCallback.cbFuncBinding.getJavaParameterList(new StringBuilder()).toString()); @@ -563,7 +559,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { unit.emitln(); unit.emitln(" // JavaCallback handling"); unit.emitln(" "+jcb.cbFuncTypeName+" "+nativeCBFuncVarName+";"); - unit.emitln(" T_"+jcbNativeBasename+"* "+nativeUserParamVarName+";"); + unit.emitln(" "+T_JavaCallbackGlueData+"* "+nativeUserParamVarName+";"); // unit.emit(", jstring jcallbackSignature, jobject jlockObj, jlongArray jnativeUserParam"); unit.emitln(" if( NULL == jlockObj ) { (*env)->FatalError(env, \"Null jlockObj in '"+jcbFriendlyBasename+"'\"); }"); unit.emitln(" if( NULL == jnativeUserParam ) { (*env)->FatalError(env, \"Null jnativeUserParam in '"+jcbFriendlyBasename+"'\"); }"); @@ -571,7 +567,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { unit.emitln(" if( 1 > jnativeUserParam_size ) { (*env)->FatalError(env, \"nativeUserParam size < 1 in '"+jcbFriendlyBasename+"'\"); }"); unit.emitln(" if( NULL != "+cbFuncArgName+" ) {"); unit.emitln(" if( NULL == "+userParamArgName+" ) { (*env)->FatalError(env, \"Null "+userParamArgName+" in '"+jcbFriendlyBasename+"'\"); }"); - unit.emitln(" "+nativeUserParamVarName+" = (T_"+jcbNativeBasename+"*) calloc(1, sizeof(T_"+jcbNativeBasename+"));"); + unit.emitln(" "+nativeUserParamVarName+" = ("+T_JavaCallbackGlueData+"*) calloc(1, sizeof("+T_JavaCallbackGlueData+"));"); unit.emitln(" if( NULL == "+nativeUserParamVarName+" ) { (*env)->FatalError(env, \"Can't alloc "+nativeUserParamVarName+" in '"+jcbFriendlyBasename+"'\"); }"); unit.emitln(" "+nativeUserParamVarName+"->lockObj = (*env)->NewGlobalRef(env, jlockObj);"); unit.emitln(" if( NULL == "+nativeUserParamVarName+"->lockObj ) { (*env)->FatalError(env, \"Failed NewGlobalRef(lock) in '"+jcbFriendlyBasename+"'\"); }"); @@ -616,13 +612,13 @@ public class CMethodBindingEmitter extends FunctionEmitter { unit.emit(JavaEmitter.getJNIMethodNamePrefix(getJavaPackageName(), getJavaClassName())); unit.emitln("_release"+capIfaceName+"Impl(JNIEnv *env, jobject _unused, jlong jnativeUserParam) {"); unit.emitln(" // already locked"); - unit.emitln(" T_"+jcbNativeBasename+"* nativeUserParam = (T_"+jcbNativeBasename+"*) (intptr_t) jnativeUserParam;"); + unit.emitln(" "+T_JavaCallbackGlueData+"* nativeUserParam = ("+T_JavaCallbackGlueData+"*) (intptr_t) jnativeUserParam;"); unit.emitln(" if( NULL != nativeUserParam ) {"); unit.emitln(" (*env)->DeleteGlobalRef(env, nativeUserParam->lockObj);"); unit.emitln(" (*env)->DeleteGlobalRef(env, nativeUserParam->cbFunc);"); unit.emitln(" (*env)->DeleteGlobalRef(env, nativeUserParam->userParam);"); unit.emitln(" // Ensure even w/ use-after-free jobject refs are NULL and invalid to avoid accidental reuse."); - unit.emitln(" memset(nativeUserParam, 0, sizeof(T_"+jcbNativeBasename+"));"); + unit.emitln(" memset(nativeUserParam, 0, sizeof("+T_JavaCallbackGlueData+"));"); unit.emitln(" free(nativeUserParam);"); unit.emitln(" }"); unit.emitln("}"); |