1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/include/ruby
Dimitry Andric 06aafeb4b3 Fix clang -Wcompound-token-split-by-macro warning in ruby.h
Building certain ruby gem native extensions (such as thrift), with clang
12.0.0 or later fails, because they have -Werror in their CFLAGS,
resulting in complaints about the expansion of the `rb_intern()` macro:

```
current directory: /wrkdirs/usr/ports/devel/rubygem-thrift/work/stage/usr/local/lib/ruby/gems/2.7/gems/thrift-0.14.0/ext
make "DESTDIR="
compiling binary_protocol_accelerated.c
binary_protocol_accelerated.c:404:68: error: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Werror,-Wcompound-token-split-by-macro]
  VALUE thrift_binary_protocol_class = rb_const_get(thrift_module, rb_intern("BinaryProtocol"));
                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/ruby-2.7/ruby/ruby.h:1847:23: note: expanded from macro 'rb_intern'
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                      ^
binary_protocol_accelerated.c:404:68: note: '{' token is here
  VALUE thrift_binary_protocol_class = rb_const_get(thrift_module, rb_intern("BinaryProtocol"));
                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/ruby-2.7/ruby/ruby.h:1847:24: note: expanded from macro 'rb_intern'
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/ruby-2.7/ruby/ruby.h:1832:5: note: expanded from macro 'RUBY_CONST_ID_CACHE'
    {                                                   \
    ^
```

Part of the `rb_intern()` macro expands to `(RUBY_CONST_ID_CACHE((ID),
(str)))`, and in turn `RUBY_CONST_ID_CACHE()` expands to a brace
enclosed compound statement. The intended effect is to get a gcc
statement expression, which is normally delimited by `({ ... })`.

However, clang 12.0.0 and later have a warning enabled by default, about
pasting together the `(` and `{` tokens via different macros (see
<0e00a95b4f>).

To work around this warning:
* Add `RUBY_CONST_ID_CACHE_NB()` (i.e. no-brace) which contains the code
  itself, without any braces
* `RUBY_CONST_ID_CACHE()` which uses `RUBY_CONST_ID_CACHE_NB()`, but
   puts braces around it (so no existing code using this macro breaks)
* Finally, change `rb_intern()` so the `__extension__` directly creates
  a gcc statement expression, using the `RUBY_CONST_ID_CACHE_NB()` macro
2021-11-24 17:49:38 +09:00
..
backward Fixed misspellings 2019-12-20 09:32:42 +09:00
assert.h Revert "Always evaluate the expression RUBY_ASSERT_MESG_WHEN just once" 2019-08-05 08:55:09 +09:00
backward.h Renamed ruby_finalize_{0,1} 2019-08-13 09:47:08 +09:00
debug.h Revert "vm_trace: implement postponed_jobs as st_table" 2018-10-23 03:47:45 +00:00
defines.h merge revision(s) 511b55bcef: [Backport #17215] 2021-03-20 14:23:45 +09:00
encoding.h rb_enc_alias 2018-06-28 23:46:59 +00:00
intern.h forward declare struct timespec 2019-12-10 11:43:55 +09:00
io.h io.c: export rb_io_extract_modeenc 2019-08-14 11:20:58 +09:00
missing.h include/ruby/missing.h: defined(__cplusplus) before using __cplusplus 2018-06-05 14:16:50 +00:00
onigmo.h Reduce ONIG_NREGION from 10 to 4: power of 2 and testing revealed most pattern matches are less than or equal to 4 results 2019-05-07 21:58:55 +09:00
oniguruma.h Merge Onigmo 6.0.0 2016-12-10 17:47:04 +00:00
re.h Remove member char_offset_updated from struct rmatch as member char_offset_num_allocated can serve the same purpose as that predicate 2019-04-24 02:02:05 +09:00
regex.h
ruby.h Fix clang -Wcompound-token-split-by-macro warning in ruby.h 2021-11-24 17:49:38 +09:00
st.h st.c: Use rb_st_* prefix instead of st_* (#2479) 2019-09-22 22:12:18 +09:00
subst.h
thread.h introduce rb_nogvl C-API to mark ubf as async-signal-safe 2019-01-04 13:14:11 +00:00
thread_native.h
util.h util.h: remove my_getcwd 2017-11-26 01:36:33 +00:00
version.h version.h (RUBY_VERSION): 2.7.0 development has started. 2018-12-25 13:45:17 +00:00
vm.h ViewVC of svn.ruby-lang.org was shutdown status. 2019-04-22 19:37:22 +09:00
win32.h Fix errno at seeking socket/pipe on Windows 2019-07-25 06:39:40 +09:00