X-Git-Url: http://git.code-monkey.de/?p=ruby-vorbistagger.git;a=blobdiff_plain;f=ext%2Fext.c;h=6a45359772e325ff0ca6c75f8a265917cb77df76;hp=67fa6b14b24811514db40966ca373d1050c9bbf8;hb=2f95f6bbefc52f171610f8a4c49157907ced3e14;hpb=2a86264bbe06e4e24e86170ece78e0ed8bf24e32 diff --git a/ext/ext.c b/ext/ext.c index 67fa6b1..6a45359 100644 --- a/ext/ext.c +++ b/ext/ext.c @@ -25,6 +25,10 @@ #include "vcedit.h" #include "comments.h" +#define CHECK_CLOSED(o) \ + if (!o->state) \ + rb_raise (eClosed, "closed stream"); + typedef struct { vcedit_state *state; VALUE comments; @@ -32,8 +36,8 @@ typedef struct { static VALUE c_close (VALUE self); -static VALUE cComments, eVT, eOpen, eInvalidData, eInvalidComment, - eTempFile, eReopen; +static VALUE cComments, eVT, eClosed, eOpen, eInvalidData, + eInvalidComment, eTempFile, eReopen; static ID id_length; static void @@ -149,6 +153,8 @@ c_close (VALUE self) Data_Get_Struct (self, RbVorbisTagger, o); + CHECK_CLOSED (o); + vcedit_state_unref (o->state); o->state = NULL; @@ -169,6 +175,8 @@ c_write (VALUE self) Data_Get_Struct (self, RbVorbisTagger, o); + CHECK_CLOSED (o); + comments_sync (o->comments, o->state); switch (vcedit_write (o->state)) { @@ -199,6 +207,8 @@ c_comments (VALUE self) Data_Get_Struct (self, RbVorbisTagger, o); + CHECK_CLOSED (o); + return o->comments; } @@ -225,6 +235,7 @@ Init_vorbistagger_ext (void) rb_define_method (cVT, "comments", c_comments, 0); eVT = rb_define_class_under (cVT, "TaggerError", eVorbis); + eClosed = rb_define_class_under (cVT, "ClosedStreamError", eVT); eOpen = rb_define_class_under (cVT, "OpenError", eVT); eInvalidData = rb_define_class_under (cVT, "InvalidDataError", eVT); eInvalidComment = rb_define_class_under (cVT, "InvalidCommentError",