https://github.com/python/cpython/commit/e26bafd107aa86a4bdd6051848640f36a56d0efb
commit: e26bafd107aa86a4bdd6051848640f36a56d0efb
branch: main
author: Victor Stinner <vstin...@python.org>
committer: vstinner <vstin...@python.org>
date: 2025-05-01T17:55:49+02:00
summary:

gh-133256: Add _Py_NONSTRING macro (#133257)

Fix GCC 15 compiler warnings such as:

    Modules/fcntlmodule.c:27:36: warning: initializer-string for
    array of 'char' truncates NUL terminator but destination lacks
    'nonstring' attribute (9 chars into 8 available)
    [-Wunterminated-string-initialization]
    static const char guard[GUARDSZ] = "\x00\xfa\x69\xc4\x67\xa3\x6c\x58";

files:
M Include/internal/pycore_debug_offsets.h
M Include/pyport.h
M Modules/fcntlmodule.c

diff --git a/Include/internal/pycore_debug_offsets.h 
b/Include/internal/pycore_debug_offsets.h
index b280633c9ef679..59d2c9d5377953 100644
--- a/Include/internal/pycore_debug_offsets.h
+++ b/Include/internal/pycore_debug_offsets.h
@@ -59,7 +59,7 @@ extern "C" {
 
 
 typedef struct _Py_DebugOffsets {
-    char cookie[8];
+    char cookie[8] _Py_NONSTRING;
     uint64_t version;
     uint64_t free_threaded;
     // Runtime state offset;
diff --git a/Include/pyport.h b/Include/pyport.h
index ebce31f1d14a01..3eac119bf8e8d8 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -685,4 +685,19 @@ extern "C" {
 #endif
 
 
+// _Py_NONSTRING: The nonstring variable attribute specifies that an object or
+// member declaration with type array of char, signed char, or unsigned char,
+// or pointer to such a type is intended to store character arrays that do not
+// necessarily contain a terminating NUL.
+//
+// Usage:
+//
+//   char name [8] _Py_NONSTRING;
+#if _Py__has_attribute(nonstring)
+#  define _Py_NONSTRING __attribute__((nonstring))
+#else
+#  define _Py_NONSTRING
+#endif
+
+
 #endif /* Py_PYPORT_H */
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index ebcacd2fb0ece1..220ee9ecdffc8a 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -24,7 +24,7 @@
 
 #define GUARDSZ 8
 // NUL followed by random bytes.
-static const char guard[GUARDSZ] = "\x00\xfa\x69\xc4\x67\xa3\x6c\x58";
+static const char guard[GUARDSZ] _Py_NONSTRING = 
"\x00\xfa\x69\xc4\x67\xa3\x6c\x58";
 
 /*[clinic input]
 module fcntl

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to