cppcoreguidelines-pro-type-union-access
According to https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md using union for type-punning is undefined behaviour. Replace it with std::memcpy
This commit is contained in:
@@ -228,8 +228,7 @@ void ViewProviderFemMeshPy::setNodeDisplacement(Py::Dict arg)
|
||||
this->getViewProviderFemMeshPtr()->resetColorByNodeId();
|
||||
else {
|
||||
std::map<long, Base::Vector3d> NodeDispMap;
|
||||
union PyType_Object pyType = { &(Base::VectorPy::Type) };
|
||||
Py::Type vType(pyType.o);
|
||||
Py::Type vType(Base::getTypeAsObject(&Base::VectorPy::Type));
|
||||
|
||||
for (Py::Dict::iterator it = arg.begin(); it != arg.end(); ++it) {
|
||||
Py::Long id((*it).first);
|
||||
|
||||
@@ -375,8 +375,7 @@ PyObject* MeshPy::crossSections(PyObject *args)
|
||||
return nullptr;
|
||||
|
||||
Py::Sequence list(obj);
|
||||
union PyType_Object pyType = {&(Base::VectorPy::Type)};
|
||||
Py::Type vType(pyType.o);
|
||||
Py::Type vType(Base::getTypeAsObject(&Base::VectorPy::Type));
|
||||
|
||||
std::vector<MeshObject::TPlane> csPlanes;
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
@@ -655,11 +654,8 @@ PyObject* MeshPy::addFacets(PyObject *args)
|
||||
PyObject *list;
|
||||
if (PyArg_ParseTuple(args, "O!", &PyList_Type, &list)) {
|
||||
Py::List list_f(list);
|
||||
union PyType_Object pyVType = {&(Base::VectorPy::Type)};
|
||||
Py::Type vVType(pyVType.o);
|
||||
|
||||
union PyType_Object pyFType = {&(Mesh::FacetPy::Type)};
|
||||
Py::Type vFType(pyFType.o);
|
||||
Py::Type vVType(Base::getTypeAsObject(&Base::VectorPy::Type));
|
||||
Py::Type vFType(Base::getTypeAsObject(&Mesh::FacetPy::Type));
|
||||
|
||||
std::vector<MeshCore::MeshGeomFacet> facets;
|
||||
MeshCore::MeshGeomFacet facet;
|
||||
@@ -724,8 +720,7 @@ PyObject* MeshPy::addFacets(PyObject *args)
|
||||
Py::Tuple tuple(list);
|
||||
Py::List list_v(tuple.getItem(0));
|
||||
std::vector<Base::Vector3f> vertices;
|
||||
union PyType_Object pyVertType = {&(Base::VectorPy::Type)};
|
||||
Py::Type vType(pyVertType.o);
|
||||
Py::Type vType(Base::getTypeAsObject(&Base::VectorPy::Type));
|
||||
for (Py::List::iterator it = list_v.begin(); it != list_v.end(); ++it) {
|
||||
if ((*it).isType(vType)) {
|
||||
Base::Vector3d v = static_cast<Base::VectorPy*>((*it).ptr())->value();
|
||||
|
||||
@@ -1593,8 +1593,8 @@ private:
|
||||
double angle=360;
|
||||
PyObject *pPnt=nullptr, *pDir=nullptr, *pCrv;
|
||||
Handle(Geom_Curve) curve;
|
||||
union PyType_Object defaultType = {&Part::TopoShapeSolidPy::Type};
|
||||
PyObject* type = defaultType.o;
|
||||
PyObject* defaultType = Base::getTypeAsObject(&Part::TopoShapeSolidPy::Type);
|
||||
PyObject* type = defaultType;
|
||||
|
||||
do {
|
||||
if (PyArg_ParseTuple(args.ptr(), "O!|dddO!O!O!", &(GeometryPy::Type), &pCrv,
|
||||
@@ -1667,19 +1667,19 @@ private:
|
||||
d.SetCoord(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
union PyType_Object shellType = {&Part::TopoShapeShellPy::Type};
|
||||
union PyType_Object faceType = {&Part::TopoShapeFacePy::Type};
|
||||
PyObject* shellType = Base::getTypeAsObject(&Part::TopoShapeShellPy::Type);
|
||||
PyObject* faceType = Base::getTypeAsObject(&Part::TopoShapeFacePy::Type);
|
||||
|
||||
BRepPrimAPI_MakeRevolution mkRev(gp_Ax2(p,d),curve, vmin, vmax, angle*(M_PI/180));
|
||||
if (type == defaultType.o) {
|
||||
if (type == defaultType) {
|
||||
TopoDS_Shape shape = mkRev.Solid();
|
||||
return Py::asObject(new TopoShapeSolidPy(new TopoShape(shape)));
|
||||
}
|
||||
else if (type == shellType.o) {
|
||||
else if (type == shellType) {
|
||||
TopoDS_Shape shape = mkRev.Shell();
|
||||
return Py::asObject(new TopoShapeShellPy(new TopoShape(shape)));
|
||||
}
|
||||
else if (type == faceType.o) {
|
||||
else if (type == faceType) {
|
||||
TopoDS_Shape shape = mkRev.Face();
|
||||
return Py::asObject(new TopoShapeFacePy(new TopoShape(shape)));
|
||||
}
|
||||
|
||||
@@ -99,8 +99,7 @@ PyObject* BSplineCurvePy::__reduce__(PyObject *args)
|
||||
Py::Tuple tuple(2);
|
||||
|
||||
// type object to create an instance
|
||||
union PyType_Object pyType = {&BSplineCurvePy::Type};
|
||||
Py::Object type(pyType.o);
|
||||
Py::Object type(Base::getTypeAsObject(&BSplineCurvePy::Type));
|
||||
tuple.setItem(0, type);
|
||||
|
||||
// create an argument tuple to create a copy
|
||||
|
||||
@@ -231,8 +231,7 @@ Py::Object CommandPy::getPlacement(void) const
|
||||
|
||||
void CommandPy::setPlacement(Py::Object arg)
|
||||
{
|
||||
union PyType_Object pyType = {&(Base::PlacementPy::Type)};
|
||||
Py::Type PlacementType(pyType.o);
|
||||
Py::Type PlacementType(Base::getTypeAsObject(&(Base::PlacementPy::Type)));
|
||||
if(arg.isType(PlacementType)) {
|
||||
getCommandPtr()->setFromPlacement( *static_cast<Base::PlacementPy*>((*arg))->getPlacementPtr() );
|
||||
parameters_copy_dict.clear();
|
||||
|
||||
@@ -142,8 +142,7 @@ PyObject* PointsPy::addPoints(PyObject * args)
|
||||
|
||||
try {
|
||||
Py::Sequence list(obj);
|
||||
union PyType_Object pyType = {&(Base::VectorPy::Type)};
|
||||
Py::Type vType(pyType.o);
|
||||
Py::Type vType(Base::getTypeAsObject(&Base::VectorPy::Type));
|
||||
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
if ((*it).isType(vType)) {
|
||||
|
||||
@@ -202,8 +202,7 @@ Py::Object WaypointPy::getPos(void) const
|
||||
|
||||
void WaypointPy::setPos(Py::Object arg)
|
||||
{
|
||||
union PyType_Object pyType = {&(Base::PlacementPy::Type)};
|
||||
Py::Type PlacementType(pyType.o);
|
||||
Py::Type PlacementType(Base::getTypeAsObject(&(Base::PlacementPy::Type)));
|
||||
if(arg.isType(PlacementType))
|
||||
getWaypointPtr()->EndPos = *static_cast<Base::PlacementPy*>((*arg))->getPlacementPtr();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user