diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-13 02:56:14 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-13 02:56:14 +0000 |
commit | 54af8757b337a7347a230d450cfda9e2b0c94560 (patch) | |
tree | 709753e211aee6f76724c045f360271ecda0fede | |
parent | 867aafe409b8c8ba8c443d9c0651b804538fa71f (diff) | |
download | ruby-54af8757b337a7347a230d450cfda9e2b0c94560.tar.gz |
internal.h: STATIC_ASSERT
* st.c: include "internal.h" for STATIC_ASSERT.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | common.mk | 2 | ||||
-rw-r--r-- | internal.h | 10 | ||||
-rw-r--r-- | st.c | 9 |
4 files changed, 17 insertions, 8 deletions
@@ -1,3 +1,7 @@ +Thu Nov 13 11:56:12 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * st.c: include "internal.h" for STATIC_ASSERT. + Thu Nov 13 03:56:38 2014 Eric Wong <e@80x24.org> * gc.c (struct heap_page): trivial packing @@ -778,7 +778,7 @@ signal.$(OBJEXT): {$(VPATH)}signal.c $(RUBY_H_INCLUDES) \ $(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 \ diff --git a/internal.h b/internal.h index ca3649d0f6..5f38b4e146 100644 --- a/internal.h +++ b/internal.h @@ -63,15 +63,18 @@ extern "C" { #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); 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); \ }) @@ -7,6 +7,7 @@ #include "st.h" #else #include "ruby/ruby.h" +#include "internal.h" #endif #include <stdio.h> @@ -30,7 +31,9 @@ typedef struct st_packed_entry { 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 { #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 |