Skip to content

Commit 7fb72a5

Browse files
committed
deps,src: align ssize_t ABI between Node & nghttp2
Previously, we performed casts that are considered undefined behavior. Instead, just define `ssize_t` for nghttp2 the same way we define it for the rest of Node. Also, remove a TODO comment that would probably also be *technically* correct but shouldn’t matter as long as nobody is complaining. PR-URL: #18565 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 7dd3c8a commit 7fb72a5

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

deps/nghttp2/lib/includes/config.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
/* Hint to the compiler that a function never returns */
22
#define NGHTTP2_NORETURN
33

4-
/* Define to `int' if <sys/types.h> does not define. */
5-
#define ssize_t int
4+
/* Edited to match src/node.h. */
5+
#include <stdint.h>
6+
7+
#ifdef _WIN32
8+
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
9+
typedef intptr_t ssize_t;
10+
# define _SSIZE_T_
11+
# define _SSIZE_T_DEFINED
12+
#endif
13+
#else // !_WIN32
14+
# include <sys/types.h> // size_t, ssize_t
15+
#endif // _WIN32
616

717
/* Define to 1 if you have the `std::map::emplace`. */
818
#define HAVE_STD_MAP_EMPLACE 1

src/node.h

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ NODE_EXTERN v8::Local<v8::Value> MakeCallback(
184184
#endif
185185

186186
#ifdef _WIN32
187-
// TODO(tjfontaine) consider changing the usage of ssize_t to ptrdiff_t
188187
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
189188
typedef intptr_t ssize_t;
190189
# define _SSIZE_T_

src/node_http2.cc

+2-11
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,7 @@ inline ssize_t Http2Session::Write(const uv_buf_t* bufs, size_t nbufs) {
764764
bufs[n].len);
765765
CHECK_NE(ret, NGHTTP2_ERR_NOMEM);
766766

767-
// If there is an error calling any of the callbacks, ret will be a
768-
// negative number identifying the error code. This can happen, for
769-
// instance, if the session is destroyed during any of the JS callbacks
770-
// Note: if ssize_t is not defined (e.g. on Win32), nghttp2 will typedef
771-
// ssize_t to int. Cast here so that the < 0 check actually works on
772-
// Windows.
773-
if (static_cast<int>(ret) < 0)
767+
if (ret < 0)
774768
return ret;
775769

776770
total += ret;
@@ -1709,10 +1703,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
17091703
statistics_.data_received += nread;
17101704
ssize_t ret = Write(&stream_buf_, 1);
17111705

1712-
// Note: if ssize_t is not defined (e.g. on Win32), nghttp2 will typedef
1713-
// ssize_t to int. Cast here so that the < 0 check actually works on
1714-
// Windows.
1715-
if (static_cast<int>(ret) < 0) {
1706+
if (ret < 0) {
17161707
DEBUG_HTTP2SESSION2(this, "fatal error receiving data: %d", ret);
17171708

17181709
Local<Value> argv[] = {

0 commit comments

Comments
 (0)