Fix for pointers to auto variables returned from Python wrapper class methods.
The previous implementation was a quick workaround of C++ const references. Also removed the unused 'borrowed' flag from the Python wrapper of FrsMaterial.
This commit is contained in:
@@ -322,10 +322,9 @@ PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs ) {
|
||||
return py_vs;
|
||||
}
|
||||
|
||||
PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m ){
|
||||
PyObject * BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial& m) {
|
||||
PyObject *py_m = FrsMaterial_Type.tp_new( &FrsMaterial_Type, 0, 0 );
|
||||
((BPy_FrsMaterial*) py_m)->m = &m;
|
||||
((BPy_FrsMaterial*) py_m)->borrowed = 1;
|
||||
((BPy_FrsMaterial*) py_m)->m = new FrsMaterial( m );
|
||||
|
||||
return py_m;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ PyObject * BPy_Id_from_Id( Id& id );
|
||||
PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
|
||||
PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D );
|
||||
PyObject * BPy_IntegrationType_from_IntegrationType( IntegrationType i );
|
||||
PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m );
|
||||
PyObject * BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial& m);
|
||||
PyObject * BPy_Nature_from_Nature( unsigned short n );
|
||||
PyObject * BPy_MediumType_from_MediumType( Stroke::MediumType n );
|
||||
PyObject * BPy_SShape_from_SShape( SShape& ss );
|
||||
|
||||
@@ -75,7 +75,7 @@ static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwd
|
||||
PyErr_SetString(PyExc_RuntimeError, "invalid FrsMaterial object");
|
||||
return -1;
|
||||
}
|
||||
self->m = new FrsMaterial( *m );
|
||||
self->m = new FrsMaterial(*m);
|
||||
|
||||
} else if (float_array_from_PyObject(obj1, f1, 4) && obj2 &&
|
||||
float_array_from_PyObject(obj2, f2, 4) && obj3 &&
|
||||
@@ -87,15 +87,13 @@ static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwd
|
||||
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
|
||||
return -1;
|
||||
}
|
||||
self->borrowed = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void FrsMaterial_dealloc(BPy_FrsMaterial* self)
|
||||
{
|
||||
if (self->m && !self->borrowed)
|
||||
delete self->m;
|
||||
delete self->m;
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ extern PyTypeObject FrsMaterial_Type;
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
FrsMaterial *m;
|
||||
int borrowed; /* non-zero if *m is a borrowed object */
|
||||
} BPy_FrsMaterial;
|
||||
|
||||
/*---------------------------Python BPy_FrsMaterial visible prototypes-----------*/
|
||||
|
||||
@@ -288,9 +288,7 @@ PyDoc_STRVAR(FEdgeSharp_material_right_doc,
|
||||
|
||||
static PyObject *FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
|
||||
{
|
||||
// FIXME aFrsMaterial() returns a const reference.
|
||||
FrsMaterial m(self->fes->aFrsMaterial());
|
||||
return BPy_FrsMaterial_from_FrsMaterial(m);
|
||||
return BPy_FrsMaterial_from_FrsMaterial(self->fes->aFrsMaterial());
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(FEdgeSharp_material_left_doc,
|
||||
@@ -300,9 +298,7 @@ PyDoc_STRVAR(FEdgeSharp_material_left_doc,
|
||||
|
||||
static PyObject *FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
|
||||
{
|
||||
// FIXME bFrsMaterial() returns a const reference.
|
||||
FrsMaterial m(self->fes->bFrsMaterial());
|
||||
return BPy_FrsMaterial_from_FrsMaterial(m);
|
||||
return BPy_FrsMaterial_from_FrsMaterial(self->fes->bFrsMaterial());
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(FEdgeSharp_face_mark_right_doc,
|
||||
|
||||
@@ -179,9 +179,7 @@ PyDoc_STRVAR(FEdgeSmooth_material_doc,
|
||||
|
||||
static PyObject *FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
|
||||
{
|
||||
// FIXME frs_material() returns a const reference.
|
||||
FrsMaterial m(self->fes->frs_material());
|
||||
return BPy_FrsMaterial_from_FrsMaterial(m);
|
||||
return BPy_FrsMaterial_from_FrsMaterial(self->fes->frs_material());
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(FEdgeSmooth_face_mark_doc,
|
||||
|
||||
Reference in New Issue
Block a user