[C++-sig] Segfault when calling python method from C++
Pierre Barbier de Reuille
pierre.barbier at cirad.fr
Fri Jul 18 16:32:07 CEST 2003
Some more details ...
I made some experiment and it appears that if I use an ob ject of the
class :
******************************
class EmptyMean:
def __init__(self,walls):
self.walls = walls
def __call__(self,cell):
poly = self.walls.getCell(cell)
l = len(poly)
return vertex_type(l,l)
***********************************
as a parameter for my C++ method, it works. But if I use :
******************************
class EmptyMean:
def __init__(self,walls):
self.walls = walls
def __call__(self,cell):
poly = self.walls.getCell(cell)
return poly[0]
***********************************
it crashes ! poly is an exported vector<vertex_type>. I exported it so
that it has the same behaviour as a python list.
Here is the code of the __getitem__ method used to export the vector to
python :
***************************************************************************
template <class ToExport>
typename container_trait<ToExport>::value_type
list_getItem(ToExport* exp,
typename container_trait<ToExport>::difference_type i)
{
typename container_trait<ToExport>::iterator it;
it = PosInRange(exp, i);
return *it;
}
template <class ToExport>
typename container_trait<ToExport>::iterator
PosInRange(ToExport *l,
typename container_trait<ToExport>::difference_type i)
{
typename container_trait<ToExport>::difference_type size = l->size();
if((i >= size) || (i < -size))
{
PythonExc_IndexError ind;
ind.error_str = "assignment index out of range";
throw ind;
}
if(i < 0)
{
typename container_trait<ToExport>::difference_type size = l->size();
i += size;
}
typename container_trait<ToExport>::iterator it = l->begin();
advance(it, i);
return it;
}
*********************************************************************
The template parameter ToExport is here std::vector<vertex_type>.
container_trait<std::vector<vertex_type> >::iterator is
std::vector<vertex_type>::iterator
container_trait<std::vector<vertex_type> >::difference_type is
std::vector<vertex_type>::difference_type
container_trait<std::vector<vertex_type> >::iterator is
std::vector<vertex_type>::iterator
I'm still looking for more precise information, but I still have
absolutely no clue abour what is going on ...
--
Pierre Barbier de Reuille
INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France
tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68
More information about the Cplusplus-sig
mailing list