Skip to content

Commit 1131241

Browse files
addaleaxMylesBorins
authored andcommitted
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. Backport-PR-URL: #20456 PR-URL: #18565 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent fe3c85f commit 1131241

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
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
@@ -178,7 +178,6 @@ NODE_EXTERN v8::Local<v8::Value> MakeCallback(
178178
#endif
179179

180180
#ifdef _WIN32
181-
// TODO(tjfontaine) consider changing the usage of ssize_t to ptrdiff_t
182181
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
183182
typedef intptr_t ssize_t;
184183
# define _SSIZE_T_

src/node_http2.cc

+2-8
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,7 @@ inline ssize_t Http2Session::Write(const uv_buf_t* bufs, size_t nbufs) {
775775
bufs[n].len);
776776
CHECK_NE(ret, NGHTTP2_ERR_NOMEM);
777777

778-
// If there is an error calling any of the callbacks, ret will be a
779-
// negative number identifying the error code. This can happen, for
780-
// instance, if the session is destroyed during any of the JS callbacks
781-
// Note: if ssize_t is not defined (e.g. on Win32), nghttp2 will typedef
782-
// ssize_t to int. Cast here so that the < 0 check actually works on
783-
// Windows.
784-
if (static_cast<int>(ret) < 0)
778+
if (ret < 0)
785779
return ret;
786780

787781
total += ret;
@@ -1693,7 +1687,7 @@ void Http2Session::OnStreamReadImpl(ssize_t nread,
16931687
// ssize_t to int. Cast here so that the < 0 check actually works on
16941688
// Windows.
16951689
if (static_cast<int>(ret) < 0) {
1696-
DEBUG_HTTP2SESSION2(session, "fatal error receiving data: %d", ret);
1690+
DEBUG_HTTP2SESSION2(this, "fatal error receiving data: %d", ret);
16971691

16981692
Local<Value> argv[1] = {
16991693
Integer::New(isolate, ret),

0 commit comments

Comments
 (0)