madler / zlib

A massively spiffy yet delicately unobtrusive compression library.
http://zlib.net/
Other
5.58k stars 2.43k forks source link

include <stdint.h> only if HAS_STDINT_H is defined #999

Closed minchai23 closed 1 month ago

minchai23 commented 1 month ago

https://github.com/madler/zlib/blob/develop/contrib/minizip/zip.c#L28

#include <stdint.h>

https://github.com/madler/zlib/blob/develop/contrib/minizip/ioapi.h#L89

#ifdef HAS_STDINT_H
#include "stdint.h"
typedef uint64_t ZPOS64_T;
#else
...
#endif
minchai23 commented 1 month ago

Otherwise,compiling error on an older compiler,because the stdint.h header file is not found. @madler

madler commented 1 month ago

What compiler is this?

minchai23 commented 1 month ago

What compiler is this?

gcc 2.96 in tornado 2.2,support C standard library version is C89

madler commented 1 month ago

Does it have limits.h? long long?

minchai23 commented 1 month ago

Does it have limits.h? long long?

yes, both limits.h and long long exists

madler commented 1 month ago

Please let me know if this compiles without error:

#ifndef INTS_H
#define INTS_H
#include <limits.h>
#if defined(UCHAR_MAX) && UCHAR_MAX == 0xff
    typedef signed char i8_t;
    typedef unsigned char ui8_t;
#else
#   error "no 8-bit integer"
#endif
#if defined(USHRT_MAX) && USHRT_MAX == 0xffff
    typedef short i16_t;
    typedef unsigned short ui16_t;
#elif defined(UINT_MAX) && UINT_MAX == 0xffff
    typedef int i16_t;
    typedef unsigned ui16_t;
#else
#   error "no 16-bit integer"
#endif
#if defined(UINT_MAX) && UINT_MAX == 0xffffffff
    typedef int i32_t;
    typedef unsigned ui32_t;
#elif defined(ULONG_MAX) && ULONG_MAX == 0xffffffff
    typedef long i32_t;
    typedef unsigned long ui32_t;
#else
#   error "no 32-bit integer"
#endif
#if defined(ULONG_MAX) && ULONG_MAX == 0xffffffffffffffff
    typedef long i64_t;
    typedef unsigned long ui64_t;
#elif defined(ULLONG_MAX) && ULLONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#else
#   error "no 64-bit integer"
#endif
#endif
minchai23 commented 1 month ago

error "no 64-bit integer

image

madler commented 1 month ago

Is ULLONG_MAX not defined in limits.h (or what it may itself include)?

minchai23 commented 1 month ago

Is ULLONG_MAX not defined in limits.h (or what it may itself include)?

ULLONG_MAX not defined,but ULONG_MAX and ULONG_LONG_MAX image image

minchai23 commented 1 month ago

View Commit Log , #include <stdint.h> just to use uintptr_t.

zi->ci.stream.next_in = (Bytef*)(uintptr_t)buf;

Can uintptr_t typecast be removed here? Direct typecast seems to be fine.

madler commented 1 month ago

It's not fine as is, since that generates a warning about removing the const constraint on buf. However I have already removed the uintptr_t cast in my local branch by preceding the #include "zlib.h" with a #define ZLIB_CONST, which makes next_in const, and also removing the Bytef* cast. There is then no removal of the const constraint, and no warning.

madler commented 1 month ago

Weird. Ok. Please try this:

#ifndef INTS_H
#define INTS_H
#include <limits.h>
#if defined(UCHAR_MAX) && UCHAR_MAX == 0xff
    typedef signed char i8_t;
    typedef unsigned char ui8_t;
#else
#   error "no 8-bit integer"
#endif
#if defined(USHRT_MAX) && USHRT_MAX == 0xffff
    typedef short i16_t;
    typedef unsigned short ui16_t;
#elif defined(UINT_MAX) && UINT_MAX == 0xffff
    typedef int i16_t;
    typedef unsigned ui16_t;
#else
#   error "no 16-bit integer"
#endif
#if defined(UINT_MAX) && UINT_MAX == 0xffffffff
    typedef int i32_t;
    typedef unsigned ui32_t;
#   define PI32 "d"
#   define PUI32 "u"
#elif defined(ULONG_MAX) && ULONG_MAX == 0xffffffff
    typedef long i32_t;
    typedef unsigned long ui32_t;
#   define PI32 "ld"
#   define PUI32 "lu"
#else
#   error "no 32-bit integer"
#endif
#if defined(ULONG_MAX) && ULONG_MAX == 0xffffffffffffffff
    typedef long i64_t;
    typedef unsigned long ui64_t;
#   define PI64 "ld"
#   define PUI64 "lu"
#elif defined(ULLONG_MAX) && ULLONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#   define PI64 "lld"
#   define PUI64 "llu"
#elif defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#   define PI64 "lld"
#   define PUI64 "llu"
#else
#   error "no 64-bit integer"
#endif
#endif
minchai23 commented 1 month ago

Weird. Ok. Please try this:

#ifndef INTS_H
#define INTS_H
#include <limits.h>
#if defined(UCHAR_MAX) && UCHAR_MAX == 0xff
    typedef signed char i8_t;
    typedef unsigned char ui8_t;
#else
#   error "no 8-bit integer"
#endif
#if defined(USHRT_MAX) && USHRT_MAX == 0xffff
    typedef short i16_t;
    typedef unsigned short ui16_t;
#elif defined(UINT_MAX) && UINT_MAX == 0xffff
    typedef int i16_t;
    typedef unsigned ui16_t;
#else
#   error "no 16-bit integer"
#endif
#if defined(UINT_MAX) && UINT_MAX == 0xffffffff
    typedef int i32_t;
    typedef unsigned ui32_t;
#   define PI32 "d"
#   define PUI32 "u"
#elif defined(ULONG_MAX) && ULONG_MAX == 0xffffffff
    typedef long i32_t;
    typedef unsigned long ui32_t;
#   define PI32 "ld"
#   define PUI32 "lu"
#else
#   error "no 32-bit integer"
#endif
#if defined(ULONG_MAX) && ULONG_MAX == 0xffffffffffffffff
    typedef long i64_t;
    typedef unsigned long ui64_t;
#   define PI64 "ld"
#   define PUI64 "lu"
#elif defined(ULLONG_MAX) && ULLONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#   define PI64 "lld"
#   define PUI64 "llu"
#elif defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 0xffffffffffffffff
    typedef long long i64_t;
    typedef unsigned long long ui64_t;
#   define PI64 "lld"
#   define PUI64 "llu"
#else
#   error "no 64-bit integer"
#endif
#endif

compile success !!!

madler commented 1 month ago

Great! Thank you for your help.

minchai23 commented 1 month ago

if there's a rough estimate of when a fix might be available?

madler commented 1 month ago

Soon.

As an aside, I found that gcc 2.96 was never a released version! https://gcc.gnu.org/gcc-2.96.html

madler commented 1 month ago

https://github.com/madler/zlib/commit/be24a8f4ca8ae9870c1af4bd5a59375bb36c49fc should fix it.