summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ffeb1ba)
Ogg::Vorbis::Comments doesn't need to hold a reference to the
vcedit_state structure. Instead, now a pointer to that struct is passed
to comments_sync(), too. This means we no longer need to make
Ogg::Vorbis::Comments a class of type T_DATA.
-typedef struct {
- vcedit_state *state;
-
- VALUE items;
-} RbVorbisComments;
-
static ID id_casecmp, id_replace, id_compare;
void
comments_init (VALUE self, vcedit_state *state)
{
static ID id_casecmp, id_replace, id_compare;
void
comments_init (VALUE self, vcedit_state *state)
{
vorbis_comment *vc;
int i;
vorbis_comment *vc;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- o->state = state;
- vcedit_state_ref (state);
+ vc = vcedit_comments (state);
- vc = vcedit_comments (o->state);
-
- o->items = rb_ary_new2 (vc->comments);
+ items = rb_ary_new2 (vc->comments);
+ rb_iv_set (self, "items", items);
for (i = 0; i < vc->comments; i++) {
VALUE k, v, pair;
for (i = 0; i < vc->comments; i++) {
VALUE k, v, pair;
pair = rb_ary_new3 (2, k, v);
OBJ_FREEZE (pair);
pair = rb_ary_new3 (2, k, v);
OBJ_FREEZE (pair);
- rb_ary_store (o->items, i, pair);
+ rb_ary_store (items, i, pair);
-comments_sync (VALUE self)
+comments_sync (VALUE self, vcedit_state *state)
vorbis_comment *vc;
struct RArray *items;
int i;
vorbis_comment *vc;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- vc = vcedit_comments (o->state);
+ vc = vcedit_comments (state);
vorbis_comment_clear (vc);
vorbis_comment_init (vc);
vorbis_comment_clear (vc);
vorbis_comment_init (vc);
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
-static void
-c_mark (RbVorbisComments *o)
-{
- rb_gc_mark (o->items);
-}
-
-static void
-c_free (RbVorbisComments *o)
-{
- vcedit_state_unref (o->state);
-
- ruby_xfree (o);
-}
-
-static VALUE
-c_alloc (VALUE klass)
-{
- RbVorbisComments *o;
-
- return Data_Make_Struct (klass, RbVorbisComments, c_mark, c_free, o);
-}
-
/*
* call-seq:
* object.inspect -> string
/*
* call-seq:
* object.inspect -> string
c_inspect (VALUE self)
{
VALUE ret;
c_inspect (VALUE self)
{
VALUE ret;
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
ret = rb_str_buf_new (128);
rb_str_buf_cat (ret, "{", 1);
ret = rb_str_buf_new (128);
rb_str_buf_cat (ret, "{", 1);
static VALUE
c_clear (VALUE self)
{
static VALUE
c_clear (VALUE self)
{
- RbVorbisComments *o;
-
- Data_Get_Struct (self, RbVorbisComments, o);
-
- rb_ary_clear (o->items);
+ rb_ary_clear (rb_iv_get (self, "items"));
c_delete (VALUE self, VALUE key)
{
VALUE ret = Qnil;
c_delete (VALUE self, VALUE key)
{
VALUE ret = Qnil;
struct RArray *items;
int i, pos = -1;
struct RArray *items;
int i, pos = -1;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
- rb_ary_delete_at (o->items, pos);
+ rb_ary_delete_at (rb_iv_get (self, "items"), pos);
c_keys (VALUE self)
{
VALUE ret;
c_keys (VALUE self)
{
VALUE ret;
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
ret = rb_ary_new2 (items->len);
for (i = 0; i < items->len; i++) {
ret = rb_ary_new2 (items->len);
for (i = 0; i < items->len; i++) {
c_values (VALUE self)
{
VALUE ret;
c_values (VALUE self)
{
VALUE ret;
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
ret = rb_ary_new2 (items->len);
for (i = 0; i < items->len; i++) {
ret = rb_ary_new2 (items->len);
for (i = 0; i < items->len; i++) {
static VALUE
c_length (VALUE self)
{
static VALUE
c_length (VALUE self)
{
- Data_Get_Struct (self, RbVorbisComments, o);
+ items = RARRAY (rb_iv_get (self, "items"));
- return LONG2NUM (RARRAY (o->items)->len);
+ return LONG2NUM (items->len);
static VALUE
c_get_empty (VALUE self)
{
static VALUE
c_get_empty (VALUE self)
{
- Data_Get_Struct (self, RbVorbisComments, o);
+ items = RARRAY (rb_iv_get (self, "items"));
- return RARRAY(o->items)->len ? Qfalse : Qtrue;
+ return items->len ? Qfalse : Qtrue;
static VALUE
c_aref (VALUE self, VALUE key)
{
static VALUE
c_aref (VALUE self, VALUE key)
{
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
c_aset (VALUE self, VALUE key, VALUE value)
{
VALUE tmp;
c_aset (VALUE self, VALUE key, VALUE value)
{
VALUE tmp;
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
tmp = rb_ary_new3 (2, rb_str_dup_frozen (key), value);
OBJ_FREEZE (tmp);
tmp = rb_ary_new3 (2, rb_str_dup_frozen (key), value);
OBJ_FREEZE (tmp);
- rb_ary_push (o->items, tmp);
+ rb_ary_push (rb_iv_get (self, "items"), tmp);
static VALUE
c_has_key (VALUE self, VALUE key)
{
static VALUE
c_has_key (VALUE self, VALUE key)
{
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
static VALUE
c_compare (VALUE self, VALUE other)
{
static VALUE
c_compare (VALUE self, VALUE other)
{
- RbVorbisComments *o, *o2;
struct RArray *a, *b;
int i, j;
if (rb_obj_is_kind_of (other, CLASS_OF (self)) != Qtrue)
rb_raise (rb_eArgError, "invalid argument");
struct RArray *a, *b;
int i, j;
if (rb_obj_is_kind_of (other, CLASS_OF (self)) != Qtrue)
rb_raise (rb_eArgError, "invalid argument");
- Data_Get_Struct (self, RbVorbisComments, o);
- Data_Get_Struct (other, RbVorbisComments, o2);
-
- a = RARRAY (o->items);
- b = RARRAY (o2->items);
+ a = RARRAY (rb_iv_get (self, "items"));
+ b = RARRAY (rb_iv_get (other, "items"));
if (a->len < b->len)
return -1;
if (a->len < b->len)
return -1;
static VALUE
c_each (VALUE self)
{
static VALUE
c_each (VALUE self)
{
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
static VALUE
c_each_key (VALUE self)
{
static VALUE
c_each_key (VALUE self)
{
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
static VALUE
c_each_value (VALUE self)
{
static VALUE
c_each_value (VALUE self)
{
struct RArray *items;
int i;
struct RArray *items;
int i;
- Data_Get_Struct (self, RbVorbisComments, o);
-
- items = RARRAY (o->items);
+ items = RARRAY (rb_iv_get (self, "items"));
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
c = rb_define_class_under (mVorbis, "Comments", rb_cObject);
c = rb_define_class_under (mVorbis, "Comments", rb_cObject);
- rb_define_alloc_func (c, c_alloc);
-
rb_define_method (c, "inspect", c_inspect, 0);
rb_define_method (c, "clear", c_clear, 0);
rb_define_method (c, "delete", c_delete, 1);
rb_define_method (c, "inspect", c_inspect, 0);
rb_define_method (c, "clear", c_clear, 0);
rb_define_method (c, "delete", c_delete, 1);
VALUE Init_Comments (VALUE mVorbis);
void comments_init (VALUE self, vcedit_state *state);
VALUE Init_Comments (VALUE mVorbis);
void comments_init (VALUE self, vcedit_state *state);
-void comments_sync (VALUE self);
+void comments_sync (VALUE self, vcedit_state *state);
#endif /* __COMMENTS_H */
#endif /* __COMMENTS_H */
Data_Get_Struct (self, RbVorbisTagger, o);
Data_Get_Struct (self, RbVorbisTagger, o);
- comments_sync (o->comments);
+ comments_sync (o->comments, o->state);
/* seek back to BOF */
rb_funcall (o->io, id_seek, 1, INT2FIX (0));
/* seek back to BOF */
rb_funcall (o->io, id_seek, 1, INT2FIX (0));