From eec5ae96e89d3349440a46d34880470c429a0f6f Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Tue, 7 Mar 2023 15:36:33 +0100 Subject: [PATCH] Update docs and fix string allocation The docs say you should always unref the string and NULL is never returned. The implementation should follow that. --- deltachat-ffi/deltachat.h | 13 ++++++++++--- deltachat-ffi/src/lib.rs | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index d00d9c0d7..bdf9bd025 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -2645,12 +2645,17 @@ void dc_str_unref (char* str); /** * Creates an object for sending a backup to another device. * + * Before calling this function IO must be stopped using dc_accounts_stop_io() + * or dc_stop_io(). IO should only be restarted once + * dc_backup_provider_wait() has returned. + * * The backup is sent to through a peer-to-peer channel which is bootstrapped * by a QR-code. The backup contains the entire state of the account * including credentials. This can be used to setup a new device. * - * Once this function returns, the backup is being offered to remote devices. - * To wait until one device received the backup, use + * This is a blocking call as some preparations are made like e.g. exporting + * the database. Once this function returns, the backup is being offered to + * remote devices. To wait until one device received the backup, use * dc_backup_provider_wait(). Alternatively abort the operation using * dc_stop_ongoing_process(). * @@ -2706,7 +2711,9 @@ char* dc_backup_provider_get_qr_svg (const dc_backup_provider_t* backup_provider /** * Waits for the sending to finish and frees the backup provider object. * - * This should only be called once. + * This is a blocking call and should only be called once. Once this function + * returns IO can be started again using dc_accounts_start_io() or + * dc_start_io(). * * @memberof dc_backup_provider_t * @param context The context. diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 87bc517e2..9e6edb7c4 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -4171,7 +4171,7 @@ pub unsafe extern "C" fn dc_backup_provider_get_qr( ) -> *mut libc::c_char { if provider.is_null() { eprintln!("ignoring careless call to dc_backup_provider_qr"); - return ptr::null_mut(); + return "".strdup(); } let ffi_provider = &*provider; deltachat::qr::format_backup(&ffi_provider.provider.qr()) @@ -4185,7 +4185,7 @@ pub unsafe extern "C" fn dc_backup_provider_get_qr_svg( ) -> *mut libc::c_char { if provider.is_null() { eprintln!("ignoring careless call to dc_backup_provider_qr_svg()"); - return ptr::null_mut(); + return "".strdup(); } let ffi_provider = &*provider; let ctx = &*ffi_provider.context;