Skip to content

Commit b5c4eb3

Browse files
stgatilovaothms
authored andcommitted
IfcParse dynamic linking, IFCPARSE_NO_REGEX, fixes for three memory leaks (IfcOpenShell#76)
* CMake: moved setting link directories before all the projects. * Added IfcParse_Export header for declaring export macro. * Added IFCPARSE_STATIC_DEFINE macro to all projects. * Added include for export macro to swig file. * Added IfcParse_EXPORT macro for all classes in headers generated by express parser. * Allow removing boost.regex dependency by defining macro IFCPARSE_NO_REGEX. * Fixed bug in deletion of ICU converter. * Added export macro to most of the classes across headers * Fixed memory leak: delete nested IfcAbstractEntity in EntityArgument. * Fixed memory leak in destructor of IfcWritableEntity (args values).
1 parent a298903 commit b5c4eb3

22 files changed

+1784
-1718
lines changed

cmake/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ if(NOT Boost_VERSION LESS 105800)
408408
add_definitions(-DBOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE)
409409
endif()
410410

411+
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${IfcOpenShell_BINARY_DIR} ${OCC_LIBRARY_DIR} ${OPENCOLLADA_LIBRARY_DIR}
412+
${ICU_LIBRARY_DIR} ${Boost_LIBRARY_DIRS}
413+
)
414+
if(NOT WIN32)
415+
LINK_DIRECTORIES(${LINK_DIRECTORIES} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
416+
endif()
417+
411418
# IfcParse
412419
file(GLOB IFCPARSE_H_FILES ../src/ifcparse/*.h)
413420
file(GLOB IFCPARSE_CPP_FILES ../src/ifcparse/*.cpp)
@@ -422,6 +429,9 @@ endforeach()
422429

423430
set(IFCPARSE_FILES ${IFCPARSE_CPP_FILES} ${IFCPARSE_H_FILES})
424431

432+
# add macro for every project: use IfcParse as static lib
433+
add_definitions(-DIFCPARSE_STATIC_DEFINE)
434+
425435
ADD_LIBRARY(IfcParse STATIC ${IFCPARSE_FILES})
426436

427437
IF(UNICODE_SUPPORT)
@@ -445,13 +455,6 @@ ENDIF()
445455

446456
TARGET_LINK_LIBRARIES(IfcGeom IfcParse)
447457

448-
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${IfcOpenShell_BINARY_DIR} ${OCC_LIBRARY_DIR} ${OPENCOLLADA_LIBRARY_DIR}
449-
${ICU_LIBRARY_DIR} ${Boost_LIBRARY_DIRS}
450-
)
451-
if(NOT WIN32)
452-
LINK_DIRECTORIES(${LINK_DIRECTORIES} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
453-
endif()
454-
455458
# IfcConvert
456459
if (IFCCONVERT_DOUBLE_PRECISION)
457460
add_definitions(-DIFCCONVERT_DOUBLE_PRECISION)

src/ifcexpressparser/templates.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
2727
#include <boost/optional.hpp>
2828
29+
#include "../ifcparse/IfcParse_Export.h"
30+
2931
#include "../ifcparse/IfcUtil.h"
3032
#include "../ifcparse/IfcException.h"
3133
#include "../ifcparse/%(schema_name)senum.h"
@@ -62,6 +64,8 @@
6264
#ifndef %(schema_name_upper)sENUM_H
6365
#define %(schema_name_upper)sENUM_H
6466
67+
#include "../ifcparse/IfcParse_Export.h"
68+
6569
#include <boost/optional.hpp>
6670
6771
#define IfcSchema %(schema_name)s
@@ -72,10 +76,10 @@
7276
typedef enum {
7377
%(types)s, UNDEFINED
7478
} Enum;
75-
boost::optional<Enum> Parent(Enum v);
76-
Enum FromString(const std::string& s);
77-
std::string ToString(Enum v);
78-
bool IsSimple(Enum v);
79+
IfcParse_EXPORT boost::optional<Enum> Parent(Enum v);
80+
IfcParse_EXPORT Enum FromString(const std::string& s);
81+
IfcParse_EXPORT std::string ToString(Enum v);
82+
IfcParse_EXPORT bool IsSimple(Enum v);
7983
}
8084
8185
}
@@ -352,7 +356,7 @@
352356
derived_field_statement_attrs = 'idxs.insert(%d); '
353357

354358
simpletype = """%(documentation)s
355-
class %(name)s : public %(superclass)s {
359+
class IfcParse_EXPORT %(name)s : public %(superclass)s {
356360
public:
357361
virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
358362
virtual Argument* getArgument(unsigned int i) const;
@@ -391,7 +395,7 @@ class %(name)s : public %(superclass)s {
391395
"""
392396

393397
entity = """%(documentation)s
394-
class %(name)s %(superclass)s{
398+
class IfcParse_EXPORT %(name)s %(superclass)s{
395399
public:
396400
%(attributes)s virtual unsigned int getArgumentCount() const { return %(argument_count)d; }
397401
virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const {%(argument_type_function_body)s}

src/ifcparse/Ifc2x3.h

Lines changed: 772 additions & 770 deletions
Large diffs are not rendered by default.

src/ifcparse/Ifc2x3enum.h

Lines changed: 6 additions & 4 deletions
Large diffs are not rendered by default.

src/ifcparse/Ifc4.h

Lines changed: 900 additions & 898 deletions
Large diffs are not rendered by default.

src/ifcparse/Ifc4enum.h

Lines changed: 6 additions & 4 deletions
Large diffs are not rendered by default.

src/ifcparse/IfcCharacterDecoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ IfcCharacterEncoder::IfcCharacterEncoder(const std::string& input) {
322322

323323
IfcCharacterEncoder::~IfcCharacterEncoder() {
324324
#ifdef HAVE_ICU
325-
if ( !converter) ucnv_close(converter);
325+
if ( converter) ucnv_close(converter);
326326
converter = 0;
327327
#endif
328328
}

src/ifcparse/IfcFile.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
#include <map>
2424
#include <set>
2525

26+
#include "../ifcparse/IfcParse_Export.h"
27+
2628
#include "../ifcparse/IfcParse.h"
2729
#include "../ifcparse/IfcSpfHeader.h"
2830

2931
namespace IfcParse {
3032

3133
/// This class provides several static convenience functions and variables
3234
/// and provide access to the entities in an IFC file
33-
class IfcFile {
35+
class IfcParse_EXPORT IfcFile {
3436
public:
3537
typedef std::map<IfcSchema::Type::Enum, IfcEntityList::ptr> entities_by_type_t;
3638
typedef std::map<unsigned int, IfcUtil::IfcBaseClass*> entity_by_id_t;

src/ifcparse/IfcGlobalId.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
#include <string>
2424
#include <boost/uuid/uuid.hpp>
2525

26+
#include "../ifcparse/IfcParse_Export.h"
27+
2628
namespace IfcParse {
2729

2830
/// A helper class for the creation of IFC GlobalIds.
29-
class IfcGlobalId {
31+
class IfcParse_EXPORT IfcGlobalId {
3032
private:
3133
std::string string_data, formatted_string;
3234
boost::uuids::uuid uuid_data;

src/ifcparse/IfcHierarchyHelper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include <map>
3232

33+
#include "../ifcparse/IfcParse_Export.h"
34+
3335
#ifdef USE_IFC4
3436
#include "../ifcparse/Ifc4.h"
3537
#else
@@ -40,7 +42,7 @@
4042
#include "../ifcparse/IfcWrite.h"
4143
#include "../ifcparse/IfcGlobalId.h"
4244

43-
class IfcHierarchyHelper : public IfcParse::IfcFile {
45+
class IfcParse_EXPORT IfcHierarchyHelper : public IfcParse::IfcFile {
4446
public:
4547
template <class T>
4648
T* addTriplet(double x, double y, double z) {

0 commit comments

Comments
 (0)