Skip to content

Truly independent web browser

LibWeb: Take shadowed pointer parameters as references

Andreas Kling753094aacbc2
diff --git a/Libraries/LibWeb/Rust/src/css/animated_overlay.rs b/Libraries/LibWeb/Rust/src/css/animated_overlay.rs
index ca8330146ca..0b8a0ca29b4 100644
--- a/Libraries/LibWeb/Rust/src/css/animated_overlay.rs
+++ b/Libraries/LibWeb/Rust/src/css/animated_overlay.rs
@@ -220,7 +220,7 @@ pub unsafe extern "C" fn rust_animated_overlay_free(overlay: *mut AnimatedOverla
/// value data.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_animated_overlay_set(
- overlay: *mut AnimatedOverlay,
+ overlay: &mut AnimatedOverlay,
property: u16,
value: *const c_void,
inherited: bool,
@@ -229,7 +229,6 @@ pub unsafe extern "C" fn rust_animated_overlay_set(
let retained = unsafe {
RetainedStyleValueData::from_retained_pointer(crate::css::style_value::retain_style_value(value.cast()))
};
- let overlay = unsafe { &mut *overlay };
overlay.set_owned(property, retained, inherited, result_of_transition);
}
diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rs
index 42a7b8b0c72..191d1d88bc0 100644
--- a/Libraries/LibWeb/Rust/src/css/animation.rs
+++ b/Libraries/LibWeb/Rust/src/css/animation.rs
@@ -7292,9 +7292,8 @@ pub(crate) fn animation_preparation_matches(
/// `computed` must point to a live batch. Its range of sampled effects must be readable. On a cache miss both storage pointers must be live, unconsumed results from their
/// producing calls. `underlying_longhand_table` and `overlay` must point at live values, and the
/// overlay must be uniquely owned for the duration of the call.
-pub(crate) unsafe fn evaluate_animations(computed: *const FfiComputedAnimationBatch) -> usize {
+pub(crate) unsafe fn evaluate_animations(computed: &FfiComputedAnimationBatch) -> usize {
crate::css::ffi_stats::note_animation_evaluation();
- let computed = unsafe { &*computed };
assert!(!computed.underlying_longhand_table.is_null());
assert!(!computed.overlay.is_null());
let sampled = unsafe { std::slice::from_raw_parts(computed.sampled_effects, computed.sampled_effect_count) };
diff --git a/Libraries/LibWeb/Rust/src/css/calc.rs b/Libraries/LibWeb/Rust/src/css/calc.rs
index 26515068760..2451b6a64f6 100644
--- a/Libraries/LibWeb/Rust/src/css/calc.rs
+++ b/Libraries/LibWeb/Rust/src/css/calc.rs
@@ -3404,11 +3404,10 @@ pub(crate) fn resolve_calculated_line_height_without_context(
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_calc_resolve(
calculated: *const std::ffi::c_void,
- context: *const FfiCalcResolutionContext,
+ context: &FfiCalcResolutionContext,
apply_censoring_and_clamping: bool,
) -> FfiResolvedCalc {
let calculated = unsafe { &*calculated.cast::<crate::css::style_value::StyleValueData>() };
- let context = unsafe { &*context };
let externals = prepare_external_resolutions(
unsafe { &*calc_root_from_calculated(std::ptr::from_ref(calculated).cast()) },
context,
diff --git a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
index d394125784a..67f26a29a32 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
@@ -1469,14 +1469,8 @@ pub unsafe extern "C" fn rust_computed_longhand_table_copy_from_values(
/// Returns the table's value span: one borrowed data pointer per longhand,
/// null where the drive stored no value. The span stays valid while the
/// caller's table reference is live and the table stays frozen.
-///
-/// # Safety
-/// `table` must be a valid, frozen table.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn rust_computed_longhand_table_values(
- table: *const ComputedLonghandTable,
-) -> *const *const c_void {
- let table = unsafe { &*table };
+pub extern "C" fn rust_computed_longhand_table_values(table: &ComputedLonghandTable) -> *const *const c_void {
debug_assert!(table.frozen, "only frozen tables hand out their value span");
table.value_pointers().as_ptr()
}
@@ -1518,13 +1512,12 @@ pub extern "C" fn rust_computed_longhand_table_inheritance_bits(table: &Computed
/// have exactly `LONGHAND_BITMAP_BYTES` readable bytes.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_computed_longhand_table_load_flag_bitmaps(
- table: *mut ComputedLonghandTable,
+ table: &mut ComputedLonghandTable,
importance: *const u8,
importance_count: usize,
inheritance: *const u8,
inheritance_count: usize,
) {
- let table = unsafe { &mut *table };
table.load_flag_bitmaps(
unsafe { std::slice::from_raw_parts(importance, importance_count) },
unsafe { std::slice::from_raw_parts(inheritance, inheritance_count) },
@@ -1573,10 +1566,9 @@ pub extern "C" fn rust_computed_longhand_table_metadata(
/// `table` must be a valid table and `out_count` writable.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_computed_longhand_table_inheritance_dependent_values(
- table: *const ComputedLonghandTable,
+ table: &ComputedLonghandTable,
out_count: *mut usize,
) -> *const FfiTableInheritanceDependentValue {
- let table = unsafe { &*table };
unsafe { *out_count = table.inheritance_dependent_view.len() };
table.inheritance_dependent_view.as_ptr()
}
diff --git a/Libraries/LibWeb/Rust/src/css/declaration_block.rs b/Libraries/LibWeb/Rust/src/css/declaration_block.rs
index 8fc672d209f..40b3e0090a3 100644
--- a/Libraries/LibWeb/Rust/src/css/declaration_block.rs
+++ b/Libraries/LibWeb/Rust/src/css/declaration_block.rs
@@ -409,8 +409,7 @@ pub(crate) fn visit_declaration_images(data: &DeclarationBlockData, visit: &mut
}
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn rust_declaration_block_is_empty(block: *const DeclarationBlock) -> bool {
- let block = unsafe { &*block };
+pub extern "C" fn rust_declaration_block_is_empty(block: &DeclarationBlock) -> bool {
let data = block.data();
data.properties.is_empty() && data.custom_properties.is_empty()
}
@@ -735,7 +734,7 @@ mod tests {
let borrowed = block.data();
assert_eq!(borrowed.properties.len(), 1);
assert_eq!(borrowed.custom_properties.len(), 1);
- assert!(!unsafe { rust_declaration_block_is_empty(block) });
+ assert!(!rust_declaration_block_is_empty(block));
assert_eq!(rust_declaration_block_revision(block), 0);
assert!(rust_declaration_block_external_memory_size(block) > 0);
let mut fork = unsafe { Box::from_raw(rust_declaration_block_share(block)) };
diff --git a/Libraries/LibWeb/Rust/src/css/layer_names.rs b/Libraries/LibWeb/Rust/src/css/layer_names.rs
index 809d7e612f7..c6faeac8505 100644
--- a/Libraries/LibWeb/Rust/src/css/layer_names.rs
+++ b/Libraries/LibWeb/Rust/src/css/layer_names.rs
@@ -34,8 +34,7 @@ pub unsafe extern "C" fn rust_layer_names_at(names: *const LayerNames, index: us
}
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn rust_layer_names_external_memory_size(names: *const LayerNames) -> usize {
- let names = unsafe { &*names };
+pub extern "C" fn rust_layer_names_external_memory_size(names: &LayerNames) -> usize {
names.names.iter().fold(
size_of::<LayerNames>().saturating_add(size_of_val(&*names.names)),
|size, name| size.saturating_add(size_of_val(name.units())),
diff --git a/Libraries/LibWeb/Rust/src/css/parser/stylesheet_cache.rs b/Libraries/LibWeb/Rust/src/css/parser/stylesheet_cache.rs
index c79279d5e52..845595766aa 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/stylesheet_cache.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/stylesheet_cache.rs
@@ -332,10 +332,9 @@ fn find(entries: &Entries, hash: u64, key: &StyleSheetKey) -> Option<Arc<ParsedS
/// All pointers in `context` must remain valid for this call, just as for parsing.
pub(super) unsafe fn parse_with_cache(
source: TokenizerInput<'_>,
- context: *const ParseContext,
+ context: Option<&ParseContext>,
parse: impl FnOnce() -> ParsedStyleSheet,
) -> Arc<ParsedStyleSheet> {
- let context = unsafe { context.as_ref() };
let context_key = match context {
Some(context) => match unsafe { ContextKey::new(context) } {
Some(key) => Some(key),
diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs
index 65ce56f0351..b2ad61014db 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs
@@ -3580,7 +3580,7 @@ pub(crate) unsafe fn parse_shared_stylesheet(
parse_context: *const ParseContext,
) -> Arc<ParsedStyleSheet> {
unsafe {
- parse_with_cache(source, parse_context, || {
+ parse_with_cache(source, parse_context.as_ref(), || {
let mut parser = Parser::streaming(source);
let mut parse = SyntaxParseBuilder::new(parse_context, false);
while let Some(rule) = parser.consume_next_stylesheet_rule() {
@@ -3918,7 +3918,7 @@ mod tests {
let context = parse_context();
let input = crate::css::css_tokenizer::TokenizerInput::Utf16(&source);
unsafe {
- super::super::stylesheet_cache::parse_with_cache(input, &raw const context, || {
+ super::super::stylesheet_cache::parse_with_cache(input, Some(&context), || {
parses.fetch_add(1, Ordering::SeqCst);
if let Some((started, may_finish)) = &held {
started.wait();
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index dee29d7d8dd..9f5a5ec9406 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -5010,9 +5010,8 @@ pub(crate) fn effective_display(table: &ComputedLonghandTable, overlay: Option<&
/// returned pointer transfers one strong reference to the caller.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_create_document_longhand_table(
- input: *const FfiDocumentLonghandInput,
+ input: &FfiDocumentLonghandInput,
) -> *mut ComputedLonghandTable {
- let input = unsafe { &*input };
let mut longhand_table = ComputedLonghandTable::new();
let store = CascadedPropertyStore::new();
let environment = FfiStyleComputationEnvironment {
@@ -5148,14 +5147,13 @@ pub unsafe extern "C" fn rust_intern_document_style(
/// duration of the call. Every returned value transfers one strong reference
/// to the caller.
pub(crate) unsafe fn compute_animation_keyframe_longhands(
- input: *const FfiAnimationKeyframeLonghandInput,
+ input: &FfiAnimationKeyframeLonghandInput,
) -> FfiAnimationKeyframeLonghandResult {
crate::css::ffi_stats::bump(crate::css::ffi_stats::FfiOp::AnimationKeyframeLonghandEntry);
use crate::css::property_metadata::{
FIRST_LONGHAND_PROPERTY_ID, LAST_LONGHAND_PROPERTY_ID, NUMBER_OF_LONGHAND_PROPERTIES,
};
- let input = unsafe { &*input };
let properties = if input.property_count == 0 {
&[][..]
} else {
@@ -5653,13 +5651,12 @@ impl FfiHostAnimationSample {
/// engine.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_sample_animation_effects(
- input: *const FfiHostAnimationSample,
+ input: &FfiHostAnimationSample,
read: &crate::render_state::BegunRead,
) -> FfiHostAnimationSampleResult {
use crate::css::style::engine_calls::{document_host, with_engine_and_arena};
// SAFETY: Guaranteed by the caller.
- let input = unsafe { &*input };
// SAFETY: As above.
let host = unsafe { document_host(input.host) };
// The first sample of the transitions a step just started rides the style job that decided the step.
@@ -5983,7 +5980,7 @@ unsafe fn begin_animation_sample(
custom_results: std::ptr::null_mut(),
custom_result_count: std::ptr::null_mut(),
};
- unsafe { anim::evaluate_animations(&raw const batch) };
+ unsafe { anim::evaluate_animations(&batch) };
return finished(Evaluated);
}
@@ -6147,7 +6144,7 @@ unsafe fn finish_animation_sample(
remaining_length_resolution_context: &raw const length_contexts.remaining,
custom_property_values: custom_value_pointers.as_ptr(),
};
- let computed_keyframes = unsafe { compute_animation_keyframe_longhands(&raw const keyframe_input) };
+ let computed_keyframes = unsafe { compute_animation_keyframe_longhands(&keyframe_input) };
result.depends_on_viewport_metrics = computed_keyframes.depends_on_viewport_metrics;
result.font_metrics_depend_on_viewport_metrics = computed_keyframes.font_metrics_depend_on_viewport_metrics;
// A custom property's keyframe that asks where the element sits among its siblings makes the
@@ -6192,7 +6189,7 @@ unsafe fn finish_animation_sample(
custom_results: custom_results.as_mut_ptr(),
custom_result_count: &raw mut custom_result_count,
};
- unsafe { anim::evaluate_animations(&raw const batch) };
+ unsafe { anim::evaluate_animations(&batch) };
result.outcome = FfiHostAnimationSampleOutcome::Evaluated;
if custom_result_count != 0 {
let retained = custom_results[..custom_result_count]
@@ -6967,12 +6964,11 @@ fn resolve_effective_color_scheme(
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_resolve_effective_color_scheme(
value: *const c_void,
- input: *const FfiEffectiveColorSchemeInput,
+ input: &FfiEffectiveColorSchemeInput,
) -> u8 {
let StyleValueData::ColorScheme { scheme_codes, .. } = (unsafe { &*(value as *const StyleValueData) }) else {
unreachable!("computed color-scheme must have color-scheme data");
};
- let input = unsafe { &*input };
resolve_effective_color_scheme(scheme_codes.as_slice(), input.preferred_color_scheme, unsafe {
input.document_supported_schemes()
})
diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rs
index def26381715..13a7c7e4a6e 100644
--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs
+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs
@@ -655,7 +655,7 @@ pub struct FfiImagePaintRecordInputs {
/// storage and visual context tree handles.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn ladybird_web_record_image_paint_display_list(
- inputs: *const FfiImagePaintRecordInputs,
+ inputs: &FfiImagePaintRecordInputs,
context: *mut c_void,
consume: unsafe extern "C" fn(*mut c_void, *const c_void, *const c_void),
) {
@@ -668,7 +668,6 @@ pub unsafe extern "C" fn ladybird_web_record_image_paint_display_list(
};
use crate::painting::visual_context::{TransformData, TransformDataRole, VisualContextTree};
use libgfx_rust::{CompositingAndBlendingOperator, FloatMatrix4x4, FloatPoint};
- let inputs = unsafe { &*inputs };
let tree = VisualContextTree::create(TransformData {
matrix: FloatMatrix4x4::identity(),
origin: FloatPoint::default(),