From: Guillaume B. <gui...@ub...> - 2011-10-26 10:59:15
|
Hi all ! Considering this function : void my_function( std::vector<float> my_param ) ; I want to call this function using the builtin Python array, made possible using : %include <std_vector.i> %template () std::vector<float>; // anonymous template because this type is useless in Python. Doing this, though, leads to segfault when I (wrongly) call the function with any wrapped object. Indead, the type checker will look for the < std::vector<float, allocator...> > type, which does not exist (return NULL), then will assume the parameter is a pointer to a std::vector<float> ! This leads quickly to a segfault. ------------------------------------------------------------------------ %module test %include "std_vector.i" %template () std::vector<int>; %{ struct Anything { }; void function( const std::vector<int> ) { } %} struct Anything { }; void function( const std::vector<int> ); ------------------------------------------------------------------------ It is not clear to me why the conversion always succeed when no type info is given to SWIG_Python_ConvertPtrAndOwn, is it on purpose ? It could also be solved in the trait : traits_asptr_stdseq ::asptr, checking if swig::type_info<sequence>() returns NULL. Remark : the problem does not occur if the template instanciation has a name. %template (std_vector_int) std::vector<int>; Any thoughts ? Guillaume |