gh-133256: Add _Py_NONSTRING macro (#133257) · python/cpython@e26bafd · GitHub
Skip to content

Commit e26bafd

Browse files
authored
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";
1 parent ad2f088 commit e26bafd

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

Include/internal/pycore_debug_offsets.h

Lines changed: 1 addition & 1 deletion

Include/pyport.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,4 +685,19 @@ extern "C" {
685685
#endif
686686

687687

688+
// _Py_NONSTRING: The nonstring variable attribute specifies that an object or
689+
// member declaration with type array of char, signed char, or unsigned char,
690+
// or pointer to such a type is intended to store character arrays that do not
691+
// necessarily contain a terminating NUL.
692+
//
693+
// Usage:
694+
//
695+
// char name [8] _Py_NONSTRING;
696+
#if _Py__has_attribute(nonstring)
697+
# define _Py_NONSTRING __attribute__((nonstring))
698+
#else
699+
# define _Py_NONSTRING
700+
#endif
701+
702+
688703
#endif /* Py_PYPORT_H */

Modules/fcntlmodule.c

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)