Skip to content

Commit

Permalink
fix compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tiainen committed Nov 23, 2024
1 parent 99562dd commit 7c8df43
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 166 deletions.
245 changes: 106 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

39 changes: 26 additions & 13 deletions rust/bridge/shared/types/src/jni/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,19 @@ impl<'storage, 'param: 'storage, 'context: 'param> ArgTypeInfo<'storage, 'param,
}
}

impl<'storage, 'param: 'storage, 'context: 'param> ArgTypeInfo<'storage, 'param, 'context>
for &'storage mut dyn QuicCallbackListener
{
type ArgType = JavaQuicCallbackListener<'param>;
type StoredType = JniQuicCallbackListener<'storage>;

fn borrow(env: &mut JNIEnv<'context>, store: &'param Self::ArgType) -> Result<Self::StoredType, BridgeLayerError> {
Self::StoredType::new(env, store)
}
fn load_from(stored: &'storage mut Self::StoredType) -> Self {
stored
}
}

/// A translation from a Java interface where the implementing class wraps the Rust handle.
impl<'a> SimpleArgTypeInfo<'a> for CiphertextMessageRef<'a> {
Expand Down Expand Up @@ -629,14 +642,14 @@ impl<'a> SimpleArgTypeInfo<'a> for crate::grpc::GrpcHeaders {

let mut headers = HashMap::new();

let jmap = env.get_map(foreign)?;
let mut jmap_iter = jmap.iter(env)?;
let jmap = env.get_map(foreign).check_exceptions(env, "grpc::GrpcHeaders::convert_from")?;
let mut jmap_iter = jmap.iter(env).check_exceptions(env, "grpc::GrpcHeaders::convert_from")?;
while let Ok(Some((key, value))) = jmap_iter.next(env) {
let header_key: String = env.get_string(&key.into())?.into();
let values = env.get_list(&value)?;
let mut values_iter = values.iter(env)?;
let header_key: String = env.get_string(&key.into()).check_exceptions(env, "grpc::GrpcHeaders::convert_from")?.into();
let values = env.get_list(&value).check_exceptions(env, "grpc::GrpcHeaders::convert_from")?;
let mut values_iter = values.iter(env).check_exceptions(env, "grpc::GrpcHeaders::convert_from")?;
while let Ok(Some(value)) = values_iter.next(env) {
let header_value: String = env.get_string(&value.into())?.into();
let header_value: String = env.get_string(&value.into()).check_exceptions(env, "grpc::GrpcHeaders::convert_from")?.into();
headers
.entry(header_key.clone())
.and_modify(|l: &mut Vec<String>| l.push(header_value.clone()))
Expand All @@ -652,17 +665,17 @@ impl <'a> ResultTypeInfo<'a> for signal_grpc::GrpcReply {
type ResultType = JByteArray<'a>;

fn convert_into(self, env: &mut JNIEnv<'a>) -> Result<Self::ResultType, BridgeLayerError> {
let message = env.byte_array_from_slice(&self.message)?;
let message = env.byte_array_from_slice(&self.message).check_exceptions(env, "signal_grpc::GrpcReply::convert_from")?;
let args = jni_args!((
self.statuscode => int,
message => [byte],
) -> void);
let class_name = env.find_class(jni_class_name!(org.signal.libsignal.grpc.SignalRpcReply))?;
let class_name = env.find_class(jni_class_name!(org.signal.libsignal.grpc.SignalRpcReply)).check_exceptions(env, "signal_grpc::GrpcReply::convert_from")?;
let jobj = env.new_object(
class_name,
args.sig,
&args.args,
)?;
).check_exceptions(env, "signal_grpc::GrpcReply::convert_from")?;
Ok(jobj.into())
}
}
Expand All @@ -676,11 +689,11 @@ impl<'a> SimpleArgTypeInfo<'a> for crate::quic::QuicHeaders {

let mut headers = HashMap::new();

let jmap = env.get_map(foreign)?;
let mut jmap_iter = jmap.iter(env)?;
let jmap = env.get_map(foreign).check_exceptions(env, "quic::QuicHeaders::convert_from")?;
let mut jmap_iter = jmap.iter(env).check_exceptions(env, "quic::QuicHeaders::convert_from")?;
while let Ok(Some((key, value))) = jmap_iter.next(env) {
let header_key: String = env.get_string(&key.into())?.into();
let header_value: String = env.get_string(&value.into())?.into();
let header_key: String = env.get_string(&key.into()).check_exceptions(env, "quic::QuicHeaders::convert_from")?.into();
let header_value: String = env.get_string(&value.into()).check_exceptions(env, "quic::QuicHeaders::convert_from")?.into();
headers.insert(header_key.clone(), header_value.clone());
}

Expand Down
10 changes: 5 additions & 5 deletions rust/bridge/shared/types/src/jni/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl<'a> JniGrpcReplyListener<'a> {
}

impl<'a> JniGrpcReplyListener<'a> {
fn do_on_reply(&mut self, reply: GrpcReply) -> Result<(), BridgeLayerError> {
self.env.borrow_mut().with_local_frame(8, |env| {
fn do_on_reply(&mut self, reply: GrpcReply) -> SignalJniResult<()> {
self.env.borrow_mut().with_local_frame(8, "on_reply", |env| {
let jni_reply = reply.convert_into(env)?;
let callback_args = jni_args!((
jni_reply => org.signal.libsignal.grpc.SignalRpcReply,
Expand All @@ -39,9 +39,9 @@ impl<'a> JniGrpcReplyListener<'a> {
})
}

fn do_on_error(&mut self, error: String) -> Result<(), BridgeLayerError> {
self.env.borrow_mut().with_local_frame(8, |env| {
let message = env.new_string(error.to_string())?;
fn do_on_error(&mut self, error: String) -> SignalJniResult<()> {
self.env.borrow_mut().with_local_frame(8, "on_error", |env| {
let message = env.new_string(error.to_string()).check_exceptions(env, "on_error")?;
let callback_args = jni_args!((
message => java.lang.String,
) -> void);
Expand Down
6 changes: 3 additions & 3 deletions rust/bridge/shared/types/src/jni/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl<'a> JniQuicCallbackListener<'a> {
}

impl<'a> JniQuicCallbackListener<'a> {
fn do_on_data(&mut self, data: Vec<u8>) -> Result<(), BridgeLayerError> {
self.env.borrow_mut().with_local_frame(8, |env| {
let bytes = env.byte_array_from_slice(&data)?;
fn do_on_data(&mut self, data: Vec<u8>) -> SignalJniResult<()> {
self.env.borrow_mut().with_local_frame(8, "on_data", |env| {
let bytes = env.byte_array_from_slice(&data).check_exceptions(env, "on_data")?;
let callback_args = jni_args!((
bytes => [byte],
) -> void);
Expand Down
4 changes: 2 additions & 2 deletions rust/chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ prost = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync","rt","rt-multi-thread"] }
tokio-stream = { workspace = true }
tonic = { version = "0.11.0", features = [ "tls", "tls-webpki-roots" ] }
tonic = { version = "0.12.3", features = [ "tls", "tls-webpki-roots" ] }

[build-dependencies]
tonic-build = "0.11.0"
tonic-build = "0.12.3"
2 changes: 1 addition & 1 deletion rust/chat/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
];
tonic_build::configure()
.build_server(false)
.compile(&protos, &["../../proto"])?;
.compile_protos(&protos, &["../../proto"])?;
for proto in &protos {
println!("cargo:rerun-if-changed={}", proto);
}
Expand Down
4 changes: 2 additions & 2 deletions rust/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ prost = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync","rt","rt-multi-thread"] }
tokio-stream = { workspace = true }
tonic = { version = "0.11.0", features = [ "tls", "tls-webpki-roots" ] }
tonic = { version = "0.12.3", features = [ "tls", "tls-webpki-roots" ] }

[build-dependencies]
tonic-build = "0.11.0"
tonic-build = "0.12.3"
2 changes: 1 addition & 1 deletion rust/grpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
];
tonic_build::configure()
.build_server(false)
.compile(&protos, &["src/proto"])?;
.compile_protos(&protos, &["src/proto"])?;
for proto in &protos {
println!("cargo:rerun-if-changed={}", proto);
}
Expand Down

0 comments on commit 7c8df43

Please sign in to comment.