Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
abf2d653
Unverified
Commit
abf2d653
authored
3 years ago
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
3 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5564 from dearblue/static_assert
Make `mrb_static_assert()` a variable argument
parents
5c6e8b32
b774832e
master
stable
3.1.0-rc
No related merge requests found
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
13 deletions
+31
-13
include/mruby.h
include/mruby.h
+23
-5
include/mruby/boxing_nan.h
include/mruby/boxing_nan.h
+1
-1
include/mruby/boxing_word.h
include/mruby/boxing_word.h
+1
-1
mrbgems/mruby-random/src/random.c
mrbgems/mruby-random/src/random.c
+1
-1
src/gc.c
src/gc.c
+1
-1
src/hash.c
src/hash.c
+3
-3
src/load.c
src/load.c
+1
-1
No files found.
include/mruby.h
View file @
abf2d653
...
...
@@ -69,14 +69,18 @@
#define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
#endif
#if (defined __cplusplus && __cplusplus >= 201103L) || \
#if (defined __cplusplus && __cplusplus >= 201703L)
# define mrb_static_assert(...) static_assert(__VA_ARGS__)
# define mrb_static_assert1(exp) static_assert(exp)
# define mrb_static_assert2(exp, str) static_assert(exp, str)
#elif (defined __cplusplus && __cplusplus >= 201103L) || \
(defined _MSC_VER) || \
(defined __GXX_EXPERIMENTAL_CXX0X__)
/* for old G++/Clang++ */
# define mrb_static_assert(exp, str) static_assert(exp, str)
# define mrb_static_assert
2
(exp, str) static_assert(exp, str)
#elif defined __STDC_VERSION__ && \
((__STDC_VERSION__ >= 201112L) || \
(defined __GNUC__ && __GNUC__ * 100 + __GNUC_MINOR__ >= 406))
# define mrb_static_assert(exp, str) _Static_assert(exp, str)
# define mrb_static_assert
2
(exp, str) _Static_assert(exp, str)
#else
#
/* alternative implementation of static_assert() */
# define _mrb_static_assert_cat0(a, b) a##b
...
...
@@ -86,10 +90,24 @@
# else
# define _mrb_static_assert_id(prefix) _mrb_static_assert_cat(prefix, __LINE__)
# endif
# define mrb_static_assert(exp, str) \
# define mrb_static_assert
2
(exp, str) \
struct _mrb_static_assert_id(_mrb_static_assert_) { char x[(exp) ? 1 : -1]; }
#endif
#define mrb_static_assert1(exp) mrb_static_assert(exp, #exp)
#ifndef mrb_static_assert
# define mrb_static_assert1(exp) mrb_static_assert2(exp, #exp)
# define mrb_static_assert_expand(...) __VA_ARGS__
/* for MSVC behaviour - https://stackoverflow.com/q/5530505 */
# define mrb_static_assert_selector(a, b, name, ...) name
/**
* The `mrb_static_assert()` macro function takes one or two arguments.
*
* !!!c
* mrb_static_assert(expect_condition);
* mrb_static_assert(expect_condition, error_message);
*/
# define mrb_static_assert(...) \
mrb_static_assert_expand(mrb_static_assert_selector(__VA_ARGS__, mrb_static_assert2, mrb_static_assert1)(__VA_ARGS__))
#endif
#include "mrbconf.h"
...
...
This diff is collapsed.
Click to expand it.
include/mruby/boxing_nan.h
View file @
abf2d653
...
...
@@ -54,7 +54,7 @@ union mrb_value_ {
mrb_value
value
;
};
mrb_static_assert
1
(
sizeof
(
mrb_value
)
==
sizeof
(
union
mrb_value_
));
mrb_static_assert
(
sizeof
(
mrb_value
)
==
sizeof
(
union
mrb_value_
));
static
inline
union
mrb_value_
mrb_val_union
(
mrb_value
v
)
...
...
This diff is collapsed.
Click to expand it.
include/mruby/boxing_word.h
View file @
abf2d653
...
...
@@ -130,7 +130,7 @@ union mrb_value_ {
mrb_value
value
;
};
mrb_static_assert
1
(
sizeof
(
mrb_value
)
==
sizeof
(
union
mrb_value_
));
mrb_static_assert
(
sizeof
(
mrb_value
)
==
sizeof
(
union
mrb_value_
));
static
inline
union
mrb_value_
mrb_val_union
(
mrb_value
v
)
...
...
This diff is collapsed.
Click to expand it.
mrbgems/mruby-random/src/random.c
View file @
abf2d653
...
...
@@ -355,7 +355,7 @@ void mrb_mruby_random_gem_init(mrb_state *mrb)
struct
RClass
*
random
;
struct
RClass
*
array
=
mrb
->
array_class
;
mrb_static_assert
1
(
sizeof
(
rand_state
)
<=
ISTRUCT_DATA_SIZE
);
mrb_static_assert
(
sizeof
(
rand_state
)
<=
ISTRUCT_DATA_SIZE
);
mrb_define_method
(
mrb
,
mrb
->
kernel_module
,
"rand"
,
random_f_rand
,
MRB_ARGS_OPT
(
1
));
mrb_define_method
(
mrb
,
mrb
->
kernel_module
,
"srand"
,
random_f_srand
,
MRB_ARGS_OPT
(
1
));
...
...
This diff is collapsed.
Click to expand it.
src/gc.c
View file @
abf2d653
...
...
@@ -200,7 +200,7 @@ gettimeofday_time(void)
#define GC_RED MRB_GC_RED
#define GC_WHITES (GC_WHITE_A | GC_WHITE_B)
#define GC_COLOR_MASK 7
mrb_static_assert
1
(
MRB_GC_RED
<=
GC_COLOR_MASK
);
mrb_static_assert
(
MRB_GC_RED
<=
GC_COLOR_MASK
);
#define paint_gray(o) ((o)->color = GC_GRAY)
#define paint_black(o) ((o)->color = GC_BLACK)
...
...
This diff is collapsed.
Click to expand it.
src/hash.c
View file @
abf2d653
...
...
@@ -69,8 +69,8 @@
#define AR_MAX_SIZE 16
#define H_MAX_SIZE EA_MAX_CAPA
mrb_static_assert
1
(
offsetof
(
struct
RHash
,
iv
)
==
offsetof
(
struct
RObject
,
iv
));
mrb_static_assert
1
(
AR_MAX_SIZE
<
(
1
<<
MRB_HASH_AR_EA_CAPA_BIT
));
mrb_static_assert
(
offsetof
(
struct
RHash
,
iv
)
==
offsetof
(
struct
RObject
,
iv
));
mrb_static_assert
(
AR_MAX_SIZE
<
(
1
<<
MRB_HASH_AR_EA_CAPA_BIT
));
typedef
struct
hash_entry
{
mrb_value
key
;
...
...
@@ -243,7 +243,7 @@ DEFINE_SWITCHER(ht, HT)
* assumptions.
*/
# define HT_ASSERT_SAFE_READ(attr_name) \
mrb_static_assert
1(
\
mrb_static_assert
(
\
offsetof(hash_table, attr_name) + sizeof(((hash_table*)0)->attr_name) <= \
sizeof(hash_entry))
HT_ASSERT_SAFE_READ
(
ea
);
...
...
This diff is collapsed.
Click to expand it.
src/load.c
View file @
abf2d653
...
...
@@ -98,7 +98,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
if
(
irep
->
ilen
>
0
)
{
size_t
data_len
=
sizeof
(
mrb_code
)
*
irep
->
ilen
+
sizeof
(
struct
mrb_irep_catch_handler
)
*
irep
->
clen
;
mrb_static_assert
1
(
sizeof
(
struct
mrb_irep_catch_handler
)
==
13
);
mrb_static_assert
(
sizeof
(
struct
mrb_irep_catch_handler
)
==
13
);
if
(
SIZE_ERROR_MUL
(
irep
->
ilen
,
sizeof
(
mrb_code
)))
{
return
FALSE
;
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment