Serialized.setFile: use file ref instead of pointer for safety

This commit is contained in:
Andrej730
2026-07-24 19:47:11 +05:00
parent 310eaedc8e
commit 34f8a2c54e
17 changed files with 27 additions and 27 deletions
+1 -1
View File
@@ -906,7 +906,7 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
serializer->setFile(ifc_file);
serializer->setFile(*ifc_file);
if (context_iterator && geometry_settings.get<ifcopenshell::geometry::settings::ConvertBackUnits>().get()) {
serializer->setUnitNameAndMagnitude(context_iterator->unit_name(), static_cast<float>(context_iterator->unit_magnitude()));
+1 -1
View File
@@ -35,7 +35,7 @@ public:
virtual bool is_streaming() const { return false; }
virtual void writeHeader() = 0;
virtual void finalize() = 0;
virtual void setFile(ifcopenshell::file*) = 0;
virtual void setFile(ifcopenshell::file&) = 0;
};
#endif
+3 -3
View File
@@ -350,7 +350,7 @@ public:
serializer_->finalize();
}
void setFile(ifcopenshell::file* file) override {
void setFile(ifcopenshell::file& file) override {
serializer_->setFile(file);
}
@@ -405,7 +405,7 @@ private:
$self->finalize();
}
void setFile(ifcopenshell::file* file) {
void setFile(ifcopenshell::file& file) {
$self->setFile(file);
}
}
@@ -1256,7 +1256,7 @@ ifcopenshell::geometry::taxonomy::item::ptr try_upcast(PyObject* obj0, swig_type
%}
%inline %{
IfcGeom::ConversionResultShape* nary_union(PyObject* sequence) {
IfcGeom::ConversionResultShape* nary_union(PyObject* sequence) {
std::vector<const CGAL::Nef_polyhedron_3<CGAL::Epeck>*> nefs;
for(Py_ssize_t i = 0; i < PySequence_Size(sequence); ++i) {
PyObject* element = PySequence_GetItem(sequence, i);
+1 -1
View File
@@ -238,7 +238,7 @@ public:
unit_name = name;
unit_magnitude = magnitude;
}
void setFile(ifcopenshell::file*) {}
void setFile(ifcopenshell::file&) {}
std::string object_id(const IfcGeom::Element* o) /*override*/;
+4 -4
View File
@@ -530,7 +530,7 @@ namespace {
}
}
void GltfSerializer::setFile(ifcopenshell::file* f) {
void GltfSerializer::setFile(ifcopenshell::file& f) {
if (!settings_.get<ifcopenshell::geometry::settings::WriteGltfEcef>().get()) {
return;
}
@@ -541,7 +541,7 @@ void GltfSerializer::setFile(ifcopenshell::file* f) {
std::vector<express::Base> coordops;
try {
coordops = f->instances_by_type("IfcCoordinateOperation");
coordops = f.instances_by_type("IfcCoordinateOperation");
} catch (ifcopenshell::exception&) {
// Ignored. Schema likely doesn't support IfcCoordinateOperation.
}
@@ -578,7 +578,7 @@ void GltfSerializer::setFile(ifcopenshell::file* f) {
}
if (!crs_epsg) {
auto sites = f->instances_by_type("IfcSite");
auto sites = f.instances_by_type("IfcSite");
if (sites.size() == 1) {
auto lat_attr = sites.front().as<express::Entity>().get("RefLatitude");
@@ -613,7 +613,7 @@ void GltfSerializer::setFile(ifcopenshell::file* f) {
}
}
auto contexts = f->instances_by_type_excl_subtypes("IfcGeometricRepresentationContext");
auto contexts = f.instances_by_type_excl_subtypes("IfcGeometricRepresentationContext");
if (!contexts.empty()) {
auto context = contexts.front().as<express::Entity>();
+1 -1
View File
@@ -52,7 +52,7 @@ public:
void finalize();
bool isTesselated() const { return true; }
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
void setFile(ifcopenshell::file*);
void setFile(ifcopenshell::file&);
};
#endif
+1 -1
View File
@@ -51,7 +51,7 @@ class JsonSerializer : public Serializer {
}
implementation_->finalize();
}
void setFile(ifcopenshell::file*) { throw ifcopenshell::exception("Should be supplied on construction"); }
void setFile(ifcopenshell::file&) { throw ifcopenshell::exception("Should be supplied on construction"); }
};
#endif
+1 -1
View File
@@ -47,7 +47,7 @@ public:
void write(const IfcGeom::TriangulationElement* /*o*/) {}
void write(const IfcGeom::BRepElement* o);
bool isTesselated() const { return false; }
void setFile(ifcopenshell::file*) {}
void setFile(ifcopenshell::file&) {}
};
#endif
+1 -1
View File
@@ -25,7 +25,7 @@ public:
void writeHeader() override {}
void finalize() override;
void setFile(ifcopenshell::file*) override { throw ifcopenshell::exception("Streaming serializer uses input filename supplied on construction"); }
void setFile(ifcopenshell::file&) override { throw ifcopenshell::exception("Streaming serializer uses input filename supplied on construction"); }
};
#endif
+6 -6
View File
@@ -2463,10 +2463,10 @@ std::string SvgSerializer::nameElement(express::Base elem_) {
});
}
void SvgSerializer::setFile(ifcopenshell::file* f) {
void SvgSerializer::setFile(ifcopenshell::file& f) {
using namespace ifcopenshell::geometry::settings;
file = f;
file = &f;
auto apply_section_heights_from_storeys = [&]() {
if (settings().get<SvgSectionHeightFromStoreys>().get()) {
if (settings().get<SvgSectionHeight>().has()) {
@@ -2477,15 +2477,15 @@ void SvgSerializer::setFile(ifcopenshell::file* f) {
}
};
auto storeys = f->instances_by_type("IfcBuildingStorey");
auto storeys = f.instances_by_type("IfcBuildingStorey");
if (storeys.empty()) {
auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(file, geometry_settings_, logger());
std::vector<const ifcopenshell::declaration*> to_derive_from;
to_derive_from.push_back(f->schema()->declaration_by_name("IfcBuilding"));
to_derive_from.push_back(f->schema()->declaration_by_name("IfcSite"));
to_derive_from.push_back(f.schema()->declaration_by_name("IfcBuilding"));
to_derive_from.push_back(f.schema()->declaration_by_name("IfcSite"));
for (auto it = to_derive_from.begin(); it != to_derive_from.end(); ++it) {
auto insts = f->instances_by_type(*it);
auto insts = f.instances_by_type(*it);
for (auto& inst : insts) {
auto product = inst.as<express::Entity>();
if (!product.get("ObjectPlacement").isNull()) {
+1 -1
View File
@@ -650,7 +650,7 @@ public:
bool isTesselated() const { return false; }
void finalize();
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
void setFile(ifcopenshell::file* f);
void setFile(ifcopenshell::file& f);
void setBoundingRectangle(double width, double height);
void setSectionHeight(double h, express::Base storey = express::Base());
void setSectionHeightsFromStoreys(double offset=1.2);
+1 -1
View File
@@ -41,7 +41,7 @@ public:
void finalize() {}
bool isTesselated() const;
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
void setFile(ifcopenshell::file*) {}
void setFile(ifcopenshell::file&) {}
std::string ttl_object_id(const IfcGeom::Element* o, const char* const postfix = nullptr);
};
+1 -1
View File
@@ -95,7 +95,7 @@ public:
void finalize();
bool isTesselated() const { return true; }
void setUnitNameAndMagnitude(const std::string&, float) {}
void setFile(ifcopenshell::file*) {}
void setFile(ifcopenshell::file&) {}
std::string object_id_unique(const IfcGeom::Element* o);
};
+1 -1
View File
@@ -45,7 +45,7 @@ public:
void finalize() {}
bool isTesselated() const { return true; }
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
void setFile(ifcopenshell::file*) {}
void setFile(ifcopenshell::file&) {}
};
#endif
+1 -1
View File
@@ -44,7 +44,7 @@ public:
}
implementation_->finalize();
}
void setFile(ifcopenshell::file*) { throw ifcopenshell::exception("Should be supplied on construction"); }
void setFile(ifcopenshell::file&) { throw ifcopenshell::exception("Should be supplied on construction"); }
};
#endif
@@ -50,7 +50,7 @@ class POSTFIX_SCHEMA(JsonSerializer) : public JsonSerializer {
}
void finalize();
void setFile(ifcopenshell::file*) {}
void setFile(ifcopenshell::file&) {}
};
#endif
@@ -48,7 +48,7 @@ public:
}
void finalize();
void setFile(ifcopenshell::file*) {}
void setFile(ifcopenshell::file&) {}
};
#endif