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

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
This commit is contained in:
nobu 2014-11-13 02:56:14 +00:00
parent 867aafe409
commit 54af8757b3
4 changed files with 17 additions and 8 deletions

View file

@ -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

View file

@ -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 \

View file

@ -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); \
})

9
st.c
View file

@ -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