Skip to content

Commit

Permalink
src: fix ssize_t error from nghttp2.h
Browse files Browse the repository at this point in the history
The "node_http2.h" include reordering enforced by clang-format (nodejs@32446d8#diff-33f026e43570112875cf4c8eab6743496f3aa014329611128e348ec23d6f771cR1)
broke Electron's Node.js upgrade on Windows.

```sh
In file included from ../../third_party/electron_node/src/node_http2.cc:1:
In file included from ../../third_party/electron_node/src/node_http2.h:8:
../../third_party/electron_node/deps/nghttp2/lib/includes\nghttp2/nghttp2.h(930,9): error: unknown type name 'ssize_t'
typedef ssize_t (*nghttp2_data_source_read_callback)(
        ^
```

ssize_t is a part of the POSIX standard and it's not available on
Windows, so the fix for this is to typedef it on Windows like in
https://github.com/nodejs/node/blob/bb4dff783ddb3b20c67041f7ccef796c335c2407/src/node.h#L212-L220.

Refs: electron/electron#35350 (comment)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen committed Aug 25, 2022
1 parent 937520a commit a5a023c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

// nghttp2.h needs ssize_t to compile on Windows.
// Refs: https://github.com/electron/electron/pull/35350#discussion_r954890551
// Same as
// https://github.com/nodejs/node/blob/bb4dff783ddb3b20c67041f7ccef796c335c2407/src/node.h#L212-L220.
#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 <sys/types.h> // size_t, ssize_t
#endif // _WIN32

// FIXME(joyeecheung): nghttp2.h needs stdint.h to compile on Windows
#include <cstdint>
#include "nghttp2/nghttp2.h"
Expand Down

0 comments on commit a5a023c

Please sign in to comment.