ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
@ 2020-09-28 11:40 baptiste.courtois
  2020-10-20 15:55 ` [ruby-core:100446] " chris
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: baptiste.courtois @ 2020-09-28 11:40 UTC (permalink / raw)
  To: ruby-core

Issue #17199 has been reported by Annih (Baptiste Courtois).

----------------------------------------
Misc #17199: id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
https://bugs.ruby-lang.org/issues/17199

* Author: Annih (Baptiste Courtois)
* Status: Open
* Priority: Normal
----------------------------------------
Hello, here is my first ruby issue sorry in advance if it is incorrectly filled.

# Issue

The value returned by `#object_id` is not aligned anymore with displayed info in `#inspect` and `#to_s` methods.

## with ruby < 2.7

``` ruby
Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to_s(16)}" }
"#to_s=#<Object:0x0000000000d202a8>, #inspect=#<Object:0x0000000000d202a8>, #__id__=6881620, shifted_id=d202a8"
```

## with ruby >= 2.7

``` ruby
 Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to
s(16)}" }
"#to_s=#<Object:0x0000555dc8640b88>, #inspect=#<Object:0x0000555dc8640b88>, #__id__=220, shifted_id=1b8"
```


# Consequences

It makes harder:
- to implement a clean override of the `#inspect` method. i.e. How to keep the same output without ability to compute to the same "object_id" value.
- to debug the object using the inspect output. i.e. `ObjectSpace._id2ref(id_from_inspect >> 1)` used to work, now it doesn't (`RangeError: <xXx> is not id value`).

# Suggestion

IMHO either:
- the `#to_s` and `#inspect` documentation are obsolete `The default [...] [shows|prints] [...] an encoding of the object id` and the change could have been a bit more advertised
- they should use the result of `#object_id` instead of displaying the object pointer address

Another solution could be to provide a method to get access to the address, but I'm not sure you want that.

P.S. While debugging my problem I found [this ruby-forum thread](https://www.ruby-forum.com/t/understanding-object-id-in-ruby-2-7/260268/4) where people dived a bit more than me into ruby's code.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:100446] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
  2020-09-28 11:40 [ruby-core:100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa baptiste.courtois
@ 2020-10-20 15:55 ` chris
  2020-10-20 18:31 ` [ruby-core:100448] " johnson.joel.b
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: chris @ 2020-10-20 15:55 UTC (permalink / raw)
  To: ruby-core

Issue #17199 has been updated by chrisseaton (Chris Seaton).


Additional context is that `#object_id` used to the object's address, and is now a simple incrementing number, and `#inspect` still and has always used the object's address.

I believe the documentation is correct though?

https://ruby-doc.org/core-2.7.2/Object.html#method-i-inspect

Note that an additional complicating issue is that Ruby objects may now move, so addresses are not stable, and so *the result of `#inspect` is not stable*. Two calls to `#inspect` on the same object can return different values non-deterministically. Is that what we want?

I think that `#inspect` should be changed to use `#object_id`.

----------------------------------------
Misc #17199: id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
https://bugs.ruby-lang.org/issues/17199#change-88065

* Author: Annih (Baptiste Courtois)
* Status: Open
* Priority: Normal
----------------------------------------
Hello, here is my first ruby issue sorry in advance if it is incorrectly filled.

# Issue

The value returned by `#object_id` is not aligned anymore with displayed info in `#inspect` and `#to_s` methods.

## with ruby < 2.7

``` ruby
Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to_s(16)}" }
"#to_s=#<Object:0x0000000000d202a8>, #inspect=#<Object:0x0000000000d202a8>, #__id__=6881620, shifted_id=d202a8"
```

## with ruby >= 2.7

``` ruby
 Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to
s(16)}" }
"#to_s=#<Object:0x0000555dc8640b88>, #inspect=#<Object:0x0000555dc8640b88>, #__id__=220, shifted_id=1b8"
```


# Consequences

It makes harder:
- to implement a clean override of the `#inspect` method. i.e. How to keep the same output without ability to compute to the same "object_id" value.
- to debug the object using the inspect output. i.e. `ObjectSpace._id2ref(id_from_inspect >> 1)` used to work, now it doesn't (`RangeError: <xXx> is not id value`).

# Suggestion

IMHO either:
- the `#to_s` and `#inspect` documentation are obsolete `The default [...] [shows|prints] [...] an encoding of the object id` and the change could have been a bit more advertised
- they should use the result of `#object_id` instead of displaying the object pointer address

Another solution could be to provide a method to get access to the address, but I'm not sure you want that.

P.S. While debugging my problem I found [this ruby-forum thread](https://www.ruby-forum.com/t/understanding-object-id-in-ruby-2-7/260268/4) where people dived a bit more than me into ruby's code.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:100448] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
  2020-09-28 11:40 [ruby-core:100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa baptiste.courtois
  2020-10-20 15:55 ` [ruby-core:100446] " chris
@ 2020-10-20 18:31 ` johnson.joel.b
  2020-10-20 20:06 ` [ruby-core:100450] " eregontp
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: johnson.joel.b @ 2020-10-20 18:31 UTC (permalink / raw)
  To: ruby-core

Issue #17199 has been updated by jorel (Joel Johnson).


Similarly, the `object_id` and object addresses are potentially problematic when making use of `ObjectSpace.trace_object_allocations_start` and dumping the json data periodically in trying to match up the object over time if `GC.compact` has happened. 

I think this highlights having `object_id` being a nice higher level concept for these use cases instead of relying on the address that is effectively an implementation detail.

----------------------------------------
Misc #17199: id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
https://bugs.ruby-lang.org/issues/17199#change-88067

* Author: Annih (Baptiste Courtois)
* Status: Open
* Priority: Normal
----------------------------------------
Hello, here is my first ruby issue sorry in advance if it is incorrectly filled.

# Issue

The value returned by `#object_id` is not aligned anymore with displayed info in `#inspect` and `#to_s` methods.

## with ruby < 2.7

``` ruby
Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to_s(16)}" }
"#to_s=#<Object:0x0000000000d202a8>, #inspect=#<Object:0x0000000000d202a8>, #__id__=6881620, shifted_id=d202a8"
```

## with ruby >= 2.7

``` ruby
 Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to
s(16)}" }
"#to_s=#<Object:0x0000555dc8640b88>, #inspect=#<Object:0x0000555dc8640b88>, #__id__=220, shifted_id=1b8"
```


# Consequences

It makes harder:
- to implement a clean override of the `#inspect` method. i.e. How to keep the same output without ability to compute to the same "object_id" value.
- to debug the object using the inspect output. i.e. `ObjectSpace._id2ref(id_from_inspect >> 1)` used to work, now it doesn't (`RangeError: <xXx> is not id value`).

# Suggestion

IMHO either:
- the `#to_s` and `#inspect` documentation are obsolete `The default [...] [shows|prints] [...] an encoding of the object id` and the change could have been a bit more advertised
- they should use the result of `#object_id` instead of displaying the object pointer address

Another solution could be to provide a method to get access to the address, but I'm not sure you want that.

P.S. While debugging my problem I found [this ruby-forum thread](https://www.ruby-forum.com/t/understanding-object-id-in-ruby-2-7/260268/4) where people dived a bit more than me into ruby's code.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:100450] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
  2020-09-28 11:40 [ruby-core:100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa baptiste.courtois
  2020-10-20 15:55 ` [ruby-core:100446] " chris
  2020-10-20 18:31 ` [ruby-core:100448] " johnson.joel.b
@ 2020-10-20 20:06 ` eregontp
  2020-10-20 20:15 ` [ruby-core:100451] " nate.berkopec
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: eregontp @ 2020-10-20 20:06 UTC (permalink / raw)
  To: ruby-core

Issue #17199 has been updated by Eregon (Benoit Daloze).


Agreed on showing the `#object_id` in `#inspect` seems better (and more useful for identifying a specific object).

Annih (Baptiste Courtois) wrote:
> It makes harder:
> - to implement a clean override of the `#inspect` method. i.e. How to keep the same output without ability to compute to the same "object_id" value.

A simple way is `"#{super[0...-1]} extra info>"`.
Trying to manually format the `object_id` is often not a good idea, notably because `object_id` can be negative (especially on 32-bit platforms).


----------------------------------------
Misc #17199: id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
https://bugs.ruby-lang.org/issues/17199#change-88069

* Author: Annih (Baptiste Courtois)
* Status: Open
* Priority: Normal
----------------------------------------
Hello, here is my first ruby issue sorry in advance if it is incorrectly filled.

# Issue

The value returned by `#object_id` is not aligned anymore with displayed info in `#inspect` and `#to_s` methods.

## with ruby < 2.7

``` ruby
Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to_s(16)}" }
"#to_s=#<Object:0x0000000000d202a8>, #inspect=#<Object:0x0000000000d202a8>, #__id__=6881620, shifted_id=d202a8"
```

## with ruby >= 2.7

``` ruby
 Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to
s(16)}" }
"#to_s=#<Object:0x0000555dc8640b88>, #inspect=#<Object:0x0000555dc8640b88>, #__id__=220, shifted_id=1b8"
```


# Consequences

It makes harder:
- to implement a clean override of the `#inspect` method. i.e. How to keep the same output without ability to compute to the same "object_id" value.
- to debug the object using the inspect output. i.e. `ObjectSpace._id2ref(id_from_inspect >> 1)` used to work, now it doesn't (`RangeError: <xXx> is not id value`).

# Suggestion

IMHO either:
- the `#to_s` and `#inspect` documentation are obsolete `The default [...] [shows|prints] [...] an encoding of the object id` and the change could have been a bit more advertised
- they should use the result of `#object_id` instead of displaying the object pointer address

Another solution could be to provide a method to get access to the address, but I'm not sure you want that.

P.S. While debugging my problem I found [this ruby-forum thread](https://www.ruby-forum.com/t/understanding-object-id-in-ruby-2-7/260268/4) where people dived a bit more than me into ruby's code.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:100451] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
  2020-09-28 11:40 [ruby-core:100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa baptiste.courtois
                   ` (2 preceding siblings ...)
  2020-10-20 20:06 ` [ruby-core:100450] " eregontp
@ 2020-10-20 20:15 ` nate.berkopec
  2020-10-20 21:32 ` [ruby-core:100458] " tenderlove
  2020-10-20 21:35 ` [ruby-core:100459] " tenderlove
  5 siblings, 0 replies; 7+ messages in thread
From: nate.berkopec @ 2020-10-20 20:15 UTC (permalink / raw)
  To: ruby-core

Issue #17199 has been updated by nateberkopec (Nate Berkopec).


This looks like an oversight to me? I agree with Benoit - showing object_id everywhere we used to show address seems the best way forward.

----------------------------------------
Misc #17199: id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
https://bugs.ruby-lang.org/issues/17199#change-88070

* Author: Annih (Baptiste Courtois)
* Status: Open
* Priority: Normal
----------------------------------------
Hello, here is my first ruby issue sorry in advance if it is incorrectly filled.

# Issue

The value returned by `#object_id` is not aligned anymore with displayed info in `#inspect` and `#to_s` methods.

## with ruby < 2.7

``` ruby
Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to_s(16)}" }
"#to_s=#<Object:0x0000000000d202a8>, #inspect=#<Object:0x0000000000d202a8>, #__id__=6881620, shifted_id=d202a8"
```

## with ruby >= 2.7

``` ruby
 Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to
s(16)}" }
"#to_s=#<Object:0x0000555dc8640b88>, #inspect=#<Object:0x0000555dc8640b88>, #__id__=220, shifted_id=1b8"
```


# Consequences

It makes harder:
- to implement a clean override of the `#inspect` method. i.e. How to keep the same output without ability to compute to the same "object_id" value.
- to debug the object using the inspect output. i.e. `ObjectSpace._id2ref(id_from_inspect >> 1)` used to work, now it doesn't (`RangeError: <xXx> is not id value`).

# Suggestion

IMHO either:
- the `#to_s` and `#inspect` documentation are obsolete `The default [...] [shows|prints] [...] an encoding of the object id` and the change could have been a bit more advertised
- they should use the result of `#object_id` instead of displaying the object pointer address

Another solution could be to provide a method to get access to the address, but I'm not sure you want that.

P.S. While debugging my problem I found [this ruby-forum thread](https://www.ruby-forum.com/t/understanding-object-id-in-ruby-2-7/260268/4) where people dived a bit more than me into ruby's code.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:100458] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
  2020-09-28 11:40 [ruby-core:100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa baptiste.courtois
                   ` (3 preceding siblings ...)
  2020-10-20 20:15 ` [ruby-core:100451] " nate.berkopec
@ 2020-10-20 21:32 ` tenderlove
  2020-10-20 21:35 ` [ruby-core:100459] " tenderlove
  5 siblings, 0 replies; 7+ messages in thread
From: tenderlove @ 2020-10-20 21:32 UTC (permalink / raw)
  To: ruby-core

Issue #17199 has been updated by tenderlovemaking (Aaron Patterson).

File 0001-Use-the-object-id-in-the-default-implementation-of-i.patch added

I think adding the object id to `inspect` is a good idea, though I think it should just have the object id, not `object_id >> 1` (or any other permutation).  I don't think adding the object id to heap dumps is a good idea though since we would have to generate an object id for every object in the heap.

I've attached a patch with the object id in `inspect`

----------------------------------------
Misc #17199: id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
https://bugs.ruby-lang.org/issues/17199#change-88077

* Author: Annih (Baptiste Courtois)
* Status: Open
* Priority: Normal
----------------------------------------
Hello, here is my first ruby issue sorry in advance if it is incorrectly filled.

# Issue

The value returned by `#object_id` is not aligned anymore with displayed info in `#inspect` and `#to_s` methods.

## with ruby < 2.7

``` ruby
Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to_s(16)}" }
"#to_s=#<Object:0x0000000000d202a8>, #inspect=#<Object:0x0000000000d202a8>, #__id__=6881620, shifted_id=d202a8"
```

## with ruby >= 2.7

``` ruby
 Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to
s(16)}" }
"#to_s=#<Object:0x0000555dc8640b88>, #inspect=#<Object:0x0000555dc8640b88>, #__id__=220, shifted_id=1b8"
```


# Consequences

It makes harder:
- to implement a clean override of the `#inspect` method. i.e. How to keep the same output without ability to compute to the same "object_id" value.
- to debug the object using the inspect output. i.e. `ObjectSpace._id2ref(id_from_inspect >> 1)` used to work, now it doesn't (`RangeError: <xXx> is not id value`).

# Suggestion

IMHO either:
- the `#to_s` and `#inspect` documentation are obsolete `The default [...] [shows|prints] [...] an encoding of the object id` and the change could have been a bit more advertised
- they should use the result of `#object_id` instead of displaying the object pointer address

Another solution could be to provide a method to get access to the address, but I'm not sure you want that.

P.S. While debugging my problem I found [this ruby-forum thread](https://www.ruby-forum.com/t/understanding-object-id-in-ruby-2-7/260268/4) where people dived a bit more than me into ruby's code.

---Files--------------------------------
0001-Use-the-object-id-in-the-default-implementation-of-i.patch (1.16 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:100459] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
  2020-09-28 11:40 [ruby-core:100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa baptiste.courtois
                   ` (4 preceding siblings ...)
  2020-10-20 21:32 ` [ruby-core:100458] " tenderlove
@ 2020-10-20 21:35 ` tenderlove
  5 siblings, 0 replies; 7+ messages in thread
From: tenderlove @ 2020-10-20 21:35 UTC (permalink / raw)
  To: ruby-core

Issue #17199 has been updated by tenderlovemaking (Aaron Patterson).


> Another solution could be to provide a method to get access to the address, but I'm not sure you want that.

btw you can get the address of an object like this:

```
irb(main):001:0> require "fiddle"
=> true
irb(main):002:0> x = Object.new
=> #<Object:0x00007fee918e0148>
irb(main):003:0> Fiddle.dlwrap(x).to_s(16)
=> "7fee918e0148"
irb(main):004:0> 
```

----------------------------------------
Misc #17199: id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa
https://bugs.ruby-lang.org/issues/17199#change-88078

* Author: Annih (Baptiste Courtois)
* Status: Open
* Priority: Normal
----------------------------------------
Hello, here is my first ruby issue sorry in advance if it is incorrectly filled.

# Issue

The value returned by `#object_id` is not aligned anymore with displayed info in `#inspect` and `#to_s` methods.

## with ruby < 2.7

``` ruby
Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to_s(16)}" }
"#to_s=#<Object:0x0000000000d202a8>, #inspect=#<Object:0x0000000000d202a8>, #__id__=6881620, shifted_id=d202a8"
```

## with ruby >= 2.7

``` ruby
 Object.new.tap { |o| p "#to_s=#{o.to_s}, #inspect=#{o.inspect}, #__id__=#{o.__id__}, shifted_id=#{(o.__id__ << 1).to
s(16)}" }
"#to_s=#<Object:0x0000555dc8640b88>, #inspect=#<Object:0x0000555dc8640b88>, #__id__=220, shifted_id=1b8"
```


# Consequences

It makes harder:
- to implement a clean override of the `#inspect` method. i.e. How to keep the same output without ability to compute to the same "object_id" value.
- to debug the object using the inspect output. i.e. `ObjectSpace._id2ref(id_from_inspect >> 1)` used to work, now it doesn't (`RangeError: <xXx> is not id value`).

# Suggestion

IMHO either:
- the `#to_s` and `#inspect` documentation are obsolete `The default [...] [shows|prints] [...] an encoding of the object id` and the change could have been a bit more advertised
- they should use the result of `#object_id` instead of displaying the object pointer address

Another solution could be to provide a method to get access to the address, but I'm not sure you want that.

P.S. While debugging my problem I found [this ruby-forum thread](https://www.ruby-forum.com/t/understanding-object-id-in-ruby-2-7/260268/4) where people dived a bit more than me into ruby's code.

---Files--------------------------------
0001-Use-the-object-id-in-the-default-implementation-of-i.patch (1.16 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-10-20 21:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-28 11:40 [ruby-core:100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa baptiste.courtois
2020-10-20 15:55 ` [ruby-core:100446] " chris
2020-10-20 18:31 ` [ruby-core:100448] " johnson.joel.b
2020-10-20 20:06 ` [ruby-core:100450] " eregontp
2020-10-20 20:15 ` [ruby-core:100451] " nate.berkopec
2020-10-20 21:32 ` [ruby-core:100458] " tenderlove
2020-10-20 21:35 ` [ruby-core:100459] " tenderlove

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).