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

Go: Implement connection logic in lib.rs #119

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c0cb6fb
Add Rust connection logic and example
jonathanl-bq Feb 27, 2024
22bbf74
Add error handling logic for connections
jonathanl-bq Feb 27, 2024
79343ff
Add license headers
jonathanl-bq Feb 27, 2024
2a92415
Refactor cArgs
jonathanl-bq Feb 27, 2024
3278942
Update API for client creation
jonathanl-bq Feb 29, 2024
2b258e5
Remove non-connection logic
jonathanl-bq Mar 4, 2024
6ccc6c1
Update lib.h
jonathanl-bq Mar 4, 2024
bdf9c19
Add additional documentation to lib.rs functions
jonathanl-bq Mar 5, 2024
4bd25cc
Properly free connection response and error
jonathanl-bq Mar 6, 2024
dc4df76
Run go fmt
jonathanl-bq Mar 6, 2024
cd5c2da
Add error for when user closes client before creating it
jonathanl-bq Mar 6, 2024
055e74b
Add doc comments about avoiding memory leaks
jonathanl-bq Mar 6, 2024
f23b01a
Allow unused Client fields for now
jonathanl-bq Mar 6, 2024
aa1fb08
Add formatting directive to fmt.Errorf
jonathanl-bq Mar 6, 2024
2fe5bdd
Replace callback implementations with TODO implementations
jonathanl-bq Mar 6, 2024
6289bfb
Resolve merge conflicts
jonathanl-bq Mar 6, 2024
53c8d7d
Remove RedisErrorFFI struct and use glide-core RequetErrorType instead
jonathanl-bq Mar 7, 2024
926e050
Update go/glide/lib.h
jonathanl-bq Mar 7, 2024
b9e61c8
Update go/glide/lib.h
jonathanl-bq Mar 7, 2024
70fb74b
Update go/src/lib.rs
jonathanl-bq Mar 7, 2024
db8959b
Update go/src/lib.rs
jonathanl-bq Mar 7, 2024
b32408c
Update documentation for create_client
jonathanl-bq Mar 7, 2024
478acd6
Adjust documentation regarding memory leaks
jonathanl-bq Mar 7, 2024
0e52d91
Make free_connection_response also free its error
jonathanl-bq Mar 7, 2024
a02912f
Update doc comment for free_connection_response
jonathanl-bq Mar 8, 2024
7ea7bdd
Re-expose free_error for the error callback to use and update docs
jonathanl-bq Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion go/glide/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef enum RequestErrorType {
*
* It contains either a connection or an error. It is represented as a struct instead of an enum for ease of use in the wrapper language.
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
*
* This struct should be freed using both `free_connection_response` and `free_error` to avoid memory leaks.
* This struct should be freed using `free_connection_response` to avoid memory leaks.
*/
typedef struct ConnectionResponse {
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
const void *conn_ptr;
Expand Down Expand Up @@ -78,3 +78,13 @@ void close_client(const void *client_ptr);
* * The contained `error_message` must be able to be safely casted to a valid `CString` via `CString::from_raw`. See the safety documentation of [`std::ffi::CString::from_raw`](https://doc.rust-lang.org/std/ffi/struct.CString.html#method.from_raw).
*/
void free_connection_response(const struct ConnectionResponse *connection_response_ptr);

/**
* Deallocates an error message `CString`.
*
* # Safety
*
* * `error_msg_ptr` must be able to be safely casted to a valid `CString` via `CString::from_raw`. See the safety documentation of [`std::ffi::CString::from_raw`](https://doc.rust-lang.org/std/ffi/struct.CString.html#method.from_raw).
* * `error_msg_ptr` must not be null.
*/
void free_error(const char *error_msg_ptr);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why re-expose?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that the failure callback would use it for the error it gets for commands. Not relevant for connection logic though, so I guess it can be reverted. Up to you, since you have all the changes in your branch now.

5 changes: 3 additions & 2 deletions go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub type FailureCallback = unsafe extern "C" fn(
///
/// It contains either a connection or an error. It is represented as a struct instead of an enum for ease of use in the wrapper language.
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
///
/// This struct should be freed using both `free_connection_response` and `free_error` to avoid memory leaks.
/// This struct should be freed using `free_connection_response` to avoid memory leaks.
#[repr(C)]
pub struct ConnectionResponse {
conn_ptr: *const c_void,
Expand Down Expand Up @@ -162,7 +162,8 @@ pub unsafe extern "C" fn free_connection_response(
///
/// * `error_msg_ptr` must be able to be safely casted to a valid `CString` via `CString::from_raw`. See the safety documentation of [`std::ffi::CString::from_raw`](https://doc.rust-lang.org/std/ffi/struct.CString.html#method.from_raw).
/// * `error_msg_ptr` must not be null.
unsafe fn free_error(error_msg_ptr: *const c_char) {
#[no_mangle]
pub unsafe extern "C" fn free_error(error_msg_ptr: *const c_char) {
let error_msg = unsafe { CString::from_raw(error_msg_ptr as *mut c_char) };
drop(error_msg);
}
Loading