Skip to content

Commit

Permalink
windows: fix size of ssize_t
Browse files Browse the repository at this point in the history
Previously, `long long` was used unconditionally to define `ssize_t` on
Windows. This meant it was always a 64-bit value. However, typically
the size type is a 32-bit value on 32-bit machines and 64-bit value on
64-bit machines.

This didn't cause any issues until it was used on 32-bit Windows build
of `libvalkey-py`. CPython defines the `ssize_t` type as well as
`libvalkey`, but it defines the size to be 32 bit on 32 bit machines
which caused a compilation error.

This commit changes the typedef to be `SSIZE_T` on Windows. Hence, it
will be aligned with everything else.

Signed-off-by: Mikhail Koviazin <[email protected]>
  • Loading branch information
mkmkme committed Jul 30, 2024
1 parent 0713e81 commit 838d51a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/valkey/sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

#define SDS_MAX_PREALLOC (1024*1024)
#ifdef _MSC_VER
typedef long long ssize_t;
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#define SSIZE_MAX (LLONG_MAX >> 1)
#ifndef __clang__
#define __attribute__(x)
Expand Down
3 changes: 2 additions & 1 deletion include/valkey/sockcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
#include <mstcpip.h>

#ifdef _MSC_VER
typedef long long ssize_t;
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#endif

/* Emulate the parts of the BSD socket API that we need (override the winsock signatures). */
Expand Down
3 changes: 2 additions & 1 deletion include/valkey/valkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
#ifndef _MSC_VER
#include <sys/time.h> /* for struct timeval */
#else
#include <basetsd.h>
struct timeval; /* forward declaration */
typedef long long ssize_t;
typedef SSIZE_T ssize_t;
#endif
#include <stdint.h> /* uintXX_t, etc */
#include "sds.h" /* for sds */
Expand Down

0 comments on commit 838d51a

Please sign in to comment.