Skip to content

Commit

Permalink
Support for swig 4.1.0
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nxhack authored and tingleby committed Jul 1, 2022
1 parent 3b22201 commit 046bdd0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
4 changes: 4 additions & 0 deletions api/mraa/gpio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ class Gpio
v8::Local<v8::Value> argv[] = { SWIGV8_INTEGER_NEW(-1) };
#if NODE_MODULE_VERSION >= 0x000D
v8::Local<v8::Function> f = v8::Local<v8::Function>::New(v8::Isolate::GetCurrent(), This->m_v8isr);
#if (V8_MAJOR_VERSION-0) < 4
f->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
#else
f->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
#endif
#else
This->m_v8isr->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
#endif
Expand Down
7 changes: 6 additions & 1 deletion src/javascript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ if (BUILDCPP)
message (STATUS "INFO - Using V8 version > 3 so requiring C++11 compiler")
# Node 0.12.x V8 engine major version is '3'.
# Node 2.1.0 V8 engine major version is '4'.
set_property (TARGET mraajs PROPERTY CXX_STANDARD 11)
# Node 16.0.0 V8 engine major version is '9'.
if (${V8_VERSION_MAJOR} GREATER 8)
set_property (TARGET mraajs PROPERTY CXX_STANDARD 14)
else ()
set_property (TARGET mraajs PROPERTY CXX_STANDARD 11)
endif ()
set_property (TARGET mraajs PROPERTY CXX_STANDARD_REQUIRED ON)
if (CMAKE_VERSION VERSION_LESS "3.1")
message (WARNING "Need to use CMAKE version 3.1+, but it is ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}, using a workaround.")
Expand Down
42 changes: 21 additions & 21 deletions src/javascript/mraajs.i
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ namespace mraa {
class Spi;
%typemap(out) uint8_t*
{
%#if SWIG_V8_VERSION > 0x040000
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION <= 0x032870)
$result = node::Buffer::New((char*) result, arg3)->handle_;
free(result);
%#elif (V8_MAJOR_VERSION-0) < 4
$result = node::Buffer::New((char*) result, arg3);
free(result);
%#else
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) result, arg3);
free(result);
if(!objret.ToLocal(&$result)){
SWIG_exception_fail(SWIG_ERROR, "Spi buffer failed");
}
%#elif SWIG_V8_VERSION > 0x032870
$result = node::Buffer::New((char*) result, arg3);
free(result);
%#else
$result = node::Buffer::New((char*) result, arg3)->handle_;
free(result);
%#endif
}
}
Expand Down Expand Up @@ -81,18 +81,18 @@ class Spi;
free($1);
SWIG_exception_fail(SWIG_ERROR, "Uart write failed");
}
%#if SWIG_V8_VERSION > 0x040000
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) $1, result);
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION <= 0x032870)
$result = node::Buffer::New((char*) $1, result)->handle_;
free($1);
if(!objret.ToLocal(&$result)) {
SWIG_exception_fail(SWIG_ERROR, "Uart buffer failed");
}
%#elif SWIG_V8_VERSION > 0x032870
%#elif (V8_MAJOR_VERSION-0) < 4
$result = node::Buffer::New((char*) $1, result);
free($1);
%#else
$result = node::Buffer::New((char*) $1, result)->handle_;
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) $1, result);
free($1);
if(!objret.ToLocal(&$result)) {
SWIG_exception_fail(SWIG_ERROR, "Uart buffer failed");
}
%#endif

}
Expand All @@ -116,18 +116,18 @@ class Spi;
free($1);
SWIG_exception_fail(SWIG_ERROR, "I2c write failed");
}
%#if SWIG_V8_VERSION > 0x040000
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) $1, result);
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION <= 0x032870)
$result = node::Buffer::New((char*) $1, result)->handle_;
free($1);
if(!objret.ToLocal(&$result)) {
SWIG_exception_fail(SWIG_ERROR, "I2c buffer failed");
}
%#elif SWIG_V8_VERSION > 0x032870
%#elif (V8_MAJOR_VERSION-0) < 4
$result = node::Buffer::New((char*) $1, result);
free($1);
%#else
$result = node::Buffer::New((char*) $1, result)->handle_;
v8::MaybeLocal<v8::Object> objret = node::Buffer::Copy(v8::Isolate::GetCurrent(), (char*) $1, result);
free($1);
if(!objret.ToLocal(&$result)) {
SWIG_exception_fail(SWIG_ERROR, "I2c buffer failed");
}
%#endif
}

Expand Down

0 comments on commit 046bdd0

Please sign in to comment.