Skip to content

Commit

Permalink
+ remove Py_TPFLAGS_BASETYPE flag for all generated Python bindings b…
Browse files Browse the repository at this point in the history
…ecause they can't be sub-classed in Python
  • Loading branch information
wwmayer committed Oct 12, 2015
1 parent 706d159 commit 5cc7f8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
9 changes: 0 additions & 9 deletions src/App/Application.cpp
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/Tools/generateTemplates/templateClassPyExport.py
Expand Up @@ -272,13 +272,13 @@ class @self.export.Namespace@Export @self.export.Name@ : public @self.export.Fat
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 */
Expand Down

0 comments on commit 5cc7f8b

Please sign in to comment.