1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-09-28 15:27:24 +00:00
parent ae7eb5fe83
commit c47b523246
3 changed files with 49 additions and 22 deletions

View file

@ -38,6 +38,8 @@ Init_md5()
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));
}

View file

@ -49,6 +49,8 @@ extern "C" {
#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 {
*/
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_data_type_t *);
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)
}
}
#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))

View file

@ -28,8 +28,6 @@
#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)
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);