FFI: Pass pointer to uninit Features struct in tts_supported_features()

This is done because the ABI for returning struct values isn't well
defined.
This commit is contained in:
Michael Connor Buchan 2022-07-23 13:41:39 +01:00
parent 1597797c57
commit f39f86aa13
1 changed files with 5 additions and 4 deletions

View File

@ -7,7 +7,7 @@ use std::{
ptr,
};
use crate::{Backends, Features, UtteranceId, Tts};
use crate::{Backends, Features, Tts, UtteranceId};
thread_local! {
/// Stores the last reported error, so it can be retrieved at will from C
@ -78,11 +78,12 @@ pub unsafe extern "C" fn tts_free(tts: *mut Tts) {
Box::from_raw(tts); // Goes out of scope and is dropped
}
/// Returns the features supported by this Tts engine.
/// Returns the features supported by this Tts engine in the object specified by `features`.
/// `tts` must be a valid pointer to a Tts object.
/// `features` must be a valid pointer to an uninitialized `Features` object.
#[no_mangle]
pub unsafe extern "C" fn tts_supported_features(tts: *const Tts) -> Features {
tts.as_ref().unwrap().supported_features()
pub unsafe extern "C" fn tts_supported_features(tts: *const Tts, features: *mut Features) {
*features = tts.as_ref().unwrap().supported_features()
}
/// Speaks the specified text, optionally interrupting current speech.