diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-08 03:24:27 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-08 03:25:02 +0900 |
| commit | b4f16a379e919eefc2cb37bcddee589c0f26eaad (patch) | |
| tree | fcd970b83deb89a04fb5daf2c107d6f75b34e0f2 /crates/shirabe-php-shim/src/runtime.rs | |
| parent | da0d38a8e16ebefd59ef5291b5788e6238cc78ba (diff) | |
| download | php-shirabe-b4f16a379e919eefc2cb37bcddee589c0f26eaad.tar.gz php-shirabe-b4f16a379e919eefc2cb37bcddee589c0f26eaad.tar.zst php-shirabe-b4f16a379e919eefc2cb37bcddee589c0f26eaad.zip | |
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<T>
from &T.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src/runtime.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/runtime.rs | 24 |
1 files changed, 16 insertions, 8 deletions
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<T: ?Sized>(_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<T>(_object: &T) -> String { - format!("{:032x}", _object as *const T as usize) +impl<T: ?Sized> HasAddress for &T { + fn address(&self) -> usize { + *self as *const T as *const u8 as usize + } +} + +impl<T: ?Sized> HasAddress for std::rc::Rc<T> { + fn address(&self) -> usize { + std::rc::Rc::as_ptr(self) as *const u8 as usize + } +} + +pub fn spl_object_hash<T: HasAddress>(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 |
