X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=ext%2Fcomments.c;h=a8236a51af5e514873d1ee0c318414ac5f74cdf1;hb=12497b34fc0601f03e124552e489be8afcf12d1d;hp=23967289b5e20ad56222171dafb9279147b84ee7;hpb=5f8f314af751ff5b0849df5bf4ba85149d8330f1;p=ruby-vorbistagger.git diff --git a/ext/comments.c b/ext/comments.c index 2396728..a8236a5 100644 --- a/ext/comments.c +++ b/ext/comments.c @@ -48,7 +48,7 @@ comments_init (VALUE self, vcedit_state *state) o->items = rb_ary_new2 (vc->comments); for (i = 0; i < vc->comments; i++) { - VALUE k, v; + VALUE k, v, pair; char *ptr, *content = vc->user_comments[i]; ptr = strchr (content, '='); @@ -59,11 +59,11 @@ comments_init (VALUE self, vcedit_state *state) v = rb_str_new2 (ptr + 1); - rb_ary_store (o->items, i, - rb_ary_new3 (2, k, v)); - } + pair = rb_ary_new3 (2, k, v); + OBJ_FREEZE (pair); - rb_iv_set (self, "@items", o->items); + rb_ary_store (o->items, i, pair); + } } void @@ -291,7 +291,7 @@ c_get_empty (VALUE self) Data_Get_Struct (self, RbVorbisComments, o); - return !RARRAY(o->items)->len; + return RARRAY(o->items)->len ? Qfalse : Qtrue; } /* @@ -333,6 +333,7 @@ c_aref (VALUE self, VALUE key) static VALUE c_aset (VALUE self, VALUE key, VALUE value) { + VALUE tmp; RbVorbisComments *o; struct RArray *items; int i; @@ -352,7 +353,10 @@ c_aset (VALUE self, VALUE key, VALUE value) } } - rb_ary_push (o->items, rb_ary_new3 (2, key, value)); + tmp = rb_ary_new3 (2, rb_str_dup_frozen (key), value); + OBJ_FREEZE (tmp); + + rb_ary_push (o->items, tmp); return value; } @@ -545,6 +549,9 @@ Init_Comments (VALUE mVorbis) rb_define_alias (c, "size", "length"); rb_define_alias (c, "each_pair", "each"); + rb_define_alias (c, "key?", "has_key?"); + rb_define_alias (c, "include?", "has_key?"); + rb_define_alias (c, "member?", "has_key?"); id_casecmp = rb_intern ("casecmp"); id_replace = rb_intern ("replace");