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

Revisit the name mangling rule usage for the '$' character (method and filenames named differently) #57

Closed
wants to merge 2 commits into from

Conversation

pomadchin
Copy link
Member

@pomadchin pomadchin commented Jul 27, 2021

@jodersky also mentioned that it works here without extra rules for $.

This PR is made to check what's going on with the header functions generation.

Closes #36 (eventually)

Context

JDK8 javah preserves a specific file naming when dealing with generating methods for Scala objects. It generates filenames for objects that contain $ (all Scala objects) as package_ObjectName__.h (mangles $ into __). However, methods mangling is a bit different and for all methods it converts $ into _00024.

Right now in the master branch, for the following Adder.scala:

package multiclasses

object Adder {

  @native def sum(term1: Int, term2: Int): Int

}

The following multiclasses_Adder__.h would be generated:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class multiclasses_Adder__ */

#ifndef _Included_multiclasses_Adder__
#define _Included_multiclasses_Adder__
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:      multiclasses_Adder__
 * Method:     sum
 * Signature:  (II)I
 */
 // An incorrect method name is generated!
JNIEXPORT jint JNICALL Java_multiclasses_Adder___sum
  (JNIEnv *, jobject, jint, jint);

#ifdef __cplusplus
}
#endif
#endif

With this PR the following multiclasses_Adder__.h would be generated:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class multiclasses_Adder_00024 */

#ifndef _Included_multiclasses_Adder_00024
#define _Included_multiclasses_Adder_00024
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:      multiclasses_Adder_00024
 * Method:     sum
 * Signature:  (II)I
 */
JNIEXPORT jint JNICALL Java_multiclasses_Adder_00024_sum
  (JNIEnv *, jobject, jint, jint);

#ifdef __cplusplus
}
#endif
#endif

cc @jodersky do we need to preserve the original jdk8 javah filename?
The alternative can be just to remove a special case around $ and use the new namings generated by gjavah: multiclasses_Adder_00024.h which can be a bit more obvious (i.e. I would expect multiclasses_Adder_00024 methods to be stored in a multiclasses_Adder_00024.h file).

TLDR; the whole difference in behavior is in this diff: pomadchin@ea4ecc8

@pomadchin pomadchin added the fix label Jul 27, 2021
@pomadchin pomadchin changed the title Remove unnecessary name mangling rule for '$' [WIP] Remove unnecessary (?) name mangling rule for '$' Jul 27, 2021
@pomadchin pomadchin changed the title [WIP] Remove unnecessary (?) name mangling rule for '$' [WIP] Revisit the name mangling rule for '$' usage Jul 27, 2021
@pomadchin pomadchin changed the title [WIP] Revisit the name mangling rule for '$' usage Revisit the name mangling rule usage for the '$' character Jul 27, 2021
@pomadchin pomadchin changed the title Revisit the name mangling rule usage for the '$' character Revisit the name mangling rule usage for the '$' character (method and filenames named differently) Jul 27, 2021
@pomadchin
Copy link
Member Author

Closed in favor of #58 which I think makes more sense.

@pomadchin pomadchin closed this Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sbt-javah mangles names of @native methods in objects incorrectly
1 participant