From b58553f67867dc3e09243a137de560f83758f4a4 Mon Sep 17 00:00:00 2001 From: Hugo Lima Date: Wed, 11 Nov 2009 17:22:56 -0200 Subject: Add visibility policies to libshiboken and for bindings generated by shiboken generator. As shiboken generator needs minor changes to support inter-module dependencies, these changes about symbol visibility does not support inter-module dependencies, however support it is simple, because we just need to make some symbols visible to other DSO's. Reviewed by Marcelo Lira --- libshiboken/basewrapper.h | 6 ++--- libshiboken/bindingmanager.cpp | 34 +++++++++++++++++++------- libshiboken/bindingmanager.h | 12 ++++++--- libshiboken/helper.h | 27 ++------------------- libshiboken/pyenum.h | 11 +++++---- libshiboken/shiboken.h | 11 +++++---- libshiboken/shibokenmacros.h | 55 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 105 insertions(+), 51 deletions(-) create mode 100644 libshiboken/shibokenmacros.h (limited to 'libshiboken') 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 -#include +#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 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 #include +#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 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 +#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 +#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 -#include -#include -#include -#include -#include +#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 +* +* 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 -- cgit v1.2.3