1From 23c46e045a2a44331aafd3245d82c4fb216044b9 Mon Sep 17 00:00:00 2001
2From: Michael Forney <mforney@mforney.org>
3Date: Sat, 2 May 2026 20:10:48 -0700
4Subject: [PATCH] Add C23 attribute support
5
6---
7 pngconf.h | 25 +++++++++++++++++++++++--
8 pngerror.c | 8 ++++----
9 pngpriv.h | 6 +++---
10 3 files changed, 30 insertions(+), 9 deletions(-)
11
12diff --git a/pngconf.h b/pngconf.h
13index 000d7b1a8..16d290ccd 100644
14--- a/pngconf.h
15+++ b/pngconf.h
16@@ -299,7 +299,7 @@
17 #ifndef PNG_EXPORTA
18 # define PNG_EXPORTA(ordinal, type, name, args, attributes) \
19 PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), PNGARG(args), \
20- PNG_LINKAGE_API attributes)
21+ attributes PNG_LINKAGE_API)
22 #endif
23
24 /* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,
25@@ -339,7 +339,28 @@
26 * version 1.2.41. Disabling these removes the warnings but may also produce
27 * less efficient code.
28 */
29-# if defined(__clang__) && defined(__has_attribute)
30+# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
31+# if !defined(PNG_USE_RESULT)
32+# define PNG_USE_RESULT [[nodiscard]]
33+# endif
34+# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__)
35+# define PNG_NORETURN [[noreturn]]
36+# endif
37+# if !defined(PNG_ALLOCATED) && defined(__has_c_attribute) && __has_c_attribute(gnu::malloc)
38+# define PNG_ALLOCATED [[gnu::malloc]]
39+# endif
40+# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__)
41+# define PNG_DEPRECATED [[deprecated]]
42+# endif
43+# if !defined(PNG_PRIVATE) && defined(__has_c_attribute) && __has_c_attribute(gnu::unavailable)
44+# define PNG_PRIVATE [[gnu::unavailable(\
45+ "This function is not exported by libpng.")]]
46+# endif
47+# ifndef PNG_RESTRICT
48+# define PNG_RESTRICT restrict
49+# endif
50+
51+# elif defined(__clang__) && defined(__has_attribute)
52 /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
53 # if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
54 # define PNG_USE_RESULT __attribute__((__warn_unused_result__))
55diff --git a/pngerror.c b/pngerror.c
56index 29ebda794..4bab0a63c 100644
57--- a/pngerror.c
58+++ b/pngerror.c
59@@ -20,8 +20,8 @@
60
61 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
62
63-static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
64- png_const_charp error_message)),PNG_NORETURN);
65+PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
66+ png_const_charp error_message)),PNG_NORETURN static);
67
68 #ifdef PNG_WARNINGS_SUPPORTED
69 static void /* PRIVATE */
70@@ -707,9 +707,9 @@ png_free_jmpbuf(png_structrp png_ptr)
71 * function is used by default, or if the program supplies NULL for the
72 * error function pointer in png_set_error_fn().
73 */
74-static PNG_FUNCTION(void /* PRIVATE */,
75+PNG_FUNCTION(void /* PRIVATE */,
76 png_default_error,(png_const_structrp png_ptr, png_const_charp error_message),
77- PNG_NORETURN)
78+ PNG_NORETURN static)
79 {
80 #ifdef PNG_CONSOLE_IO_SUPPORTED
81 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
82diff --git a/pngpriv.h b/pngpriv.h
83index 9bfdb7134..2dcf50c7b 100644
84--- a/pngpriv.h
85+++ b/pngpriv.h
86@@ -396,13 +396,13 @@
87
88 #ifndef PNG_INTERNAL_FUNCTION
89 # define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\
90- PNG_LINKAGE_FUNCTION PNG_FUNCTION(type, name, args, PNG_EMPTY attributes)
91+ PNG_FUNCTION(type, name, args, attributes PNG_LINKAGE_FUNCTION)
92 #endif
93
94 #ifndef PNG_INTERNAL_CALLBACK
95 # define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\
96- PNG_LINKAGE_CALLBACK PNG_FUNCTION(type, (PNGCBAPI name), args,\
97- PNG_EMPTY attributes)
98+ PNG_FUNCTION(type, (PNGCBAPI name), args,\
99+ attributes PNG_LINKAGE_CALLBACK)
100 #endif
101
102 /* If floating or fixed point APIs are disabled they may still be compiled
103--
1042.49.0
105