[前][次][番号順一覧][スレッド一覧]

ruby-changes:35709

From: normal <ko1@a...>
Date: Sun, 5 Oct 2014 05:56:20 +0900 (JST)
Subject: [ruby-changes:35709] normal:r47791 (trunk): ext/zlib/zlib.c: TypedData conversion

normal	2014-10-05 05:56:10 +0900 (Sun, 05 Oct 2014)

  New Revision: 47791

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47791

  Log:
    ext/zlib/zlib.c: TypedData conversion
    
    * ext/zlib/zlib.c (zstream_mark, zstream_free): update signature
      (gzfile_mark, gzfile_free): ditto
      (zstream_memsize): new function for rb_data_type->dsize
      (gzfile_memsize): ditto
      (zstream_data_type, gzfile_data_type): new data types
      (zstream_new): Data_Make_Struct => TypedData_Make_Struct
      (gzfile_new): ditto
      (get_zstream, get_gzfile): Data_Get_Struct => TypedData_Get_Struct
      (rb_zstream_flush_next_in): ditto
      (rb_zstream_flush_next_out): ditto
      (rb_zstream_avail_out): ditto
      (rb_zstream_avail_in): ditto
      (rb_zstream_closed_p): ditto
      (rb_deflate_initialize): ditto
      (rb_deflate_init_copy): ditto
      (rb_inflate_initialize): ditto
      (gzfile_ensure_close): ditto
      (rb_gzfile_closed_p): ditto
      (rb_gzfile_path): ditto
      (rb_gzwriter_initialize): ditto
      (rb_gzreader_initialize): ditto
      (rb_gzreader_unused): ditto
      [ruby-core:65377] [Feature #10319]

  Modified files:
    trunk/ChangeLog
    trunk/ext/zlib/zlib.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47790)
+++ ChangeLog	(revision 47791)
@@ -1,3 +1,29 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Oct  5 05:46:00 2014  Eric Wong  <e@8...>
+
+	* ext/zlib/zlib.c (zstream_mark, zstream_free): update signature
+	  (gzfile_mark, gzfile_free): ditto
+	  (zstream_memsize): new function for rb_data_type->dsize
+	  (gzfile_memsize): ditto
+	  (zstream_data_type, gzfile_data_type): new data types
+	  (zstream_new): Data_Make_Struct => TypedData_Make_Struct
+	  (gzfile_new): ditto
+	  (get_zstream, get_gzfile): Data_Get_Struct => TypedData_Get_Struct
+	  (rb_zstream_flush_next_in): ditto
+	  (rb_zstream_flush_next_out): ditto
+	  (rb_zstream_avail_out): ditto
+	  (rb_zstream_avail_in): ditto
+	  (rb_zstream_closed_p): ditto
+	  (rb_deflate_initialize): ditto
+	  (rb_deflate_init_copy): ditto
+	  (rb_inflate_initialize): ditto
+	  (gzfile_ensure_close): ditto
+	  (rb_gzfile_closed_p): ditto
+	  (rb_gzfile_path): ditto
+	  (rb_gzwriter_initialize): ditto
+	  (rb_gzreader_initialize): ditto
+	  (rb_gzreader_unused): ditto
+	  [ruby-core:65377] [Feature #10319]
+
 Sat Oct  4 16:24:41 2014  Rei Odaira  <Rei.Odaira@g...>
 
 	* test/test_syslog.rb (TestSyslog#test_log): In AIX, each output
Index: ext/zlib/zlib.c
===================================================================
--- ext/zlib/zlib.c	(revision 47790)
+++ ext/zlib/zlib.c	(revision 47791)
@@ -88,8 +88,8 @@ static void zstream_reset(struct zstream https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L88
 static VALUE zstream_end(struct zstream*);
 static void zstream_run(struct zstream*, Bytef*, long, int);
 static VALUE zstream_sync(struct zstream*, Bytef*, long);
-static void zstream_mark(struct zstream*);
-static void zstream_free(struct zstream*);
+static void zstream_mark(void*);
+static void zstream_free(void*);
 static VALUE zstream_new(VALUE, const struct zstream_funcs*);
 static struct zstream *get_zstream(VALUE);
 static void zstream_finalize(struct zstream*);
@@ -134,8 +134,8 @@ static VALUE rb_inflate_set_dictionary(V https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L134
 
 #if GZIP_SUPPORT
 struct gzfile;
-static void gzfile_mark(struct gzfile*);
-static void gzfile_free(struct gzfile*);
+static void gzfile_mark(void*);
+static void gzfile_free(void*);
 static VALUE gzfile_new(VALUE, const struct zstream_funcs*, void (*) _((struct gzfile*)));
 static void gzfile_reset(struct gzfile*);
 static void gzfile_close(struct gzfile*, int);
@@ -1135,8 +1135,9 @@ zstream_sync(struct zstream *z, Bytef *s https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1135
 }
 
 static void
-zstream_mark(struct zstream *z)
+zstream_mark(void *p)
 {
+    struct zstream *z = p;
     rb_gc_mark(z->buf);
     rb_gc_mark(z->input);
 }
@@ -1152,22 +1153,36 @@ zstream_finalize(struct zstream *z) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1153
 }
 
 static void
-zstream_free(struct zstream *z)
+zstream_free(void *p)
 {
+    struct zstream *z = p;
+
     if (ZSTREAM_IS_READY(z)) {
 	zstream_finalize(z);
     }
     xfree(z);
 }
 
+static size_t
+zstream_memsize(const void *p)
+{
+    /* n.b. this does not track memory managed via zalloc/zfree callbacks */
+    return sizeof(struct zstream);
+}
+
+static const rb_data_type_t zstream_data_type = {
+    "zstream",
+    { zstream_mark, zstream_free, zstream_memsize, },
+     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
+};
+
 static VALUE
 zstream_new(VALUE klass, const struct zstream_funcs *funcs)
 {
     VALUE obj;
     struct zstream *z;
 
-    obj = Data_Make_Struct(klass, struct zstream,
-			   zstream_mark, zstream_free, z);
+    obj = TypedData_Make_Struct(klass, struct zstream, &zstream_data_type, z);
     zstream_init(z, funcs);
     z->stream.opaque = (voidpf)obj;
     return obj;
@@ -1181,7 +1196,7 @@ get_zstream(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1196
 {
     struct zstream *z;
 
-    Data_Get_Struct(obj, struct zstream, z);
+    TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
     if (!ZSTREAM_IS_READY(z)) {
 	rb_raise(cZError, "stream is not ready");
     }
@@ -1304,7 +1319,7 @@ rb_zstream_flush_next_in(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1319
     struct zstream *z;
     VALUE dst;
 
-    Data_Get_Struct(obj, struct zstream, z);
+    TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
     dst = zstream_detach_input(z);
     OBJ_INFECT(dst, obj);
     return dst;
@@ -1324,7 +1339,7 @@ rb_zstream_flush_next_out(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1339
 {
     struct zstream *z;
 
-    Data_Get_Struct(obj, struct zstream, z);
+    TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
 
     return zstream_detach_buffer(z);
 }
@@ -1337,7 +1352,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1352
 rb_zstream_avail_out(VALUE obj)
 {
     struct zstream *z;
-    Data_Get_Struct(obj, struct zstream, z);
+    TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
     return rb_uint2inum(z->stream.avail_out);
 }
 
@@ -1364,7 +1379,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1379
 rb_zstream_avail_in(VALUE obj)
 {
     struct zstream *z;
-    Data_Get_Struct(obj, struct zstream, z);
+    TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
     return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_LEN(z->input)));
 }
 
@@ -1422,7 +1437,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1437
 rb_zstream_closed_p(VALUE obj)
 {
     struct zstream *z;
-    Data_Get_Struct(obj, struct zstream, z);
+    TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
     return ZSTREAM_IS_READY(z) ? Qfalse : Qtrue;
 }
 
@@ -1534,7 +1549,7 @@ rb_deflate_initialize(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1549
     int err;
 
     rb_scan_args(argc, argv, "04", &level, &wbits, &memlevel, &strategy);
-    Data_Get_Struct(obj, struct zstream, z);
+    TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
 
     err = deflateInit2(&z->stream, ARG_LEVEL(level), Z_DEFLATED,
 		       ARG_WBITS(wbits), ARG_MEMLEVEL(memlevel),
@@ -1558,7 +1573,7 @@ rb_deflate_init_copy(VALUE self, VALUE o https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1573
     struct zstream *z1, *z2;
     int err;
 
-    Data_Get_Struct(self, struct zstream, z1);
+    TypedData_Get_Struct(self, struct zstream, &zstream_data_type, z1);
     z2 = get_zstream(orig);
 
     if (z1 == z2) return self;
@@ -1877,7 +1892,7 @@ rb_inflate_initialize(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1892
     int err;
 
     rb_scan_args(argc, argv, "01", &wbits);
-    Data_Get_Struct(obj, struct zstream, z);
+    TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
 
     err = inflateInit2(&z->stream, ARG_WBITS(wbits));
     if (err != Z_OK) {
@@ -2226,8 +2241,10 @@ struct gzfile { https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2241
 
 
 static void
-gzfile_mark(struct gzfile *gz)
+gzfile_mark(void *p)
 {
+    struct gzfile *gz = p;
+
     rb_gc_mark(gz->io);
     rb_gc_mark(gz->orig_name);
     rb_gc_mark(gz->comment);
@@ -2237,8 +2254,9 @@ gzfile_mark(struct gzfile *gz) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2254
 }
 
 static void
-gzfile_free(struct gzfile *gz)
+gzfile_free(void *p)
 {
+    struct gzfile *gz = p;
     struct zstream *z = &gz->z;
 
     if (ZSTREAM_IS_READY(z)) {
@@ -2253,6 +2271,24 @@ gzfile_free(struct gzfile *gz) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2271
     xfree(gz);
 }
 
+static size_t
+gzfile_memsize(const void *p)
+{
+    const struct gzfile *gz = p;
+    size_t size = sizeof(struct gzfile);
+
+    if (gz->cbuf)
+	size += GZFILE_CBUF_CAPA;
+
+    return size;
+}
+
+static const rb_data_type_t gzfile_data_type = {
+    "gzfile",
+    { gzfile_mark, gzfile_free, gzfile_memsize, },
+     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
+};
+
 static VALUE
 gzfile_new(klass, funcs, endfunc)
     VALUE klass;
@@ -2262,7 +2298,7 @@ gzfile_new(klass, funcs, endfunc) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2298
     VALUE obj;
     struct gzfile *gz;
 
-    obj = Data_Make_Struct(klass, struct gzfile, gzfile_mark, gzfile_free, gz);
+    obj = TypedData_Make_Struct(klass, struct gzfile, &gzfile_data_type, gz);
     zstream_init(&gz->z, funcs);
     gz->z.flags |= ZSTREAM_FLAG_GZFILE;
     gz->io = Qnil;
@@ -2927,7 +2963,7 @@ get_gzfile(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2963
 {
     struct gzfile *gz;
 
-    Data_Get_Struct(obj, struct gzfile, gz);
+    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
     if (!ZSTREAM_IS_READY(&gz->z)) {
 	rb_raise(cGzError, "closed gzip stream");
     }
@@ -2993,7 +3029,7 @@ gzfile_ensure_close(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3029
 {
     struct gzfile *gz;
 
-    Data_Get_Struct(obj, struct gzfile, gz);
+    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
     if (ZSTREAM_IS_READY(&gz->z)) {
 	gzfile_close(gz, 1);
     }
@@ -3297,7 +3333,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3333
 rb_gzfile_closed_p(VALUE obj)
 {
     struct gzfile *gz;
-    Data_Get_Struct(obj, struct gzfile, gz);
+    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
     return NIL_P(gz->io) ? Qtrue : Qfalse;
 }
 
@@ -3383,7 +3419,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3419
 rb_gzfile_path(VALUE obj)
 {
     struct gzfile *gz;
-    Data_Get_Struct(obj, struct gzfile, gz);
+    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
     return gz->path;
 }
 
@@ -3481,7 +3517,7 @@ rb_gzwriter_initialize(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3517
     }
 
     rb_scan_args(argc, argv, "12", &io, &level, &strategy);
-    Data_Get_Struct(obj, struct gzfile, gz);
+    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
 
     /* this is undocumented feature of zlib */
     gz->level = ARG_LEVEL(level);
@@ -3683,7 +3719,7 @@ rb_gzreader_initialize(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3719
     struct gzfile *gz;
     int err;
 
-    Data_Get_Struct(obj, struct gzfile, gz);
+    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
     rb_scan_args(argc, argv, "1:", &io, &opt);
 
     /* this is undocumented feature of zlib */
@@ -3728,7 +3764,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3764
 rb_gzreader_unused(VALUE obj)
 {
     struct gzfile *gz;
-    Data_Get_Struct(obj, struct gzfile, gz);
+    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
     return gzfile_reader_get_unused(gz);
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]