Skip to content

Commit 6a16e67

Browse files
committed
Initialize libssh2 from separate .cc file to avoid type redifinition conflicts
This is better than silencing the redefinition in case the two definitions really need to be different.
1 parent a299094 commit 6a16e67

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef INIT_SSH2
2+
#define INIT_SSH2
3+
4+
void init_ssh2();
5+
6+
#endif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// We are initializing libssh2 from a separate .cc file to avoid ssize_t
2+
// redefinition conflicts caused by incliding both node.h and libssh2.h from
3+
// the same file (e.g. nodegit.cc)
4+
//
5+
// The redefinition can also be avoided by #defines but that is risky in case
6+
// the libraries depend on the different definitions.
7+
8+
#include <libssh2.h>
9+
10+
void init_ssh2() {
11+
libssh2_init(0);
12+
}

generate/templates/templates/binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"sources": [
1717
"src/lock_master.cc",
1818
"src/nodegit.cc",
19+
"src/init_ssh2.cc",
1920
"src/promise_completion.cc",
2021
"src/wrapper.cc",
2122
"src/functions/copy.cc",

generate/templates/templates/nodegit.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88
#include <set>
99

1010
#include <openssl/crypto.h>
11-
// we have to include <libssh2.h> first so it defines ssize_t
12-
// and then node.h with _SSIZE_T_ defined to prevent it from redefining
13-
// in a conflicting way on 32 bit windows
14-
#define ssize_t ssize_t
15-
#include <libssh2.h>
1611

12+
#include "../include/init_ssh2.h"
1713
#include "../include/lock_master.h"
1814
#include "../include/wrapper.h"
1915
#include "../include/promise_completion.h"
@@ -75,7 +71,7 @@ void OpenSSL_ThreadSetup() {
7571
extern "C" void init(Local<v8::Object> target) {
7672
// Initialize thread safety in openssl and libssh2
7773
OpenSSL_ThreadSetup();
78-
libssh2_init(0);
74+
init_ssh2();
7975
// Initialize libgit2.
8076
git_libgit2_init();
8177

0 commit comments

Comments
 (0)