Skip to content

Commit 04d9cf3

Browse files
committed
api(Windows): Remove the ordinals attached to exported functions
In order to make ABI compatibility guarantees about the Windows DLL, we had to keep maintaining the API ordinals consistently. As we are now designing a fresh new ABI, we use this opportunity to stop using ordinals altogether. Exporting API functions by ordinal numbers instead of names was a necessity in the early (16-bit) versions of Windows, by design, to minimize the memory requirements. Although using ordinals was still possible in all subsequent versions of Windows, it was no longer necessary from the 32-bit versions of Windows onwards. The libpng DLL will still have ordinals, assigned arbitrarily, but the dynamic linking of applications to this DLL will be done by name. (The applications that use the zlib DLL operate in the same manner.)
1 parent 363aa62 commit 04d9cf3

File tree

9 files changed

+570
-677
lines changed

9 files changed

+570
-677
lines changed

png.h

Lines changed: 262 additions & 274 deletions
Large diffs are not rendered by default.

pngconf.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,8 @@
290290
# define PNG_EXPORT_TYPE(type) PNG_IMPEXP type
291291
#endif
292292

293-
/* The ordinal value is only relevant when preprocessing png.h for symbol
294-
* table entries, so we discard it here. See the .dfn files in the
295-
* scripts directory.
296-
*/
297-
298293
#ifndef PNG_EXPORTA
299-
# define PNG_EXPORTA(ordinal, type, name, args, attributes) \
294+
# define PNG_EXPORTA(type, name, args, attributes) \
300295
PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), args, \
301296
PNG_LINKAGE_API attributes)
302297
#endif
@@ -306,12 +301,11 @@
306301
*/
307302
#define PNG_EMPTY /*empty list*/
308303

309-
#define PNG_EXPORT(ordinal, type, name, args) \
310-
PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)
304+
#define PNG_EXPORT(type, name, args) PNG_EXPORTA(type, name, args, PNG_EMPTY)
311305

312306
/* Use PNG_REMOVED to comment out a removed interface. */
313307
#ifndef PNG_REMOVED
314-
# define PNG_REMOVED(ordinal, type, name, args, attributes)
308+
# define PNG_REMOVED(type, name, args, attributes)
315309
#endif
316310

317311
#ifndef PNG_CALLBACK
@@ -446,18 +440,16 @@
446440

447441
#ifndef PNG_FP_EXPORT /* A floating point API. */
448442
# ifdef PNG_FLOATING_POINT_SUPPORTED
449-
# define PNG_FP_EXPORT(ordinal, type, name, args)\
450-
PNG_EXPORT(ordinal, type, name, args);
443+
# define PNG_FP_EXPORT(type, name, args) PNG_EXPORT(type, name, args);
451444
# else /* No floating point APIs */
452-
# define PNG_FP_EXPORT(ordinal, type, name, args)
445+
# define PNG_FP_EXPORT(type, name, args)
453446
# endif
454447
#endif
455448
#ifndef PNG_FIXED_EXPORT /* A fixed point API. */
456449
# ifdef PNG_FIXED_POINT_SUPPORTED
457-
# define PNG_FIXED_EXPORT(ordinal, type, name, args)\
458-
PNG_EXPORT(ordinal, type, name, args);
450+
# define PNG_FIXED_EXPORT(type, name, args) PNG_EXPORT(type, name, args);
459451
# else /* No fixed point APIs */
460-
# define PNG_FIXED_EXPORT(ordinal, type, name, args)
452+
# define PNG_FIXED_EXPORT(type, name, args)
461453
# endif
462454
#endif
463455

pngpriv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* pngpriv.h - private declarations for use inside libpng
22
*
3-
* Copyright (c) 2018-2024 Cosmin Truta
3+
* Copyright (c) 2018-2025 Cosmin Truta
44
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
55
* Copyright (c) 1996-1997 Andreas Dilger
66
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -185,7 +185,7 @@
185185
*/
186186
#ifndef PNG_FP_EXPORT
187187
# ifndef PNG_FLOATING_POINT_SUPPORTED
188-
# define PNG_FP_EXPORT(ordinal, type, name, args)\
188+
# define PNG_FP_EXPORT(type, name, args)\
189189
PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);
190190
# ifndef PNG_VERSION_INFO_ONLY
191191
typedef struct png_incomplete png_double;
@@ -197,7 +197,7 @@
197197
#endif
198198
#ifndef PNG_FIXED_EXPORT
199199
# ifndef PNG_FIXED_POINT_SUPPORTED
200-
# define PNG_FIXED_EXPORT(ordinal, type, name, args)\
200+
# define PNG_FIXED_EXPORT(type, name, args)\
201201
PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);
202202
# endif
203203
#endif

scripts/checksym.awk

Lines changed: 34 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,19 @@
1717
BEGIN {
1818
err = 0
1919
master = "" # master file
20-
official[1] = "" # defined symbols from master file
21-
symbol[1] = "" # defined symbols from png.h
22-
removed[1] = "" # removed symbols from png.h
23-
lasto = 0 # last ordinal value from png.h
24-
mastero = 0 # highest ordinal in master file
25-
symbolo = 0 # highest ordinal in png.h
20+
official[""] = "" # defined symbols from master file
21+
symbol[""] = "" # defined symbols from png.h
22+
removed[""] = "" # removed symbols from png.h
2623
missing = "error" # log an error on missing symbols
2724
of = "symbols.new" # default to a fixed name
2825
}
2926

3027
# Read existing definitions from the master file (the first
31-
# file on the command line.) This must be a def file and it
32-
# has definition lines (others are ignored) of the form:
33-
#
34-
# symbol @ordinal
35-
#
28+
# file on the command line.) This is a Windows .def file
29+
# which must NOT have definitions of the form "symbol @ordinal".
3630
master == "" {
3731
master = FILENAME
3832
}
39-
FILENAME == master && NF == 2 && $2 ~ /^@/ && $1 !~ /^;/ {
40-
o = 0 + substr($2, 2)
41-
if (o > 0) {
42-
if (official[o] == "") {
43-
official[o] = $1
44-
if (o > mastero) mastero = o
45-
next
46-
} else {
47-
print master ": duplicated symbol:", official[o] ":", $0
48-
}
49-
} else {
50-
print master ": bad export line format:", $0
51-
}
52-
err = 1
53-
}
5433
FILENAME == master && $1 == ";missing" && NF == 2 {
5534
# This allows the master file to control how missing symbols
5635
# are handled; symbols that aren't in either the master or
@@ -62,67 +41,36 @@ FILENAME == master {
6241
next
6342
}
6443

65-
# Read new definitions, these are free form but the lines must
44+
# Read the definitions, which are free-form, but the lines must
6645
# just be symbol definitions. Lines will be commented out for
6746
# 'removed' symbols, introduced in png.h using PNG_REMOVED rather
68-
# than PNG_EXPORT. Use symbols.dfn or pngwin.dfn to generate the
69-
# input file.
47+
# than PNG_EXPORT. Use symbols.dfn to generate the input file.
7048
#
71-
# symbol @ordinal # two fields, exported symbol
72-
# ; symbol @ordinal # three fields, removed symbol
73-
# ; @ordinal # two fields, the last ordinal
74-
NF == 2 && $1 == ";" && $2 ~ /^@[1-9][0-9]*$/ {
75-
# last ordinal
76-
o = 0 + substr($2, 2)
77-
if (lasto == 0 || lasto == o) {
78-
lasto = o
79-
} else {
80-
print "png.h: duplicated last ordinal:", lasto, o
81-
err = 1
82-
}
49+
# symbol # one field, exported symbol
50+
# ; symbol # two fields, removed symbol
51+
#
52+
NF == 0 {
53+
# empty line
8354
next
8455
}
85-
NF == 3 && $1 == ";" && $3 ~ /^@[1-9][0-9]*$/ {
86-
# removed symbol
87-
o = 0 + substr($3, 2)
88-
if (removed[o] == "" || removed[o] == $2) {
89-
removed[o] = $2
90-
if (o > symbolo) symbolo = o
91-
} else {
92-
print "png.h: duplicated removed symbol", o ": '" removed[o] "' != '" $2 "'"
93-
err = 1
94-
}
56+
NF == 1 && $1 ~ /^[A-Za-z_][A-Za-z_0-9]*$/ {
57+
# exported symbol (one field)
58+
symbol[$1] = $1
9559
next
9660
}
97-
NF == 2 && $2 ~ /^@[1-9][0-9]*$/ {
98-
# exported symbol
99-
o = 0 + substr($2, 2)
100-
if (symbol[o] == "" || symbol[o] == $1) {
101-
symbol[o] = $1
102-
if (o > symbolo) symbolo = o
103-
} else {
104-
print "png.h: duplicated symbol", o ": '" symbol[o] "' != '" $1 "'"
105-
err = 1
106-
}
61+
NF == 2 && $1 == ";" && $2 ~ /^[A-Za-z_][A-Za-z_0-9]*$/ {
62+
# removed symbol (two fields)
63+
removed[$1] = $1
64+
next
10765
}
10866
{
109-
next # skip all other lines
67+
print "error: invalid line:", $0
68+
err = 1
69+
next
11070
}
11171

112-
# At the end check for symbols marked as both duplicated and removed
11372
END {
114-
if (symbolo > lasto) {
115-
print "highest symbol ordinal in png.h,",
116-
symbolo ", exceeds last ordinal from png.h", lasto
117-
err = 1
118-
}
119-
if (mastero > lasto) {
120-
print "highest symbol ordinal in", master ",",
121-
mastero ", exceeds last ordinal from png.h", lasto
122-
err = 1
123-
}
124-
unexported = 0
125-
# Add a standard header to symbols.new:
73+
# Write the standard header to "symbols.new":
12674
print ";Version INSERT-VERSION-HERE" >of
12775
print ";--------------------------------------------------------------" >of
12876
print "; LIBPNG symbol list as a Win32 DEF file" >of
@@ -132,59 +80,22 @@ END {
13280
print "" >of
13381
print "EXPORTS" >of
13482

135-
for (o = 1; o <= lasto; ++o) {
136-
if (symbol[o] == "" && removed[o] == "") {
137-
if (unexported == 0) unexported = o
138-
if (official[o] == "") {
139-
# missing in export list too, so ok
140-
if (o < lasto) continue
141-
}
142-
}
143-
if (unexported != 0) {
144-
# Symbols in the .def but not in the new file are errors, but
145-
# the 'unexported' symbols aren't in either. By default this
146-
# is an error too (see the setting of 'missing' at the start),
147-
# but this can be reset on the command line or by stuff in the
148-
# file - see the comments above.
149-
if (missing != "ignore") {
150-
if (o - 1 > unexported) {
151-
print "png.h:", missing ": missing symbols:", unexported "-" o - 1
152-
} else {
153-
print "png.h:", missing ": missing symbol:", unexported
154-
}
155-
if (missing != "warning") {
156-
err = 1
157-
}
158-
}
159-
unexported = 0
160-
}
161-
if (symbol[o] != "" && removed[o] != "") {
162-
print "png.h: symbol", o,
163-
"both exported as '" symbol[o] "' and removed as '" removed[o] "'"
164-
err = 1
165-
} else if (symbol[o] != official[o]) {
166-
# either the symbol is missing somewhere or it changed
167-
err = 1
168-
if (symbol[o] == "") {
169-
print "png.h: symbol", o,
170-
"is exported as '" official[o] "' in", master
171-
} else if (official[o] == "") {
172-
print "png.h: exported symbol", o,
173-
"'" symbol[o] "' not present in", master
174-
} else {
175-
print "png.h: exported symbol", o,
176-
"'" symbol[o] "' exists as '" official[o] "' in", master
177-
}
178-
}
83+
# Collect all unique symbols into a plain array for sorting.
84+
i = 1
85+
for (sym in symbol) {
86+
if (sym != "") sorted_symbols[i++] = sym
87+
}
17988

180-
# Finally generate symbols.new
181-
if (symbol[o] != "") {
182-
print " " symbol[o], "@" o > of
183-
}
89+
# Sort and print the symbols.
90+
asort(sorted_symbols)
91+
for (i = 1; i <= length(sorted_symbols); i++) {
92+
print " " sorted_symbols[i] >of
18493
}
18594

18695
if (err != 0) {
18796
print "*** A new list is in", of, "***"
18897
exit 1
18998
}
99+
100+
# TODO: Check for symbols that are both defined and removed.
190101
}

scripts/prefix.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* prefix.c - generate an unprefixed symbol list
22
*
3+
* Copyright (c) 2025 Cosmin Truta
34
* Copyright (c) 2013-2014 Glenn Randers-Pehrson
45
*
56
* This code is released under the libpng license.
67
* For conditions of distribution and use, see the disclaimer
78
* and license in png.h
89
*/
910

10-
#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
11+
#define PNG_EXPORTA(type, name, args, attributes)\
1112
PNG_DFN "@" name "@"
1213

1314
/* The configuration information *before* the additional of symbol renames,

scripts/sym.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* sym.c - define format of libpng.sym
22
*
3+
* Copyright (c) 2025 Cosmin Truta
34
* Copyright (c) 2011-2014 Glenn Randers-Pehrson
45
*
56
* This code is released under the libpng license.
67
* For conditions of distribution and use, see the disclaimer
78
* and license in png.h
89
*/
910

10-
#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
11+
#define PNG_EXPORTA(type, name, args, attributes)\
1112
PNG_DFN "@" SYMBOL_PREFIX "@@" name "@"
1213

1314
#include "../png.h"

scripts/symbols.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* symbols.c - find all exported symbols
22
*
3+
* Copyright (c) 2025 Cosmin Truta
34
* Copyright (c) 2011-2014 Glenn Randers-Pehrson
45
*
56
* This code is released under the libpng license.
@@ -14,12 +15,10 @@
1415
* scripts/pnglibconf.dfa then this checks the .dfa file too.
1516
*/
1617

17-
#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
18-
PNG_DFN "@" name "@ @@" ordinal "@"
19-
#define PNG_REMOVED(ordinal, type, name, args, attributes)\
20-
PNG_DFN "; @" name "@ @@" ordinal "@"
21-
#define PNG_EXPORT_LAST_ORDINAL(ordinal)\
22-
PNG_DFN "; @@" ordinal "@"
18+
#define PNG_EXPORTA(type, name, args, attributes)\
19+
PNG_DFN "@" name "@"
20+
#define PNG_REMOVED(type, name, args, attributes)\
21+
PNG_DFN "; @" name "@"
2322

2423
/* Read the defaults, but use scripts/pnglibconf.h.prebuilt; the 'standard'
2524
* header file.

0 commit comments

Comments
 (0)