Suppress gcc 15 unterminated-string-initialization warnings

	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:
Takashi Kokubun 2025-07-14 14:50:56 -07:00
parent 782aef10bb
commit 596126ee5a
16 changed files with 69 additions and 14 deletions

View file

@ -854,7 +854,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)
@ -9955,6 +9958,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
@ -10575,6 +10579,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
@ -17191,6 +17196,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
@ -17956,6 +17962,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
@ -18418,6 +18425,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

@ -1250,8 +1250,6 @@ main()
ac_cv_func_gmtime_r=yes ac_cv_func_gmtime_r=yes
rb_cv_large_fd_select=yes rb_cv_large_fd_select=yes
ac_cv_type_struct_timeval=yes ac_cv_type_struct_timeval=yes
ac_cv_func_clock_gettime=yes
ac_cv_func_clock_getres=yes
ac_cv_func_malloc_usable_size=no ac_cv_func_malloc_usable_size=no
ac_cv_type_off_t=yes ac_cv_type_off_t=yes
ac_cv_sizeof_off_t=8 ac_cv_sizeof_off_t=8

View file

@ -505,7 +505,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

@ -7016,6 +7016,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 = {
@ -436,7 +437,7 @@ rb_cp50221_encoder = {
/* JIS0201 to JIS0208 conversion table */ /* JIS0201 to JIS0208 conversion table */
enum {tbl0208_num = 0xDF - 0xA1 + 1}; enum {tbl0208_num = 0xDF - 0xA1 + 1};
static const char tbl0208[tbl0208_num][2] = { RBIMPL_ATTR_NONSTRING() static const char tbl0208[tbl0208_num][2] = {
"\x21\x23", "\x21\x56", "\x21\x57", "\x21\x22", "\x21\x23", "\x21\x56", "\x21\x57", "\x21\x22",
"\x21\x26", "\x25\x72", "\x25\x21", "\x25\x23", "\x21\x26", "\x25\x72", "\x25\x21", "\x25\x23",
"\x25\x25", "\x25\x27", "\x25\x29", "\x25\x63", "\x25\x25", "\x25\x27", "\x25\x29", "\x25\x63",

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

@ -3765,7 +3765,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)
@ -1524,7 +1525,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
@ -975,7 +976,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
@ -11557,7 +11558,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
@ -155,7 +156,7 @@ rb_id_attrset(ID id)
/* make new symbol and ID */ /* make new symbol and ID */
if (!(str = lookup_id_str(id))) { if (!(str = lookup_id_str(id))) {
static const char id_types[][8] = { RBIMPL_ATTR_NONSTRING() static const char id_types[][8] = {
"local", "local",
"instance", "instance",
"invalid", "invalid",

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

@ -88,6 +88,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"
@ -107,12 +108,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 4 #define RUBY_VERSION_TEENY 4
#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 50 #define RUBY_PATCHLEVEL 51
#include "ruby/version.h" #include "ruby/version.h"
#include "ruby/internal/abi.h" #include "ruby/internal/abi.h"