Skip to content

Commit

Permalink
Remove the vestigial support for custom API calling conventions
Browse files Browse the repository at this point in the history
The computer industry has spoken rather clearly: we shall have
8-bit bytes, powers-of-2- and multiples-of-8-bit ints and floats,
one-size-fits-all pointers, and C API calling conventions for
system-level interoperability between applications and libraries.

So we're going to have all that and we're going to like it. Which
we do. We use the opportunity to shed annotations and make libpng
less baroque, both in interface and in implementation.
  • Loading branch information
ctruta committed Feb 21, 2025
1 parent b950504 commit a2865e8
Show file tree
Hide file tree
Showing 27 changed files with 366 additions and 487 deletions.
4 changes: 2 additions & 2 deletions contrib/libtests/makepng.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
}


static void PNGCBAPI
static void
makepng_warning(png_structp png_ptr, png_const_charp message)
{
const char **ep = png_get_error_ptr(png_ptr);
Expand All @@ -760,7 +760,7 @@ makepng_warning(png_structp png_ptr, png_const_charp message)
fprintf(stderr, "%s: warning: %s\n", name, message);
}

static void PNGCBAPI
static void
makepng_error(png_structp png_ptr, png_const_charp message)
{
makepng_warning(png_ptr, message);
Expand Down
8 changes: 4 additions & 4 deletions contrib/libtests/pngimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,13 @@ display_log(struct display *dp, error_level level, const char *fmt, ...)
}

/* error handler callbacks for libpng */
static void PNGCBAPI
static void
display_warning(png_structp pp, png_const_charp warning)
{
display_log(get_dp(pp), LIBPNG_WARNING, "%s", warning);
}

static void PNGCBAPI
static void
display_error(png_structp pp, png_const_charp error)
{
struct display *dp = get_dp(pp);
Expand Down Expand Up @@ -858,7 +858,7 @@ buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
bp->read_count = read_count;
}

static void PNGCBAPI
static void
read_function(png_structp pp, png_bytep data, size_t size)
{
buffer_read(get_dp(pp), get_buffer(pp), data, size);
Expand Down Expand Up @@ -1325,7 +1325,7 @@ buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
buffer->end_count = end_count;
}

static void PNGCBAPI
static void
write_function(png_structp pp, png_bytep data, size_t size)
{
buffer_write(get_dp(pp), get_buffer(pp), data, size);
Expand Down
11 changes: 6 additions & 5 deletions contrib/libtests/pngunknown.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ clean_display(display *d)
}
}

PNG_FUNCTION(void, display_exit, (display *d), static PNG_NORETURN)
static PNG_NORETURN void
display_exit(display *d)
{
++(d->error_count);

Expand All @@ -480,16 +481,16 @@ display_rc(const display *d, int strict)
}

/* libpng error and warning callbacks */
PNG_FUNCTION(void, (PNGCBAPI error), (png_structp png_ptr, const char *message),
static PNG_NORETURN)
static PNG_NORETURN void
error(png_structp png_ptr, const char *message)
{
display *d = (display*)png_get_error_ptr(png_ptr);

fprintf(stderr, "%s(%s): libpng error: %s\n", d->file, d->test, message);
display_exit(d);
}

static void PNGCBAPI
static void
warning(png_structp png_ptr, const char *message)
{
display *d = (display*)png_get_error_ptr(png_ptr);
Expand Down Expand Up @@ -531,7 +532,7 @@ get_valid(display *d, png_infop info_ptr)
}

#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
static int PNGCBAPI
static int
read_callback(png_structp pp, png_unknown_chunkp pc)
{
/* This function mimics the behavior of png_set_keep_unknown_chunks by
Expand Down
30 changes: 15 additions & 15 deletions contrib/libtests/pngvalid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ internal_error(png_store *ps, png_const_charp message)
#endif /* PNG_READ_SUPPORTED */

/* Functions to use as PNG callbacks. */
static void PNGCBAPI
static void
store_error(png_structp ppIn, png_const_charp message) /* PNG_NORETURN */
{
png_const_structp pp = ppIn;
Expand All @@ -1109,7 +1109,7 @@ store_error(png_structp ppIn, png_const_charp message) /* PNG_NORETURN */
}
}

static void PNGCBAPI
static void
store_warning(png_structp ppIn, png_const_charp message)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -1281,7 +1281,7 @@ valid_chunktype(png_uint_32 chunktype)
return 1; /* It's valid */
}

static void PNGCBAPI
static void
store_write(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -1375,7 +1375,7 @@ store_write(png_structp ppIn, png_bytep pb, size_t st)
ps->chunklen = chunklen;
}

static void PNGCBAPI
static void
store_flush(png_structp ppIn)
{
UNUSED(ppIn) /*DOES NOTHING*/
Expand Down Expand Up @@ -1700,7 +1700,7 @@ store_read_chunk(png_store *ps, png_bytep pb, size_t max, size_t min)
return st; /* space left */
}

static void PNGCBAPI
static void
store_read(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -1903,7 +1903,7 @@ store_pool_delete(png_store *ps, store_pool *pool)
}

/* The memory callbacks: */
static png_voidp PNGCBAPI
static png_voidp
store_malloc(png_structp ppIn, png_alloc_size_t cb)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -1952,7 +1952,7 @@ store_malloc(png_structp ppIn, png_alloc_size_t cb)
return new;
}

static void PNGCBAPI
static void
store_free(png_structp ppIn, png_voidp memory)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -3198,7 +3198,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, size_t st)
}

/* The callback: */
static void PNGCBAPI
static void
modifier_read(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -5391,7 +5391,7 @@ standard_info_imp(standard_display *dp, png_structp pp, png_infop pi,
standard_info_part2(dp, pp, pi, nImages);
}

static void PNGCBAPI
static void
standard_info(png_structp pp, png_infop pi)
{
standard_display *dp = voidcast(standard_display*,
Expand All @@ -5403,7 +5403,7 @@ standard_info(png_structp pp, png_infop pi)
standard_info_imp(dp, pp, pi, 1 /*only one image*/);
}

static void PNGCBAPI
static void
progressive_row(png_structp ppIn, png_bytep new_row, png_uint_32 y, int pass)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -5703,7 +5703,7 @@ standard_image_validate(standard_display *dp, png_const_structp pp, int iImage,
dp->ps->validated = 1;
}

static void PNGCBAPI
static void
standard_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -6703,7 +6703,7 @@ transform_info_imp(transform_display *dp, png_structp pp, png_infop pi)
}
}

static void PNGCBAPI
static void
transform_info(png_structp pp, png_infop pi)
{
transform_info_imp(voidcast(transform_display*, png_get_progressive_ptr(pp)),
Expand Down Expand Up @@ -6919,7 +6919,7 @@ transform_image_validate(transform_display *dp, png_const_structp pp,
dp->this.ps->validated = 1;
}

static void PNGCBAPI
static void
transform_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -9385,7 +9385,7 @@ gamma_info_imp(gamma_display *dp, png_structp pp, png_infop pi)
standard_info_part2(&dp->this, pp, pi, 1 /*images*/);
}

static void PNGCBAPI
static void
gamma_info(png_structp pp, png_infop pi)
{
gamma_info_imp(voidcast(gamma_display*, png_get_progressive_ptr(pp)), pp,
Expand Down Expand Up @@ -10385,7 +10385,7 @@ gamma_image_validate(gamma_display *dp, png_const_structp pp,
dp->this.ps->validated = 1;
}

static void PNGCBAPI
static void
gamma_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
Expand Down
8 changes: 4 additions & 4 deletions contrib/tools/pngcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ makename(struct display *dp, const char *dir, const char *infile)
}

/* error handler callbacks for libpng */
static void PNGCBAPI
static void
display_warning(png_structp pp, png_const_charp warning)
{
struct display *dp = get_dp(pp);
Expand All @@ -1684,7 +1684,7 @@ display_warning(png_structp pp, png_const_charp warning)
display_log(get_dp(pp), LIBPNG_WARNING, "%s", warning);
}

static void PNGCBAPI
static void
display_error(png_structp pp, png_const_charp error)
{
struct display *dp = get_dp(pp);
Expand Down Expand Up @@ -1716,7 +1716,7 @@ display_start_read(struct display *dp, const char *filename)
display_log(dp, USER_ERROR, "file open failed (%s)", strerror(errno));
}

static void PNGCBAPI
static void
read_function(png_structp pp, png_bytep data, size_t size)
{
struct display *dp = get_dp(pp);
Expand Down Expand Up @@ -1896,7 +1896,7 @@ display_start_write(struct display *dp, const char *filename)
}
}

static void PNGCBAPI
static void
write_function(png_structp pp, png_bytep data, size_t size)
{
struct display *dp = get_dp(pp);
Expand Down
6 changes: 3 additions & 3 deletions contrib/tools/pngfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -3149,13 +3149,13 @@ read_chunk(struct file *file)
/* This returns a file* from a png_struct in an implementation specific way. */
static struct file *get_control(png_const_structrp png_ptr);

static void PNGCBAPI
static void
error_handler(png_structp png_ptr, png_const_charp message)
{
stop(get_control(png_ptr), LIBPNG_ERROR_CODE, message);
}

static void PNGCBAPI
static void
warning_handler(png_structp png_ptr, png_const_charp message)
{
struct file *file = get_control(png_ptr);
Expand All @@ -3167,7 +3167,7 @@ warning_handler(png_structp png_ptr, png_const_charp message)
/* Read callback - this is where the work gets done to check the stream before
* passing it to libpng
*/
static void PNGCBAPI
static void
read_callback(png_structp png_ptr, png_bytep buffer, size_t count)
/* Return 'count' bytes to libpng in 'buffer' */
{
Expand Down
29 changes: 5 additions & 24 deletions manuals/libpng-install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,30 +345,11 @@ way pngusr.h is used in the build has been changed; however, library
builders will probably want to examine the changes to take advantage of
new capabilities and to simplify their build system.

A. Specific changes to library configuration capabilities

The exact mechanism used to control attributes of API functions has
changed. A single set of operating system independent macro definitions
is used and operating system specific directives are defined in
pnglibconf.h

As part of this the mechanism used to choose procedure call standards on
those systems that allow a choice has been changed. At present this only
affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
running on Intel processors. As before, PNGAPI is defined where required
to control the exported API functions; however, two new macros, PNGCBAPI
and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
(PNGCAPI) for functions that must match a C library prototype (currently
only png_longjmp_ptr, which must match the C longjmp function.) The new
approach is documented in pngconf.h

Despite these changes, libpng 1.5.0 only supports the native C function
calling standard on those platforms tested so far ("__cdecl" on Microsoft
Windows). This is because the support requirements for alternative
calling conventions seem to no longer exist. Developers who find it
necessary to set PNG_API_RULE to 1 should advise the mailing list
(png-mng-implement) of this and library builders who use Openwatcom and
therefore set PNG_API_RULE to 2 should also contact the mailing list.
A. Changes to the library configuration capabilities

A new mechanism to control attributes of API functions was introduced in
libpng-1.5.0. A single set of system-independent macro definitions and
directives is defined in pnglibconf.h

B. Changes to the configuration mechanism

Expand Down
6 changes: 3 additions & 3 deletions manuals/libpng-manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5317,13 +5317,13 @@ We don't use C++ style ("//") comments. We have, however,
used them in the past in some now-abandoned MMX assembler
code.

Functions and their curly braces are not indented, and
exported functions are marked with PNGAPI:
Functions and their curly braces are not indented. We used to mark
the exported functions with PNGAPI, but we no longer do:

/* This is a public function that is visible to
* application programmers. It does thus-and-so.
*/
void PNGAPI
void
png_exported_function(png_ptr, png_info, foo)
{
body;
Expand Down
6 changes: 3 additions & 3 deletions manuals/libpng.3
Original file line number Diff line number Diff line change
Expand Up @@ -5826,13 +5826,13 @@ We don't use C++ style ("//") comments. We have, however,
used them in the past in some now-abandoned MMX assembler
code.

Functions and their curly braces are not indented, and
exported functions are marked with PNGAPI:
Functions and their curly braces are not indented. We used to mark
the exported functions with PNGAPI, but we no longer do:

/* This is a public function that is visible to
* application programmers. It does thus-and-so.
*/
void PNGAPI
void
png_exported_function(png_ptr, png_info, foo)
{
body;
Expand Down
Loading

0 comments on commit a2865e8

Please sign in to comment.