Suppress gcc 15 unterminated-string-initialization warnings

	Drop an ignored attribute
	MIME-Version: 1.0
	Content-Type: text/plain; charset=UTF-8
	Content-Transfer-Encoding: 8bit

	GCC 13.3.0 (Ubuntu 24.04) emits the following warning:

	../symbol.c: In function ‘rb_id_attrset’:
	../symbol.c:175:9: warning: ‘nonstring’ attribute ignored on objects of type ‘const char[][8]’ [-Wattributes]
	  175 |         RBIMPL_ATTR_NONSTRING() static const char id_types[][8] = {
	      |         ^~~~~~~~~~~~~~~~~~~~~

	Separate `__has_attribute` from `defined(__has_attribute)`

	Fix Visual C warnings:
	```
	regenc.h(121): warning C4067: unexpected tokens following preprocessor directive - expected a newline
	```

	Cast up `int` instruction code to `VALUE`

	Fix Visual C warnings:
	```
	iseq.c(3793): warning C4312: 'type cast': conversion from 'int' to 'void *' of greater size
	iseq.c(3794): warning C4312: 'type cast': conversion from 'int' to 'void *' of greater size
	```

	Do not let files depend on a phony target

	Detect `clock_gettime` and `clock_getres` for winpthreads
This commit is contained in:
nagachika 2025-07-20 16:10:41 +09:00
parent 1e37f34eaa
commit 407f6c9d05
15 changed files with 68 additions and 11 deletions

View file

@ -836,7 +836,10 @@ clean-platform distclean-platform realclean-platform:
RUBYSPEC_CAPIEXT = spec/ruby/optional/capi/ext RUBYSPEC_CAPIEXT = spec/ruby/optional/capi/ext
RUBYSPEC_CAPIEXT_SRCDIR = $(srcdir)/$(RUBYSPEC_CAPIEXT) RUBYSPEC_CAPIEXT_SRCDIR = $(srcdir)/$(RUBYSPEC_CAPIEXT)
RUBYSPEC_CAPIEXT_DEPS = $(RUBYSPEC_CAPIEXT_SRCDIR)/rubyspec.h $(RUBY_H_INCLUDES) $(LIBRUBY) build-ext RUBYSPEC_CAPIEXT_DEPS = $(RUBYSPEC_CAPIEXT_SRCDIR)/rubyspec.h $(RUBY_H_INCLUDES) $(LIBRUBY)
rubyspec-capiext: build-ext $(DOT_WAIT)
# make-dependent rules should be included after this and built after build-ext.
clean-spec: PHONY clean-spec: PHONY
-$(Q) $(RM) $(RUBYSPEC_CAPIEXT)/*.$(OBJEXT) $(RUBYSPEC_CAPIEXT)/*.$(DLEXT) -$(Q) $(RM) $(RUBYSPEC_CAPIEXT)/*.$(OBJEXT) $(RUBYSPEC_CAPIEXT)/*.$(DLEXT)
@ -9526,6 +9529,7 @@ marshal.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
marshal.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h marshal.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
marshal.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h marshal.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
marshal.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h marshal.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
marshal.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
marshal.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h marshal.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
marshal.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h marshal.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
marshal.$(OBJEXT): {$(VPATH)}internal/attr/pure.h marshal.$(OBJEXT): {$(VPATH)}internal/attr/pure.h
@ -10135,6 +10139,7 @@ miniinit.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h miniinit.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h miniinit.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/pure.h miniinit.$(OBJEXT): {$(VPATH)}internal/attr/pure.h
@ -16472,6 +16477,7 @@ signal.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
signal.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h signal.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
signal.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h signal.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
signal.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h signal.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
signal.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
signal.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h signal.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
signal.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h signal.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
signal.$(OBJEXT): {$(VPATH)}internal/attr/pure.h signal.$(OBJEXT): {$(VPATH)}internal/attr/pure.h
@ -17231,6 +17237,7 @@ string.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
string.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h string.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
string.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h string.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
string.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h string.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
string.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
string.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h string.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
string.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h string.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
string.$(OBJEXT): {$(VPATH)}internal/attr/pure.h string.$(OBJEXT): {$(VPATH)}internal/attr/pure.h
@ -17689,6 +17696,7 @@ symbol.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
symbol.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h symbol.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
symbol.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h symbol.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
symbol.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h symbol.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
symbol.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
symbol.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h symbol.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
symbol.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h symbol.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
symbol.$(OBJEXT): {$(VPATH)}internal/attr/pure.h symbol.$(OBJEXT): {$(VPATH)}internal/attr/pure.h

View file

@ -500,7 +500,8 @@ update-deps:
# order-only-prerequisites doesn't work for $(RUBYSPEC_CAPIEXT) # order-only-prerequisites doesn't work for $(RUBYSPEC_CAPIEXT)
# because the same named directory exists in the source tree. # because the same named directory exists in the source tree.
$(RUBYSPEC_CAPIEXT)/%.$(DLEXT): $(srcdir)/$(RUBYSPEC_CAPIEXT)/%.c $(RUBYSPEC_CAPIEXT_DEPS) $(RUBYSPEC_CAPIEXT)/%.$(DLEXT): $(srcdir)/$(RUBYSPEC_CAPIEXT)/%.c $(RUBYSPEC_CAPIEXT_DEPS) \
| build-ext
$(ECHO) building $@ $(ECHO) building $@
$(Q) $(MAKEDIRS) $(@D) $(Q) $(MAKEDIRS) $(@D)
$(Q) $(DLDSHARED) -L. $(XDLDFLAGS) $(XLDFLAGS) $(LDFLAGS) $(INCFLAGS) $(CPPFLAGS) $(OUTFLAG)$@ $< $(LIBRUBYARG) $(Q) $(DLDSHARED) -L. $(XDLDFLAGS) $(XLDFLAGS) $(LDFLAGS) $(INCFLAGS) $(CPPFLAGS) $(OUTFLAG)$@ $< $(LIBRUBYARG)

View file

@ -6972,6 +6972,7 @@ enc/trans/iso2022.$(OBJEXT): internal/attr/nodiscard.h
enc/trans/iso2022.$(OBJEXT): internal/attr/noexcept.h enc/trans/iso2022.$(OBJEXT): internal/attr/noexcept.h
enc/trans/iso2022.$(OBJEXT): internal/attr/noinline.h enc/trans/iso2022.$(OBJEXT): internal/attr/noinline.h
enc/trans/iso2022.$(OBJEXT): internal/attr/nonnull.h enc/trans/iso2022.$(OBJEXT): internal/attr/nonnull.h
enc/trans/iso2022.$(OBJEXT): internal/attr/nonstring.h
enc/trans/iso2022.$(OBJEXT): internal/attr/noreturn.h enc/trans/iso2022.$(OBJEXT): internal/attr/noreturn.h
enc/trans/iso2022.$(OBJEXT): internal/attr/packed_struct.h enc/trans/iso2022.$(OBJEXT): internal/attr/packed_struct.h
enc/trans/iso2022.$(OBJEXT): internal/attr/pure.h enc/trans/iso2022.$(OBJEXT): internal/attr/pure.h

View file

@ -1,4 +1,5 @@
#include "transcode_data.h" #include "transcode_data.h"
#include "ruby/internal/attr/nonstring.h"
<% <%
map = { map = {
@ -443,7 +444,7 @@ rb_cp50221_encoder = {
iso2022jp_encoder_reset_sequence_size, finish_iso2022jp_encoder iso2022jp_encoder_reset_sequence_size, finish_iso2022jp_encoder
}; };
static const char *tbl0208 = RBIMPL_ATTR_NONSTRING() static const char *tbl0208 =
"\x21\x23\x21\x56\x21\x57\x21\x22\x21\x26\x25\x72\x25\x21\x25\x23" \ "\x21\x23\x21\x56\x21\x57\x21\x22\x21\x26\x25\x72\x25\x21\x25\x23" \
"\x25\x25\x25\x27\x25\x29\x25\x63\x25\x65\x25\x67\x25\x43\x21\x3C" \ "\x25\x25\x25\x27\x25\x29\x25\x63\x25\x65\x25\x67\x25\x43\x21\x3C" \
"\x25\x22\x25\x24\x25\x26\x25\x28\x25\x2A\x25\x2B\x25\x2D\x25\x2F" \ "\x25\x22\x25\x24\x25\x26\x25\x28\x25\x2A\x25\x2B\x25\x2D\x25\x2F" \

View file

@ -0,0 +1,32 @@
#ifndef RBIMPL_ATTR_NONSTRING_H /*-*-C++-*-vi:se ft=cpp:*/
#define RBIMPL_ATTR_NONSTRING_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
* implementation details. Don't take them as canon. They could
* rapidly appear then vanish. The name (path) of this header file
* is also an implementation detail. Do not expect it to persist
* at the place it is now. Developers are free to move it anywhere
* anytime at will.
* @note To ruby-core: remember that this header can be possibly
* recursively included from extension libraries written in C++.
* Do not expect for instance `__VA_ARGS__` is always available.
* We assume C99 for ruby itself but we don't assume languages of
* extension libraries. They could be written in C++98.
* @brief Defines #RBIMPL_ATTR_NONSTRING.
*/
#include "ruby/internal/has/attribute.h"
/** Wraps (or simulates) `__attribute__((nonstring))` */
#if RBIMPL_HAS_ATTRIBUTE(nonstring)
# define RBIMPL_ATTR_NONSTRING() __attribute__((nonstring))
#else
# define RBIMPL_ATTR_NONSTRING() /* void */
#endif
#endif /* RBIMPL_ATTR_NONSTRING_H */

2
iseq.c
View file

@ -3484,7 +3484,7 @@ rb_vm_encoded_insn_data_table_init(void)
const void * const *table = rb_vm_get_insns_address_table(); const void * const *table = rb_vm_get_insns_address_table();
#define INSN_CODE(insn) ((VALUE)table[insn]) #define INSN_CODE(insn) ((VALUE)table[insn])
#else #else
#define INSN_CODE(insn) (insn) #define INSN_CODE(insn) ((VALUE)(insn))
#endif #endif
st_data_t insn; st_data_t insn;
encoded_insn_data = st_init_numtable_with_size(VM_INSTRUCTION_SIZE / 2); encoded_insn_data = st_init_numtable_with_size(VM_INSTRUCTION_SIZE / 2);

View file

@ -40,6 +40,7 @@
#include "ruby/util.h" #include "ruby/util.h"
#include "builtin.h" #include "builtin.h"
#include "shape.h" #include "shape.h"
#include "ruby/internal/attr/nonstring.h"
#define BITSPERSHORT (2*CHAR_BIT) #define BITSPERSHORT (2*CHAR_BIT)
#define SHORTMASK ((1<<BITSPERSHORT)-1) #define SHORTMASK ((1<<BITSPERSHORT)-1)
@ -1541,7 +1542,7 @@ name_equal(const char *name, size_t nlen, const char *p, long l)
static int static int
sym2encidx(VALUE sym, VALUE val) sym2encidx(VALUE sym, VALUE val)
{ {
static const char name_encoding[8] = "encoding"; RBIMPL_ATTR_NONSTRING() static const char name_encoding[8] = "encoding";
const char *p; const char *p;
long l; long l;
if (rb_enc_get_index(sym) != ENCINDEX_US_ASCII) return -1; if (rb_enc_get_index(sym) != ENCINDEX_US_ASCII) return -1;

View file

@ -118,6 +118,11 @@ typedef struct {
typedef struct { typedef struct {
short int len; short int len;
#if defined(__has_attribute)
# if __has_attribute(nonstring)
__attribute__((nonstring))
# endif
#endif
const UChar name[6]; const UChar name[6];
int ctype; int ctype;
} PosixBracketEntryType; } PosixBracketEntryType;

View file

@ -45,6 +45,7 @@
#include "ruby_atomic.h" #include "ruby_atomic.h"
#include "vm_core.h" #include "vm_core.h"
#include "ractor_core.h" #include "ractor_core.h"
#include "ruby/internal/attr/nonstring.h"
#ifdef NEED_RUBY_ATOMIC_OPS #ifdef NEED_RUBY_ATOMIC_OPS
rb_atomic_t rb_atomic_t
@ -968,7 +969,7 @@ check_reserved_signal_(const char *name, size_t name_len, int signo)
if (prev) { if (prev) {
ssize_t RB_UNUSED_VAR(err); ssize_t RB_UNUSED_VAR(err);
static const int stderr_fd = 2; static const int stderr_fd = 2;
#define NOZ(name, str) name[sizeof(str)-1] = str #define NOZ(name, str) RBIMPL_ATTR_NONSTRING() name[sizeof(str)-1] = str
static const char NOZ(msg1, " received in "); static const char NOZ(msg1, " received in ");
static const char NOZ(msg2, " handler\n"); static const char NOZ(msg2, " handler\n");

View file

@ -140,6 +140,9 @@ xor64_to(uint64_t *v, const uint64_t s)
#endif #endif
static const union { static const union {
#if defined(__has_attribute) && __has_attribute(nonstring)
__attribute__((nonstring))
#endif
char bin[32]; char bin[32];
uint64_t u64[4]; uint64_t u64[4];
} sip_init_state_bin = {"uespemos""modnarod""arenegyl""setybdet"}; } sip_init_state_bin = {"uespemos""modnarod""arenegyl""setybdet"};

View file

@ -44,6 +44,7 @@
#include "ruby/util.h" #include "ruby/util.h"
#include "ruby_assert.h" #include "ruby_assert.h"
#include "vm_sync.h" #include "vm_sync.h"
#include "ruby/internal/attr/nonstring.h"
#if defined HAVE_CRYPT_R #if defined HAVE_CRYPT_R
# if defined HAVE_CRYPT_H # if defined HAVE_CRYPT_H
@ -11123,7 +11124,7 @@ enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl, int cr)
encidx = rb_enc_to_index(enc); encidx = rb_enc_to_index(enc);
#define DEFAULT_REPLACE_CHAR(str) do { \ #define DEFAULT_REPLACE_CHAR(str) do { \
static const char replace[sizeof(str)-1] = str; \ RBIMPL_ATTR_NONSTRING() static const char replace[sizeof(str)-1] = str; \
rep = replace; replen = (int)sizeof(replace); \ rep = replace; replen = (int)sizeof(replace); \
} while (0) } while (0)

View file

@ -22,6 +22,7 @@
#include "symbol.h" #include "symbol.h"
#include "vm_sync.h" #include "vm_sync.h"
#include "builtin.h" #include "builtin.h"
#include "ruby/internal/attr/nonstring.h"
#if defined(USE_SYMBOL_GC) && !(USE_SYMBOL_GC+0) #if defined(USE_SYMBOL_GC) && !(USE_SYMBOL_GC+0)
# undef USE_SYMBOL_GC # undef USE_SYMBOL_GC

View file

@ -22,7 +22,8 @@ ops = ids[:token_op].uniq {|id, op, token| token && op}
static const struct { static const struct {
unsigned short token; unsigned short token;
const char name[3], term; RBIMPL_ATTR_NONSTRING() const char name[3];
const char term;
} op_tbl[] = { } op_tbl[] = {
% ops.each do |_id, op, token| % ops.each do |_id, op, token|
% next unless token % next unless token

View file

@ -93,6 +93,7 @@ Prelude.new(output, ARGV, vpath).instance_eval do
#include "internal/ruby_parser.h" #include "internal/ruby_parser.h"
#include "internal/warnings.h" #include "internal/warnings.h"
#include "iseq.h" #include "iseq.h"
#include "ruby/internal/attr/nonstring.h"
#include "ruby/ruby.h" #include "ruby/ruby.h"
#include "vm_core.h" #include "vm_core.h"
@ -112,12 +113,12 @@ static const struct {
% size += line.size % size += line.size
% next % next
% end % end
char L<%=beg%><%=%>[<%=size%><%=%>]; /* <%=beg+1%>..<%=n%> */ RBIMPL_ATTR_NONSTRING() char L<%=beg%><%=%>[<%=size%><%=%>]; /* <%=beg+1%>..<%=n%> */
% size = line.size % size = line.size
% beg = n % beg = n
% } % }
% if size > 0 % if size > 0
char L<%=beg%><%=%>[<%=size%><%=%>]; /* <%=beg+1%>..<%=lines.size+1%> */ RBIMPL_ATTR_NONSTRING() char L<%=beg%><%=%>[<%=size%><%=%>]; /* <%=beg+1%>..<%=lines.size+1%> */
% end % end
} prelude_code<%=i%><%=%> = { } prelude_code<%=i%><%=%> = {
% size = 0 % size = 0

View file

@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 8 #define RUBY_VERSION_TEENY 8
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 166 #define RUBY_PATCHLEVEL 167
#include "ruby/version.h" #include "ruby/version.h"
#include "ruby/internal/abi.h" #include "ruby/internal/abi.h"