Menu

#368 [java] %native generates function definition all the same

None
closed-invalid
nobody
java (79)
5
2022-02-01
2003-12-01
No

When using %native to use one's own JNI function
definition, SWIG generates just the function declaration
as expected, but then it also generates the JNI function
definition as well (the function declaration we did not
want to be generated).

See included file, module_wrap.cxx :

Line 85 - The function definition only, as expected .
Line 104 - 126 - The function definition which should not
be there

Discussion

  • Benjamin David

    Benjamin David - 2003-12-01

    Project Zip Archive

     
  • Olly Betts

    Olly Betts - 2006-09-25
    • summary: Java : %native generates function definition all the same --> [java] %native generates function definition all the same
     
  • Olly Betts

    Olly Betts - 2022-02-01
    • status: open --> closed-invalid
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2022-02-01

    Sorry nobody responded to this before. Better late than never hopefully!

    Looking at the examples of use of %native and the manual section about it, %native is there to handle wrapping a hand-coded JNI function rather than to replace the JNI wrapping generated for a C/C++ function with hand-coded JNI:

    You may have some hand written JNI functions that you want to use in addition to the SWIG generated JNI functions.
    Adding these to your SWIG generated package is possible using the %native directive.
    If you don't want SWIG to wrap your JNI function then of course you can simply use the %ignore directive.
    However, if you want SWIG to generate just the Java code for a JNI function then use the %native directive.

    If you want to also have SWIG ignore the negate function prototype and effectively replace the JNI it would generate then you need to use %ignore to ignore the C prototype as well as %native to specify the hand coded JNI.

    If I add this to your example, I get the result you want:

    %ignore negate(int*);
    
     
  • Olly Betts

    Olly Betts - 2022-02-01

    I've also added a note to the docs to clarify this point:

    Note that if you're wanting to effectively <b>replace</b> the JNI code generated for a C/C++ function then you'll need to use <tt>%ignore</tt> as well
    to tell SWIG not to automatically generate a JNI wrapper for it.
    
     

Log in to post a comment.

MongoDB Logo MongoDB