Skip to content

Commit 454bd9a

Browse files
committed
Support for swig 4.1.0
In swig 4.1.0, the complicated handling of "SWIG_V8_VERSION" has been cleaned up a bit. I made the same changes as in this swig. Signed-off-by: Hirokazu MORIKAWA <[email protected]>
1 parent 833bac5 commit 454bd9a

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

api/mraa/gpio.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ class Gpio
175175
v8::Local<v8::Value> argv[] = { SWIGV8_INTEGER_NEW(-1) };
176176
#if NODE_MODULE_VERSION >= 0x000D
177177
v8::Local<v8::Function> f = v8::Local<v8::Function>::New(v8::Isolate::GetCurrent(), This->m_v8isr);
178+
#if (V8_MAJOR_VERSION-0) < 4
178179
f->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
180+
#else
181+
f->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
182+
#endif
179183
#else
180184
This->m_v8isr->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
181185
#endif

src/javascript/mraajs.i

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ namespace mraa {
4242
class Spi;
4343
%typemap(out) uint8_t*
4444
{
45-
%#if SWIG_V8_VERSION > 0x040000
45+
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION <= 0x032870)
46+
$result = node::Buffer::New((char*) result, arg3)->handle_;
47+
free(result);
48+
%#elif (V8_MAJOR_VERSION-0) < 4
49+
$result = node::Buffer::New((char*) result, arg3);
50+
free(result);
51+
%#else
4652
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) result, arg3);
4753
free(result);
4854
if(!objret.ToLocal(&$result)){
4955
SWIG_exception_fail(SWIG_ERROR, "Spi buffer failed");
5056
}
51-
%#elif SWIG_V8_VERSION > 0x032870
52-
$result = node::Buffer::New((char*) result, arg3);
53-
free(result);
54-
%#else
55-
$result = node::Buffer::New((char*) result, arg3)->handle_;
56-
free(result);
5757
%#endif
5858
}
5959
}
@@ -81,18 +81,18 @@ class Spi;
8181
free($1);
8282
SWIG_exception_fail(SWIG_ERROR, "Uart write failed");
8383
}
84-
%#if SWIG_V8_VERSION > 0x040000
85-
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) $1, result);
84+
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION <= 0x032870)
85+
$result = node::Buffer::New((char*) $1, result)->handle_;
8686
free($1);
87-
if(!objret.ToLocal(&$result)) {
88-
SWIG_exception_fail(SWIG_ERROR, "Uart buffer failed");
89-
}
90-
%#elif SWIG_V8_VERSION > 0x032870
87+
%#elif (V8_MAJOR_VERSION-0) < 4
9188
$result = node::Buffer::New((char*) $1, result);
9289
free($1);
9390
%#else
94-
$result = node::Buffer::New((char*) $1, result)->handle_;
91+
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) $1, result);
9592
free($1);
93+
if(!objret.ToLocal(&$result)) {
94+
SWIG_exception_fail(SWIG_ERROR, "Uart buffer failed");
95+
}
9696
%#endif
9797

9898
}
@@ -116,18 +116,18 @@ class Spi;
116116
free($1);
117117
SWIG_exception_fail(SWIG_ERROR, "I2c write failed");
118118
}
119-
%#if SWIG_V8_VERSION > 0x040000
120-
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) $1, result);
119+
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION <= 0x032870)
120+
$result = node::Buffer::New((char*) $1, result)->handle_;
121121
free($1);
122-
if(!objret.ToLocal(&$result)) {
123-
SWIG_exception_fail(SWIG_ERROR, "I2c buffer failed");
124-
}
125-
%#elif SWIG_V8_VERSION > 0x032870
122+
%#elif (V8_MAJOR_VERSION-0) < 4
126123
$result = node::Buffer::New((char*) $1, result);
127124
free($1);
128125
%#else
129-
$result = node::Buffer::New((char*) $1, result)->handle_;
126+
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) $1, result);
130127
free($1);
128+
if(!objret.ToLocal(&$result)) {
129+
SWIG_exception_fail(SWIG_ERROR, "I2c buffer failed");
130+
}
131131
%#endif
132132
}
133133

0 commit comments

Comments
 (0)