strange SDBM behaviour

Discussion in 'Ruby' started by gabriele renzi, Jun 10, 2004.

  1. hi gurus and nubys,

    I just noticed this:

    >> db=SDBM.new 'foo', 0666

    => #<SDBM:0x28b3130>
    >> db[:foo]=10

    => 10
    >> db.keys

    => ["foo"]
    >> db[:foo]

    TypeError: cannot convert Symbol into String
    from (irb):8:in `[]'
    from (irb):8

    It seem that []= uses to_s while [] uses to_str:
    >> class C
    >> def to_s
    >> 'miao'
    >> end
    >> def to_str
    >> raise 'fuku fukissimo fuku'
    >> end
    >> end

    => nil
    >> db[C.new]=30

    => 30
    >> db.keys

    => ["foo", "miao"]
    >> db[C.new]

    RuntimeError: fuku fukissimo fuku
    from (irb):16:in `to_str'
    from (irb):21:in `[]'
    from (irb):21

    is this an expected behaviour? I believe wheter SDBM uses the one or
    the other it should be consistent in hi choice :)

    Anyway:
    ruby 1.8.1 (2003-12-25) [i386-mswin32]

    Can't say what version sdbm is, given that VERSION refers to 1.8.1 and
    SDBM::constants == []
     
    gabriele renzi, Jun 10, 2004
    #1
    1. Advertising

  2. In message "strange SDBM behaviour"
    on 04/06/10, gabriele renzi <> writes:

    |It seem that []= uses to_s while [] uses to_str:

    It's a bug in sdbm. Thank you for reporting.
    Here the patch for ones who need.

    matz.

    --- ext/sdbm/init.c 8 May 2004 08:12:00 -0000 1.21
    +++ ext/sdbm/init.c 10 Jun 2004 10:22:14 -0000
    @@ -477,3 +477,3 @@ fsdbm_store(obj, keystr, valstr)
    fdbm_modify(obj);
    - keystr = rb_obj_as_string(keystr);
    + StringValue(keystr);

    @@ -482,5 +482,3 @@ fsdbm_store(obj, keystr, valstr)

    - if (NIL_P(valstr)) return fsdbm_delete(obj, keystr);
    -
    - valstr = rb_obj_as_string(valstr);
    + StringValue(valstr);
    val.dptr = RSTRING(valstr)->ptr;
     
    Yukihiro Matsumoto, Jun 10, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hal Fulton

    DBM and SDBM

    Hal Fulton, Oct 15, 2004, in forum: Ruby
    Replies:
    2
    Views:
    141
    Hal Fulton
    Oct 16, 2004
  2. Hal Fulton

    SDBM and Windows

    Hal Fulton, Oct 17, 2004, in forum: Ruby
    Replies:
    2
    Views:
    127
    Reimer Behrends
    Oct 17, 2004
  3. Tassilo Horn

    SDBM troubles

    Tassilo Horn, May 1, 2006, in forum: Ruby
    Replies:
    0
    Views:
    87
    Tassilo Horn
    May 1, 2006
  4. snacktime

    bug with sdbm?

    snacktime, Oct 26, 2006, in forum: Ruby
    Replies:
    1
    Views:
    120
    Vincent Fourmond
    Oct 26, 2006
  5. Guest

    [OT?] SDBM file HUGE on disk

    Guest, Sep 19, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    270
    Guest
    Sep 23, 2004
Loading...

Share This Page