IfcParse dynamic linking, IFCPARSE_NO_REGEX, fixes for three memory leaks (#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).
This commit is contained in:
stgatilov
2016-05-29 18:12:57 +06:00
committed by Thomas Krijnen
parent a298903fdd
commit b5c4eb3b6f
22 changed files with 1784 additions and 1718 deletions
+10 -7
View File
@@ -408,6 +408,13 @@ if(NOT Boost_VERSION LESS 105800)
add_definitions(-DBOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE)
endif()
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${IfcOpenShell_BINARY_DIR} ${OCC_LIBRARY_DIR} ${OPENCOLLADA_LIBRARY_DIR}
${ICU_LIBRARY_DIR} ${Boost_LIBRARY_DIRS}
)
if(NOT WIN32)
LINK_DIRECTORIES(${LINK_DIRECTORIES} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
endif()
# IfcParse
file(GLOB IFCPARSE_H_FILES ../src/ifcparse/*.h)
file(GLOB IFCPARSE_CPP_FILES ../src/ifcparse/*.cpp)
@@ -422,6 +429,9 @@ endforeach()
set(IFCPARSE_FILES ${IFCPARSE_CPP_FILES} ${IFCPARSE_H_FILES})
# add macro for every project: use IfcParse as static lib
add_definitions(-DIFCPARSE_STATIC_DEFINE)
ADD_LIBRARY(IfcParse STATIC ${IFCPARSE_FILES})
IF(UNICODE_SUPPORT)
@@ -445,13 +455,6 @@ ENDIF()
TARGET_LINK_LIBRARIES(IfcGeom IfcParse)
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${IfcOpenShell_BINARY_DIR} ${OCC_LIBRARY_DIR} ${OPENCOLLADA_LIBRARY_DIR}
${ICU_LIBRARY_DIR} ${Boost_LIBRARY_DIRS}
)
if(NOT WIN32)
LINK_DIRECTORIES(${LINK_DIRECTORIES} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
endif()
# IfcConvert
if (IFCCONVERT_DOUBLE_PRECISION)
add_definitions(-DIFCCONVERT_DOUBLE_PRECISION)
+10 -6
View File
@@ -26,6 +26,8 @@ header = """
#include <boost/optional.hpp>
#include "../ifcparse/IfcParse_Export.h"
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/IfcException.h"
#include "../ifcparse/%(schema_name)senum.h"
@@ -62,6 +64,8 @@ enum_header = """
#ifndef %(schema_name_upper)sENUM_H
#define %(schema_name_upper)sENUM_H
#include "../ifcparse/IfcParse_Export.h"
#include <boost/optional.hpp>
#define IfcSchema %(schema_name)s
@@ -72,10 +76,10 @@ namespace Type {
typedef enum {
%(types)s, UNDEFINED
} Enum;
boost::optional<Enum> Parent(Enum v);
Enum FromString(const std::string& s);
std::string ToString(Enum v);
bool IsSimple(Enum v);
IfcParse_EXPORT boost::optional<Enum> Parent(Enum v);
IfcParse_EXPORT Enum FromString(const std::string& s);
IfcParse_EXPORT std::string ToString(Enum v);
IfcParse_EXPORT bool IsSimple(Enum v);
}
}
@@ -352,7 +356,7 @@ derived_field_statement = ' {std::set<int> idxs; %(statements)sderived_map[Ty
derived_field_statement_attrs = 'idxs.insert(%d); '
simpletype = """%(documentation)s
class %(name)s : public %(superclass)s {
class IfcParse_EXPORT %(name)s : public %(superclass)s {
public:
virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
virtual Argument* getArgument(unsigned int i) const;
@@ -391,7 +395,7 @@ const char* ToString(%(name)s v);
"""
entity = """%(documentation)s
class %(name)s %(superclass)s{
class IfcParse_EXPORT %(name)s %(superclass)s{
public:
%(attributes)s virtual unsigned int getArgumentCount() const { return %(argument_count)d; }
virtual IfcUtil::ArgumentType getArgumentType(unsigned int i) const {%(argument_type_function_body)s}
+772 -770
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+900 -898
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -322,7 +322,7 @@ IfcCharacterEncoder::IfcCharacterEncoder(const std::string& input) {
IfcCharacterEncoder::~IfcCharacterEncoder() {
#ifdef HAVE_ICU
if ( !converter) ucnv_close(converter);
if ( converter) ucnv_close(converter);
converter = 0;
#endif
}
+3 -1
View File
@@ -23,6 +23,8 @@
#include <map>
#include <set>
#include "../ifcparse/IfcParse_Export.h"
#include "../ifcparse/IfcParse.h"
#include "../ifcparse/IfcSpfHeader.h"
@@ -30,7 +32,7 @@ namespace IfcParse {
/// This class provides several static convenience functions and variables
/// and provide access to the entities in an IFC file
class IfcFile {
class IfcParse_EXPORT IfcFile {
public:
typedef std::map<IfcSchema::Type::Enum, IfcEntityList::ptr> entities_by_type_t;
typedef std::map<unsigned int, IfcUtil::IfcBaseClass*> entity_by_id_t;
+3 -1
View File
@@ -23,10 +23,12 @@
#include <string>
#include <boost/uuid/uuid.hpp>
#include "../ifcparse/IfcParse_Export.h"
namespace IfcParse {
/// A helper class for the creation of IFC GlobalIds.
class IfcGlobalId {
class IfcParse_EXPORT IfcGlobalId {
private:
std::string string_data, formatted_string;
boost::uuids::uuid uuid_data;
+3 -1
View File
@@ -30,6 +30,8 @@
#include <map>
#include "../ifcparse/IfcParse_Export.h"
#ifdef USE_IFC4
#include "../ifcparse/Ifc4.h"
#else
@@ -40,7 +42,7 @@
#include "../ifcparse/IfcWrite.h"
#include "../ifcparse/IfcGlobalId.h"
class IfcHierarchyHelper : public IfcParse::IfcFile {
class IfcParse_EXPORT IfcHierarchyHelper : public IfcParse::IfcFile {
public:
template <class T>
T* addTriplet(double x, double y, double z) {
+3 -1
View File
@@ -22,6 +22,8 @@
#include <string>
#include "../ifcparse/IfcParse_Export.h"
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/IfcWrite.h"
#include "../ifcparse/IfcWritableEntity.h"
@@ -32,7 +34,7 @@ namespace IfcParse {
// that in the IfcFile class the distinction what entity type to be created is
// no longer necessary and weird diagonal casts when creating geometry from
// IfcLateBoundEntities are eliminated.
class IfcLateBoundEntity : public IfcUtil::IfcBaseEntity {
class IfcParse_EXPORT IfcLateBoundEntity : public IfcUtil::IfcBaseEntity {
private:
IfcWrite::IfcWritableEntity* writable_entity();
void invalid_argument(unsigned int i, const std::string& t);
+1 -1
View File
@@ -780,7 +780,7 @@ std::string EntityArgument::toString(bool upper) const {
}
//return entity->entity->toString(); }
bool EntityArgument::isNull() const { return false; }
EntityArgument::~EntityArgument() { delete entity; }
EntityArgument::~EntityArgument() { delete entity->entity; delete entity;}
//
// Reads an Entity from the list of Tokens
+9 -7
View File
@@ -40,6 +40,8 @@
#include <boost/shared_ptr.hpp>
#include <boost/dynamic_bitset.hpp>
#include "../ifcparse/IfcParse_Export.h"
#include "../ifcparse/IfcCharacterDecoder.h"
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/IfcLogger.h"
@@ -62,7 +64,7 @@ namespace IfcParse {
/// Provides functions to convert Tokens to binary data
/// Tokens are merely offsets to where they can be read in the file
class TokenFunc {
class IfcParse_EXPORT TokenFunc {
private:
static bool startsWith(const Token& t, char c);
public:
@@ -109,7 +111,7 @@ namespace IfcParse {
Token TokenPtr();
/// A stream of tokens to be read from a IfcSpfStream.
class IfcSpfLexer {
class IfcParse_EXPORT IfcSpfLexer {
private:
IfcCharacterDecoder* decoder;
unsigned int skipWhitespace();
@@ -126,7 +128,7 @@ namespace IfcParse {
/// Argument of type list, e.g.
/// #1=IfcDirection((1.,0.,0.));
/// ==========
class ArgumentList: public Argument {
class IfcParse_EXPORT ArgumentList: public Argument {
private:
std::vector<Argument*> list;
void push(Argument* l);
@@ -166,7 +168,7 @@ namespace IfcParse {
/// Argument of type scalar or string, e.g.
/// #1=IfcVector(#2,1.0);
/// == ===
class TokenArgument : public Argument {
class IfcParse_EXPORT TokenArgument : public Argument {
private:
public:
@@ -202,7 +204,7 @@ namespace IfcParse {
/// Argument of an IFC simple type
/// #1=IfcTrimmedCurve(#2,(IFCPARAMETERVALUE(0.)),(IFCPARAMETERVALUE(1.)),.T.,.PARAMETER.);
/// ===================== =====================
class EntityArgument : public Argument {
class IfcParse_EXPORT EntityArgument : public Argument {
private:
IfcUtil::IfcBaseClass* entity;
public:
@@ -238,7 +240,7 @@ namespace IfcParse {
/// Entity defined in an IFC file, e.g.
/// #1=IfcDirection((1.,0.,0.));
/// ============================
class Entity : public IfcAbstractEntity {
class IfcParse_EXPORT Entity : public IfcAbstractEntity {
private:
mutable ArgumentList* args;
mutable IfcSchema::Type::Enum _type;
@@ -264,6 +266,6 @@ namespace IfcParse {
}
std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f);
IfcParse_EXPORT std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f);
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef IfcParse_EXPORT_H
#define IfcParse_EXPORT_H
#ifdef IFCPARSE_STATIC_DEFINE
#define IfcParse_EXPORT
#else
#ifdef _WIN32
#ifndef IfcParse_EXPORT
#ifdef IfcParse_EXPORTS
#define IfcParse_EXPORT __declspec(dllexport)
#else
#define IfcParse_EXPORT __declspec(dllimport)
#endif
#endif
#elif __linux__
#define IfcParse_EXPORT __attribute__((visibility("default")))
#else
#define IfcParse_EXPORT
#endif
#endif
#endif
+7 -5
View File
@@ -20,12 +20,14 @@
#ifndef IFCSPFHEADER_H
#define IFCSPFHEADER_H
#include "../ifcparse/IfcParse_Export.h"
#include "../ifcparse/IfcSpfStream.h"
#include "../ifcparse/IfcWrite.h"
namespace IfcParse {
class HeaderEntity : public IfcAbstractEntity {
class IfcParse_EXPORT HeaderEntity : public IfcAbstractEntity {
private:
ArgumentList* _list;
const char * const _datatype;
@@ -103,7 +105,7 @@ public:
}
};
class FileDescription : public HeaderEntity {
class IfcParse_EXPORT FileDescription : public HeaderEntity {
public:
explicit FileDescription(IfcSpfLexer* = 0);
@@ -114,7 +116,7 @@ public:
void implementation_level(const std::string& value) { setArgument(1, value); }
};
class FileName : public HeaderEntity {
class IfcParse_EXPORT FileName : public HeaderEntity {
public:
explicit FileName(IfcSpfLexer* = 0);
@@ -135,7 +137,7 @@ public:
void authorization(const std::string& value) { setArgument(6, value); }
};
class FileSchema : public HeaderEntity {
class IfcParse_EXPORT FileSchema : public HeaderEntity {
public:
explicit FileSchema(IfcSpfLexer* = 0);
@@ -144,7 +146,7 @@ public:
void schema_identifiers(const std::vector<std::string>& value) { setArgument(0, value); }
};
class IfcSpfHeader {
class IfcParse_EXPORT IfcSpfHeader {
private:
IfcSpfLexer* _lexer;
FileDescription* _file_description;
+3 -1
View File
@@ -30,6 +30,8 @@
#include <fstream>
#include <string>
#include "../ifcparse/IfcParse_Export.h"
// As of IfcOpenShell version 0.3.0 the paging functionality, which
// loads a file on disk into multiple chunks, has been disabled.
// It proved to be an inefficient way of working with large files,
@@ -46,7 +48,7 @@ namespace IfcParse {
/// which only one is simultaneously kept in memory, for files
/// that define their entities not in a sequential nature, this is
/// detrimental for the performance of the parser.
class IfcSpfStream {
class IfcParse_EXPORT IfcSpfStream {
private:
FILE* stream;
char* buffer;
+2
View File
@@ -111,6 +111,7 @@ bool IfcUtil::valid_binary_string(const std::string& s) {
return true;
}
#ifndef IFCPARSE_NO_REGEX
boost::regex IfcUtil::wildcard_string_to_regex(std::string str)
{
// Escape all non-"*?" regex special chars
@@ -124,6 +125,7 @@ boost::regex IfcUtil::wildcard_string_to_regex(std::string str)
boost::replace_all(str, "*", ".*");
return boost::regex(str);
}
#endif
void IfcUtil::sanitate_material_name(std::string &str)
{
+14 -8
View File
@@ -26,6 +26,8 @@
#include <sstream>
#include <algorithm>
#include "../ifcparse/IfcParse_Export.h"
#ifdef USE_IFC4
#include "../ifcparse/Ifc4enum.h"
#else
@@ -34,7 +36,9 @@
#include <boost/shared_ptr.hpp>
#include <boost/dynamic_bitset.hpp>
#include <boost/regex.hpp>
#ifndef IFCPARSE_NO_REGEX //allow builds without boost.regex
#include <boost/regex.hpp>
#endif
#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH
@@ -75,7 +79,7 @@ namespace IfcUtil {
const char* ArgumentTypeToString(ArgumentType argument_type);
class IfcBaseClass {
class IfcParse_EXPORT IfcBaseClass {
public:
IfcAbstractEntity* entity;
virtual bool is(IfcSchema::Type::Enum v) const = 0;
@@ -102,11 +106,11 @@ namespace IfcUtil {
}
};
class IfcBaseEntity : public IfcBaseClass {
class IfcParse_EXPORT IfcBaseEntity : public IfcBaseClass {
};
// TODO: Investigate whether these should be template classes instead
class IfcBaseType : public IfcBaseEntity {
class IfcParse_EXPORT IfcBaseType : public IfcBaseEntity {
public:
unsigned int getArgumentCount() const;
Argument* getArgument(unsigned int i) const;
@@ -116,7 +120,9 @@ namespace IfcUtil {
bool valid_binary_string(const std::string& s);
#ifndef IFCPARSE_NO_REGEX
boost::regex wildcard_string_to_regex(std::string str);
#endif
/// Replaces spaces and potentially other problem causing characters with underscores.
void sanitate_material_name(std::string &str);
@@ -127,7 +133,7 @@ namespace IfcUtil {
template <class T>
class IfcTemplatedEntityList;
class IfcEntityList {
class IfcParse_EXPORT IfcEntityList {
std::vector<IfcUtil::IfcBaseClass*> ls;
public:
typedef boost::shared_ptr<IfcEntityList> ptr;
@@ -185,7 +191,7 @@ public:
template <class T>
class IfcTemplatedEntityListList;
class IfcEntityListList {
class IfcParse_EXPORT IfcEntityListList {
std::vector< std::vector<IfcUtil::IfcBaseClass*> > ls;
public:
typedef boost::shared_ptr< IfcEntityListList > ptr;
@@ -283,7 +289,7 @@ namespace IfcParse {
class IfcFile;
}
class Argument {
class IfcParse_EXPORT Argument {
public:
virtual operator int() const = 0;
virtual operator bool() const = 0;
@@ -312,7 +318,7 @@ public:
virtual ~Argument() {};
};
class IfcAbstractEntity {
class IfcParse_EXPORT IfcAbstractEntity {
public:
IfcParse::IfcFile* file;
virtual IfcEntityList::ptr getInverse(IfcSchema::Type::Enum type, int attribute_index) = 0;
+3 -1
View File
@@ -35,10 +35,12 @@
#include <boost/dynamic_bitset.hpp>
#include "../ifcparse/IfcParse_Export.h"
#include "IfcUtil.h"
namespace IfcWrite {
class IfcWritableEntity : public IfcAbstractEntity {
class IfcParse_EXPORT IfcWritableEntity : public IfcAbstractEntity {
private:
std::map<int,bool> writemask;
std::map<int,Argument*> args;
+2
View File
@@ -44,6 +44,8 @@ IfcWritableEntity::IfcWritableEntity(IfcSchema::Type::Enum t) {
}
IfcWritableEntity::~IfcWritableEntity() {
delete _id;
for (std::map<int,Argument*>::iterator it = args.begin(); it != args.end(); ++it)
delete it->second;
}
int IfcWritableEntity::setId(int i) {
if (i > 0) {
+3 -1
View File
@@ -32,6 +32,8 @@
#include <boost/optional.hpp>
#include <boost/dynamic_bitset.hpp>
#include "../ifcparse/IfcParse_Export.h"
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/IfcParse.h"
@@ -42,7 +44,7 @@ namespace IfcWrite {
/// IfcParse namespace is that this class has a Boost.Variant member
/// for storing its value, whereas the IfcParse classes only contain
/// lazy references to byte offsets in the IFC-SPF file.
class IfcWriteArgument : public Argument {
class IfcParse_EXPORT IfcWriteArgument : public Argument {
public:
class EnumerationReference {
public:
+1
View File
@@ -199,6 +199,7 @@ namespace IfcUtil {
%}
};
%include "../ifcparse/IfcParse_Export.h"
%include "../ifcparse/IfcSpfHeader.h"
%include "../ifcparse/IfcFile.h"
%include "../ifcparse/IfcLateBoundEntity.h"