{"action":"opened","issue":{"url":"https://api.github.com/repos/swig/swig/issues/773","repository_url":"https://api.github.com/repos/swig/swig","labels_url":"https://api.github.com/repos/swig/swig/issues/773/labels{/name}","comments_url":"https://api.github.com/repos/swig/swig/issues/773/comments","events_url":"https://api.github.com/repos/swig/swig/issues/773/events","html_url":"https://github.com/swig/swig/issues/773","id":173665384,"number":773,"title":"C++/Python with shared_ptr lists: Assertion `own' failed.","user":{"login":"nschloe","id":181628,"avatar_url":"https://avatars.githubusercontent.com/u/181628?v=3","gravatar_id":"","url":"https://api.github.com/users/nschloe","html_url":"https://github.com/nschloe","followers_url":"https://api.github.com/users/nschloe/followers","following_url":"https://api.github.com/users/nschloe/following{/other_user}","gists_url":"https://api.github.com/users/nschloe/gists{/gist_id}","starred_url":"https://api.github.com/users/nschloe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nschloe/subscriptions","organizations_url":"https://api.github.com/users/nschloe/orgs","repos_url":"https://api.github.com/users/nschloe/repos","events_url":"https://api.github.com/users/nschloe/events{/privacy}","received_events_url":"https://api.github.com/users/nschloe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-28T20:18:46Z","updated_at":"2016-08-28T20:18:46Z","closed_at":null,"body":"In a SWIGged C++/Python application, I'd like to create a function that accepts a `std::vector`/Python list of abstract base class objects, e.g.,\r\n```c++\r\n#ifndef MYTEST_HPP\r\n#define MYTEST_HPP\r\n\r\n#include <iostream>\r\n#include <vector>\r\n#include <memory>\r\n\r\nclass MyBaseClass {\r\n  public:\r\n  virtual void eval() const = 0;\r\n};\r\n\r\nclass MyTestClass: public MyBaseClass {\r\n  public:\r\n  virtual void eval() const {\r\n    std::cout << \"MyTestClass::eval()\" << std::endl;\r\n  }\r\n};\r\n\r\nvoid\r\nmytest(const std::vector<std::shared_ptr<MyBaseClass>> & a) {\r\n  std::cout << \"length: \" << a.size() << std::endl;\r\n}\r\n\r\n#endif // MYTEST_HPP\r\n```\r\nNote that we're using `std::shared_ptr`s here. Using this with\r\n```swig\r\n%module mytest\r\n\r\n%{\r\n#define SWIG_FILE_WITH_INIT\r\n#include \"mytest.hpp\"\r\n%}\r\n\r\n%include <std_shared_ptr.i>\r\n%shared_ptr(MyBaseClass);\r\n%shared_ptr(MyTestClass);\r\n\r\n%include <std_vector.i>\r\nnamespace std {\r\n%template(List) vector<std::shared_ptr<MyBaseClass>>;\r\n}\r\n\r\n%include \"mytest.hpp\"\r\n```\r\ndoes compile, but fails at runtime. From\r\n```python\r\nimport mytest\r\na = mytest.MyTestClass()\r\nmytest.mytest([a])\r\n```\r\nI'm getting\r\n````\r\npython: /tmp/l/build/mytestPYTHON_wrap.cxx:2385: int SWIG_Python_ConvertPtrAndOwn(PyObject*, void**, swig_type_info*, int, int*): Assertion `own' failed.\r\nAborted (core dumped)\r\n```\r\nThis is with SWIG 3.0.8.\r\n\r\n---\r\n_Note:_ The corresponding Gist is [here](https://gist.github.com/nschloe/c6d1dcb0837031183da0da5423ea23f6)."}}
{"actor":{"display_login":"nschloe"}}