Skip to content

Commit fe8de45

Browse files
authored
Use SSIZE_T for ssize_t on Windows (#5811)
The PR adds a compile assert to ensure that size_t and ssize_t have the same size, just to be sure. * Use SSIZE_T for ssize_t on Windows * Use SSIZE_T and SSIZE_T_MAX * Add missing header * Exclude MinGW from ssize_t ifdefs
1 parent ceea2c3 commit fe8de45

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

src/H5.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ H5_init_library(void)
154154
*/
155155
H5_INIT_GLOBAL = true;
156156

157+
/* Make sure we picked a good type for ssize_t if it wasn't present */
158+
HDcompile_assert(sizeof(size_t) == sizeof(ssize_t));
159+
157160
#ifdef H5_HAVE_PARALLEL
158161
{
159162
int mpi_initialized;

src/H5private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
* Only needed where ssize_t isn't a thing (e.g., Windows)
372372
*/
373373
#ifndef SSIZE_MAX
374-
#define SSIZE_MAX ((ssize_t)(((size_t)1 << (8 * sizeof(ssize_t) - 1)) - 1))
374+
#define SSIZE_MAX SSIZE_T_MAX
375375
#endif
376376

377377
/*

src/H5public.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,11 @@ typedef int htri_t;
289289
*
290290
* Use of ssize_t should be discouraged in new code.
291291
*/
292-
#if H5_SIZEOF_SSIZE_T == 0
293-
/* Undefine this size, we will re-define it in one of the sections below */
294-
#undef H5_SIZEOF_SSIZE_T
295-
#if H5_SIZEOF_SIZE_T == H5_SIZEOF_INT
296-
typedef int ssize_t;
297-
#define H5_SIZEOF_SSIZE_T H5_SIZEOF_INT
298-
#elif H5_SIZEOF_SIZE_T == H5_SIZEOF_LONG
299-
typedef long ssize_t;
300-
#define H5_SIZEOF_SSIZE_T H5_SIZEOF_LONG
301-
#elif H5_SIZEOF_SIZE_T == H5_SIZEOF_LONG_LONG
302-
typedef long long ssize_t;
303-
#define H5_SIZEOF_SSIZE_T H5_SIZEOF_LONG_LONG
304-
#else /* Can't find matching type for ssize_t */
305-
#error "nothing appropriate for ssize_t"
306-
#endif
292+
#if defined(_WIN32) && !defined(__MINGW32__)
293+
#include <BaseTsd.h>
294+
typedef SSIZE_T ssize_t;
295+
/* This will have been defined to 0 in configure */
296+
#define H5_SIZEOF_SSIZE_T H5_SIZEOF_SIZE_T
307297
#endif
308298

309299
/**

0 commit comments

Comments
 (0)