aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt6
-rw-r--r--cppgenerator.cpp2
-rw-r--r--headergenerator.cpp21
-rw-r--r--headergenerator.h1
-rw-r--r--libshiboken/basewrapper.h6
-rw-r--r--libshiboken/bindingmanager.cpp34
-rw-r--r--libshiboken/bindingmanager.h12
-rw-r--r--libshiboken/helper.h27
-rw-r--r--libshiboken/pyenum.h11
-rw-r--r--libshiboken/shiboken.h11
-rw-r--r--libshiboken/shibokenmacros.h55
-rw-r--r--shibokengenerator.cpp6
-rw-r--r--shibokengenerator.h2
-rw-r--r--tests/libsample/CMakeLists.txt1
14 files changed, 140 insertions, 55 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d050dd408..50806e8ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,8 +9,10 @@ find_package(Boost COMPONENTS graph REQUIRED)
add_definitions(${QT_DEFINITIONS})
-set(CMAKE_CXX_FLAGS_RELEASE "-Wall -DNDEBUG -O2 -Wl,-O1 -Wl,--hash-style=gnu")
-set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall")
+set(CMAKE_CXX_FLAGS_RELEASE "-Wall -DNDEBUG -O2 -Wl,-O1 -Wl,--hash-style=gnu -fvisibility=hidden")
+set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -fvisibility=hidden")
+# We need to define this when building shiboken, because windows need to known when to use dll_export or dll_import.
+add_definitions("-DLIBSHIBOKEN_BUILD")
set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE)
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 6e59ca81d..019a8b8a0 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -2042,7 +2042,7 @@ void CppGenerator::finishGeneration()
s << "------------------------------------------------------------" << endl;
s << "extern \"C\" {" << endl << endl;
- s << "PyMODINIT_FUNC" << endl << "init" << moduleName() << "()" << endl;
+ s << getApiExportMacro() << " PyMODINIT_FUNC" << endl << "init" << moduleName() << "()" << endl;
s << '{' << endl;
foreach (const QString& requiredModule, TypeDatabase::instance()->requiredTargetImports()) {
diff --git a/headergenerator.cpp b/headergenerator.cpp
index cba8ffb75..6b3ec40af 100644
--- a/headergenerator.cpp
+++ b/headergenerator.cpp
@@ -89,7 +89,7 @@ void HeaderGenerator::generateClass(QTextStream& s, const AbstractMetaClass* met
*/
// Class
- s << "class SHIBOKEN_LOCAL " << wrapperName;
+ s << "class " << wrapperName;
s << " : public " << metaClass->qualifiedCppName();
s << endl << '{' << endl << "public:" << endl;
@@ -318,6 +318,7 @@ void HeaderGenerator::finishGeneration()
s << "#include <bindingmanager.h>" << endl << endl;
s << "#include <memory>" << endl << endl;
+ writeExportMacros(s);
s << "// Class Includes" << endl;
s << classIncludes << endl;
@@ -369,3 +370,21 @@ void HeaderGenerator::finishGeneration()
s << "#endif // " << includeShield << endl << endl;
}
}
+
+
+void HeaderGenerator::writeExportMacros(QTextStream& s)
+{
+ QString macro = getApiExportMacro();
+ s << "\
+#if defined _WIN32 || defined __CYGWIN__\n\
+ #define " << macro << " __declspec(dllexport)\n\
+#else\n\
+#if __GNUC__ >= 4\n\
+ #define " << macro << " __attribute__ ((visibility(\"default\")))\n\
+#else\n\
+ #define " << macro << "\n\
+#endif\n\
+#endif\n\
+\n";
+}
+
diff --git a/headergenerator.h b/headergenerator.h
index 431130844..e035b5621 100644
--- a/headergenerator.h
+++ b/headergenerator.h
@@ -43,6 +43,7 @@ private:
void writeDefaultImplementation(QTextStream& s, const AbstractMetaFunction* func) const;
void writeVirtualDispatcher(QTextStream &s, const AbstractMetaFunction *func) const;
void writeTypeCheckMacro(QTextStream& s, const TypeEntry* type);
+ void writeExportMacros(QTextStream& s);
void writeTypeConverterDecl(QTextStream& s, const TypeEntry* type);
};
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
index c59d3653b..a31e22638 100644
--- a/libshiboken/basewrapper.h
+++ b/libshiboken/basewrapper.h
@@ -36,7 +36,7 @@
#define BASEWRAPPER_H
#include <Python.h>
-#include <bindingmanager.h>
+#include "bindingmanager.h"
namespace Shiboken
{
@@ -114,7 +114,7 @@ typedef struct {
#endif
-PyAPI_FUNC(PyObject*)
+LIBSHIBOKEN_API PyAPI_FUNC(PyObject*)
PyBaseWrapper_New(PyTypeObject *instanceType, PyTypeObject *baseWrapperType,
const void *cptr, uint hasOwnership = 1);
@@ -137,7 +137,7 @@ PyBaseWrapper_Dealloc(PyObject* self)
Py_TYPE(((PyBaseWrapper*)self))->tp_free((PyObject*)self);
}
-PyAPI_FUNC(void) PyBaseWrapper_Dealloc_PrivateDtor(PyObject* self);
+LIBSHIBOKEN_API PyAPI_FUNC(void) PyBaseWrapper_Dealloc_PrivateDtor(PyObject* self);
} // namespace Shiboken
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp
index b00d8341b..4ae49f868 100644
--- a/libshiboken/bindingmanager.cpp
+++ b/libshiboken/bindingmanager.cpp
@@ -38,6 +38,22 @@
namespace Shiboken
{
+typedef std::map<const void*, PyObject*> WrapperMap;
+
+struct BindingManager::BindingManagerPrivate {
+ WrapperMap wrapperMapper;
+};
+
+BindingManager::BindingManager()
+{
+ m_d = new BindingManager::BindingManagerPrivate;
+}
+
+BindingManager::~BindingManager()
+{
+ delete m_d;
+}
+
BindingManager& BindingManager::instance() {
static BindingManager singleton;
return singleton;
@@ -45,23 +61,23 @@ BindingManager& BindingManager::instance() {
bool BindingManager::hasWrapper(const void* cptr)
{
- return m_wrapperMapper.count(cptr);
+ return m_d->wrapperMapper.count(cptr);
}
void BindingManager::assignWrapper(PyObject* wrapper, const void* cptr)
{
- WrapperMap::iterator iter = m_wrapperMapper.find(cptr);
- if (iter == m_wrapperMapper.end())
- m_wrapperMapper.insert(std::make_pair(cptr, wrapper));
+ WrapperMap::iterator iter = m_d->wrapperMapper.find(cptr);
+ if (iter == m_d->wrapperMapper.end())
+ m_d->wrapperMapper.insert(std::make_pair(cptr, wrapper));
else
iter->second = wrapper;
}
void BindingManager::releaseWrapper(void *cptr)
{
- WrapperMap::iterator iter = m_wrapperMapper.find(cptr);
- if (iter != m_wrapperMapper.end())
- m_wrapperMapper.erase(iter);
+ WrapperMap::iterator iter = m_d->wrapperMapper.find(cptr);
+ if (iter != m_d->wrapperMapper.end())
+ m_d->wrapperMapper.erase(iter);
}
void BindingManager::releaseWrapper(PyObject* wrapper)
@@ -71,8 +87,8 @@ void BindingManager::releaseWrapper(PyObject* wrapper)
PyObject* BindingManager::retrieveWrapper(const void* cptr)
{
- WrapperMap::iterator iter = m_wrapperMapper.find(cptr);
- if (iter == m_wrapperMapper.end())
+ WrapperMap::iterator iter = m_d->wrapperMapper.find(cptr);
+ if (iter == m_d->wrapperMapper.end())
return 0;
return iter->second;
}
diff --git a/libshiboken/bindingmanager.h b/libshiboken/bindingmanager.h
index 306c17f21..3646a77a2 100644
--- a/libshiboken/bindingmanager.h
+++ b/libshiboken/bindingmanager.h
@@ -37,11 +37,12 @@
#include <Python.h>
#include <map>
+#include "shibokenmacros.h"
namespace Shiboken
{
-class BindingManager
+class LIBSHIBOKEN_API BindingManager
{
public:
static BindingManager& instance();
@@ -54,11 +55,14 @@ public:
PyObject* getOverride(const void* cptr, const char* methodName);
private:
- BindingManager() {}
+ ~BindingManager();
+ // disable copy
+ BindingManager();
BindingManager(const BindingManager&);
+ BindingManager& operator=(const BindingManager&);
- typedef std::map<const void*, PyObject*> WrapperMap;
- WrapperMap m_wrapperMapper;
+ struct BindingManagerPrivate;
+ BindingManagerPrivate* m_d;
};
} // namespace Shiboken
diff --git a/libshiboken/helper.h b/libshiboken/helper.h
index fc2f1aab9..c6ab2c98e 100644
--- a/libshiboken/helper.h
+++ b/libshiboken/helper.h
@@ -36,35 +36,12 @@
#define HELPER_H
#include <Python.h>
+#include "shibokenmacros.h"
namespace Shiboken
{
-// Generic helper definitions for shared library support
-#if defined _WIN32 || defined __CYGWIN__
-#define SHIBOKEN_HELPER_DLL_IMPORT __declspec(dllimport)
-#define SHIBOKEN_HELPER_DLL_EXPORT __declspec(dllexport)
-#define SHIBOKEN_HELPER_DLL_LOCAL
-#else
-#if __GNUC__ >= 4
-#define SHIBOKEN_HELPER_DLL_IMPORT __attribute__ ((visibility("default")))
-#define SHIBOKEN_HELPER_DLL_EXPORT __attribute__ ((visibility("default")))
-#define SHIBOKEN_HELPER_DLL_LOCAL __attribute__ ((visibility("internal")))
-#else
-#define SHIBOKEN_HELPER_DLL_IMPORT
-#define SHIBOKEN_HELPER_DLL_EXPORT
-#define SHIBOKEN_HELPER_DLL_LOCAL
-#endif
-#endif
-
-// Now we use the generic helper definitions above to define SHIBOKEN_API and SHIBOKEN_LOCAL.
-// SHIBOKEN_API is used for the public API symbols. It either DLL imports or DLL exports (or does nothing for static build)
-// SHIBOKEN_LOCAL is used for non-api symbols.
-
-#define SHIBOKEN_API SHIBOKEN_HELPER_DLL_EXPORT
-#define SHIBOKEN_LOCAL SHIBOKEN_HELPER_DLL_LOCAL
-
-bool PySequence_to_argc_argv(PyObject* argList, int* argc, char*** argv);
+LIBSHIBOKEN_API bool PySequence_to_argc_argv(PyObject* argList, int* argc, char*** argv);
} // namespace Shiboken
diff --git a/libshiboken/pyenum.h b/libshiboken/pyenum.h
index ab32052a4..18dc6730c 100644
--- a/libshiboken/pyenum.h
+++ b/libshiboken/pyenum.h
@@ -36,6 +36,7 @@
#define PYENUM_H
#include <Python.h>
+#include "shibokenmacros.h"
namespace Shiboken
{
@@ -49,16 +50,16 @@ typedef struct {
PyObject* ob_name;
} PyEnumObject;
-PyAPI_FUNC(PyObject*) PyEnumObject_repr(PyObject* self);
-PyAPI_FUNC(PyObject*) PyEnumObject_name(PyObject* self);
-PyAPI_FUNC(PyObject*) PyEnumObject_NonExtensibleNew(PyTypeObject* type, PyObject* args, PyObject* kwds);
+LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) PyEnumObject_repr(PyObject* self);
+LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) PyEnumObject_name(PyObject* self);
+LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) PyEnumObject_NonExtensibleNew(PyTypeObject* type, PyObject* args, PyObject* kwds);
} // extern "C"
-PyObject* PyEnumObject_New(PyTypeObject *instanceType,
+LIBSHIBOKEN_API PyObject* PyEnumObject_New(PyTypeObject *instanceType,
long item_value,
const char* item_name);
-PyObject* PyEnumObject_New(PyTypeObject *instanceType,
+LIBSHIBOKEN_API PyObject* PyEnumObject_New(PyTypeObject *instanceType,
long item_value,
PyObject* item_name = 0);
diff --git a/libshiboken/shiboken.h b/libshiboken/shiboken.h
index 33a77c50b..9c0090d34 100644
--- a/libshiboken/shiboken.h
+++ b/libshiboken/shiboken.h
@@ -36,11 +36,12 @@
#define SHIBOKEN_H
#include <Python.h>
-#include <basewrapper.h>
-#include <conversions.h>
-#include <helper.h>
-#include <pyenum.h>
-#include <bindingmanager.h>
+#include "shibokenmacros.h"
+#include "basewrapper.h"
+#include "conversions.h"
+#include "helper.h"
+#include "pyenum.h"
+#include "bindingmanager.h"
#endif // SHIBOKEN_H
diff --git a/libshiboken/shibokenmacros.h b/libshiboken/shibokenmacros.h
new file mode 100644
index 000000000..7da6c0a2f
--- /dev/null
+++ b/libshiboken/shibokenmacros.h
@@ -0,0 +1,55 @@
+/*
+* This file is part of the Shiboken Python Bindings Generator project.
+*
+* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* version 2.1 as published by the Free Software Foundation. Please
+* review the following information to ensure the GNU Lesser General
+* Public License version 2.1 requirements will be met:
+* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+*
+* As a special exception to the GNU Lesser General Public License
+* version 2.1, the object code form of a "work that uses the Library"
+* may incorporate material from a header file that is part of the
+* Library. You may distribute such object code under terms of your
+* choice, provided that the incorporated material (i) does not exceed
+* more than 5% of the total size of the Library; and (ii) is limited to
+* numerical parameters, data structure layouts, accessors, macros,
+* inline functions and templates.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*/
+
+#ifndef SHIBOKENMACROS_H
+#define SHIBOKENMACROS_H
+
+// LIBSHIBOKEN_API is used for the public API symbols.
+// LIBSHIBOKEN_LOCAL is used for non-api symbols, i.e. internal functions and classes.
+// Generic helper definitions for shared library support
+#if defined _WIN32 || defined __CYGWIN__
+ #if LIBSHIBOKEN_BUILD
+ #define LIBSHIBOKEN_API __declspec(dllimport)
+ #else
+ #define LIBSHIBOKEN_API __declspec(dllexport)
+ #endif
+#else
+#if __GNUC__ >= 4
+ #define LIBSHIBOKEN_API __attribute__ ((visibility("default")))
+#else
+ #define LIBSHIBOKEN_API
+#endif
+#endif
+
+#endif
diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp
index 72d20d40e..1ebfb3017 100644
--- a/shibokengenerator.cpp
+++ b/shibokengenerator.cpp
@@ -897,6 +897,12 @@ QStringList ShibokenGenerator::getBaseClasses(const AbstractMetaClass* metaClass
return baseClass;
}
+
+QString ShibokenGenerator::getApiExportMacro() const
+{
+ return "SHIBOKEN_"+moduleName().toUpper()+"_API"; // a longer name to avoid name clashes
+}
+
static void dumpFunction(AbstractMetaFunctionList lst)
{
qDebug() << "DUMP FUNCTIONS: ";
diff --git a/shibokengenerator.h b/shibokengenerator.h
index 82e3a30d4..945825238 100644
--- a/shibokengenerator.h
+++ b/shibokengenerator.h
@@ -183,6 +183,8 @@ public:
QString getFunctionReturnType(const AbstractMetaFunction* func, Options options = NoOption) const;
QString getFormatUnitString(const AbstractMetaFunction* func) const;
+ /// Returns the name of the macro used to export symbols
+ QString getApiExportMacro() const;
bool doSetup(const QMap<QString, QString>& args);
protected:
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt
index 7cd36760a..16a5f7561 100644
--- a/tests/libsample/CMakeLists.txt
+++ b/tests/libsample/CMakeLists.txt
@@ -26,6 +26,7 @@ str.cpp
virtualmethods.cpp
)
+add_definitions("-fvisibility=default")
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_library(libsample SHARED ${libsample_SRC})
set_property(TARGET libsample PROPERTY PREFIX "")