vcedit_state *state;
VALUE comments;
- VALUE io_buf;
} RbVorbisTagger;
static VALUE c_close (VALUE self);
-static VALUE cComments, eVTError;
+static VALUE cComments, eVTError, io_buf;
static ID id_read, id_write, id_seek, id_length;
static size_t
size_t total = size * nmemb;
VALUE tmp;
- rb_str_resize (o->io_buf, size * nmemb);
+ rb_str_resize (io_buf, size * nmemb);
- tmp = rb_funcall (o->io, id_read, 2, LONG2NUM (total), o->io_buf);
+ tmp = rb_funcall (o->io, id_read, 2, LONG2NUM (total), io_buf);
if (NIL_P (tmp))
return 0;
{
size_t total = size * nmemb;
- rb_str_resize (o->io_buf, total);
- memcpy (RSTRING (o->io_buf)->ptr, ptr, total);
+ rb_str_resize (io_buf, total);
+ memcpy (RSTRING (io_buf)->ptr, ptr, total);
- return NUM2LONG (rb_io_write (o->io, o->io_buf));
+ return NUM2LONG (rb_io_write (o->io, io_buf));
}
static void
{
rb_gc_mark (o->io);
rb_gc_mark (o->comments);
- rb_gc_mark (o->io_buf);
+ rb_gc_mark (io_buf);
}
static void
{
RbVorbisTagger *o;
vorbis_comment *vc;
- int s;
+ int s, i;
Data_Get_Struct (self, RbVorbisTagger, o);
rb_raise (rb_eArgError, "invalid argument");
o->io = io;
- o->io_buf = rb_str_buf_new (BUFSIZ);
o->state = vcedit_state_new ();
if (!o->state)
rb_raise (eVTError, "vcedit_comments() failed - %s",
vcedit_error (o->state));
+ /* check whether all comments are well-formed */
+ for (i = 0; i < vc->comments; i++) {
+ char *ptr, *content = vc->user_comments[i];
+
+ ptr = strchr (content, '=');
+ if (!ptr || ptr == content)
+ rb_raise (eVTError, "malformed comment - %s", content);
+ }
+
o->comments = rb_class_new_instance (0, NULL, cComments);
comments_init (o->comments, o->state);
id_length = rb_intern ("length");
cComments = Init_Comments (mVorbis);
+
+ io_buf = rb_str_buf_new (BUFSIZ);
+ rb_global_variable (&io_buf);
}