ext/jpeg_jpeg.c in jpeg-0.0.2 vs ext/jpeg_jpeg.c in jpeg-0.1.0

- old
+ new

@@ -3,11 +3,10 @@ #include "jpeg_jpeg.h" VALUE Jpeg; static VALUE jpeg_jpeg_s_open(int argc, VALUE *argv, VALUE sef); -static VALUE jpeg_jpeg_s_open_buffer(int argc, VALUE *argv, VALUE sef); static VALUE jpeg_jpeg_alloc(VALUE klass); static void jpeg_jpeg_mark(struct jpeg_jpeg *p); static void jpeg_jpeg_free(struct jpeg_jpeg *p); static VALUE jpeg_jpeg_width(VALUE self); static VALUE jpeg_jpeg_height(VALUE self); @@ -15,11 +14,10 @@ void Init_jpeg_jpeg() { Jpeg = rb_define_class("Jpeg", rb_cObject); rb_define_alloc_func(Jpeg, jpeg_jpeg_alloc); rb_define_singleton_method(Jpeg, "open", jpeg_jpeg_s_open, -1); - rb_define_singleton_method(Jpeg, "open_buffer", jpeg_jpeg_s_open_buffer, -1); rb_define_method(Jpeg, "width", jpeg_jpeg_width, 0); rb_define_method(Jpeg, "height", jpeg_jpeg_height, 0); rb_define_method(Jpeg, "size", jpeg_jpeg_size, 0); } @@ -37,15 +35,18 @@ static void jpeg_jpeg_mark(struct jpeg_jpeg *p) { } static void jpeg_jpeg_free(struct jpeg_jpeg *p) { - // if (p->read) { - // jpeg_destroy_compress(p->read); - // free(p->read); - //} - //xfree(p); + if (p->read) { + jpeg_destroy_compress(p->read); + free(p->read); + } + if (p->error) { + free(p->error); + } + xfree(p); } static VALUE jpeg_jpeg_s_open(int argc, VALUE *argv, VALUE self) { VALUE path; VALUE jpeg; @@ -56,38 +57,16 @@ Check_Type(path, T_STRING); jpeg = rb_funcall(Jpeg, rb_intern("new"), 0); Data_Get_Struct(jpeg, struct jpeg_jpeg, p_jpeg); - fp = fopen(RSTRING_PTR(path), "rb"); + if ((fp = fopen(RSTRING_PTR(path), "rb")) == NULL) { + rb_raise(rb_eRuntimeError, "Open file failed"); + } jpeg_stdio_src(p_jpeg->read, fp); jpeg_read_header(p_jpeg->read, TRUE); jpeg_start_decompress(p_jpeg->read); fclose(fp); - return jpeg; -} - -static VALUE jpeg_jpeg_s_open_buffer(int argc, VALUE *argv, VALUE self) { - VALUE buffer; - VALUE jpeg; - struct jpeg_jpeg *p_jpeg; - void *data = NULL; - int len = 0; - int errorp; - int buffer_is_temporary = 0; - - rb_scan_args(argc, argv, "1", &buffer); - - if (TYPE(buffer) == T_STRING) { - data = RSTRING_PTR(buffer); - len = RSTRING_LEN(buffer); - } else { - rb_raise(rb_eTypeError, "wrong argument type %s (expected String)", rb_class2name(CLASS_OF(buffer))); - } - - jpeg = rb_funcall(Jpeg, rb_intern("new"), 0); - Data_Get_Struct(jpeg, struct jpeg_jpeg, p_jpeg); - return jpeg; } static VALUE jpeg_jpeg_width(VALUE self) { struct jpeg_jpeg *p_jpeg;