Skip to content

Commit

Permalink
use cfg_or_panic
Browse files Browse the repository at this point in the history
  • Loading branch information
wenym1 committed Sep 25, 2023
1 parent 3e7ea66 commit 83e2ab8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/jni_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ normal = ["workspace-hack"]

[dependencies]
bytes = "1"
cfg-or-panic = "0.2"
futures = { version = "0.3", default-features = false, features = ["alloc"] }
itertools = "0.11"
jni = "0.21.1"
Expand Down
33 changes: 10 additions & 23 deletions src/jni_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::ops::{Deref, DerefMut};
use std::slice::from_raw_parts;
use std::sync::{Arc, LazyLock, OnceLock};

use cfg_or_panic::cfg_or_panic;
use hummock_iterator::{HummockJavaBindingIterator, KeyedRow};
use jni::objects::{
AutoElements, GlobalRef, JByteArray, JClass, JMethodID, JObject, JStaticMethodID, JString,
Expand Down Expand Up @@ -298,44 +299,30 @@ pub extern "system" fn Java_com_risingwave_java_binding_Binding_vnodeCount(
VirtualNode::COUNT as jint
}

#[cfg_or_panic(not(madsim))]
#[no_mangle]
pub extern "system" fn Java_com_risingwave_java_binding_Binding_hummockIteratorNew<'a>(
env: EnvParam<'a>,
read_plan: JByteArray<'a>,
) -> Pointer<'static, HummockJavaBindingIterator> {
execute_and_catch(env, move |env| {
#[cfg(madsim)]
{
unreachable!()
}

#[cfg(not(madsim))]
{
let read_plan = Message::decode(to_guarded_slice(&read_plan, env)?.deref())?;
let iter = RUNTIME.block_on(HummockJavaBindingIterator::new(read_plan))?;
Ok(iter.into())
}
let read_plan = Message::decode(to_guarded_slice(&read_plan, env)?.deref())?;
let iter = RUNTIME.block_on(HummockJavaBindingIterator::new(read_plan))?;
Ok(iter.into())
})
}

#[cfg_or_panic(not(madsim))]
#[no_mangle]
pub extern "system" fn Java_com_risingwave_java_binding_Binding_hummockIteratorNext<'a>(
env: EnvParam<'a>,
mut pointer: Pointer<'a, HummockJavaBindingIterator>,
) -> Pointer<'static, JavaBindingRow> {
execute_and_catch(env, move |_env| {
#[cfg(madsim)]
{
unreachable!()
}

#[cfg(not(madsim))]
{
let iter = pointer.as_mut();
match RUNTIME.block_on(iter.next())? {
None => Ok(Pointer::null()),
Some(row) => Ok(JavaBindingRow::with_keyed(row, iter.class_cache.clone()).into()),
}
let iter = pointer.as_mut();
match RUNTIME.block_on(iter.next())? {
None => Ok(Pointer::null()),
Some(row) => Ok(JavaBindingRow::with_keyed(row, iter.class_cache.clone()).into()),
}
})
}
Expand Down

0 comments on commit 83e2ab8

Please sign in to comment.