aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/CMakeLists.txt37
-rw-r--r--libshiboken/FindShiboken.cmake.in13
-rw-r--r--libshiboken/basewrapper.cpp56
-rw-r--r--libshiboken/basewrapper.h92
-rw-r--r--libshiboken/bindingmanager.cpp107
-rw-r--r--libshiboken/bindingmanager.h66
-rw-r--r--libshiboken/containers.cpp41
-rw-r--r--libshiboken/containers.h47
-rw-r--r--libshiboken/conversions.h191
-rw-r--r--libshiboken/helper.cpp67
-rw-r--r--libshiboken/helper.h72
-rw-r--r--libshiboken/pyenum.cpp96
-rw-r--r--libshiboken/pyenum.h68
-rw-r--r--libshiboken/shiboken.h47
-rw-r--r--libshiboken/shiboken.pc.in13
15 files changed, 1013 insertions, 0 deletions
diff --git a/libshiboken/CMakeLists.txt b/libshiboken/CMakeLists.txt
new file mode 100644
index 000000000..8471fad8d
--- /dev/null
+++ b/libshiboken/CMakeLists.txt
@@ -0,0 +1,37 @@
+project(libshiboken)
+
+find_package(PythonLibs REQUIRED)
+
+set(libshiboken_VERSION 0.1)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/FindShiboken.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/FindShiboken.cmake @ONLY)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/shiboken.pc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/shiboken.pc @ONLY)
+
+set(libshiboken_SRC
+basewrapper.cpp
+containers.cpp
+helper.cpp
+pyenum.cpp
+bindingmanager.cpp
+)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+ ${PYTHON_INCLUDE_PATH})
+add_library(libshiboken SHARED ${libshiboken_SRC})
+set_property(TARGET libshiboken PROPERTY PREFIX "")
+target_link_libraries(libshiboken
+ ${PYTHON_LIBRARIES}
+ -lutil)
+
+install(DIRECTORY . DESTINATION include/shiboken
+ FILES_MATCHING PATTERN "*.h"
+ PATTERN ".git" EXCLUDE
+ )
+install(TARGETS libshiboken DESTINATION lib)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FindShiboken.cmake
+ DESTINATION share/cmake-2.6/Modules)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/shiboken.pc
+ DESTINATION lib/pkgconfig)
+
diff --git a/libshiboken/FindShiboken.cmake.in b/libshiboken/FindShiboken.cmake.in
new file mode 100644
index 000000000..e63310dc8
--- /dev/null
+++ b/libshiboken/FindShiboken.cmake.in
@@ -0,0 +1,13 @@
+# - try to find Shiboken
+# SHIBOKEN_INCLUDE_DIR - Directories to include to use Shiboken
+# SHIBOKEN_LIBRARIES - Files to link against to use Shiboken
+# SHIBOKEN_FOUND - Shiboken was found
+
+find_path(SHIBOKEN_INCLUDE_DIR shiboken.h @CMAKE_INSTALL_PREFIX@/include/shiboken)
+find_library(SHIBOKEN_LIBRARY shiboken @CMAKE_INSTALL_PREFIX@/lib)
+
+set(SHIBOKEN_FOUND "NO")
+if(SHIBOKEN_LIBRARY AND SHIBOKEN_INCLUDE_DIR)
+ set(SHIBOKEN_FOUND "YES")
+endif(SHIBOKEN_LIBRARY AND SHIBOKEN_INCLUDE_DIR)
+
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
new file mode 100644
index 000000000..d2c5101c5
--- /dev/null
+++ b/libshiboken/basewrapper.cpp
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the Shiboken Python Binding 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
+ */
+
+#include "basewrapper.h"
+#include "bindingmanager.h"
+
+namespace Shiboken
+{
+
+PyObject*
+PyBaseWrapper_New(PyTypeObject* instanceType, PyTypeObject* baseWrapperType, void* cptr, uint hasOwnership)
+{
+ if (!cptr)
+ return 0;
+
+ PyObject *self = instanceType->tp_alloc(instanceType, 0);
+ ((Shiboken::PyBaseWrapper*)self)->baseWrapperType = baseWrapperType;
+ ((Shiboken::PyBaseWrapper*)self)->cptr = cptr;
+ ((Shiboken::PyBaseWrapper*)self)->hasOwnership = hasOwnership;
+ ((Shiboken::PyBaseWrapper*)self)->validCppObject = 1;
+ BindingManager::instance().assignWrapper(self, cptr);
+ return self;
+}
+
+} // namespace Shiboken
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
new file mode 100644
index 000000000..201851cc6
--- /dev/null
+++ b/libshiboken/basewrapper.h
@@ -0,0 +1,92 @@
+/*
+ * This file is part of the Shiboken Python Binding 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 BASEWRAPPER_H
+#define BASEWRAPPER_H
+
+#include <Python.h>
+
+namespace Shiboken
+{
+
+extern "C"
+{
+
+struct PyBaseWrapper
+{
+ PyObject_HEAD
+ PyTypeObject* baseWrapperType;
+ void* cptr;
+ uint hasOwnership : 1;
+ uint validCppObject : 1;
+};
+
+} // extern "C"
+
+#define PyBaseWrapper_Check(op) PyObject_TypeCheck(op, &PyBaseWrapper_Type)
+#define PyBaseWrapper_CheckExact(op) ((op)->ob_type == &PyBaseWrapper_Type)
+
+#define PyBaseWrapper_cptr(pyobj) (((Shiboken::PyBaseWrapper*)pyobj)->cptr)
+#define PyBaseWrapper_setCptr(pyobj,c) (((Shiboken::PyBaseWrapper*)pyobj)->cptr = c)
+#define PyBaseWrapper_hasOwnership(pyobj) (((Shiboken::PyBaseWrapper*)pyobj)->hasOwnership)
+#define PyBaseWrapper_setOwnership(pyobj,o) (((Shiboken::PyBaseWrapper*)pyobj)->hasOwnership = o)
+#define PyBaseWrapper_validCppObject(pyobj) (((Shiboken::PyBaseWrapper*)pyobj)->validCppObject)
+#define PyBaseWrapper_setValidCppObject(pyobj,v) (((Shiboken::PyBaseWrapper*)pyobj)->validCppObject = v)
+
+PyAPI_FUNC(PyObject*)
+PyBaseWrapper_New(PyTypeObject *instanceType, PyTypeObject *baseWrapperType,
+ void *cptr, uint hasOwnership = 1);
+
+inline bool
+cppObjectIsValid(PyBaseWrapper* self)
+{
+ if (self->validCppObject)
+ return true;
+ PyErr_SetString(PyExc_RuntimeError, "internal C++ object already deleted.");
+ return false;
+}
+
+template <typename T>
+PyAPI_FUNC(void)
+PyBaseWrapper_Dealloc(PyObject* self)
+{
+ if (PyBaseWrapper_hasOwnership(self)) {
+ delete ((T*)PyBaseWrapper_cptr(self));
+ }
+ Py_TYPE(((PyBaseWrapper*)self))->tp_free((PyObject*)self);
+}
+
+} // namespace Shiboken
+
+#endif // BASEWRAPPER_H
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp
new file mode 100644
index 000000000..c81ad07b4
--- /dev/null
+++ b/libshiboken/bindingmanager.cpp
@@ -0,0 +1,107 @@
+/*
+ * This file is part of the Shiboken Python Binding 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
+ */
+
+#include "bindingmanager.h"
+
+namespace Shiboken
+{
+
+BindingManager& BindingManager::instance() {
+ static BindingManager singleton;
+ return singleton;
+}
+
+bool BindingManager::hasWrapper(void* cptr)
+{
+ return m_wrapperMapper.count(cptr);
+}
+
+void BindingManager::assignWrapper(PyObject* wrapper, void* cptr)
+{
+ std::map<void*, PyObject*>::iterator iter = m_wrapperMapper.find(cptr);
+ if (iter == m_wrapperMapper.end())
+ m_wrapperMapper.insert(std::pair<void*, PyObject*>(cptr, wrapper));
+ else
+ iter->second = wrapper;
+}
+
+void BindingManager::releaseWrapper(void *cptr)
+{
+ std::map<void*, PyObject*>::iterator iter = m_wrapperMapper.find(cptr);
+ if (iter != m_wrapperMapper.end())
+ m_wrapperMapper.erase(iter);
+}
+
+inline void BindingManager::releaseWrapper(PyObject* wrapper)
+{
+ releaseWrapper(PyBaseWrapper_cptr(wrapper));
+}
+
+PyObject* BindingManager::retrieveWrapper(void* cptr)
+{
+ std::map<void*, PyObject*>::iterator iter = m_wrapperMapper.find(cptr);
+ if (iter == m_wrapperMapper.end())
+ return 0;
+ return iter->second;
+}
+
+PyObject* BindingManager::getOverride(void* cptr, const char* methodName)
+{
+ PyObject* wrapper = retrieveWrapper(cptr);
+
+ fprintf(stderr, "[%s:%d] method: %s, wrapper: %s\n", __FUNCTION__, __LINE__, methodName, wrapper->ob_type->tp_name);
+
+ if (wrapper) {
+ PyTypeObject* baseWrapperType = ((Shiboken::PyBaseWrapper*)wrapper)->baseWrapperType;
+ fprintf(stderr, "[%s:%d] basewrapper: %s\n", __FUNCTION__, __LINE__, baseWrapperType->tp_name);
+ PyObject* method = PyObject_GetAttrString(wrapper, const_cast<char*>(methodName));
+ if (method != 0) {
+ PyObject* defaultMethod = 0;
+ if (PyMethod_Check(method) &&
+ ((PyMethodObject*) method)->im_self == wrapper &&
+ baseWrapperType->tp_dict != 0) {
+ defaultMethod = PyDict_GetItemString(baseWrapperType->tp_dict, const_cast<char*>(methodName));
+ }
+
+ if (((PyMethodObject*)method)->im_func != defaultMethod)
+ return method;
+
+ Py_DECREF(method);
+ }
+ }
+
+ return 0;
+}
+
+} // namespace Shiboken
diff --git a/libshiboken/bindingmanager.h b/libshiboken/bindingmanager.h
new file mode 100644
index 000000000..bd4472154
--- /dev/null
+++ b/libshiboken/bindingmanager.h
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the Shiboken Python Binding 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 BINDINGMANAGER_H
+#define BINDINGMANAGER_H
+
+#include <map>
+#include <Python.h>
+#include <basewrapper.h>
+
+namespace Shiboken
+{
+
+class BindingManager
+{
+public:
+ static BindingManager& instance();
+
+ bool hasWrapper(void *cptr);
+ void assignWrapper(PyObject* wrapper, void* cptr);
+ void releaseWrapper(void* cptr);
+ inline void releaseWrapper(PyObject* wrapper);
+ PyObject* retrieveWrapper(void* cptr);
+ PyObject* getOverride(void* cptr, const char* methodName);
+
+private:
+ BindingManager() {}
+ BindingManager(const BindingManager&);
+
+ std::map<void*, PyObject*> m_wrapperMapper;
+};
+
+} // namespace Shiboken
+
+#endif // BINDINGMANAGER_H
diff --git a/libshiboken/containers.cpp b/libshiboken/containers.cpp
new file mode 100644
index 000000000..ce756871f
--- /dev/null
+++ b/libshiboken/containers.cpp
@@ -0,0 +1,41 @@
+/*
+ * This file is part of the Shiboken Python Binding 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
+ */
+
+#include "containers.h"
+
+namespace Shiboken
+{
+
+
+} // namespace Shiboken
diff --git a/libshiboken/containers.h b/libshiboken/containers.h
new file mode 100644
index 000000000..85cadb0df
--- /dev/null
+++ b/libshiboken/containers.h
@@ -0,0 +1,47 @@
+/*
+ * This file is part of the Shiboken Python Binding 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 CONTAINERS_H
+#define CONTAINERS_H
+
+#include <Python.h>
+
+namespace Shiboken
+{
+
+
+} // namespace Shiboken
+
+#endif // CONTAINERS_H
+
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h
new file mode 100644
index 000000000..cbd4ee550
--- /dev/null
+++ b/libshiboken/conversions.h
@@ -0,0 +1,191 @@
+/*
+ * This file is part of the Shiboken Python Binding 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 CONVERSIONS_H
+#define CONVERSIONS_H
+
+#include <Python.h>
+#include <basewrapper.h>
+#include <bindingmanager.h>
+
+namespace Shiboken
+{
+
+template <typename T>
+struct ValueHolder
+{
+ explicit ValueHolder(T val) : value(val) {}
+ T value;
+};
+
+template <typename T>
+struct Converter
+{
+ static PyObject* toPython(ValueHolder<T> cppobj) {
+ return 0;
+ }
+ static T toCpp(PyObject* pyobj) {
+ return T();
+ }
+};
+
+// Object Types ---------------------------------------------------------------
+template <>
+struct Converter<void*>
+{
+ static PyObject* toPython(ValueHolder<void*> cppobj)
+ {
+ PyObject* obj = BindingManager::instance().retrieveWrapper(cppobj.value);
+ Py_XINCREF(obj);
+ return obj;
+ }
+ static void* toCpp(PyObject* pyobj)
+ {
+ return ((Shiboken::PyBaseWrapper*) pyobj)->cptr;
+ }
+};
+
+// Primitive Types ------------------------------------------------------------
+template <>
+struct Converter<bool>
+{
+ static PyObject* toPython(ValueHolder<bool> holder)
+ {
+ return PyBool_FromLong(holder.value);
+ }
+ static bool toCpp(PyObject* pyobj)
+ {
+ return pyobj == Py_True;
+ }
+};
+
+template <typename PyIntEquiv>
+struct Converter_PyInt
+{
+ static PyObject* toPython(ValueHolder<PyIntEquiv> holder)
+ {
+ return PyInt_FromLong((long) holder.value);
+ }
+ static PyIntEquiv toCpp(PyObject* pyobj)
+ {
+ if (PyFloat_Check(pyobj))
+ return (PyIntEquiv) PyFloat_AS_DOUBLE(pyobj);
+ return (PyIntEquiv) PyInt_AS_LONG(pyobj);
+ }
+};
+
+template <> struct Converter<char> : Converter_PyInt<char> {};
+template <> struct Converter<unsigned char> : Converter_PyInt<unsigned char> {};
+template <> struct Converter<int> : Converter_PyInt<int> {};
+template <> struct Converter<unsigned int> : Converter_PyInt<unsigned int> {};
+template <> struct Converter<short> : Converter_PyInt<short> {};
+template <> struct Converter<unsigned short> : Converter_PyInt<unsigned short> {};
+template <> struct Converter<long> : Converter_PyInt<long> {};
+
+template <>
+struct Converter<unsigned long>
+{
+ static PyObject* toPython(ValueHolder<unsigned long> holder)
+ {
+ return PyLong_FromUnsignedLong(holder.value);
+ }
+ static unsigned long toCpp(PyObject* pyobj)
+ {
+ return (unsigned long) PyLong_AsUnsignedLong(pyobj);
+ }
+};
+
+template <>
+struct Converter<PY_LONG_LONG>
+{
+ static PyObject* toPython(ValueHolder<PY_LONG_LONG> holder)
+ {
+ return PyLong_FromLongLong(holder.value);
+ }
+ static PY_LONG_LONG toCpp(PyObject* pyobj)
+ {
+ return (PY_LONG_LONG) PyLong_AsLongLong(pyobj);
+ }
+};
+
+template <>
+struct Converter<unsigned PY_LONG_LONG>
+{
+ static PyObject* toPython(ValueHolder<unsigned PY_LONG_LONG> holder)
+ {
+ return PyLong_FromUnsignedLongLong(holder.value);
+ }
+ static unsigned PY_LONG_LONG toCpp(PyObject* pyobj)
+ {
+ return (unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(pyobj);
+ }
+};
+
+template <typename PyFloatEquiv>
+struct Converter_PyFloat
+{
+ static PyObject* toPython(ValueHolder<PyFloatEquiv> holder)
+ {
+ return PyFloat_FromDouble((double) holder.value);
+ }
+ static PyFloatEquiv toCpp(PyObject* pyobj)
+ {
+ if (PyInt_Check(pyobj))
+ return (PyFloatEquiv) PyInt_AS_LONG(pyobj);
+ return (PyFloatEquiv) PyFloat_AS_DOUBLE(pyobj);
+ }
+};
+
+template <> struct Converter<float> : Converter_PyFloat<float> {};
+template <> struct Converter<double> : Converter_PyFloat<double> {};
+
+// C Sting Types --------------------------------------------------------------
+
+template <>
+struct Converter<const char*>
+{
+ static PyObject* toPython(ValueHolder<const char*> holder)
+ {
+ return PyString_FromString(holder.value);
+ }
+ static const char* toCpp(PyObject* pyobj)
+ {
+ return PyString_AsString(pyobj);
+ }
+};
+
+} // namespace Shiboken
+
+#endif // CONVERSIONS_H
+
diff --git a/libshiboken/helper.cpp b/libshiboken/helper.cpp
new file mode 100644
index 000000000..eb213ed3d
--- /dev/null
+++ b/libshiboken/helper.cpp
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the Shiboken Python Binding 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
+ */
+
+#include "helper.h"
+
+namespace Shiboken
+{
+
+int
+PySequence_to_argc_argv(_object* argList, char** argv[])
+{
+ if (!PySequence_Check(argList))
+ return -1;
+
+ int argc = (int) PySequence_Size(argList);
+ (*argv) = new char*[argc];
+ for (int i = 0; i < argc; ++i) {
+ PyObject* item = PySequence_GetItem(argList, i);
+ if (!PyString_Check(item)) {
+ argc = -1;
+ for (int j = 0; j < i; ++j)
+ delete (*argv)[j];
+ Py_DECREF(item);
+ return -1;
+ }
+ char *origArg = PyString_AS_STRING(item);
+ int size = strlen(origArg);
+ (*argv)[i] = new char[size+1];
+ (*argv)[i] = strcpy((*argv)[i], origArg);
+ Py_DECREF(item);
+ }
+
+ return argc;
+}
+
+} // namespace Shiboken
diff --git a/libshiboken/helper.h b/libshiboken/helper.h
new file mode 100644
index 000000000..588f0c3f0
--- /dev/null
+++ b/libshiboken/helper.h
@@ -0,0 +1,72 @@
+/*
+ * This file is part of the Shiboken Python Binding 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 HELPER_H
+#define HELPER_H
+
+#include <Python.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
+
+int PySequence_to_argc_argv(PyObject* argList, char** argv[]);
+
+} // namespace Shiboken
+
+#endif // HELPER_H
+
diff --git a/libshiboken/pyenum.cpp b/libshiboken/pyenum.cpp
new file mode 100644
index 000000000..d60d03443
--- /dev/null
+++ b/libshiboken/pyenum.cpp
@@ -0,0 +1,96 @@
+/*
+ * This file is part of the Shiboken Python Binding 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
+ */
+
+#include "pyenum.h"
+
+namespace Shiboken
+{
+
+PyObject*
+PyEnumObject_New(PyTypeObject *type, PyObject* item_name, long item_value)
+{
+ PyEnumObject* enum_obj = (PyEnumObject*) type->tp_alloc(type, 0);
+ enum_obj->ob_name = item_name;
+ enum_obj->ob_ival = item_value;
+ return (PyObject*) enum_obj;
+}
+
+PyObject*
+PyEnumObject_New(PyTypeObject *type, const char* item_name, long item_value)
+{
+ PyObject* py_item_name = PyString_FromString(item_name);
+ PyObject* enum_obj = PyEnumObject_New(type, py_item_name, item_value);
+ if (!enum_obj) {
+ Py_DECREF(py_item_name);
+ return 0;
+ }
+ PyObject* values = PyDict_GetItemString(type->tp_dict, const_cast<char*>("values"));
+ if (!values) {
+ values = PyDict_New();
+ PyDict_SetItemString(type->tp_dict, const_cast<char*>("values"), values);
+ }
+ PyDict_SetItemString(values, item_name, enum_obj);
+ return enum_obj;
+}
+
+extern "C"
+{
+
+PyObject*
+PyEnumObject_NonExtensibleNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyErr_SetString(PyExc_TypeError, "this enum is not extensible");
+ return 0;
+}
+
+
+PyObject*
+PyEnumObject_repr(PyObject* self)
+{
+ return PyString_FromFormat("<enum-item %s.%s (%ld)>",
+ self->ob_type->tp_name,
+ PyString_AS_STRING(((PyEnumObject*)self)->ob_name),
+ ((PyEnumObject*)self)->ob_ival);
+}
+
+PyObject*
+PyEnumObject_name(PyObject* self)
+{
+ Py_INCREF(((PyEnumObject*)self)->ob_name);
+ return ((PyEnumObject*)self)->ob_name;
+}
+
+} // extern "C"
+
+} // namespace Shiboken
diff --git a/libshiboken/pyenum.h b/libshiboken/pyenum.h
new file mode 100644
index 000000000..6fb9f52ef
--- /dev/null
+++ b/libshiboken/pyenum.h
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the Shiboken Python Binding 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 PYENUM_H
+#define PYENUM_H
+
+#include <Python.h>
+
+namespace Shiboken
+{
+
+extern "C"
+{
+
+typedef struct {
+ PyObject_HEAD
+ long ob_ival;
+ 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);
+
+} // extern "C"
+
+PyObject* PyEnumObject_New(PyTypeObject *instanceType,
+ const char* item_name,
+ long item_value);
+PyObject* PyEnumObject_New(PyTypeObject *instanceType,
+ PyObject* item_name,
+ long item_value);
+
+} // namespace Shiboken
+
+#endif // PYENUM_H
+
diff --git a/libshiboken/shiboken.h b/libshiboken/shiboken.h
new file mode 100644
index 000000000..3f7e6781e
--- /dev/null
+++ b/libshiboken/shiboken.h
@@ -0,0 +1,47 @@
+/*
+ * This file is part of the Shiboken Python Binding 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 SHIBOKEN_H
+#define SHIBOKEN_H
+
+#include <Python.h>
+#include <basewrapper.h>
+#include <containers.h>
+#include <conversions.h>
+#include <helper.h>
+#include <pyenum.h>
+#include <bindingmanager.h>
+
+#endif // SHIBOKEN_H
+
diff --git a/libshiboken/shiboken.pc.in b/libshiboken/shiboken.pc.in
new file mode 100644
index 000000000..f120f00da
--- /dev/null
+++ b/libshiboken/shiboken.pc.in
@@ -0,0 +1,13 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=@CMAKE_INSTALL_PREFIX@/lib
+includedir=@CMAKE_INSTALL_PREFIX@/include/shiboken
+generator_location=@CMAKE_INSTALL_PREFIX@/bin/shiboken
+
+Name: shiboken
+Description: support library for Python bindings created with Shiboken generator.
+Requires: Python
+Version: @libshiboken_VERSION@
+Libs: -L${libdir} -lpython
+Cflags: -I${includedir}
+