-
Notifications
You must be signed in to change notification settings - Fork 255
chore: bump jni from 0.21.1 to 0.22.4 #6274
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
Open
dependabot
wants to merge
2
commits into
main
Choose a base branch
from
dependabot/cargo/jni-0.22.4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,114 +1,121 @@ | ||
| use std::str::FromStr; | ||
|
|
||
| use jni::errors::{Error as JniError, Result as JniResult, ThrowRuntimeExAndDefault}; | ||
| use jni::objects::{JClass, JString}; | ||
| use jni::sys::{jboolean, jstring}; | ||
| use jni::JNIEnv; | ||
| use jni::strings::JNIString; | ||
| use jni::sys::jboolean; | ||
| use jni::{jni_str, Env, EnvUnowned}; | ||
| use prqlc::{json, pl_to_prql, prql_to_pl, ErrorMessages, Options, Target}; | ||
|
|
||
| #[no_mangle] | ||
| #[allow(non_snake_case)] | ||
| pub extern "system" fn Java_org_prql_prql4j_PrqlCompiler_toSql( | ||
| mut env: JNIEnv, | ||
| _class: JClass, | ||
| query: JString, | ||
| target: JString, | ||
| pub extern "system" fn Java_org_prql_prql4j_PrqlCompiler_toSql<'local>( | ||
| mut env: EnvUnowned<'local>, | ||
| _class: JClass<'local>, | ||
| query: JString<'local>, | ||
| target: JString<'local>, | ||
| format: jboolean, | ||
| signature: jboolean, | ||
| ) -> jstring { | ||
| let prql_query = match jstring_to_string(&mut env, &query, "query") { | ||
| Some(s) => s, | ||
| None => return std::ptr::null_mut(), | ||
| }; | ||
| let target_str = match jstring_to_string(&mut env, &target, "target") { | ||
| Some(s) => s, | ||
| None => return std::ptr::null_mut(), | ||
| }; | ||
| let prql_dialect = match Target::from_str(&target_str) { | ||
| Ok(t) => t, | ||
| Err(e) => { | ||
| throw_illegal_argument(&mut env, &format!("invalid target dialect: {e}")); | ||
| return std::ptr::null_mut(); | ||
| } | ||
| }; | ||
| let opt = Options { | ||
| format: format != 0, | ||
| target: prql_dialect, | ||
| signature_comment: signature != 0, | ||
| // TODO: add support for `display` | ||
| ..Default::default() | ||
| }; | ||
| let result = prqlc::compile(&prql_query, &opt); | ||
| java_string_with_exception(result, &mut env) | ||
| ) -> JString<'local> { | ||
| env.with_env(|env| -> JniResult<JString<'local>> { | ||
| let prql_query = jstring_to_string(env, &query, "query")?; | ||
| let target_str = jstring_to_string(env, &target, "target")?; | ||
| let prql_dialect = match Target::from_str(&target_str) { | ||
| Ok(t) => t, | ||
| Err(e) => { | ||
| return Err(throw_illegal_argument( | ||
| env, | ||
| &format!("invalid target dialect: {e}"), | ||
| )) | ||
| } | ||
| }; | ||
| let opt = Options { | ||
| format, | ||
| target: prql_dialect, | ||
| signature_comment: signature, | ||
| // TODO: add support for `display` | ||
| ..Default::default() | ||
| }; | ||
| let result = prqlc::compile(&prql_query, &opt); | ||
| java_string_with_exception(result, env) | ||
| }) | ||
| .resolve::<ThrowRuntimeExAndDefault>() | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| #[allow(non_snake_case)] | ||
| pub extern "system" fn Java_org_prql_prql4j_PrqlCompiler_format( | ||
| mut env: JNIEnv, | ||
| _class: JClass, | ||
| query: JString, | ||
| ) -> jstring { | ||
| let prql_query = match jstring_to_string(&mut env, &query, "query") { | ||
| Some(s) => s, | ||
| None => return std::ptr::null_mut(), | ||
| }; | ||
| let result = prql_to_pl(&prql_query).and_then(|x| pl_to_prql(&x)); | ||
| java_string_with_exception(result, &mut env) | ||
| pub extern "system" fn Java_org_prql_prql4j_PrqlCompiler_format<'local>( | ||
| mut env: EnvUnowned<'local>, | ||
| _class: JClass<'local>, | ||
| query: JString<'local>, | ||
| ) -> JString<'local> { | ||
| env.with_env(|env| -> JniResult<JString<'local>> { | ||
| let prql_query = jstring_to_string(env, &query, "query")?; | ||
| let result = prql_to_pl(&prql_query).and_then(|x| pl_to_prql(&x)); | ||
| java_string_with_exception(result, env) | ||
| }) | ||
| .resolve::<ThrowRuntimeExAndDefault>() | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| #[allow(non_snake_case)] | ||
| pub extern "system" fn Java_org_prql_prql4j_PrqlCompiler_toJson( | ||
| mut env: JNIEnv, | ||
| _class: JClass, | ||
| query: JString, | ||
| ) -> jstring { | ||
| let prql_query = match jstring_to_string(&mut env, &query, "query") { | ||
| Some(s) => s, | ||
| None => return std::ptr::null_mut(), | ||
| }; | ||
| let result = prql_to_pl(&prql_query).and_then(|x| json::from_pl(&x)); | ||
| java_string_with_exception(result, &mut env) | ||
| pub extern "system" fn Java_org_prql_prql4j_PrqlCompiler_toJson<'local>( | ||
| mut env: EnvUnowned<'local>, | ||
| _class: JClass<'local>, | ||
| query: JString<'local>, | ||
| ) -> JString<'local> { | ||
| env.with_env(|env| -> JniResult<JString<'local>> { | ||
| let prql_query = jstring_to_string(env, &query, "query")?; | ||
| let result = prql_to_pl(&prql_query).and_then(|x| json::from_pl(&x)); | ||
| java_string_with_exception(result, env) | ||
| }) | ||
| .resolve::<ThrowRuntimeExAndDefault>() | ||
| } | ||
|
|
||
| fn jstring_to_string(env: &mut JNIEnv, s: &JString, name: &str) -> Option<String> { | ||
| match env.get_string(s) { | ||
| Ok(js) => Some(js.into()), | ||
| Err(e) => { | ||
| throw_illegal_argument(env, &format!("failed to read {name}: {e}")); | ||
| None | ||
| } | ||
| fn jstring_to_string(env: &mut Env, s: &JString, name: &str) -> JniResult<String> { | ||
| match s.try_to_string(env) { | ||
| Ok(text) => Ok(text), | ||
| Err(e) => Err(throw_illegal_argument( | ||
| env, | ||
| &format!("failed to read {name}: {e}"), | ||
| )), | ||
| } | ||
| } | ||
|
|
||
| fn throw_illegal_argument(env: &mut JNIEnv, message: &str) { | ||
| if let Err(e) = env.throw_new("java/lang/IllegalArgumentException", message) { | ||
| eprintln!("Error throwing IllegalArgumentException: {e:?}"); | ||
| /// Throws an `IllegalArgumentException` and returns the error to propagate out | ||
| /// of the `with_env` closure. The error policy leaves an already-pending | ||
| /// exception alone, so the exception thrown here is the one Java observes. | ||
| fn throw_illegal_argument(env: &mut Env, message: &str) -> JniError { | ||
| match env.throw_new( | ||
| jni_str!("java/lang/IllegalArgumentException"), | ||
| JNIString::from(message), | ||
| ) { | ||
| // `throw_new` reports `Err(Error::JavaException)` once the exception is | ||
| // pending; anything else means the throw itself failed. | ||
| Ok(()) => JniError::JavaException, | ||
| Err(e) => e, | ||
| } | ||
| } | ||
|
|
||
| fn java_string_with_exception(result: Result<String, ErrorMessages>, env: &mut JNIEnv) -> jstring { | ||
| fn java_string_with_exception<'local>( | ||
| result: Result<String, ErrorMessages>, | ||
| env: &mut Env<'local>, | ||
| ) -> JniResult<JString<'local>> { | ||
| match result { | ||
| Ok(text) => match env.new_string(text) { | ||
| Ok(js) => js.into_raw(), | ||
| Err(e) => { | ||
| throw_illegal_argument(env, &format!("failed to create java string: {e}")); | ||
| std::ptr::null_mut() | ||
| } | ||
| Ok(js) => Ok(js), | ||
| Err(e) => Err(throw_illegal_argument( | ||
| env, | ||
| &format!("failed to create java string: {e}"), | ||
| )), | ||
| }, | ||
| Err(err) => { | ||
| let message = err.to_string(); | ||
| match env.find_class("java/lang/Exception") { | ||
| Ok(exception) => { | ||
| if let Err(e) = env.throw_new(exception, message) { | ||
| eprintln!("Error throwing exception: {e:?}"); | ||
| } | ||
| } | ||
| Err(e) => { | ||
| eprintln!("Error finding java/lang/Exception: {e:?}"); | ||
| } | ||
| } | ||
| std::ptr::null_mut() | ||
| let exception = env.find_class(jni_str!("java/lang/Exception"))?; | ||
| Err(match env.throw_new(exception, JNIString::from(message)) { | ||
| Ok(()) => JniError::JavaException, | ||
| Err(e) => e, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw_newaccepts anything that implementsDesc<JClass>, which includes the&JNIStrthatjni_str!produces — that's howthrow_illegal_argumentthrowsjava/lang/IllegalArgumentExceptiona few lines up. So thefind_classlookup and theJClasslocal reference it returns aren't needed here.