diff --git a/drop-struct-macro-derive/src/lib.rs b/drop-struct-macro-derive/src/lib.rs index bdddc33..8705fa0 100644 --- a/drop-struct-macro-derive/src/lib.rs +++ b/drop-struct-macro-derive/src/lib.rs @@ -11,7 +11,7 @@ struct FieldNameType { field_type: proc_macro2::TokenStream, } -/// The actual code to free the *const pointers +/// The actual code to free the *mut pointers impl quote::ToTokens for FieldNameType { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let field_type = &self.field_type; @@ -72,13 +72,13 @@ pub fn drop_struct_macro_derive(input: TokenStream) -> TokenStream { // A list of fields that should get dropped let mut to_be_dropped = Vec::new(); - // Only take *const pointers into account (also not *mut) + // Only take *mut pointers into account (also not *mut) match ast.data { syn::Data::Struct(ref data_struct) => { if let syn::Fields::Named(ref fields_named) = data_struct.fields { for field in fields_named.named.iter() { if let syn::Type::Ptr(ref type_ptr) = field.ty { - if type_ptr.const_token.is_some() { + if type_ptr.mutability.is_some() { if let syn::Type::Path(ref type_path) = *type_ptr.elem { let field_name = field.ident.clone().unwrap().to_string(); let field_type = type_path.path.clone().into_token_stream(); diff --git a/ffi-toolkit/src/lib.rs b/ffi-toolkit/src/lib.rs index 870ded9..19b351a 100644 --- a/ffi-toolkit/src/lib.rs +++ b/ffi-toolkit/src/lib.rs @@ -16,18 +16,18 @@ pub enum FCPResponseStatus { /// All FFI responses need to implement this trait in order to be able to use `catch_panic()` pub trait CodeAndMessage { /// Set the status code and error message - fn set_error(&mut self, code_and_message: (FCPResponseStatus, *const libc::c_char)); + fn set_error(&mut self, code_and_message: (FCPResponseStatus, *mut libc::c_char)); } /// A simple macro to create implementations for the `CodeAndMessage` trait /// /// The only requirement is that the response has an `status_code: FCPResponseStatus` and -/// `error_msg: *const libc::c_char` field. +/// `error_msg: *mut libc::c_char` field. #[macro_export] macro_rules! code_and_message_impl { { $response:ty } => { impl CodeAndMessage for $response { - fn set_error(&mut self, (code, message): (FCPResponseStatus, *const libc::c_char)) { + fn set_error(&mut self, (code, message): (FCPResponseStatus, *mut libc::c_char)) { self.status_code = code; self.error_msg = message; } diff --git a/ffi-toolkit/tests/catch_panic_response.rs b/ffi-toolkit/tests/catch_panic_response.rs index c44d2b2..2113838 100644 --- a/ffi-toolkit/tests/catch_panic_response.rs +++ b/ffi-toolkit/tests/catch_panic_response.rs @@ -13,7 +13,7 @@ use ffi_toolkit::{ #[derive(DropStructMacro)] pub struct BasicResponse { pub status_code: FCPResponseStatus, - pub error_msg: *const libc::c_char, + pub error_msg: *mut libc::c_char, pub is_valid: bool, } @@ -21,7 +21,7 @@ impl Default for BasicResponse { fn default() -> Self { BasicResponse { status_code: FCPResponseStatus::FCPNoError, - error_msg: ptr::null(), + error_msg: ptr::null_mut(), is_valid: false, } } @@ -55,7 +55,7 @@ fn does_not_panic() { let response = fn_does_not_panic(); assert!((*response).is_valid); assert_eq!((*response).status_code, FCPResponseStatus::FCPNoError); - assert_eq!((*response).error_msg, ptr::null()); + assert!((*response).error_msg.is_null()); } } @@ -66,7 +66,7 @@ fn does_not_panic_with_catch_panic_response() { let response = fn_does_not_panic_with_catch_panic(); assert!((*response).is_valid); assert_eq!((*response).status_code, FCPResponseStatus::FCPNoError); - assert_eq!((*response).error_msg, ptr::null()); + assert!((*response).error_msg.is_null()); } }