mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
Remove to_cstring() naming convention ambiguity
Add a trait for str.strdup() to replace to_cstring() which avoid the signature ambiguity with .to_string(). Also instruduce CString::yolo() as a shortcut to CString::new().unwrap() and use it whenever the variable does can be deallocated by going out of scope. This is less error prone. Use some Path.to_c_string() functions where possible.
This commit is contained in:
committed by
Floris Bruynooghe
parent
e7428887d0
commit
b6b0849bce
@@ -15,6 +15,7 @@ use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use std::ptr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use deltachat::dc_tools::StrExt;
|
||||
use deltachat::*;
|
||||
|
||||
// TODO: constants
|
||||
@@ -126,10 +127,7 @@ pub unsafe extern "C" fn dc_get_config(
|
||||
let context = &*context;
|
||||
|
||||
match config::Config::from_str(dc_tools::as_str(key)) {
|
||||
Ok(key) => {
|
||||
let value = context.get_config(key).unwrap_or_default();
|
||||
dc_tools::to_cstring(value)
|
||||
}
|
||||
Ok(key) => context.get_config(key).unwrap_or_default().strdup(),
|
||||
Err(_) => std::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
@@ -154,7 +152,7 @@ pub unsafe extern "C" fn dc_get_oauth2_url(
|
||||
let addr = dc_tools::to_string(addr);
|
||||
let redirect = dc_tools::to_string(redirect);
|
||||
match oauth2::dc_get_oauth2_url(context, addr, redirect) {
|
||||
Some(res) => dc_tools::to_cstring(res),
|
||||
Some(res) => res.strdup(),
|
||||
None => std::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user