X-Git-Url: http://git.code-monkey.de/?p=ruby-eet.git;a=blobdiff_plain;f=ext%2Fext.c;h=d85cd56088783be0f2be26c30c44fdfd2a7a7017;hp=1819958b73976137104e2b3f316ac024e0efaab0;hb=3ec32d2eaff86d232c43cea68d9abb021b7971ac;hpb=3eb6e149e8a04c8e9571588b1782b31891c70a90 diff --git a/ext/ext.c b/ext/ext.c index 1819958..d85cd56 100644 --- a/ext/ext.c +++ b/ext/ext.c @@ -1,5 +1,5 @@ /* - * $Id: ext.c 30 2005-04-12 18:38:31Z tilman $ + * $Id: ext.c 31 2005-04-12 19:03:50Z tilman $ * * Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) * @@ -27,8 +27,6 @@ #include #define CHECK_KEY(key) \ - StringValue((key)); \ -\ if (rb_funcall (key, rb_intern ("include?"), \ 1, INT2FIX (0)) == Qtrue) \ rb_raise (rb_eArgError, "key must not contain binary zeroes"); @@ -108,8 +106,6 @@ c_init (int argc, VALUE *argv, VALUE self) cfile = StringValuePtr (file); if (!NIL_P (mode)) { - StringValue (mode); - tmp = StringValuePtr (mode); if (!strcmp (tmp, "r+")) m = EET_FILE_MODE_READ_WRITE; @@ -221,17 +217,16 @@ static VALUE c_delete (VALUE self, VALUE key) { Eet_File **ef = NULL; - char *tmp; + char *ckey; Data_Get_Struct (self, Eet_File *, ef); CHECK_CLOSED (ef); + ckey = StringValuePtr (key); CHECK_KEY (key); - tmp = StringValuePtr (key); - - if (!eet_delete (*ef, tmp)) - rb_raise (rb_eIOError, "cannot delete entry - %s", tmp); + if (!eet_delete (*ef, ckey)) + rb_raise (rb_eIOError, "cannot delete entry - %s", ckey); return self; } @@ -250,16 +245,18 @@ c_read (VALUE self, VALUE key) VALUE ret; Eet_File **ef = NULL; void *data; + char *ckey; int size = 0; Data_Get_Struct (self, Eet_File *, ef); CHECK_CLOSED (ef); + ckey = StringValuePtr (key); CHECK_KEY (key); - data = eet_read (*ef, StringValuePtr (key), &size); + data = eet_read (*ef, ckey, &size); if (!data) - rb_raise (rb_eIOError, "cannot read entry - %s", key); + rb_raise (rb_eIOError, "cannot read entry - %s", ckey); ret = rb_str_new (data, size); @@ -283,6 +280,7 @@ c_write (int argc, VALUE *argv, VALUE self) { VALUE key = Qnil, buf = Qnil, comp = Qnil; Eet_File **ef = NULL; + char *ckey, *cbuf; int n; Data_Get_Struct (self, Eet_File *, ef); @@ -293,11 +291,12 @@ c_write (int argc, VALUE *argv, VALUE self) if (NIL_P (comp)) comp = Qtrue; + ckey = StringValuePtr (key); CHECK_KEY (key); - StringValue (buf); + cbuf = StringValuePtr (buf); - n = eet_write (*ef, StringValuePtr (key), - StringValuePtr (buf), RSTRING (buf)->len, + n = eet_write (*ef, ckey, + cbuf, RSTRING (buf)->len, comp == Qtrue); if (!n) rb_raise (rb_eIOError, "couldn't write to file"); @@ -323,18 +322,20 @@ c_read_image (VALUE self, VALUE key) VALUE ret, comp; Eet_File **ef = NULL; void *data; + char *ckey; int w = 0, h = 0, has_alpha = 0, level = 0, quality = 0, lossy = 0; Data_Get_Struct (self, Eet_File *, ef); CHECK_CLOSED (ef); + ckey = StringValuePtr (key); CHECK_KEY (key); - data = eet_data_image_read (*ef, StringValuePtr (key), &w, &h, + data = eet_data_image_read (*ef, ckey, &w, &h, &has_alpha, &level, &quality, &lossy); if (!data) - rb_raise (rb_eIOError, "cannot read entry - %s", key); + rb_raise (rb_eIOError, "cannot read entry - %s", ckey); comp = rb_hash_new (); rb_hash_aset (comp, ID2SYM (rb_intern ("lossy")), INT2FIX (lossy)); @@ -371,6 +372,7 @@ c_write_image (int argc, VALUE *argv, VALUE self) VALUE key = Qnil, buf = Qnil, w = Qnil, h = Qnil, has_alpha = Qnil; VALUE comp = Qnil, tmp; Eet_File **ef = NULL; + char *ckey, *cbuf; int n, lossy = 0, level = 9, quality = 100; Data_Get_Struct (self, Eet_File *, ef); @@ -382,8 +384,9 @@ c_write_image (int argc, VALUE *argv, VALUE self) if (NIL_P (has_alpha)) has_alpha = Qfalse; + ckey = StringValuePtr (key); CHECK_KEY (key); - StringValue (buf); + cbuf = StringValuePtr (buf); Check_Type (w, T_FIXNUM); Check_Type (h, T_FIXNUM); @@ -406,8 +409,7 @@ c_write_image (int argc, VALUE *argv, VALUE self) if (!RSTRING (buf)->len) return INT2FIX (0); - n = eet_data_image_write (*ef, StringValuePtr (key), - StringValuePtr (buf), + n = eet_data_image_write (*ef, ckey, cbuf, FIX2INT (w), FIX2INT (h), has_alpha == Qtrue, level, quality, lossy);