ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: yosy101@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:71109] [Ruby trunk - Feature #11599] Dump entries of hash in ObjectSpace
Date: Mon, 19 Oct 2015 05:28:16 +0000	[thread overview]
Message-ID: <redmine.journal-54480.20151019052815.ca575597e9ae216c@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11599.20151017120607@ruby-lang.org

Issue #11599 has been updated by Yosi Attias.


Nobuyoshi Nakada wrote:
> Yosi Attias wrote:
> > and to make sure there are no confusion some one did some like this:
> > 
> > ~~~ruby
> > h = {address: "0x007fbc01110368" }
> > ~~~
> 
> I can't get your point here.
> `{"key":":a","value":"0x007f8f3c8baf88"}` seems clear enough to me.

Yes, but how can you distinguish between string value which is address or address to other ruby object:
`h = {a: "0x007f8f3c8baf88"}` to `h = {a: {b: 1}}`



----------------------------------------
Feature #11599: Dump entries of hash in ObjectSpace
https://bugs.ruby-lang.org/issues/11599#change-54480

* Author: Yosi Attias
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hi,

*This is my first c code contribution :)*

I am helping developing heap-analyzer (github.com/tenderlove/heap-analyzer), and currently the dumps lacks of "type metadata" information, like:

* Hash entries - the keys and value
* Array items - the items of the array

etc.

In the included patch, I have changed the dump of hash to add entries of hash.
For example, given the next hash:

~~~ruby
hash = {
    int_key: 1,
    str_key: "This is my string",
    inner_hash: { b: 2 }
}
~~~

The dump result (ObjectSpace.dump(hash)) will be:

~~~json
{
    "address": "0x007fbc01110340",
    "type": "HASH",
    "class": "0x007fbc0109b400",
    "size": 3,
    "entries": [
        {
            "is_key_address": false,
            "key": ":int_key",
            "is_value_address": false,
            "value": "1"
        },
        {
            "is_key_address": false,
            "key": ":str_key",
            "is_value_address": true,
            "value": "0x007fbc01110390"
        },
        {
            "is_key_address": false,
            "key": ":inner_hash",
            "is_value_address": true,
            "value": "0x007fbc01110368"
        }
    ],
    "references": [
        "0x007fbc01110390",
        "0x007fbc01110368"
    ],
    "memsize": 232,
    "flags": {
        "wb_protected": true
    }
}
~~~

As you can see, I have the "entries" array, where each entry contains:  "is_key_address", "is_value_address" - if the key/value are special consts the inspected value will be printed in the "key"/"value" properties, other their address will be print. 


Hope you will accept the patch (and I can submit another one for arrays),
Yosi.


---Files--------------------------------
objspace_dump_hash_entries.patch (4.8 KB)


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

  parent reply	other threads:[~2015-10-19  5:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11599.20151017120607@ruby-lang.org>
2015-10-17 12:06 ` [ruby-core:71099] [Ruby trunk - Feature #11599] [Open] Dump entries of hash in ObjectSpace yosy101
2015-10-18 13:24 ` [ruby-core:71103] [Ruby trunk - Feature #11599] " nobu
2015-10-18 17:18 ` [ruby-core:71105] " yosy101
2015-10-19  1:50 ` [ruby-core:71108] " nobu
2015-10-19  5:28 ` yosy101 [this message]
2015-10-19  6:52 ` [ruby-core:71110] " nobu
2015-10-19 18:28 ` [ruby-core:71118] " yosy101
2015-10-19 18:49 ` [ruby-core:71119] " yosy101
2015-10-23  8:57 ` [ruby-core:71171] " yosy101
2015-10-24 15:51 ` [ruby-core:71180] " yosy101
2015-11-21 12:00 ` [ruby-core:71624] " yosy101
2015-11-23 21:34 ` [ruby-core:71644] " tenderlove
2015-11-23 21:37 ` [ruby-core:71645] " yosy101
2015-11-24 17:52 ` [ruby-core:71657] " yosy101

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-54480.20151019052815.ca575597e9ae216c@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).