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:
Floris Bruynooghe
2019-08-01 00:08:23 +02:00
committed by Floris Bruynooghe
parent e7428887d0
commit b6b0849bce
31 changed files with 395 additions and 381 deletions

View File

@@ -278,14 +278,13 @@ pub unsafe fn dc_contact_load_from_db(
if contact_id == 1 as libc::c_uint {
(*contact).id = contact_id;
(*contact).name = to_cstring((*contact).context.stock_str(StockMessage::SelfMsg));
(*contact).addr = to_cstring(
(*contact)
.context
.sql
.get_config((*contact).context, "configured_addr")
.unwrap_or_default(),
);
(*contact).name = (*contact).context.stock_str(StockMessage::SelfMsg).strdup();
(*contact).addr = (*contact)
.context
.sql
.get_config((*contact).context, "configured_addr")
.unwrap_or_default()
.strdup();
true
} else {
sql.query_row(
@@ -293,11 +292,11 @@ pub unsafe fn dc_contact_load_from_db(
params![contact_id as i32],
|row| {
(*contact).id = contact_id;
(*contact).name = to_cstring(row.get::<_, String>(0)?);
(*contact).addr = to_cstring(row.get::<_, String>(1)?);
(*contact).name = row.get::<_, String>(0)?.strdup();
(*contact).addr = row.get::<_, String>(1)?.strdup();
(*contact).origin = row.get(2)?;
(*contact).blocked = row.get::<_, Option<i32>>(3)?.unwrap_or_default();
(*contact).authname = to_cstring(row.get::<_, String>(4)?);
(*contact).authname = row.get::<_, String>(4)?.strdup();
Ok(())
}
).is_ok()
@@ -726,7 +725,7 @@ pub unsafe fn dc_get_contact_encrinfo(
free(fingerprint_other_verified as *mut libc::c_void);
free(fingerprint_other_unverified as *mut libc::c_void);
to_cstring(ret)
ret.strdup()
}
unsafe fn cat_fingerprint(
@@ -901,7 +900,7 @@ pub fn dc_contact_get_profile_image(contact: *const dc_contact_t) -> *mut libc::
if unsafe { (*contact).id } == 1 {
let context = unsafe { (*contact) }.context;
if let Some(avatar) = context.get_config(config::Config::Selfavatar) {
image_abs = unsafe { to_cstring(avatar) };
image_abs = unsafe { avatar.strdup() };
}
}
// TODO: else get image_abs from contact param