ruby-changes:36312
From: nobu <ko1@a...>
Date: Thu, 13 Nov 2014 11:56:31 +0900 (JST)
Subject: [ruby-changes:36312] nobu:r48393 (trunk): internal.h: STATIC_ASSERT
nobu 2014-11-13 11:56:14 +0900 (Thu, 13 Nov 2014) New Revision: 48393 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48393 Log: internal.h: STATIC_ASSERT * st.c: include "internal.h" for STATIC_ASSERT. Modified files: trunk/ChangeLog trunk/common.mk trunk/internal.h trunk/st.c Index: ChangeLog =================================================================== --- ChangeLog (revision 48392) +++ ChangeLog (revision 48393) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Nov 13 11:56:12 2014 Nobuyoshi Nakada <nobu@r...> + + * st.c: include "internal.h" for STATIC_ASSERT. + Thu Nov 13 03:56:38 2014 Eric Wong <e@8...> * gc.c (struct heap_page): trivial packing Index: st.c =================================================================== --- st.c (revision 48392) +++ st.c (revision 48393) @@ -7,6 +7,7 @@ https://github.com/ruby/ruby/blob/trunk/st.c#L7 #include "st.h" #else #include "ruby/ruby.h" +#include "internal.h" #endif #include <stdio.h> @@ -30,7 +31,9 @@ typedef struct st_packed_entry { https://github.com/ruby/ruby/blob/trunk/st.c#L31 st_data_t key, val; } st_packed_entry; -#define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[(expr) ? 1 : -1]; +#ifndef STATIC_ASSERT +#define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[(expr) ? 1 : -1] +#endif #define ST_DEFAULT_MAX_DENSITY 5 #define ST_DEFAULT_INIT_TABLE_SIZE 16 @@ -38,8 +41,8 @@ typedef struct st_packed_entry { https://github.com/ruby/ruby/blob/trunk/st.c#L41 #define PACKED_UNIT (int)(sizeof(st_packed_entry) / sizeof(st_table_entry*)) #define MAX_PACKED_HASH (int)(ST_DEFAULT_PACKED_TABLE_SIZE * sizeof(st_table_entry*) / sizeof(st_packed_entry)) -STATIC_ASSERT(st_packed_entry, sizeof(st_packed_entry) == sizeof(st_table_entry*[PACKED_UNIT])) -STATIC_ASSERT(st_packed_bins, sizeof(st_packed_entry[MAX_PACKED_HASH]) <= sizeof(st_table_entry*[ST_DEFAULT_PACKED_TABLE_SIZE])) +STATIC_ASSERT(st_packed_entry, sizeof(st_packed_entry) == sizeof(st_table_entry*[PACKED_UNIT])); +STATIC_ASSERT(st_packed_bins, sizeof(st_packed_entry[MAX_PACKED_HASH]) <= sizeof(st_table_entry*[ST_DEFAULT_PACKED_TABLE_SIZE])); /* * DEFAULT_MAX_DENSITY is the default for the largest we allow the Index: common.mk =================================================================== --- common.mk (revision 48392) +++ common.mk (revision 48393) @@ -778,7 +778,7 @@ signal.$(OBJEXT): {$(VPATH)}signal.c $(R https://github.com/ruby/ruby/blob/trunk/common.mk#L778 $(VM_CORE_H_INCLUDES) {$(VPATH)}vm_opts.h {$(VPATH)}internal.h {$(VPATH)}ruby_atomic.h {$(VPATH)}eval_intern.h sprintf.$(OBJEXT): {$(VPATH)}sprintf.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h {$(VPATH)}id.h \ {$(VPATH)}regex.h {$(VPATH)}vsnprintf.c $(ENCODING_H_INCLUDES) {$(VPATH)}internal.h -st.$(OBJEXT): {$(VPATH)}st.c $(RUBY_H_INCLUDES) +st.$(OBJEXT): {$(VPATH)}st.c $(RUBY_H_INCLUDES) {$(VPATH)}internal.h strftime.$(OBJEXT): {$(VPATH)}strftime.c $(RUBY_H_INCLUDES) \ {$(VPATH)}timev.h $(ENCODING_H_INCLUDES) string.$(OBJEXT): {$(VPATH)}string.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h {$(VPATH)}gc.h \ Index: internal.h =================================================================== --- internal.h (revision 48392) +++ internal.h (revision 48393) @@ -63,15 +63,18 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L63 #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0]))) -#define STATIC_ASSERT_TYPE(name) static_assert_##name##_check -#define STATIC_ASSERT(name, expr) typedef int STATIC_ASSERT_TYPE(name)[1 - 2*!(expr)] - #define GCC_VERSION_SINCE(major, minor, patchlevel) \ (defined(__GNUC__) && !defined(__INTEL_COMPILER) && \ ((__GNUC__ > (major)) || \ (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \ (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))) +#if GCC_VERSION_SINCE(4, 6, 0) +# STATIC_ASSERT(name, expr) _Static_assert(expr, #name ": " #expr) +#else +# define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[1 - 2*!(expr)] +#endif + #define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1) #define SIGNED_INTEGER_MAX(sint_type) \ (sint_type) \ @@ -516,7 +519,6 @@ VALUE rb_ary_tmp_new_fill(long capa); https://github.com/ruby/ruby/blob/trunk/internal.h#L519 const VALUE args_to_new_ary[] = {__VA_ARGS__}; \ if (__builtin_constant_p(n)) { \ STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \ - (void)sizeof(STATIC_ASSERT_TYPE(rb_ary_new_from_args)); /* suppress warnings by gcc 4.8 or later */ \ } \ rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \ }) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/