emscripten-core / emscripten-core/emscripten
IDL generator with gluecode failed std::vector
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I am trying to generate the glue code for the cpp lib (libavoid), and it uses std::vector. I extracted the main issue and made a simple version of it. See the code blow. Basically, a class method expects `const std::vector& items`.
I updated the idl to expect a `sequence`. When trying to compile it throws an error, because the generated glue code `emscripten_bind_MyContainer_setItems_1` takes a raw pointer, but the method is expecting a std::vector.
What I am missing, how to properly generate the sequence or std::vector?
**Version of emscripten/emsdk:**
version 3.1.38, 3.1.74, 4.0.18
**Failing command line in full:**
**Full link command and output with `-v` appended:**
```cpp
#pragma once
#include
#include
class MyClass {
public:
MyClass();
MyClass(std::string name);
std::string getName() const;
void setName(const std::string &n);
private:
std::string name_;
};
class MyContainer {
public:
std::vector getItems() const;
void setItems(const std::vector &items);
private:
std::vector items_;
};
std::vector MyContainer::getItems() const {
return items_;
}
void MyContainer::setItems(const std::vector& items) {
items_ = items;
}
```
```webidl
interface MyClass {
void MyClass();
void MyClass(DOMString name);
attribute DOMString name;
};
interface MyContainer {
[Value] sequence getItems();
void setItems([Ref] sequence items);
};
```
The generated glue code
```cpp
#include
#include
EM_JS_DEPS(webidl_binder, "$intArrayFromString,$UTF8ToString,$alignMemory,$addOnInit");
extern "C" {
// Define custom allocator functions that we can force export using
// EMSCRIPTEN_KEEPALIVE. This avoids all webidl users having to add
// malloc/free to -sEXPORTED_FUNCTIONS.
EMSCRIPTEN_KEEPALIVE void webidl_free(void* p) { free(p); }
EMSCRIPTEN_KEEPALIVE void* webidl_malloc(size_t len) { return malloc(len); }
// Interface: VoidPtr
void EMSCRIPTEN_KEEPALIVE emscripten_bind_VoidPtr___destroy___0(void** self) {
delete self;
}
// Interface: MyClass
MyClass* EMSCRIPTEN_KEEPALIVE emscripten_bind_MyClass_MyClass_0() {
return new MyClass();
}
MyClass* EMSCRIPTEN_KEEPALIVE emscripten_bind_MyClass_MyClass_1(char* name) {
return new MyClass(name);
}
char* EMSCRIPTEN_KEEPALIVE emscripten_bind_MyClass_get_name_0(MyClass* self) {
return self->name;
}
void EMSCRIPTEN_KEEPALIVE emscripten_bind_MyClass_set_name_1(MyClass* self, char* arg0) {
self->name = arg0;
}
void EMSCRIPTEN_KEEPALIVE emscripten_bind_MyClass___destroy___0(MyClass* self) {
delete self;
}
// Interface: MyContainer
MyClass* EMSCRIPTEN_KEEPALIVE emscripten_bind_MyContainer_getItems_0(MyContainer* self) {
static thread_local MyClass temp;
return (temp = self->getItems(), &temp);
}
void EMSCRIPTEN_KEEPALIVE emscripten_bind_MyContainer_setItems_1(MyContainer* self, const MyClass* items) {
self->setItems(*items);
}
void EMSCRIPTEN_KEEPALIVE emscripten_bind_MyContainer___destroy___0(MyContainer* self) {
delete self;
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.