Truly independent web browser
LibWeb: Take FFI out-parameters as mutable references
Andreas Klingefd39ee21813
diff --git a/Libraries/LibWeb/Rust/src/layout/node_facts.rs b/Libraries/LibWeb/Rust/src/layout/node_facts.rsindex c32e7f73292..e2320a21684 100644--- a/Libraries/LibWeb/Rust/src/layout/node_facts.rs+++ b/Libraries/LibWeb/Rust/src/layout/node_facts.rs@@ -1450,15 +1450,11 @@ mod node_facts_tests {/// Writes the natural size of the document's `<svg>` document element as its last layout/// negotiated it to `natural_size` and returns true, unless it is what the last call handed over./// The size is all absent if the document element is no `<svg>` with a box.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread, and `natural_size` writable.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_take_changed_document_svg_root_natural_size(+pub extern "C" fn render_state_take_changed_document_svg_root_natural_size(host: &crate::render_state::DocumentHost,read: &crate::render_state::BegunRead,- natural_size: *mut crate::painting::host::FfiNaturalSize,+ natural_size: &mut crate::painting::host::FfiNaturalSize,) -> bool {let changed = super::shell_reads::read_arena(host, read, (), |arena, ()| {arena.take_changed_document_svg_root_natural_size()@@ -1466,7 +1462,6 @@ pub unsafe extern "C" fn render_state_take_changed_document_svg_root_natural_sizlet Some(changed) = changed else {return false;};- // SAFETY: Guaranteed by the caller.- unsafe { natural_size.write(changed.into()) };+ *natural_size = changed.into();true}diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex b5aa2d39856..2f8c72fa41f 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -119,14 +119,11 @@ pub extern "C" fn layout_row_paintable_wheel_scrollable_axes(}}-/// # Safety-///-/// As for [`layout_row_paintable_physical_resize_axes`], and `out_geometry` must be writable.#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_snap_container_geometry(+pub extern "C" fn layout_row_snap_container_geometry(host: &crate::render_state::DocumentHost,snap_container: NodeSlotId,- out_geometry: *mut crate::painting::host::FfiSnapContainerGeometry,+ out_geometry: &mut crate::painting::host::FfiSnapContainerGeometry,) -> bool {let geometry = read_measured_rows(host, super::node_read(), |rows| {crate::painting::scroll_snap::snap_container_geometry(rows, snap_container)@@ -134,8 +131,7 @@ pub unsafe extern "C" fn layout_row_snap_container_geometry(let Some(geometry) = geometry else {return false;};- // SAFETY: The caller provides writable storage for the geometry.- unsafe { *out_geometry = geometry };+ *out_geometry = geometry;true}@@ -518,13 +514,13 @@ pub unsafe extern "C" fn render_state_for_each_snap_area(/// # Safety////// `host` must be a live document host, on its document's thread; the callbacks in `publish` are called-/// synchronously with their context while the recording's resources are live. `out` must point to writable storage.+/// synchronously with their context while the recording's resources are live.#[unsafe(no_mangle)]pub unsafe extern "C" fn render_state_publish_recording(host: &crate::render_state::DocumentHost,read: &crate::render_state::BegunRead,publish: crate::painting::host::FfiRecordingPublishCallbacks,- out: *mut crate::painting::ffi::FfiPresentedRecording,+ out: &mut crate::painting::ffi::FfiPresentedRecording,) {// SAFETY: Guaranteed by the entry point's contract.let main_thread = unsafe { main_thread(host) };@@ -536,8 +532,7 @@ pub unsafe extern "C" fn render_state_publish_recording(let presented = read_arena(host, read, (), |arena, ()| {crate::painting::ffi::FfiPresentedRecording::of_last_recording(arena)});- // SAFETY: The caller provides writable storage for what it reads of the recording.- unsafe { out.write(presented) };+ *out = presented;}/// # Safety@@ -814,11 +809,11 @@ pub extern "C" fn render_state_release_held_recording_for_testing() {/// # Safety////// `host` must be a live document host, on its document's thread, and the event loop must call this between two tasks.-/// `presentation` must be valid for writes; the host takes over what it names.+/// The host takes over what `presentation` names.#[unsafe(no_mangle)]pub unsafe extern "C" fn render_state_take_finished_recording_in(host: &crate::render_state::DocumentHost,- presentation: *mut crate::painting::ffi::FfiPresentation,+ presentation: &mut crate::painting::ffi::FfiPresentation,) -> FfiRecordingLanding {let boundary = crate::render_state::TaskBoundary::at_event_loop_entry(&TAKES_FINISHED_RECORDING_IN);let landing = host.recording().take_finished_recording_in(@@ -828,21 +823,15 @@ pub unsafe extern "C" fn render_state_take_finished_recording_in(take_in_presented_recording(host, output, hit_test_list_changed, publishes_recording);},);- // SAFETY: As above.- unsafe { recording_landing(landing, presentation) }+ recording_landing(landing, presentation)}/// Waits for the recording in flight of `host`'s document and takes it in, and answers how it landed (see-/// [`render_state_take_finished_recording_in`]).-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread. `presentation` must be valid for writes; the host-/// takes over what it names.+/// [`render_state_take_finished_recording_in`]). The host takes over what `presentation` names.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_join_recording_in_flight(+pub extern "C" fn render_state_join_recording_in_flight(host: &crate::render_state::DocumentHost,- presentation: *mut crate::painting::ffi::FfiPresentation,+ presentation: &mut crate::painting::ffi::FfiPresentation,) -> FfiRecordingLanding {let landing = host.recording().join_recording_in_flight(|rows_version| landed_recording_stands(host, rows_version),@@ -850,8 +839,7 @@ pub unsafe extern "C" fn render_state_join_recording_in_flight(take_in_presented_recording(host, output, hit_test_list_changed, publishes_recording);},);- // SAFETY: As above.- unsafe { recording_landing(landing, presentation) }+ recording_landing(landing, presentation)}/// Takes the output of a recording that presented itself in as the document's last.@@ -871,36 +859,28 @@ fn take_in_presented_recording(}/// Answers how a recording landed, and writes the presentation it gave back to `presentation`.-///-/// # Safety-///-/// `presentation` must be valid for writes.-unsafe fn recording_landing(+fn recording_landing(landing: crate::painting::recording_slot::RecordingLanding,- presentation: *mut crate::painting::ffi::FfiPresentation,+ presentation: &mut crate::painting::ffi::FfiPresentation,) -> FfiRecordingLanding {use crate::painting::recording_slot::RecordingLanding;match landing {RecordingLanding::NoneInFlight => FfiRecordingLanding::NoneInFlight,RecordingLanding::StillInFlight => FfiRecordingLanding::StillInFlight,RecordingLanding::Landed(given_back) => {- // SAFETY: Guaranteed by the caller.- unsafe { give_back(given_back, presentation) };+ give_back(given_back, presentation);FfiRecordingLanding::Landed}RecordingLanding::LandedBehindRows(given_back) => {- // SAFETY: Guaranteed by the caller.- unsafe { give_back(given_back, presentation) };+ give_back(given_back, presentation);FfiRecordingLanding::LandedBehindRows}RecordingLanding::NothingRecorded(given_back) => {- // SAFETY: Guaranteed by the caller.- unsafe { give_back(given_back, presentation) };+ give_back(given_back, presentation);FfiRecordingLanding::NothingRecorded}RecordingLanding::PresentedUnrecorded(given_back) => {- // SAFETY: Guaranteed by the caller.- unsafe { give_back(given_back, presentation) };+ give_back(given_back, presentation);FfiRecordingLanding::PresentedUnrecorded}RecordingLanding::NeedsVectorImages => FfiRecordingLanding::NeedsVectorImages,@@ -908,17 +888,11 @@ unsafe fn recording_landing(}/// Writes the presentation a recording gave back, if any, to `presentation`.-///-/// # Safety-///-/// `presentation` must be valid for writes.-unsafe fn give_back(+fn give_back(given_back: Option<crate::painting::presentation::Presentation>,- presentation: *mut crate::painting::ffi::FfiPresentation,+ presentation: &mut crate::painting::ffi::FfiPresentation,) {- let given_back = given_back.map_or_else(Default::default, crate::painting::presentation::Presentation::into_ffi);- // SAFETY: Guaranteed by the caller.- unsafe { presentation.write(given_back) };+ *presentation = given_back.map_or_else(Default::default, crate::painting::presentation::Presentation::into_ffi);}/// Whether the rows of `host`'s document are still at `version`, so that the hit-test list of a recording that landeddiff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex d0c564179ca..0bebde5fcb0 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -1774,17 +1774,12 @@ pub(super) fn settle_lanes_for_testing() {/// Writes the color the box of `element` showed in the last frame a tick of a lane of `host`'s document presented to/// `color`, as `0xAARRGGBB`, or that of its pseudo-element `generated_for` names where that is not 0, and answers whether/// a tick restyled the box in it. For a test.-///-/// # Safety-///-/// `host` must come from `document_host_create` and not be destroyed yet, on its document's thread, and `color` must be-/// valid for writes.#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_presented_color(+pub extern "C" fn document_host_presented_color(host: &DocumentHost,element: u32,generated_for: u8,- color: *mut u32,+ color: &mut u32,) -> bool {super::wait_for_render_side();let Some(presented) =@@ -1792,8 +1787,7 @@ pub unsafe extern "C" fn document_host_presented_color(else {return false;};- // SAFETY: Guaranteed by the caller.- unsafe { color.write(presented) };+ *color = presented;true}@@ -1814,16 +1808,11 @@ pub extern "C" fn document_host_mouse_event_is_outdated(host: &DocumentHost, inp/// Writes how many compositor animations drove the box of `element` in the last frame a tick of a lane of `host`'s/// document presented to `count`, and answers whether the frame showed the box's border box. For a test.-///-/// # Safety-///-/// `host` must come from `document_host_create` and not be destroyed yet, on its document's thread, and `count` must be-/// valid for writes.#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_presented_compositor_animation_count(+pub extern "C" fn document_host_presented_compositor_animation_count(host: &DocumentHost,element: u32,- count: *mut u32,+ count: &mut u32,) -> bool {super::wait_for_render_side();let Some(presented) = StyleNodeID::from_raw(element)@@ -1831,43 +1820,31 @@ pub unsafe extern "C" fn document_host_presented_compositor_animation_count(else {return false;};- // SAFETY: Guaranteed by the caller.- unsafe { count.write(presented) };+ *count = presented;true}/// Writes the opacity the effect nodes of the box of `element` gave it in the last frame a tick of a lane of `host`'s/// document presented to `opacity`, and answers whether the frame showed the box's border box. For a test.-///-/// # Safety-///-/// `host` must come from `document_host_create` and not be destroyed yet, on its document's thread, and `opacity` must-/// be valid for writes.#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_presented_opacity(host: &DocumentHost, element: u32, opacity: *mut f32) -> bool {+pub extern "C" fn document_host_presented_opacity(host: &DocumentHost, element: u32, opacity: &mut f32) -> bool {super::wait_for_render_side();let Some(presented) =StyleNodeID::from_raw(element).and_then(|element| host.clock_ticks().presented_opacity(element))else {return false;};- // SAFETY: Guaranteed by the caller.- unsafe { opacity.write(presented) };+ *opacity = presented;true}/// Writes the border box of `element` in the last frame a tick of a lane of `host`'s document presented to `rect`, and/// answers whether a tick presented one. For a test.-///-/// # Safety-///-/// `host` must come from `document_host_create` and not be destroyed yet, on its document's thread, and `rect` must be-/// valid for writes.#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_presented_border_box(+pub extern "C" fn document_host_presented_border_box(host: &DocumentHost,element: u32,- rect: *mut FfiCssPixelRect,+ rect: &mut FfiCssPixelRect,) -> bool {super::wait_for_render_side();let Some(presented) =@@ -1875,7 +1852,6 @@ pub unsafe extern "C" fn document_host_presented_border_box(else {return false;};- // SAFETY: Guaranteed by the caller.- unsafe { rect.write(presented.into()) };+ *rect = presented.into();true}