-
Notifications
You must be signed in to change notification settings - Fork 933
Closed
Description
Windows C environment does not offer ssize_t type out of the box. Therefore the nghhtp2 library offers to define it in the compiler flags like:
CFLAGS = ... -Dssize_t=long ...
This is a questionable way to go for a number of reasons:
- Definition of the data type in the compilation command complicates use of the library in software development: one should not forget to define ssize_t in the same way, which is pretty inconvenient and not flexible;
- Although ssize_t is not defined out of the box on Windows, it is too well known type name to define it in a specific library: a chance of conflict with other code is high;
- Finally, definition of ssize_t as long does not look correct for 64-bit builds; sizeof(long) is 4 for 64-bit Windows while 8-byte data would be more appropriate. Windows introduces SSIZE_T type though.
Looks like the best solution would be introduction of a kind of nghhtp2_ssize_t type, which would be properly typedef'ed for each platform flavor. As a quick workaround, the following method works:
- The Windows complication flags (locally for the library build only) are changed to
- The following code is added to file 'includes/nghttp2/nghttp2.h' (line ~32; after ensuring WIN32 is defined):
#if defined(WIN32) # pragma once # include <basetsd.h> typedef SSIZE_T NGHTTP2_SSIZE_T; # if !defined(BUILDING_NGHTTP2) # define ssize_t NGHTTP2_SSIZE_T # endif #endif
- The following code is added to file 'includes/nghttp2/nghttp2.h' (line ~4965; before the final #endif):
#if defined(WIN32) # if !defined(BUILDING_NGHTTP2) # undef ssize_t # endif #endif
CFLAGS = ... -Dssize_t=SSIZE_T ...
This does not require massive code changes, defines ssize_t properly and consistently for x86/x64 Windows platforms, and encapsulates ssize_t definition inside the library code offering NGHTTP2_SSIZE_T to one who uses this library in their own code.
Reactions are currently unavailable