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

sbt-javah mangles names of @native methods in objects incorrectly #36

Closed
mrobakowski opened this issue Sep 23, 2020 · 9 comments · Fixed by #58
Closed

sbt-javah mangles names of @native methods in objects incorrectly #36

mrobakowski opened this issue Sep 23, 2020 · 9 comments · Fixed by #58
Labels

Comments

@mrobakowski
Copy link

object Foo {
  @native def bar()
}

should generate

JNIEXPORT void JNICALL Java_Foo_00024_bar
  (JNIEnv *, jobject);

but instead it generates

JNIEXPORT void JNICALL Java_Foo___bar
  (JNIEnv *, jobject);

... at least on recent JVMs. This seems to be already fixed in gjavah, but for some reason $ is special-cased in here https://github.com/jodersky/sbt-jni/blob/fb2c301d550cee5491780b40b6e87b7e3fc73163/plugin/src/main/java/ch/jodersky/sbt/jni/javah/Utils.java#L55-L56

@jodersky
Copy link
Member

Thanks for the pointers. I think that at the time I included gjavah in sbt-jni it didn't support special characters, so I just added the $ case to replicate what javah generated in the past.

If you have a general fix however, I'd be happy to merge it

@mrobakowski
Copy link
Author

In my case (I'm on JDK 14) the last branch of the if-else statement (builder.append(String.format("_0%04x", (int) ch))) produces the correct result. So just removing the special case for dollar sign would fix this. I'm not sure about other JDK versions though.

@pomadchin
Copy link
Member

pomadchin commented Jul 23, 2021

@mrobakowski 👋 could you check how the current main branch works for you? #43 is merged so it could affect some things.

@pomadchin pomadchin added the bug label Jul 23, 2021
@jodersky
Copy link
Member

FYI, I recently migrated gjavah to scala and fixed the issues with symbols. See here: https://github.com/jodersky/mill-jnilib/blob/master/jnilib/src/jnilib/gjavah.scala

I can confirm that it works, even with Scala 3 top-level functions and all sorts of funky characters.

@pomadchin
Copy link
Member

pomadchin commented Jul 24, 2021

@jodersky Thanks for confirming that! 🎉

sbt-jni snapshots live here now: https://oss.sonatype.org/content/repositories/snapshots/com/github/sbt/sbt-jni_2.12_1.0/ and should be easier to test to other folks.

Let's close it for now, but @mrobakowski feel free to create a new issue and / or reopen this one.

Resolved via #43

@jodersky
Copy link
Member

oh, I realize that my comment was ambiguous. When I said "it works", I meant that my gjavah scala port works. I can't speak for the updated official version.

Thanks for setting up maven publishing again!

@pomadchin
Copy link
Member

Ooops! I'll reopen it again than :D

@pomadchin pomadchin reopened this Jul 24, 2021
@pomadchin
Copy link
Member

@mrobakowski btw, we can add the latest JDK into CI if it helps.

@mrobakowski
Copy link
Author

Hi @pomadchin, sorry for not replying earlier. I don't even remember what project I needed this for 😅, so I cannot confirm or deny whether it works for my problem (I probably abandoned that side-project already). But the fix looks good, so thank you for that! 🎉

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