From 299f5c17d6dd1e37e598976a8d5092d7bd91c211 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Mon, 25 Mar 2024 10:05:34 -0700 Subject: [PATCH 1/5] Add `deny(unsafe_op_in_unsafe_fn)` lint. Signed-off-by: Yury-Fridlyand --- glide-core/src/retry_strategies.rs | 5 ++++- glide-core/src/rotating_buffer.rs | 5 ++++- glide-core/src/scripts_container.rs | 5 ++++- glide-core/src/socket_listener.rs | 5 ++++- java/src/lib.rs | 12 +++++++++--- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/glide-core/src/retry_strategies.rs b/glide-core/src/retry_strategies.rs index 4dd5d7edb7..c0410f6bc1 100644 --- a/glide-core/src/retry_strategies.rs +++ b/glide-core/src/retry_strategies.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use crate::client::ConnectionRetryStrategy; use std::time::Duration; use tokio_retry::strategy::{jitter, ExponentialBackoff}; diff --git a/glide-core/src/rotating_buffer.rs b/glide-core/src/rotating_buffer.rs index bbc736162e..5e25a4ddf2 100644 --- a/glide-core/src/rotating_buffer.rs +++ b/glide-core/src/rotating_buffer.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use bytes::BytesMut; use integer_encoding::VarInt; use logger_core::log_error; diff --git a/glide-core/src/scripts_container.rs b/glide-core/src/scripts_container.rs index 251a69e5c3..d3411d1a40 100644 --- a/glide-core/src/scripts_container.rs +++ b/glide-core/src/scripts_container.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use arcstr::ArcStr; use logger_core::log_info; use once_cell::sync::Lazy; diff --git a/glide-core/src/socket_listener.rs b/glide-core/src/socket_listener.rs index fc72b49a46..4c6eeeaef4 100644 --- a/glide-core/src/socket_listener.rs +++ b/glide-core/src/socket_listener.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use super::rotating_buffer::RotatingBuffer; use crate::client::Client; use crate::connection_request::ConnectionRequest; diff --git a/java/src/lib.rs b/java/src/lib.rs index eb81b165f1..e7c0307038 100644 --- a/java/src/lib.rs +++ b/java/src/lib.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use glide_core::start_socket_listener; use jni::objects::{JClass, JObject, JObjectArray, JString, JThrowable}; @@ -95,8 +98,11 @@ fn redis_value_to_java<'local>(env: &mut JNIEnv<'local>, val: Value) -> JObject< } } +/// # Safety +/// +/// * `pointer` must point to a valid `Value` obtained from a [protobuf response](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/response.proto). #[no_mangle] -pub extern "system" fn Java_glide_ffi_resolvers_RedisValueResolver_valueFromPointer<'local>( +pub unsafe extern "system" fn Java_glide_ffi_resolvers_RedisValueResolver_valueFromPointer<'local>( mut env: JNIEnv<'local>, _class: JClass<'local>, pointer: jlong, @@ -106,7 +112,7 @@ pub extern "system" fn Java_glide_ffi_resolvers_RedisValueResolver_valueFromPoin } #[no_mangle] -pub extern "system" fn Java_glide_ffi_resolvers_SocketListenerResolver_startSocketListener< +pub unsafe extern "system" fn Java_glide_ffi_resolvers_SocketListenerResolver_startSocketListener< 'local, >( env: JNIEnv<'local>, From 38e2009618012222248539e428bb498d6aa4ecbf Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Mon, 25 Mar 2024 10:14:58 -0700 Subject: [PATCH 2/5] linter Signed-off-by: Yury-Fridlyand --- java/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/src/lib.rs b/java/src/lib.rs index e7c0307038..4a25e78729 100644 --- a/java/src/lib.rs +++ b/java/src/lib.rs @@ -102,7 +102,9 @@ fn redis_value_to_java<'local>(env: &mut JNIEnv<'local>, val: Value) -> JObject< /// /// * `pointer` must point to a valid `Value` obtained from a [protobuf response](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/response.proto). #[no_mangle] -pub unsafe extern "system" fn Java_glide_ffi_resolvers_RedisValueResolver_valueFromPointer<'local>( +pub unsafe extern "system" fn Java_glide_ffi_resolvers_RedisValueResolver_valueFromPointer< + 'local, +>( mut env: JNIEnv<'local>, _class: JClass<'local>, pointer: jlong, From fb5f2514ed3f38f90e64974baad5dc85c21b8004 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Mon, 25 Mar 2024 10:31:51 -0700 Subject: [PATCH 3/5] Doc Signed-off-by: Yury-Fridlyand --- java/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java/src/lib.rs b/java/src/lib.rs index 4a25e78729..864ea28ec9 100644 --- a/java/src/lib.rs +++ b/java/src/lib.rs @@ -113,6 +113,9 @@ pub unsafe extern "system" fn Java_glide_ffi_resolvers_RedisValueResolver_valueF redis_value_to_java(&mut env, *value) } +/// # Safety +/// +/// * Function throws a checked java exception if fails to get the socket path. #[no_mangle] pub unsafe extern "system" fn Java_glide_ffi_resolvers_SocketListenerResolver_startSocketListener< 'local, From 0495f87618e82b9e59e89723a47875af769e498c Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 11 Apr 2024 18:05:16 -0700 Subject: [PATCH 4/5] fix Signed-off-by: Yury-Fridlyand --- glide-core/src/client/mod.rs | 5 ++++- glide-core/src/client/reconnecting_connection.rs | 5 ++++- glide-core/src/client/standalone_client.rs | 5 ++++- glide-core/src/client/types.rs | 2 ++ glide-core/src/client/value_conversion.rs | 5 ++++- glide-core/src/errors.rs | 2 ++ glide-core/src/request_type.rs | 5 ++++- 7 files changed, 24 insertions(+), 5 deletions(-) diff --git a/glide-core/src/client/mod.rs b/glide-core/src/client/mod.rs index 645bef1118..2bb899ce5f 100644 --- a/glide-core/src/client/mod.rs +++ b/glide-core/src/client/mod.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + mod types; use crate::scripts_container::get_script; diff --git a/glide-core/src/client/reconnecting_connection.rs b/glide-core/src/client/reconnecting_connection.rs index c039d347bd..c50c9f9201 100644 --- a/glide-core/src/client/reconnecting_connection.rs +++ b/glide-core/src/client/reconnecting_connection.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use super::{NodeAddress, TlsMode}; use crate::retry_strategies::RetryStrategy; use futures_intrusive::sync::ManualResetEvent; diff --git a/glide-core/src/client/standalone_client.rs b/glide-core/src/client/standalone_client.rs index 79246a7b76..ee79d3e529 100644 --- a/glide-core/src/client/standalone_client.rs +++ b/glide-core/src/client/standalone_client.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use super::get_redis_connection_info; use super::reconnecting_connection::ReconnectingConnection; use super::{ConnectionRequest, NodeAddress, TlsMode}; diff --git a/glide-core/src/client/types.rs b/glide-core/src/client/types.rs index f942f64174..95ee04448d 100644 --- a/glide-core/src/client/types.rs +++ b/glide-core/src/client/types.rs @@ -2,6 +2,8 @@ * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ +#![deny(unsafe_op_in_unsafe_fn)] + use std::time::Duration; #[cfg(feature = "socket-layer")] diff --git a/glide-core/src/client/value_conversion.rs b/glide-core/src/client/value_conversion.rs index 84a6626efa..082feff151 100644 --- a/glide-core/src/client/value_conversion.rs +++ b/glide-core/src/client/value_conversion.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use redis::{ cluster_routing::Routable, from_owned_redis_value, Cmd, ErrorKind, RedisResult, Value, }; diff --git a/glide-core/src/errors.rs b/glide-core/src/errors.rs index 1c05aad84b..d277e4488b 100644 --- a/glide-core/src/errors.rs +++ b/glide-core/src/errors.rs @@ -2,6 +2,8 @@ * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ +#![deny(unsafe_op_in_unsafe_fn)] + use redis::RedisError; #[repr(C)] diff --git a/glide-core/src/request_type.rs b/glide-core/src/request_type.rs index 51896c2743..05ae9d31e2 100644 --- a/glide-core/src/request_type.rs +++ b/glide-core/src/request_type.rs @@ -1,6 +1,9 @@ -/** +/* * Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ + +#![deny(unsafe_op_in_unsafe_fn)] + use redis::{cmd, Cmd}; #[cfg(feature = "socket-layer")] From 7f6bb5c0216cd39a4d82f0765c1d10a6aa273768 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 11 Apr 2024 18:06:54 -0700 Subject: [PATCH 5/5] Add missing file. Signed-off-by: Yury-Fridlyand --- java/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/java/src/lib.rs b/java/src/lib.rs index 864ea28ec9..3516358b44 100644 --- a/java/src/lib.rs +++ b/java/src/lib.rs @@ -113,11 +113,8 @@ pub unsafe extern "system" fn Java_glide_ffi_resolvers_RedisValueResolver_valueF redis_value_to_java(&mut env, *value) } -/// # Safety -/// -/// * Function throws a checked java exception if fails to get the socket path. #[no_mangle] -pub unsafe extern "system" fn Java_glide_ffi_resolvers_SocketListenerResolver_startSocketListener< +pub extern "system" fn Java_glide_ffi_resolvers_SocketListenerResolver_startSocketListener< 'local, >( env: JNIEnv<'local>,