ruby-changes:35648
From: nobu <ko1@a...>
Date: Mon, 29 Sep 2014 00:27:35 +0900 (JST)
Subject: [ruby-changes:35648] nobu:r47730 (trunk): ruby.h: warn untyped Data
nobu 2014-09-29 00:27:24 +0900 (Mon, 29 Sep 2014) New Revision: 47730 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47730 Log: ruby.h: warn untyped Data * include/ruby/ruby.h (rb_data_object_alloc_warning): warn Data_Wrap_Struct and Data_Make_Struct only if RUBY_UNTYPED_DATA_WARNING is set to 1. * include/ruby/ruby.h (rb_data_object_get_warning): ditto for Data_Get_Struct. Modified files: trunk/ext/digest/md5/md5init.c trunk/include/ruby/ruby.h trunk/marshal.c Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 47729) +++ include/ruby/ruby.h (revision 47730) @@ -49,6 +49,8 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L49 #define PRINTF_ARGS(decl, string_index, first_to_check) decl #endif +#define RUBY_MACRO_SELECT(base, n) TOKEN_PASTE(base, n) + #ifdef HAVE_INTRINSICS_H # include <intrinsics.h> #endif @@ -973,23 +975,14 @@ struct RTypedData { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L975 */ typedef void (*RUBY_DATA_FUNC)(void*); -#ifndef RUBY_DEPRECATE_DATA_WRAP_STRUCT -# ifdef RUBY_EXPORT -# define RUBY_DEPRECATE_DATA_WRAP_STRUCT 1 +#ifndef RUBY_UNTYPED_DATA_WARNING +# if defined RUBY_EXPORT +# define RUBY_UNTYPED_DATA_WARNING 1 # else -# define RUBY_DEPRECATE_DATA_WRAP_STRUCT 0 +# define RUBY_UNTYPED_DATA_WARNING 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 *); @@ -1020,14 +1013,11 @@ void *rb_check_typeddata(VALUE, const rb https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1013 TypedData_Wrap_Struct((klass),(data_type),(sval))\ ) -#define Data_Get_Struct(obj,type,sval) do {\ - Check_Type((obj), T_DATA); \ - (sval) = (type*)DATA_PTR(obj);\ -} while (0) +#define Data_Get_Struct(obj,type,sval) \ + ((sval) = (type*)rb_data_object_get(obj)) -#define TypedData_Get_Struct(obj,type,data_type,sval) do {\ - (sval) = (type*)rb_check_typeddata((obj), (data_type)); \ -} while (0) +#define TypedData_Get_Struct(obj,type,data_type,sval) \ + ((sval) = (type*)rb_check_typeddata((obj), (data_type))) #define RSTRUCT_EMBED_LEN_MAX 3 struct RStruct { @@ -1144,6 +1134,41 @@ rb_obj_freeze_inline(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1134 } } +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +# define RUBY_UNTYPED_DATA_FUNC(func) func __attribute__((warning("untyped Data is unsafe; use TypedData instead"))) +#else +# define RUBY_UNTYPED_DATA_FUNC(func) DEPRECATED(func) +#endif + +RUBY_UNTYPED_DATA_FUNC(static inline VALUE rb_data_object_alloc_warning(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC)); +RUBY_UNTYPED_DATA_FUNC(static inline void *rb_data_object_get_warning(VALUE)); + +static inline VALUE +rb_data_object_alloc_warning(VALUE klass, void *ptr, RUBY_DATA_FUNC mark, RUBY_DATA_FUNC free) +{ + return rb_data_object_alloc(klass, ptr, mark, free); +} + +static inline void * +rb_data_object_get(VALUE obj) +{ + Check_Type(obj, T_DATA); + return ((struct RData *)obj)->data; +} + +static inline void * +rb_data_object_get_warning(VALUE obj) +{ + return rb_data_object_get(obj); +} + +#define rb_data_object_alloc_0 rb_data_object_alloc +#define rb_data_object_alloc_1 rb_data_object_alloc_warning +#define rb_data_object_alloc RUBY_MACRO_SELECT(rb_data_object_alloc_, RUBY_UNTYPED_DATA_WARNING) +#define rb_data_object_get_0 rb_data_object_get +#define rb_data_object_get_1 rb_data_object_get_warning +#define rb_data_object_get RUBY_MACRO_SELECT(rb_data_object_get_, RUBY_UNTYPED_DATA_WARNING) + #if USE_RGENGC #define OBJ_PROMOTED_RAW(x) ((RBASIC(x)->flags & (FL_PROMOTED0|FL_PROMOTED1)) == (FL_PROMOTED0|FL_PROMOTED1)) #define OBJ_PROMOTED(x) (SPECIAL_CONST_P(x) ? 0 : OBJ_PROMOTED_RAW(x)) Index: ext/digest/md5/md5init.c =================================================================== --- ext/digest/md5/md5init.c (revision 47729) +++ ext/digest/md5/md5init.c (revision 47730) @@ -38,6 +38,8 @@ Init_md5() https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5init.c#L38 cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base); +#undef RUBY_UNTYPED_DATA_WARNING +#define RUBY_UNTYPED_DATA_WARNING 0 rb_ivar_set(cDigest_MD5, rb_intern("metadata"), Data_Wrap_Struct(rb_cObject, 0, 0, (void *)&md5)); } Index: marshal.c =================================================================== --- marshal.c (revision 47729) +++ marshal.c (revision 47730) @@ -28,8 +28,6 @@ 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) @@ -2171,6 +2169,8 @@ Init_marshal(void) https://github.com/ruby/ruby/blob/trunk/marshal.c#L2169 rb_define_const(rb_mMarshal, "MINOR_VERSION", INT2FIX(MARSHAL_MINOR)); compat_allocator_tbl = st_init_numtable(); +#undef RUBY_UNTYPED_DATA_WARNING +#define RUBY_UNTYPED_DATA_WARNING 0 compat_allocator_tbl_wrapper = Data_Wrap_Struct(rb_cData, mark_marshal_compat_t, 0, compat_allocator_tbl); rb_gc_register_mark_object(compat_allocator_tbl_wrapper); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/