From b4f16a379e919eefc2cb37bcddee589c0f26eaad Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 8 Aug 2026 03:24:27 +0900 Subject: refactor(php-shim): dispatch spl_object_hash on Rc and references Getting a rule's identity meant spl_object_hash(&*rule.borrow()), so the solver borrowed a RefCell just to read an address, and a second function spl_object_hash_process existed because one generic fn cannot tell Rc from &T. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-shim/src/runtime.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'crates/shirabe-php-shim/src') diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs index a059a59d..591c7260 100644 --- a/crates/shirabe-php-shim/src/runtime.rs +++ b/crates/shirabe-php-shim/src/runtime.rs @@ -315,16 +315,24 @@ pub fn version_compare_ordering(v1: &str, v2: &str) -> std::cmp::Ordering { // Paired with set_error_handler, which is a no-op in this shim. pub fn restore_error_handler() {} -pub fn spl_object_hash(_object: &T) -> String { - // PHP returns a unique 32-char hex id per object instance; the object's address serves as the - // identity here. - // TODO(phase-c): as in PHP, an address can be reused after an object is freed, so uniqueness is - // not guaranteed across an object's whole lifetime without an object store. - format!("{:032x}", _object as *const T as *const u8 as usize) +pub trait HasAddress { + fn address(&self) -> usize; } -pub fn spl_object_hash_process(_object: &T) -> String { - format!("{:032x}", _object as *const T as usize) +impl HasAddress for &T { + fn address(&self) -> usize { + *self as *const T as *const u8 as usize + } +} + +impl HasAddress for std::rc::Rc { + fn address(&self) -> usize { + std::rc::Rc::as_ptr(self) as *const u8 as usize + } +} + +pub fn spl_object_hash(object: T) -> String { + format!("{:032x}", object.address()) } // TODO(phase-c): the Windows branch of php_uname is missing. There PHP reports "Windows NT" as the -- cgit v1.3.1-4-g156e