Skip to content

Commit

Permalink
[libpng16] build: Rename a private function to benefit C++Builder
Browse files Browse the repository at this point in the history
Embarcadero's compilers, old (Borland-based) and new (Clang-based),
do have full support for Standard C. The Clang-based compiler is
claiming, through the macro __STDC_VERSION__, to support C99 and C11,
whereas the Borland-based compiler supports ANSI C, as it has for
decades.

However, their run-time library is exposing global functions beyond
the scope of Standard C, for backwards compatibility with the older
Borland products. One of these functions is `randomize`, which clashes
with a function inside pngvalid.c that incidentally has the same name.

Building libpng in "Strict ANSI C" mode, in which all Borland-specific
globals are hidden (e.g. via `bcc32 -A`), would have been a workable
solution for the Borland-based ANSI C compiler, but no such solution
appears to exist for the Clang-based C90/C99/C11 compiler.

Fortunately, renaming a private function inside a test program is a
cost-free alternative fix.

This is a cherry-pick of commit 6184164
from branch 'libpng18'.
  • Loading branch information
ctruta committed Oct 18, 2024
1 parent d9d70e6 commit c1cc0f3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions contrib/libtests/pngvalid.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,20 @@ make_four_random_bytes(png_uint_32* seed, png_bytep bytes)
#if defined PNG_READ_SUPPORTED || defined PNG_WRITE_tRNS_SUPPORTED ||\
defined PNG_WRITE_FILTER_SUPPORTED
static void
randomize(void *pv, size_t size)
randomize_bytes(void *pv, size_t size)
{
static png_uint_32 random_seed[2] = {0x56789abc, 0xd};
make_random_bytes(random_seed, pv, size);
}

#define R8(this) randomize(&(this), sizeof (this))
#define R8(this) randomize_bytes(&(this), sizeof (this))

#ifdef PNG_READ_SUPPORTED
static png_byte
random_byte(void)
{
unsigned char b1[1];
randomize(b1, sizeof b1);
randomize_bytes(b1, sizeof b1);
return b1[0];
}
#endif /* READ */
Expand All @@ -325,7 +325,7 @@ static png_uint_16
random_u16(void)
{
unsigned char b2[2];
randomize(b2, sizeof b2);
randomize_bytes(b2, sizeof b2);
return png_get_uint_16(b2);
}

Expand All @@ -335,7 +335,7 @@ static png_uint_32
random_u32(void)
{
unsigned char b4[4];
randomize(b4, sizeof b4);
randomize_bytes(b4, sizeof b4);
return png_get_uint_32(b4);
}
#endif /* READ_FILLER || READ_RGB_TO_GRAY */
Expand Down

0 comments on commit c1cc0f3

Please sign in to comment.