Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced C++ -> Java mapping #798

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Advanced C++ -> Java mapping #798

wants to merge 27 commits into from

Conversation

Avdiji
Copy link

@Avdiji Avdiji commented Mar 18, 2025

Added serveral functionalities which enable the user to map more advanced and specific edgecases.
Here's a list of all the additional features:

  1. Custom Exception-Mapping

    • Using the ExceptionMapper annotation within the Platform annotation you can now map custom C++ exceptions to any java Throwable.
    • Just specify the CPP exception (as a String) and the corresponding java exception and the mapper will automatically catch any CPP exception of that type, unroll it recursively and map it to the given java exception.
  2. Custom JNI-Code in the beggining of each generated JNI-File

    • Within the Platform annotation there now is a new property 'addCustomJNIFrom' which allows the user to specify the resource-path to any file. The files content will then be inserted on top of the generated JNI-Code.
  3. Custom JNI-Mapping of individual java methods

    • The CustomMapper annotation allows the user to write his own JNI code for any function. Attirbutes are:
      • customMapping: A String which will directly replace any otherwhise generated code within the try-catch block of the mapping function
      • filePaths: A String[] which reflects the resourcePaths of the files which contain the mapping. The files content will replace the otherwhise generated code within the try-cathc block of the mapping function, in the order of the values within the String[]
      • functionCall: will replace the String '$funcName'
      • passCTypeParams: determines whether to pass the generated field ptr or the parameter arg into the calling function.
      • dereferenceParams: will dereference any occurence of 'ptr' wihtin the calling function.
      • replacements: a String[] with replacements (e.g.: ["val1", "val2", "val3", "val4"] -> val1 will be replaced by val2 and val3 by val4...)
      • typename: will change the typename of the underlying object to whatever passed String.
  4. Added several properties to the Virtual annotation, in order to enable Cross-Language Polymorphism for custom mapped datatypes.

  5. Added setClassLoader function, which ensures a ClassLoader at everytime (using it is optional though).

Overall the changes are supposed to allow the user to map C++ code in a more specific way and gives more freedom to add custom JNI-Code.

@saudet saudet requested a review from HGuillemet March 18, 2025 10:32
@saudet
Copy link
Member

saudet commented Mar 18, 2025

Would it be possible to split these changes into 4 or 5 smaller pull requests?

Also please revert any unnecessary changes in formatting

@Avdiji
Copy link
Author

Avdiji commented Mar 18, 2025

Sure thing! I'll get to it once i find the time

@saudet
Copy link
Member

saudet commented Mar 18, 2025

No need to do all of them at once, just a first small pull request that stands alone, and then when that gets merged, another small pull request based on the first set of changes, etc. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants