From 6741110f9a2d9b6c5983e87e9f2a6be4bda662df Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Wed, 2 Apr 2025 21:19:45 +0200 Subject: [PATCH 1/3] chore: Fix errors of clippy beta Fix the following additional checks: 1. use std::ptr::eq to compare pointers, 2. use IoError::other. --- core/src/avm1/debug.rs | 2 +- core/src/avm1/object.rs | 4 ++-- core/src/avm2.rs | 4 ++-- core/src/avm2/bytearray.rs | 9 +++------ core/src/avm2/domain.rs | 15 ++++++++------- core/src/avm2/filters.rs | 2 +- core/src/avm2/object.rs | 2 +- core/src/bitmap/bitmap_data.rs | 2 +- core/src/buffer.rs | 9 +++------ core/src/debug_ui/display_object.rs | 4 ++-- core/src/debug_ui/handle.rs | 8 ++++---- core/src/display_object.rs | 2 +- core/src/display_object/interactive.rs | 2 +- core/src/display_object/loader_display.rs | 2 +- core/src/streams.rs | 2 +- core/src/string/repr.rs | 2 +- render/webgl/src/lib.rs | 6 +++--- scanner/src/execute.rs | 5 +---- swf/src/avm1/read.rs | 2 +- 19 files changed, 38 insertions(+), 46 deletions(-) diff --git a/core/src/avm1/debug.rs b/core/src/avm1/debug.rs index cf0c29270791..24a4e6a0b7ab 100644 --- a/core/src/avm1/debug.rs +++ b/core/src/avm1/debug.rs @@ -40,7 +40,7 @@ impl<'a> VariableDumper<'a> { let ptr = object.as_ptr(); for (i, other) in self.objects.iter().enumerate() { - if *other == ptr { + if std::ptr::eq(*other, ptr) { return (i, false); } } diff --git a/core/src/avm1/object.rs b/core/src/avm1/object.rs index 85927fe577c3..f1a6500282ae 100644 --- a/core/src/avm1/object.rs +++ b/core/src/avm1/object.rs @@ -644,7 +644,7 @@ pub trait TObject<'gc>: 'gc + Collect<'gc> + Into> + Clone + Copy { let mut proto = other.proto(activation); while let Value::Object(proto_ob) = proto { - if self.as_ptr() == proto_ob.as_ptr() { + if std::ptr::eq(self.as_ptr(), proto_ob.as_ptr()) { return true; } @@ -699,7 +699,7 @@ pub enum ObjectPtr {} impl<'gc> Object<'gc> { pub fn ptr_eq(a: Object<'gc>, b: Object<'gc>) -> bool { - a.as_ptr() == b.as_ptr() + std::ptr::eq(a.as_ptr(), b.as_ptr()) } } diff --git a/core/src/avm2.rs b/core/src/avm2.rs index 44ac97a211b8..a50a888df1e4 100644 --- a/core/src/avm2.rs +++ b/core/src/avm2.rs @@ -361,7 +361,7 @@ impl<'gc> Avm2<'gc> { if self .orphan_objects .iter() - .all(|d| d.as_ptr() != dobj.as_ptr()) + .all(|d| !std::ptr::eq(d.as_ptr(), dobj.as_ptr())) { self.orphan_objects_mut().push(dobj.downgrade()); } @@ -493,7 +493,7 @@ impl<'gc> Avm2<'gc> { for entry in bucket.iter() { // Note: comparing pointers is correct because GcWeak keeps its allocation alive, // so the pointers can't overlap by accident. - if entry.as_ptr() == object.as_ptr() { + if std::ptr::eq(entry.as_ptr(), object.as_ptr()) { return; } } diff --git a/core/src/avm2/bytearray.rs b/core/src/avm2/bytearray.rs index c9680237f40f..3136a86aca96 100644 --- a/core/src/avm2/bytearray.rs +++ b/core/src/avm2/bytearray.rs @@ -396,9 +396,8 @@ impl ByteArrayStorage { impl Write for ByteArrayStorage { fn write(&mut self, buf: &[u8]) -> io::Result { - self.write_bytes(buf).map_err(|_| { - io::Error::new(io::ErrorKind::Other, "Failed to write to ByteArrayStorage") - })?; + self.write_bytes(buf) + .map_err(|_| io::Error::other("Failed to write to ByteArrayStorage"))?; Ok(buf.len()) } @@ -412,9 +411,7 @@ impl Read for ByteArrayStorage { fn read(&mut self, buf: &mut [u8]) -> io::Result { let bytes = self .read_bytes(cmp::min(buf.len(), self.bytes_available())) - .map_err(|_| { - io::Error::new(io::ErrorKind::Other, "Failed to read from ByteArrayStorage") - })?; + .map_err(|_| io::Error::other("Failed to read from ByteArrayStorage"))?; buf[..bytes.len()].copy_from_slice(bytes); Ok(bytes.len()) } diff --git a/core/src/avm2/domain.rs b/core/src/avm2/domain.rs index 7632c127c365..a3ff71ee22e6 100644 --- a/core/src/avm2/domain.rs +++ b/core/src/avm2/domain.rs @@ -93,7 +93,7 @@ impl<'gc> Domain<'gc> { } pub fn is_playerglobals_domain(&self, avm2: &Avm2<'gc>) -> bool { - avm2.playerglobals_domain.0.as_ptr() == self.0.as_ptr() + std::ptr::eq(avm2.playerglobals_domain.0.as_ptr(), self.0.as_ptr()) } pub fn children(&self, mc: &Mutation<'gc>) -> Vec> { @@ -341,11 +341,12 @@ impl<'gc> Domain<'gc> { pub fn is_default_domain_memory(&self) -> bool { let read = self.0.read(); - read.domain_memory.expect("Missing domain memory").as_ptr() - == read - .default_domain_memory - .expect("Missing default domain memory") - .as_ptr() + let domain_memory_ptr = read.domain_memory.expect("Missing domain memory").as_ptr(); + let default_domain_memory_ptr = read + .default_domain_memory + .expect("Missing default domain memory") + .as_ptr(); + std::ptr::eq(domain_memory_ptr, default_domain_memory_ptr) } pub fn domain_memory(&self) -> ByteArrayObject<'gc> { @@ -420,7 +421,7 @@ pub enum DomainPtr {} impl PartialEq for Domain<'_> { fn eq(&self, other: &Self) -> bool { - self.0.as_ptr() == other.0.as_ptr() + std::ptr::eq(self.0.as_ptr(), other.0.as_ptr()) } } diff --git a/core/src/avm2/filters.rs b/core/src/avm2/filters.rs index f224d7c756b0..3f4a30caa2dc 100644 --- a/core/src/avm2/filters.rs +++ b/core/src/avm2/filters.rs @@ -51,7 +51,7 @@ impl ShaderObject for ObjectWrapper { fn equals(&self, other: &dyn ShaderObject) -> bool { if let Some(other_wrapper) = other.downcast_ref::() { - self.root.as_ptr() == other_wrapper.root.as_ptr() + std::ptr::eq(self.root.as_ptr(), other_wrapper.root.as_ptr()) } else { false } diff --git a/core/src/avm2/object.rs b/core/src/avm2/object.rs index eb750f840bbc..6c90bb70483c 100644 --- a/core/src/avm2/object.rs +++ b/core/src/avm2/object.rs @@ -916,7 +916,7 @@ pub enum ObjectPtr {} impl<'gc> Object<'gc> { pub fn ptr_eq>(a: T, b: T) -> bool { - a.as_ptr() == b.as_ptr() + std::ptr::eq(a.as_ptr(), b.as_ptr()) } #[rustfmt::skip] diff --git a/core/src/bitmap/bitmap_data.rs b/core/src/bitmap/bitmap_data.rs index 1c443d8210d7..6b62483d1201 100644 --- a/core/src/bitmap/bitmap_data.rs +++ b/core/src/bitmap/bitmap_data.rs @@ -479,7 +479,7 @@ mod wrapper { self.0 .write(mc) .display_objects - .retain(|c| c.as_ptr() != callback.as_ptr()) + .retain(|c| !std::ptr::eq(c.as_ptr(), callback.as_ptr())) } pub fn add_display_object(&self, mc: &Mutation<'gc>, callback: DisplayObjectWeak<'gc>) { diff --git a/core/src/buffer.rs b/core/src/buffer.rs index cccb2870b7ed..d3579dfe0406 100644 --- a/core/src/buffer.rs +++ b/core/src/buffer.rs @@ -3,7 +3,7 @@ use gc_arena::Collect; use std::cmp::min; use std::fmt::{Debug, Formatter, LowerHex, UpperHex}; -use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read, Result as IoResult}; +use std::io::{Error as IoError, Read, Result as IoResult}; use std::ops::{Bound, Deref, RangeBounds}; use std::sync::{Arc, RwLock, RwLockReadGuard}; use thiserror::Error; @@ -463,10 +463,7 @@ impl Read for SubstreamCursor { let mut out_count = 0; let buf_owned = self.substream.buf.clone(); let buf = buf_owned.0.read().map_err(|_| { - IoError::new( - IoErrorKind::Other, - "the underlying substream is locked by a panicked process", - ) + IoError::other("the underlying substream is locked by a panicked process") })?; let chunks = self.substream.chunks.read().unwrap(); @@ -545,7 +542,7 @@ impl Deref for SliceRef<'_> { impl PartialEq for SliceRef<'_> { fn eq(&self, other: &SliceRef<'_>) -> bool { - self.guard.as_ptr() == other.guard.as_ptr() + std::ptr::eq(self.guard.as_ptr(), other.guard.as_ptr()) && self.start == other.start && self.end == other.end } diff --git a/core/src/debug_ui/display_object.rs b/core/src/debug_ui/display_object.rs index 147a23afe05a..65259e31e867 100644 --- a/core/src/debug_ui/display_object.rs +++ b/core/src/debug_ui/display_object.rs @@ -972,7 +972,7 @@ impl DisplayObjectWindow { ui.end_row(); ui.label("AVM1 Root"); - if object.avm1_root().as_ptr() != object.as_ptr() { + if !std::ptr::eq(object.avm1_root().as_ptr(), object.as_ptr()) { open_display_object_button( ui, context, @@ -987,7 +987,7 @@ impl DisplayObjectWindow { ui.label("AVM2 Root"); if let Some(other) = object.avm2_root() { - if other.as_ptr() != object.as_ptr() { + if !std::ptr::eq(other.as_ptr(), object.as_ptr()) { open_display_object_button( ui, context, diff --git a/core/src/debug_ui/handle.rs b/core/src/debug_ui/handle.rs index 51f294d7ea58..4e592a2d8932 100644 --- a/core/src/debug_ui/handle.rs +++ b/core/src/debug_ui/handle.rs @@ -48,7 +48,7 @@ impl Debug for DisplayObjectHandle { impl PartialEq for DisplayObjectHandle { #[inline(always)] fn eq(&self, other: &DisplayObjectHandle) -> bool { - self.ptr == other.ptr + std::ptr::eq(self.ptr, other.ptr) } } @@ -91,7 +91,7 @@ impl Debug for AVM1ObjectHandle { impl PartialEq for AVM1ObjectHandle { #[inline(always)] fn eq(&self, other: &AVM1ObjectHandle) -> bool { - self.ptr == other.ptr + std::ptr::eq(self.ptr, other.ptr) } } @@ -134,7 +134,7 @@ impl Debug for AVM2ObjectHandle { impl PartialEq for AVM2ObjectHandle { #[inline(always)] fn eq(&self, other: &AVM2ObjectHandle) -> bool { - self.ptr == other.ptr + std::ptr::eq(self.ptr, other.ptr) } } @@ -179,7 +179,7 @@ impl Debug for DomainHandle { impl PartialEq for DomainHandle { #[inline(always)] fn eq(&self, other: &DomainHandle) -> bool { - self.ptr == other.ptr + std::ptr::eq(self.ptr, other.ptr) } } diff --git a/core/src/display_object.rs b/core/src/display_object.rs index da007d054677..36d4c0016185 100644 --- a/core/src/display_object.rs +++ b/core/src/display_object.rs @@ -2557,7 +2557,7 @@ pub enum DisplayObjectPtr {} impl<'gc> DisplayObject<'gc> { pub fn ptr_eq(a: DisplayObject<'gc>, b: DisplayObject<'gc>) -> bool { - a.as_ptr() == b.as_ptr() + std::ptr::eq(a.as_ptr(), b.as_ptr()) } pub fn option_ptr_eq(a: Option>, b: Option>) -> bool { diff --git a/core/src/display_object/interactive.rs b/core/src/display_object/interactive.rs index 2ee50e489fa4..71b155515ced 100644 --- a/core/src/display_object/interactive.rs +++ b/core/src/display_object/interactive.rs @@ -793,7 +793,7 @@ impl<'gc> Avm2MousePick<'gc> { impl<'gc> InteractiveObject<'gc> { pub fn ptr_eq>(a: T, b: T) -> bool { - a.as_displayobject().as_ptr() == b.as_displayobject().as_ptr() + std::ptr::eq(a.as_displayobject().as_ptr(), b.as_displayobject().as_ptr()) } pub fn option_ptr_eq( diff --git a/core/src/display_object/loader_display.rs b/core/src/display_object/loader_display.rs index 944fbfa6310a..a5f1a4a9c703 100644 --- a/core/src/display_object/loader_display.rs +++ b/core/src/display_object/loader_display.rs @@ -225,7 +225,7 @@ impl<'gc> TInteractiveObject<'gc> for LoaderDisplay<'gc> { .mouse_pick_avm2(context, point, require_button_mode) .combine_with_parent((*self).into()); if let Avm2MousePick::Hit(target) = res { - if target.as_displayobject().as_ptr() == child.as_ptr() { + if std::ptr::eq(target.as_displayobject().as_ptr(), child.as_ptr()) { if self.mouse_enabled() { return Avm2MousePick::Hit((*self).into()); } else { diff --git a/core/src/streams.rs b/core/src/streams.rs index 9df917ab26c9..941194fa49af 100644 --- a/core/src/streams.rs +++ b/core/src/streams.rs @@ -153,7 +153,7 @@ pub struct NetStream<'gc>(GcCell<'gc, NetStreamData<'gc>>); impl PartialEq for NetStream<'_> { fn eq(&self, other: &Self) -> bool { - self.0.as_ptr() == other.0.as_ptr() + std::ptr::eq(self.0.as_ptr(), other.0.as_ptr()) } } diff --git a/core/src/string/repr.rs b/core/src/string/repr.rs index 34ba1175e970..2c488b7ca197 100644 --- a/core/src/string/repr.rs +++ b/core/src/string/repr.rs @@ -113,7 +113,7 @@ impl<'gc> AvmStringRepr<'gc> { let first_requested = left_ptr.add(char_size * left.len()); let mut chars_available = 0; - if first_available == first_requested { + if std::ptr::eq(first_available, first_requested) { let left_capacity_end = left_origin_ptr.add(char_size * left_origin.capacity.get().len()); chars_available = diff --git a/render/webgl/src/lib.rs b/render/webgl/src/lib.rs index 05f582d285c7..40e721eedce0 100644 --- a/render/webgl/src/lib.rs +++ b/render/webgl/src/lib.rs @@ -947,7 +947,7 @@ impl WebGlRenderBackend { // Set common render state, while minimizing unnecessary state changes. // TODO: Using designated layout specifiers in WebGL2/OpenGL ES 3, we could guarantee that uniforms // are in the same location between shaders, and avoid changing them unless necessary. - if program as *const ShaderProgram != self.active_program { + if !std::ptr::eq(program, self.active_program) { self.gl.use_program(Some(&program.program)); self.active_program = program as *const ShaderProgram; @@ -1299,7 +1299,7 @@ impl CommandHandler for WebGlRenderBackend { // Set common render state, while minimizing unnecessary state changes. // TODO: Using designated layout specifiers in WebGL2/OpenGL ES 3, we could guarantee that uniforms // are in the same location between shaders, and avoid changing them unless necessary. - if program as *const ShaderProgram != self.active_program { + if !std::ptr::eq(program, self.active_program) { self.gl.use_program(Some(&program.program)); self.active_program = program as *const ShaderProgram; @@ -1391,7 +1391,7 @@ impl CommandHandler for WebGlRenderBackend { // Set common render state, while minimizing unnecessary state changes. // TODO: Using designated layout specifiers in WebGL2/OpenGL ES 3, we could guarantee that uniforms // are in the same location between shaders, and avoid changing them unless necessary. - if program as *const ShaderProgram != self.active_program { + if !std::ptr::eq(program, self.active_program) { self.gl.use_program(Some(&program.program)); self.active_program = program as *const ShaderProgram; diff --git a/scanner/src/execute.rs b/scanner/src/execute.rs index 04d34e95aa53..886819c4c1c8 100644 --- a/scanner/src/execute.rs +++ b/scanner/src/execute.rs @@ -44,10 +44,7 @@ fn checkpoint( writer.serialize(file_result).unwrap(); if has_error { - Err(std::io::Error::new( - std::io::ErrorKind::Other, - "Error encountered, test terminated", - )) + Err(std::io::Error::other("Error encountered, test terminated")) } else { Ok(()) } diff --git a/swf/src/avm1/read.rs b/swf/src/avm1/read.rs index 2a64a479b7b8..6ed741cf2c44 100644 --- a/swf/src/avm1/read.rs +++ b/swf/src/avm1/read.rs @@ -62,7 +62,7 @@ impl<'a> Reader<'a> { // Verify that we parsed the correct amount of data. let end_pos = (start.as_ptr() as usize + length) as *const u8; - if self.input.as_ptr() != end_pos { + if !std::ptr::eq(self.input.as_ptr(), end_pos) { // We incorrectly parsed this action. // Re-sync to the expected end of the action and throw an error. self.input = &start[length.min(start.len())..]; From f3f33a7db91fefc50a1a9b11acdb1e9a116f4685 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Wed, 2 Apr 2025 22:53:55 +0200 Subject: [PATCH 2/3] chore: Wrap glyph shape variants with a Box The GlyphShape enum contains three variants, all of them differ in size. The None variant is used rarely, but the Swf variant isn't. By boxing Swf and Drawing, we can reduce the amount of wasted memory. --- core/src/font.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/font.rs b/core/src/font.rs index d4b58dc209b6..294e6fecf732 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -220,7 +220,7 @@ impl FontFace { ); Some(Glyph { shape_handle: Default::default(), - shape: GlyphShape::Drawing(drawing), + shape: GlyphShape::Drawing(Box::new(drawing)), advance, character, }) @@ -446,7 +446,9 @@ impl<'gc> Font<'gc> { let glyph = Glyph { shape_handle: None.into(), advance: Twips::new(swf_glyph.advance.into()), - shape: GlyphShape::Swf(RefCell::new(SwfGlyphOrShape::Glyph(swf_glyph))), + shape: GlyphShape::Swf(RefCell::new(Box::new(SwfGlyphOrShape::Glyph( + swf_glyph, + )))), character, }; @@ -817,8 +819,8 @@ impl SwfGlyphOrShape { #[derive(Debug, Clone)] enum GlyphShape { - Swf(RefCell), - Drawing(Drawing), + Swf(RefCell>), + Drawing(Box), None, } From 0c6b72c016796194681944a77e3226f5e21d9106 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Thu, 3 Apr 2025 19:03:57 +0200 Subject: [PATCH 3/3] chore: Wrap Bundle with a Box in PlayingContent Bundle is large and causes size differences between variants of PlayingContent. --- desktop/src/player.rs | 2 +- frontend-utils/src/content.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/src/player.rs b/desktop/src/player.rs index ae4c8910bf0a..6f7a4916992d 100644 --- a/desktop/src/player.rs +++ b/desktop/src/player.rs @@ -164,7 +164,7 @@ impl ActivePlayer { tracing::warn!("{warning}"); } } - content = PlayingContent::Bundle(movie_url.clone(), bundle); + content = PlayingContent::Bundle(movie_url.clone(), Box::new(bundle)); } Err(BundleError::BundleDoesntExist) | Err(BundleError::InvalidSource(BundleSourceError::UnknownSource)) => { diff --git a/frontend-utils/src/content.rs b/frontend-utils/src/content.rs index 164f282d6134..5dd08f85c4c6 100644 --- a/frontend-utils/src/content.rs +++ b/frontend-utils/src/content.rs @@ -6,7 +6,7 @@ use url::Url; pub enum PlayingContent { DirectFile(Url), - Bundle(Url, Bundle), + Bundle(Url, Box), } impl Debug for PlayingContent {