summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zjit/src/cruby.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/zjit/src/cruby.rs b/zjit/src/cruby.rs
index bdea8a2404..40df1fab03 100644
--- a/zjit/src/cruby.rs
+++ b/zjit/src/cruby.rs
@@ -248,7 +248,7 @@ pub struct rb_iseq_constant_body {
/// that this is a handle. Sometimes the C code briefly uses VALUE as
/// an unsigned integer type and don't necessarily store valid handles but
/// thankfully those cases are rare and don't cross the FFI boundary.
-#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[repr(transparent)] // same size and alignment as simply `usize`
pub struct VALUE(pub usize);
@@ -757,6 +757,17 @@ impl IseqParameters {
}
}
+impl Debug for VALUE {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ // Only use rb_obj_info() when {:#?} since it dereferences the pointer so carries some risk.
+ if f.alternate() {
+ write!(f, "VALUE({})", self.obj_info())
+ } else {
+ write!(f, "VALUE(0x{:x})", self.0)
+ }
+ }
+}
+
impl From<IseqPtr> for VALUE {
/// For `.into()` convenience
fn from(iseq: IseqPtr) -> Self {
@@ -1418,6 +1429,13 @@ pub mod test_utils {
fn value_from_fixnum_too_small_isize() {
assert_eq!(VALUE::fixnum_from_isize(RUBY_FIXNUM_MIN-1), VALUE(1));
}
+
+ #[test]
+ fn value_fmt_debug() {
+ assert_eq!("VALUE(0xcafe)", format!("{:?}", VALUE(0xcafe)));
+ let alternate = format!("{:#?}", eval("::Hash"));
+ assert!(alternate.contains("Hash"), "'Hash' not substring of '{alternate}'");
+ }
}
#[cfg(test)]
pub use test_utils::*;