mmomtchev / swig

This is SWIG JavaScript Evolution, a fork of the SWIG project with modern JavaScript/TypeScript support including WASM and async
http://www.swig.org
Other
7 stars 0 forks source link

including typemaps via `$typemap` does not properly expand all variables #47

Open mmomtchev opened 3 months ago

mmomtchev commented 3 months ago
%module owner_bug

%include <std_vector.i>

%apply(std::vector &OUTPUT)           { std::vector &output, std::vector *output };

%inline %{
struct Integer {
  int value;
  Integer(int v): value(v) {};
};

void return_vector_ptr(std::vector<Integer *> &output) {
  static Integer all_mine(1337);
  output.push_back(&all_mine);
  output.push_back(&all_mine);
  output.push_back(&all_mine);
}
%}

produces:

../../owner_bug_wrap.cxx: In function ‘Napi::Value _wrap_return_vector_ptr(const Napi::CallbackInfo&)’:
../../owner_bug_wrap.cxx:2006:81: error: ‘$owner’ was not declared in this scope
 2006 |         js_val = SWIG_NewPointerObj(SWIG_as_voidptr(c_val), SWIGTYPE_p_Integer, $owner |  0 );;
      |                                                                                 ^~~~~~
../../owner_bug_wrap.cxx:700:97: note: in definition of macro ‘SWIG_NewPointerObj’
  700 | #define SWIG_NewPointerObj(ptr, info, flags)            SWIG_NAPI_NewPointerObj(env, ptr, info, flags)