Bug 1836883. Avoid passing ref function arguments to Rc::from_raw. r=eemeli

It is unfortunately undefined behavior and leads to problems with LLVM
16.

Differential Revision: https://phabricator.services.mozilla.com/D180061
This commit is contained in:
Mike Hommey 2023-06-06 08:55:21 +00:00
parent 473dfcaa8f
commit a13b4ea9e8
4 changed files with 5 additions and 5 deletions

View file

@ -294,7 +294,7 @@ pub extern "C" fn fluent_bundle_format_pattern(
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn fluent_bundle_add_resource( pub unsafe extern "C" fn fluent_bundle_add_resource(
bundle: &mut FluentBundleRc, bundle: &mut FluentBundleRc,
r: &FluentResource, r: *const FluentResource,
allow_overrides: bool, allow_overrides: bool,
ret_errors: &mut ThinVec<nsCString>, ret_errors: &mut ThinVec<nsCString>,
) { ) {

View file

@ -28,7 +28,7 @@ pub extern "C" fn fluent_resource_new(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn fluent_resource_addref(res: &FluentResource) { pub unsafe extern "C" fn fluent_resource_addref(res: *const FluentResource) {
let raw = ManuallyDrop::new(Rc::from_raw(res)); let raw = ManuallyDrop::new(Rc::from_raw(res));
mem::forget(Rc::clone(&raw)); mem::forget(Rc::clone(&raw));
} }

View file

@ -255,14 +255,14 @@ pub unsafe extern "C" fn l10nregistry_register_parent_process_sources(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn l10nregistry_addref(reg: &GeckoL10nRegistry) { pub unsafe extern "C" fn l10nregistry_addref(reg: *const GeckoL10nRegistry) {
let raw = Rc::from_raw(reg); let raw = Rc::from_raw(reg);
mem::forget(Rc::clone(&raw)); mem::forget(Rc::clone(&raw));
mem::forget(raw); mem::forget(raw);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn l10nregistry_release(reg: &GeckoL10nRegistry) { pub unsafe extern "C" fn l10nregistry_release(reg: *const GeckoL10nRegistry) {
let _ = Rc::from_raw(reg); let _ = Rc::from_raw(reg);
} }

View file

@ -199,7 +199,7 @@ pub extern "C" fn l10nfilesource_new_mock(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn l10nfilesource_addref(source: &FileSource) { pub unsafe extern "C" fn l10nfilesource_addref(source: *const FileSource) {
let raw = Rc::from_raw(source); let raw = Rc::from_raw(source);
mem::forget(Rc::clone(&raw)); mem::forget(Rc::clone(&raw));
mem::forget(raw); mem::forget(raw);