Fwd: nobu:r47717 (trunk): ruby.h: deprecate plain Data

$B$A$g$C$H$$$-$J$j$3$l$OL5$$$s$8$cL5$$$G$7$g$&$+!#(B
$B%I%-%e%a%s%H$b$J$$$7!J$“$l!”$"$k$N$+$J!K!#(B

$B$"$kDxEY!“0\9T%Q%9$r9M$($F$+$i$8$c$J$$$H!#(B
$B$s$G!“0\9T$7$F$b!”$=$s$J$K9,J!$K$J$l$J$$5$$,$9$k$N$G!”$b$&$A$g$C$H4|4V$r(B
$B$*$$$F$d$k$H$$$$$H;W$$$^$9!#(B

-------- 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 [email protected]
Reply-To: [email protected]
To: [email protected]

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);
  • if (st_update((st_table *)DATA_PTR(self), (st_data_t)key,
    update_func, 0))
  • 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)

On 2014/09/28 0:34, SASADA Koichi wrote:

$B$A$g$C$H$$$-$J$j$3$l$OL5$$$s$8$cL5$$$G$7$g$&$+!#(B
$B%I%-%e%a%s%H$b$J$$$7!J$"$l!"$"$k$N$+$J!K!#(B

$B$"$kDxEY!“0\9T%Q%9$r9M$($F$+$i$8$c$J$$$H!#(B
$B$s$G!“0\9T$7$F$b!”$=$s$J$K9,J!$K$J$l$J$$5$$,$9$k$N$G!”$b$&$A$g$C$H4|4V$r(B
$B$*$$$F$d$k$H$$$$$H;W$$$^$9!#(B

DEPRECATED$B$O$J$7$K$7$^$7$?!#(B
$BFbIt$@$1$G;H$&1#$7%%V%8%’%/%H$d!"(Binitialize_copy$B$J$I$r;}$?$J$$%%V%8%’%/%H$J$i!"4m81$O$J$$$+$i$G$9!#(B

$B$=$NBe$o$j!"(B-DRUBY_UNTYPED_DATA_WARNING=1$B$G%3%s%Q%$%k$7$?$H$-$K7Y9p$r=P$9$h$&$K$7$F$_$^$7$?!#(B

斎藤と申します。

2014-09-28 0:34 GMT+09:00 SASADA Koichi [email protected]:

ドキュメントもないし(あれ、あるのかな)。

そろそろ #3064 の再オープンを希望します。