aboutsummaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* JavaCallbackEmitter.{emitCSetFuncPreCall, emitCAdditionalCode}(): Group ↵Sven Gothel2023-08-031-6/+17
| | | | 'userParamDefined' case (cleanup)
* CMethodBindingEmitter.emitBodyMapCToJNIType(..): Add proper intendation to ↵Sven Gothel2023-08-031-9/+13
| | | | NIO ByteBuffer generation (isNIOBuffer || isCompoundTypeWrapper)
* Merge remote-tracking branch ↵Sven Gothel2023-08-029-108/+350
|\ | | | | | | 'Mathieu_Fery/feature/java_callback_without_user_data' into pulled
| * feat(callbackGenerator): Add basic management of callback without userDataMathieu Féry2023-07-319-108/+350
| |
* | feat(generation): Add setter generation for not constant and not opaque ↵Mathieu Féry2023-07-314-5/+33
|/ | | | compound attribute
* GlueGen JavaCallback: Add optional custom 'Callback-UserParamClass` for ↵Sven Gothel2023-07-107-336/+376
| | | | non-compound `UserParam` types to have more clarity in resulting API
* GlueGen JavaCallback: Add capability to have UserParam as (part of) keySven Gothel2023-07-089-106/+610
| | | | | | | | | Resolves use case where UserParam reflects e.g. a context (AL_SOFT_events) and will be (part of) the key mapping. Implementation required an additional userParamID -> userParam mapping for default Object/ID usage. Added 2 test cases.
* GlueGen JavaCallback: Remove ambiguity: Config ↵Sven Gothel2023-07-067-88/+103
| | | | JavaCallbackDef/JavaCallbackKey: Always define both parameter indices; emitJavaStaticCallback(): Use cbFuncBinding and cbFuncKeyIndices from callback parameter to build key
* GlueGen JavaCallback: Fix `staticCBClazz*` initial setup (only), using a ↵Sven Gothel2023-07-051-18/+22
| | | | | | NewGlobalRef() for jclass (not required for static jmethodID) Also use a longer jclass argument name 'clazz' -> 'staticCBClazz' to avoid potential collisions
* GlueGen: Add 'PascalString' string semantics (length + value-ptr), added ↵Sven Gothel2023-07-055-25/+164
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* GlueGen JavaCallback/LibraryOnLoad: Always include the `libraryBasename` ↵Sven Gothel2023-07-053-29/+71
| | | | agnostic 'emitJNIEnvDecl()' (declaration) in JNI code; Detach the thread from the JVM if newly attach in callback!
* GlueGen JavaType.appendDescriptor(..): Fix regression: Must return a vanilla ↵Sven Gothel2023-07-041-3/+1
| | | | descriptor ('/' not '_') i.e. non JNI method-name descriptor to avoid double conversion
* GlueGen JavaCallback: Revised: Static Java callback dispatcher, dropping ↵Sven Gothel2023-07-0414-795/+1533
| | | | | | | | | | | | | | | | | | | | | | | | | native heap, support Struct UserParam ... Implementation now generates a static Java callback dispatcher for each defined SetCallbackFunction, which gets invoked by the generated native static counterpart with all arguments required. The static callback utilizes its own synchronization for thread-safety and fetches the required data set stored at SetCallbackFunction to dispatch the call to the users' CallbackFunction. In case the callback has been removed already, the static callback simply bails out quietly. The native code does not create, release or manage heap memory and therefore is considered safe. +++ Further Struct Type UserParam are now supported including Heterogeneous UserParam mapping (read GlueGen_Mapping.*). +++ Cleaned up code by extracting all JavaCallback emitter code into JavaCallbackEmitter class in one place, leaving JavaMethodbindingEmitter and CMethodbindingEmitter mostly in their original stage (non-convoluted). In this regard, I had to refactor a few function, i.e. moving CMethodbindingEmitter.getJNIMangledArg(..) into JavaType.appendDescriptor(..) and JavaType.appendJNIDescriptor(..) while reusing the toJNIMethodDescriptor(..) conversion. Test4JavaCallback covers and passes all cases.
* GlueGen JavaCallback: Unify native 'T_JavaCallbackGlueData' typedef structcallback_jniuserparamproxySven Gothel2023-07-023-11/+25
|
* GlueGen JavaCallback: CMethodBindingEmitter: Check, describe & clear ↵Sven Gothel2023-07-022-7/+103
| | | | | | exception if occurring - we must assume async off-thread source in general Covered by unit tests now
* GlueGen JavaCallback: CMethodBindingEmitter: Check lockObj for NULL before ↵Sven Gothel2023-07-021-0/+1
| | | | GetObjectRefType(), avoid certain (older) Hotspot issues
* CMethodBindingEmitter JavaCallback: Use a friendly readable basename for errorsSven Gothel2023-07-021-16/+19
|
* GlueGen Struct [18]: Drop redundant 'static get*ElemCount() { return 1 }` ↵Sven Gothel2023-07-022-3/+5
| | | | for: isPrimitive && !isPointer && staticElemCount && maxOneElement
* GlueGen JavaCallback: Native Callback: Reduce 'look-ahead' of ↵Sven Gothel2023-07-021-9/+9
| | | | read-after-free to critical lockObj only
* GlueGen JavaCallback: Document native callback use-after-free potential ↵Sven Gothel2023-07-021-1/+6
| | | | (caught), zero-mem @ release
* GlueGen JavaCallback: Native callback: Check ObjectRef validity and ↵Sven Gothel2023-07-023-21/+66
| | | | synchronize (MonitorEnter/Exit) with same Object of Java impl. -> thread safe
* GlueGen JavaCallback: Use `SetCallback-KeyClass` if manually specified, even ↵Sven Gothel2023-07-013-3/+32
| | | | if no keys are defined!
* GlueGen JavaCallback: Only produce default 'Key' class if keys are used, ↵Sven Gothel2023-07-016-171/+556
| | | | | | | | | | | expose 'Key' to public and use it. Expose release*() and get*Keys() methods Further we use a dedicated lock Object used in the Java implementation. TODO: Native static callback dispatch code shall - (also) acquire the lock - handle case where the data has been released already to render this solution thread-safe and data-race free
* GlueGen JavaCallback: Release the associated data (natively) only after the ↵Sven Gothel2023-07-011-2/+8
| | | | | | actual toolkit setCallback call .. to avoid a potential race condition
* GlueGen JavaCallback: Resolve key mapping of callback and associated ↵Sven Gothel2023-06-308-125/+911
| | | | | | | | | | | | | | | | resources via 'JavaCallbackKey' config and custom `SetCallback-KeyClass` Updated unit test and doc accordingly. Unit tests handle OpenAL's AL_SOFT_callback_buffer and AL_SOFT_events. Tested global scope (no key, default) and 1 key (default) and 1 key (custom class). Added more query functions, which all only take the `SetCallbackFunction` key arguments as specified. Cleaned up JavaCallback* config class field naminig scheme. Added 'synchronized (..Map) { }' block in crucial `SetCallbackFunction`, rendering implementation thread safe.
* GlueGen FunctionType/MethodBinding: get*ParameterList(): Use a more flexible ↵Sven Gothel2023-06-308-84/+210
| | | | way via a ParameterConsumer visitor, also usable for other iterative parameter generator
* Test4JavaCallback: Just rename myUserParam -> myUserParam01 for future tests..Sven Gothel2023-06-291-22/+22
|
* GlueGen JavaCallback: Set-Callback: Ensure a previously mapped 'userParam' ↵Sven Gothel2023-06-292-12/+42
| | | | instance is released before binding new one; Add test changing callback function.
* GlueGen JavaCallback: 1st Working Draft: Changed 'JavaCallbackDef' config, ↵Sven Gothel2023-06-299-155/+609
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | added code generation incl. native to Java dispatch and resource management Tested via Test4JavaCallback.java (using test2.[hc]). Please read the GlueGen_Mapping.md as well as Test4JavaCallback.java . +++ Some implementation details: JavaConfiguration maps JavaCallbackDef to JavaCallback set-function and maintains a list. JavaCallbackDef itself holds all configured details. JavaConfiguration also maps JavaCallbackInfo to JavaCallback set-function. JavaCallbackInfo itself holds all compile time information, as produced by JavaEmitter.beginFunctions(..). This extends JavaCallbackDef and avoid repetetive computation for the callback-function-type and its MethodBinding, parameter indices for the callback interface and userParam, etc. CMethodBindingEmitter: Native callback to Java dispatch - The JavaCallback setter function creates a native 'UserParam' struct instance, which holds the callback-interface-jobject, its callback-jmethodID and the userParam-jobject for invocation of the actual JavaCallback interface method. - To produce the C-Type -> JNI-Type conversion, An internal CMethodBindingEmitter instance for the native-callback function binding is created inside the CMethodBindingEmitter of the callback setter method. It is being used to map the types to JNI within the generated native callback function, passed to the actual JavaCallback method. JavaMethodBindingEmitter: Native callback to Java dispatch - The JavaCallbacl setter passes the callback-interface-object, the userParam-object and the callback-method-signature (to have the native method retrieve the jmethodID). - It receives the native pointer of the native `UserParam` struct instance, which gets mapped to the userParam-object. (*TODO: Refine ownership + release*).
* GlueGen ProcAddressCMethodBindingEmitter.jniMangle() override: Only add ↵Sven Gothel2023-06-291-1/+1
| | | | additional params if produced name containes '__', i.e. JNI mangled parameter
* GlueGen FunctionType: Factor out getParameterList(..) from toString(..) and ↵Sven Gothel2023-06-293-22/+113
| | | | drop 'void' and use typedef-name; MethodBinding: Add getCParameterList(..) and getJavaParameterList(..) for general usage similar to FunctionType.getParameterList()
* GlueGen CMethodBindingEmitter: Refactor emitBodyReturnResult() -> ↵Sven Gothel2023-06-291-98/+148
| | | | emitBodyMapCToJNIType(): Reuse to converting any C-type argument to java JNI type (i.e. native callback to JavaCallback)
* GlueGen: Move [de]captializeString(..) JavaEmitter -> static in CodeGenUtilsSven Gothel2023-06-292-7/+21
|
* GlueGen LibraryOnLoad Config: Generate `JNI_OnLoad(..)` for dynamic and ↵Sven Gothel2023-06-293-4/+125
| | | | `JNI_OnLoad_<LibraryBasename>(..)` for static libraries and `JVMUtil_GetJNIEnv(..)` to resolve the `JNIEnv*` as used by JavaCallback
* GlueGen Struct [17]: Handle void pointers, i.e. `void*`, within a struct as ↵Sven Gothel2023-06-292-10/+11
| | | | | | `Opaque` configured pointer-types .. includes cross-ref'ed doc and unit test
* GlueGen JavaCallback: Add JavaCallback.methodSignature to JNI arg-list and ↵Sven Gothel2023-06-261-0/+16
| | | | pass value at invocation, allowing to find the jmethodID of callback
* GlueGen JavaCallback: Move JavaCallback into JavaConfiguration, accessible ↵Sven Gothel2023-06-262-52/+82
| | | | across *Emitter (needed for CMethodEmitter as well); Add JavaCallback.methodSignature to be passed to native function later on to find the callback jmethodID
* GlueGen JavaCallback: Expose getJNIMethodDescriptor() for JNI mangled method ↵Sven Gothel2023-06-263-14/+49
| | | | names, used in CMethodBindingEmitter; Use JavaCallback's function-pointer-type capital-name as simple-class-name and its FQN for JNI resolution.
* GlueGen JavaCallback: Use new JavaType nature 'named-class', denoting the ↵Sven Gothel2023-06-262-1/+5
| | | | | | | | | | | | generated callback interface mapping the callback function. This passes the jobject for the callback function/interface and the userParam (from 'void*') down to the native implementation. TODO: Add specific native implementation for JavaCallback, wrapping the jobject's into a native struct as user-param and a universal C-function as the native callback to dispatch the call to the java method with known arguments.
* GlueGen JavaType: Add new nature 'String clazzName': Future (not yet ↵Sven Gothel2023-06-261-35/+97
| | | | | | | | | | generated or existing) Class objects (existing at runtime) New nature can be queried via isNamedClass(). Cleaned up equals() and completed hashValue() etc. Ctor validation ensures exactly one nature is set!
* GlueGen JavaCallback: Add preliminary implementation (WIP): Produces proper ↵Sven Gothel2023-06-253-9/+146
| | | | | | interfaces, TODO implementation Note: JavaCallbackDef is commented out on test2.cfg example, since implementation is missing.
* GlueGen JavaConfiguration: Add List<Integer> stringArguments(final ↵Sven Gothel2023-06-251-0/+18
| | | | AliasedSymbol symbol)
* GlueGen JavaConfiguration: Add 'JavaCallbackDef ↵Sven Gothel2023-06-251-1/+47
| | | | | | | | | <funcion-pointer-typedef-name> [user-param-idx]' Define a JavaCallback, enacted on a function-pointer argument `T2_CallbackFunc` and a user-param `void*` for Java Object mapping Example: JavaCallbackDef T2_CallbackFunc 2
* GlueGen FunctionSymbol: Simplify ctor reusing main-ctor; Be always reachable ↵Sven Gothel2023-06-251-3/+2
| | | | via type(def)name, ctor: addAliasedName( type.getCName() )
* GlueGen Add JavaType.forObjectClass()Sven Gothel2023-06-251-0/+8
|
* GlueGen FunctionType: Expose toString(..) w/ 'isPointer' argumentSven Gothel2023-06-251-0/+3
|
* GlueGen: Fix Type.getSignature(..): Test for isFunctionPointer() to ↵Sven Gothel2023-06-251-6/+9
| | | | elaborate on FunctionType as getTargetType() only retruns a function-ptr and no more a function-type.
* JavaEmitter.generateArrayGetterSetterCode(): Place elemCountExpr null check ↵Sven Gothel2023-06-251-8/+7
| | | | where it could occur -> non-opaque, non-primitive array case
* GlueGen: Add JavaEmitter(JavaConfiguration) ctorSven Gothel2023-06-251-0/+5
|
* GlueGen Fix ProcAddressCMethodBindingEmitter.jniMangle(..) override: Use ↵Sven Gothel2023-06-251-1/+1
| | | | renamed {jniMangle->getJNIMangledArg}(..)