[ruby-dev:31766] Re: packed st_table

From: Tanaka Akira <akr@...>
Date: 2007-09-09 13:50:58 UTC
List: ruby-dev #31766
In article <20070909083828.EE2EDE02AB@mail.bc9.jp>,
  Nobuyoshi Nakada <nobu@ruby-lang.org> writes:

> これは、iterationの途中でunpackしてしまうとなにかと不都合が起き
> そうなので、単純に追加するようにしたんですが、foreachのほうで
> チェックするほうがいいかもしれません。

なるほど。その状況は考えていませんでした。

> [ruby-dev:31729]からの差分です。

2要素のとき packed でなくなります。

(gdb) run -e 'p({1=>1,2=>2})'
Starting program: /home/src/ruby/phash/phash2/ruby/ruby -e 'p({1=>1,2=>2})'
Failed to read a valid object file image from memory.
[Thread debugging using libthread_db enabled]
[New Thread -1210640160 (LWP 18963)]
[New Thread -1211372624 (LWP 18964)]
[Switching to Thread -1210640160 (LWP 18963)]

Breakpoint 1, rb_p (obj=3083657840) at io.c:4038
4038        rb_io_write(rb_stdout, rb_obj_as_string(rb_inspect(obj)));
(gdb) p *((struct RHash*)obj)->ntbl
$4 = {type = 0x81319a4, num_bins = 11, entries_packed = 0, num_entries = 2, bins = 0x8199e68, head = 0x8199e98}

> @@ -350,8 +350,5 @@
>      unsigned int i;
>  
> -    if (table->num_bins >= ST_DEFAULT_INIT_TABLE_SIZE / r * r) {
> -	table->bins = xrealloc(table->bins, sizeof(struct st_table_entry *) * (table->num_bins+r));
> -    }
> -    else if (!PACKABLE(table, table->num_bins+r)) {
> +    if (!PACKABLE(table, table->num_bins+r)) {
>  	return 0;
>      }

PACKABLE の第2引数が問題ですかね。
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread