From 1131241d3cd01acd45d420e68341485c11113685 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 4 Feb 2018 19:32:26 +0100 Subject: [PATCH] deps,src: align ssize_t ABI between Node & nghttp2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/20456 PR-URL: https://github.com/nodejs/node/pull/18565 Reviewed-By: Matteo Collina Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- deps/nghttp2/lib/includes/config.h | 14 ++++++++++++-- src/node.h | 1 - src/node_http2.cc | 10 ++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/deps/nghttp2/lib/includes/config.h b/deps/nghttp2/lib/includes/config.h index 0346e0614fdb8d..242bbcfb62ff7a 100644 --- a/deps/nghttp2/lib/includes/config.h +++ b/deps/nghttp2/lib/includes/config.h @@ -1,8 +1,18 @@ /* Hint to the compiler that a function never returns */ #define NGHTTP2_NORETURN -/* Define to `int' if does not define. */ -#define ssize_t int +/* Edited to match src/node.h. */ +#include + +#ifdef _WIN32 +#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) +typedef intptr_t ssize_t; +# define _SSIZE_T_ +# define _SSIZE_T_DEFINED +#endif +#else // !_WIN32 +# include // size_t, ssize_t +#endif // _WIN32 /* Define to 1 if you have the `std::map::emplace`. */ #define HAVE_STD_MAP_EMPLACE 1 diff --git a/src/node.h b/src/node.h index a48c9bc86f6904..78b2b2b64a6feb 100644 --- a/src/node.h +++ b/src/node.h @@ -178,7 +178,6 @@ NODE_EXTERN v8::Local MakeCallback( #endif #ifdef _WIN32 -// TODO(tjfontaine) consider changing the usage of ssize_t to ptrdiff_t #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) typedef intptr_t ssize_t; # define _SSIZE_T_ diff --git a/src/node_http2.cc b/src/node_http2.cc index bd7eeee8655e52..33d8b359f3efc7 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -775,13 +775,7 @@ inline ssize_t Http2Session::Write(const uv_buf_t* bufs, size_t nbufs) { bufs[n].len); CHECK_NE(ret, NGHTTP2_ERR_NOMEM); - // If there is an error calling any of the callbacks, ret will be a - // negative number identifying the error code. This can happen, for - // instance, if the session is destroyed during any of the JS callbacks - // Note: if ssize_t is not defined (e.g. on Win32), nghttp2 will typedef - // ssize_t to int. Cast here so that the < 0 check actually works on - // Windows. - if (static_cast(ret) < 0) + if (ret < 0) return ret; total += ret; @@ -1693,7 +1687,7 @@ void Http2Session::OnStreamReadImpl(ssize_t nread, // ssize_t to int. Cast here so that the < 0 check actually works on // Windows. if (static_cast(ret) < 0) { - DEBUG_HTTP2SESSION2(session, "fatal error receiving data: %d", ret); + DEBUG_HTTP2SESSION2(this, "fatal error receiving data: %d", ret); Local argv[1] = { Integer::New(isolate, ret),