+ remove Py_TPFLAGS_BASETYPE flag for all generated Python bindings because they can't be sub-classed in Python

This commit is contained in:
wmayer
2015-10-12 19:59:58 +02:00
parent 4295301957
commit 24815ac196
2 changed files with 4 additions and 13 deletions

View File

@@ -187,15 +187,6 @@ Application::Application(ParameterManager * /*pcSysParamMngr*/,
// introducing additional classes
// 0001368: Subclassing Matrix silently fails
// Remove the Py_TPFLAGS_BASETYPE flag to disallow subclasses
Base::VectorPy::Type.tp_flags &= ~Py_TPFLAGS_BASETYPE;
Base::MatrixPy::Type.tp_flags &= ~Py_TPFLAGS_BASETYPE;
Base::BoundBoxPy::Type.tp_flags &= ~Py_TPFLAGS_BASETYPE;
Base::PlacementPy::Type.tp_flags &= ~Py_TPFLAGS_BASETYPE;
Base::RotationPy::Type.tp_flags &= ~Py_TPFLAGS_BASETYPE;
Base::AxisPy::Type.tp_flags &= ~Py_TPFLAGS_BASETYPE;
// NOTE: To finish the initialization of our own type objects we must
// call PyType_Ready, otherwise we run into a segmentation fault, later on.
// This function is responsible for adding inherited slots from a type's base class.

View File

@@ -272,13 +272,13 @@ PyTypeObject @self.export.Name@::Type = {
0, /* tp_as_buffer */
/* --- Flags to define presence of optional/expanded features */
+ if (self.export.RichCompare and self.export.NumberProtocol):
Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS|Py_TPFLAGS_HAVE_RICHCOMPARE|Py_TPFLAGS_CHECKTYPES, /*tp_flags */
Py_TPFLAGS_HAVE_CLASS|Py_TPFLAGS_HAVE_RICHCOMPARE|Py_TPFLAGS_CHECKTYPES, /*tp_flags */
= elif (self.export.RichCompare):
Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags */
Py_TPFLAGS_HAVE_CLASS|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags */
= elif (self.export.NumberProtocol):
Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS|Py_TPFLAGS_CHECKTYPES, /*tp_flags */
Py_TPFLAGS_HAVE_CLASS|Py_TPFLAGS_CHECKTYPES, /*tp_flags */
= else:
Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS, /*tp_flags */
Py_TPFLAGS_HAVE_CLASS, /*tp_flags */
-
"@self.export.Documentation.UserDocu.replace('\\n','\\\\n\\"\\n \\"')@", /*tp_doc */
0, /*tp_traverse */