ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:48582] Fwd: [ruby-changes:35635] nobu:r47717 (trunk): ruby.h: deprecate plain Data
       [not found] <20140927012901.69ACA118105@sakura2.atdot.net>
@ 2014-09-27 15:34 ` SASADA Koichi
  2014-09-29  6:39   ` [ruby-dev:48585] " Nobuyoshi Nakada
  0 siblings, 1 reply; 3+ messages in thread
From: SASADA Koichi @ 2014-09-27 15:34 UTC (permalink / raw
  To: ruby-dev

ちょっといきなりこれは無いんじゃ無いでしょうか。
ドキュメントもないし(あれ、あるのかな)。

ある程度、移行パスを考えてからじゃないと。
んで、移行しても、そんなに幸福になれない気がするので、もうちょっと期間を
おいてやるといいと思います。


-------- Forwarded Message --------
Subject: [ruby-changes:35635] nobu:r47717 (trunk): ruby.h: deprecate
plain Data
Date: Sat, 27 Sep 2014 10:29:01 +0900 (JST)
From: nobu <ko1@atdot•net>
Reply-To: ruby-changes@quickml•atdot.net
To: ruby-changes@quickml•atdot.net

nobu	2014-09-27 10:28:47 +0900 (Sat, 27 Sep 2014)

  New Revision: 47717

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

  Log:
    ruby.h: deprecate plain Data

    * include/ruby/ruby.h (rb_data_object_alloc_deprecated): deprecate
      Data_Make_Struct and Data_Wrap_Struct.  [EXPERIMENTAL]

  Modified files:
    trunk/ext/-test-/marshal/usr/usrmarshal.c
    trunk/ext/-test-/st/numhash/numhash.c
    trunk/gc.c
    trunk/include/ruby/ruby.h
    trunk/marshal.c
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 47716)
+++ include/ruby/ruby.h	(revision 47717)
@@ -973,7 +973,23 @@ struct RTypedData {
https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L973
 */
 typedef void (*RUBY_DATA_FUNC)(void*);

+#ifndef RUBY_DEPRECATE_DATA_WRAP_STRUCT
+# ifdef RUBY_EXPORT
+#   define RUBY_DEPRECATE_DATA_WRAP_STRUCT 1
+# else
+#   define RUBY_DEPRECATE_DATA_WRAP_STRUCT 0
+# endif
+#endif
 VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
+#if RUBY_DEPRECATE_DATA_WRAP_STRUCT
+DEPRECATED(static inline VALUE
rb_data_object_alloc_deprecated(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC));
+static inline VALUE
+rb_data_object_alloc_deprecated(VALUE klass, void *ptr, RUBY_DATA_FUNC
mark, RUBY_DATA_FUNC free)
+{
+    return rb_data_object_alloc(klass, ptr, mark, free);
+}
+#define rb_data_object_alloc rb_data_object_alloc_deprecated
+#endif
 VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const
rb_data_type_t *);
 int rb_typeddata_inherited_p(const rb_data_type_t *child, const
rb_data_type_t *parent);
 int rb_typeddata_is_kind_of(VALUE, const rb_data_type_t *);
Index: gc.c
===================================================================
--- gc.c	(revision 47716)
+++ gc.c	(revision 47717)
@@ -31,6 +31,8 @@ https://github.com/ruby/ruby/blob/trunk/gc.c#L31
 #include <sys/types.h>
 #include <assert.h>

+#undef rb_data_object_alloc
+
 #ifndef __has_feature
 # define __has_feature(x) 0
 #endif
Index: ext/-test-/st/numhash/numhash.c
===================================================================
--- ext/-test-/st/numhash/numhash.c	(revision 47716)
+++ ext/-test-/st/numhash/numhash.c	(revision 47717)
@@ -7,16 +7,29 @@ numhash_free(void *ptr)
https://github.com/ruby/ruby/blob/trunk/ext/-test-/st/numhash/numhash.c#L7
     if (ptr) st_free_table(ptr);
 }

+static size_t
+numhash_memsize(const void *ptr)
+{
+    return ptr ? st_memsize(ptr) : 0;
+}
+
+static const rb_data_type_t numhash_type = {
+    "numhash",
+    {0, numhash_free, numhash_memsize,},
+    NULL, NULL,
+    RUBY_TYPED_FREE_IMMEDIATELY|RUBY_TYPED_WB_PROTECTED,
+};
+
 static VALUE
 numhash_alloc(VALUE klass)
 {
-    return Data_Wrap_Struct(klass, 0, numhash_free, 0);
+    return TypedData_Wrap_Struct(klass, &numhash_type, 0);
 }

 static VALUE
 numhash_init(VALUE self)
 {
-    st_table *tbl = (st_table *)DATA_PTR(self);
+    st_table *tbl = (st_table *)Check_TypedStruct(self, &numhash_type);
     if (tbl) st_free_table(tbl);
     DATA_PTR(self) = st_init_numtable();
     return self;
@@ -26,8 +39,9 @@ static VALUE
https://github.com/ruby/ruby/blob/trunk/ext/-test-/st/numhash/numhash.c#L39
 numhash_aref(VALUE self, VALUE key)
 {
     st_data_t data;
+    st_table *tbl = (st_table *)Check_TypedStruct(self, &numhash_type);
     if (!SPECIAL_CONST_P(key)) rb_raise(rb_eArgError, "not a special
const");
-    if (st_lookup((st_table *)DATA_PTR(self), (st_data_t)key, &data))
+    if (st_lookup(tbl, (st_data_t)key, &data))
 	return (VALUE)data;
     return Qnil;
 }
@@ -35,9 +49,10 @@ numhash_aref(VALUE self, VALUE key)
https://github.com/ruby/ruby/blob/trunk/ext/-test-/st/numhash/numhash.c#L49
 static VALUE
 numhash_aset(VALUE self, VALUE key, VALUE data)
 {
+    st_table *tbl = (st_table *)Check_TypedStruct(self, &numhash_type);
     if (!SPECIAL_CONST_P(key)) rb_raise(rb_eArgError, "not a special
const");
     if (!SPECIAL_CONST_P(data)) rb_raise(rb_eArgError, "not a special
const");
-    st_insert((st_table *)DATA_PTR(self), (st_data_t)key, (st_data_t)data);
+    st_insert(tbl, (st_data_t)key, (st_data_t)data);
     return self;
 }

@@ -53,7 +68,7 @@ numhash_i(st_data_t key, st_data_t value
https://github.com/ruby/ruby/blob/trunk/ext/-test-/st/numhash/numhash.c#L68
 static VALUE
 numhash_each(VALUE self)
 {
-    st_table *table = DATA_PTR(self);
+    st_table *table = (st_table *)Check_TypedStruct(self, &numhash_type);
     st_data_t data = (st_data_t)self;
     return st_foreach_check(table, numhash_i, data, data) ? Qtrue : Qfalse;
 }
@@ -76,7 +91,8 @@ update_func(st_data_t *key, st_data_t *v
https://github.com/ruby/ruby/blob/trunk/ext/-test-/st/numhash/numhash.c#L91
 static VALUE
 numhash_update(VALUE self, VALUE key)
 {
-    if (st_update((st_table *)DATA_PTR(self), (st_data_t)key,
update_func, 0))
+    st_table *table = (st_table *)Check_TypedStruct(self, &numhash_type);
+    if (st_update(table, (st_data_t)key, update_func, 0))
 	return Qtrue;
     else
 	return Qfalse;
@@ -91,14 +107,16 @@ numhash_update(VALUE self, VALUE key)
https://github.com/ruby/ruby/blob/trunk/ext/-test-/st/numhash/numhash.c#L107
 static VALUE
 numhash_size(VALUE self)
 {
-    return ST2NUM(((st_table *)DATA_PTR(self))->num_entries);
+    st_table *table = (st_table *)Check_TypedStruct(self, &numhash_type);
+    return ST2NUM(table->num_entries);
 }

 static VALUE
 numhash_delete_safe(VALUE self, VALUE key)
 {
+    st_table *table = (st_table *)Check_TypedStruct(self, &numhash_type);
     st_data_t val, k = (st_data_t)key;
-    if (st_delete_safe((st_table *)DATA_PTR(self), &k, &val,
(st_data_t)self)) {
+    if (st_delete_safe(table, &k, &val, (st_data_t)self)) {
 	return val;
     }
     return Qnil;
Index: ext/-test-/marshal/usr/usrmarshal.c
===================================================================
--- ext/-test-/marshal/usr/usrmarshal.c	(revision 47716)
+++ ext/-test-/marshal/usr/usrmarshal.c	(revision 47717)
@@ -1,23 +1,38 @@
https://github.com/ruby/ruby/blob/trunk/ext/-test-/marshal/usr/usrmarshal.c#L1
 #include <ruby.h>

+static size_t
+usr_size(const void *ptr)
+{
+    return sizeof(int);
+}
+
+static const rb_data_type_t usrmarshal_type = {
+    "UsrMarshal",
+    {0, RUBY_DEFAULT_FREE, usr_size,},
+    NULL, NULL,
+    RUBY_TYPED_FREE_IMMEDIATELY|RUBY_TYPED_WB_PROTECTED,
+};
+
 static VALUE
 usr_alloc(VALUE klass)
 {
     int *p;
-    return Data_Make_Struct(klass, int, 0, RUBY_DEFAULT_FREE, p);
+    return TypedData_Make_Struct(klass, int, &usrmarshal_type, p);
 }

 static VALUE
 usr_init(VALUE self, VALUE val)
 {
-    *(int *)DATA_PTR(self) = NUM2INT(val);
+    int *ptr = Check_TypedStruct(self, &usrmarshal_type);
+    *ptr = NUM2INT(val);
     return self;
 }

 static VALUE
 usr_value(VALUE self)
 {
-    int val = *(int *)DATA_PTR(self);
+    int *ptr = Check_TypedStruct(self, &usrmarshal_type);
+    int val = *ptr;
     return INT2NUM(val);
 }

Index: marshal.c
===================================================================
--- marshal.c	(revision 47716)
+++ marshal.c	(revision 47717)
@@ -28,6 +28,8 @@ https://github.com/ruby/ruby/blob/trunk/marshal.c#L28
 #include <ieeefp.h>
 #endif

+#undef rb_data_object_alloc
+
 #define BITSPERSHORT (2*CHAR_BIT)
 #define SHORTMASK ((1<<BITSPERSHORT)-1)
 #define SHORTDN(x) RSHIFT((x),BITSPERSHORT)

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-dev:48585] Re: Fwd: [ruby-changes:35635] nobu:r47717 (trunk): ruby.h: deprecate plain Data
  2014-09-27 15:34 ` [ruby-dev:48582] Fwd: [ruby-changes:35635] nobu:r47717 (trunk): ruby.h: deprecate plain Data SASADA Koichi
@ 2014-09-29  6:39   ` Nobuyoshi Nakada
  2014-10-07  2:43     ` [ruby-dev:48602] " Tadashi Saito
  0 siblings, 1 reply; 3+ messages in thread
From: Nobuyoshi Nakada @ 2014-09-29  6:39 UTC (permalink / raw
  To: Ruby developers (Japanese)

On 2014/09/28 0:34, SASADA Koichi wrote:
> ちょっといきなりこれは無いんじゃ無いでしょうか。
> ドキュメントもないし(あれ、あるのかな)。
> 
> ある程度、移行パスを考えてからじゃないと。
> んで、移行しても、そんなに幸福になれない気がするので、もうちょっと期間を
> おいてやるといいと思います。

DEPRECATEDはなしにしました。
内部だけで使う隠しオブジェクトや、initialize_copyなどを持たないオブジェクトなら、危険はないからです。

その代わり、-DRUBY_UNTYPED_DATA_WARNING=1でコンパイルしたときに警告を出すようにしてみました。

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-dev:48602] Re: Fwd: [ruby-changes:35635] nobu:r47717 (trunk): ruby.h: deprecate plain Data
  2014-09-29  6:39   ` [ruby-dev:48585] " Nobuyoshi Nakada
@ 2014-10-07  2:43     ` Tadashi Saito
  0 siblings, 0 replies; 3+ messages in thread
From: Tadashi Saito @ 2014-10-07  2:43 UTC (permalink / raw
  To: Ruby developers (Japanese)

[-- Attachment #1: Type: text/plain, Size: 279 bytes --]

斎藤と申します。

2014-09-28 0:34 GMT+09:00 SASADA Koichi <ko1@atdot•net>:
> ドキュメントもないし(あれ、あるのかな)。

そろそろ #3064 の再オープンを希望します。
https://bugs.ruby-lang.org/issues/3064

-- 
斎藤ただし

[-- Attachment #2: Type: text/html, Size: 508 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-07  3:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20140927012901.69ACA118105@sakura2.atdot.net>
2014-09-27 15:34 ` [ruby-dev:48582] Fwd: [ruby-changes:35635] nobu:r47717 (trunk): ruby.h: deprecate plain Data SASADA Koichi
2014-09-29  6:39   ` [ruby-dev:48585] " Nobuyoshi Nakada
2014-10-07  2:43     ` [ruby-dev:48602] " Tadashi Saito

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).