I have made the following changes intended for : nemo:devel:mw / python-pyside-shiboken
Please review and accept or decline. BOSS has already run some checks on this request. See the "Messages from BOSS" section below. https://build.merproject.org//request/show/310 Thank You, -- -- [This message was auto-generated] --- Request # 310: Messages from BOSS: State: review at 2013-05-20T15:18:27 by cibot Reviews: accepted by cibot : Prechecks succeeded. new for nemo:devel:mw : Please replace this text with a review and approve/reject the review (not the SR). BOSS will take care of the rest Changes: submit: home:eenemo:branches:nemo:devel:mw / python-pyside-shiboken -> nemo:devel:mw / python-pyside-shiboken changes files: -------------- --- python-pyside-shiboken.changes +++ python-pyside-shiboken.changes @@ -0,0 +1,3 @@ +* Mon May 20 2013 D Wadsworth <[email protected]> - 1.1.2 +- Update to 1.1.2 + old: ---- shiboken-1.1.1.tar.bz2 new: ---- shiboken-1.1.2.tar.bz2 spec files: ----------- --- python-pyside-shiboken.spec +++ python-pyside-shiboken.spec @@ -23,13 +23,13 @@ %define libpyname %{libprefix}-python%{py_ver} %define libname %{libprefix}-python%{py_ver_mod}-%{libsoname} %define pyname Shiboken -Version: 1.1.1 +Version: 1.1.2 Release: 0 License: GPL-2.0 Summary: Generate CPython bindings from C++ code Group: Development/Libraries/C and C++ -Url: http://www.pyside.org -Source0: http://www.pyside.org/files/%{tarname}-%{version}.tar.bz2 +Url: http://qt-project.org/wiki/PySide +Source0: http://qt-project.org/uploads/pyside/%{tarname}-%{version}.tar.bz2 BuildRequires: cmake BuildRequires: fdupes BuildRequires: gcc-c++ @@ -117,6 +117,7 @@ %doc COPYING ChangeLog %{_bindir}/%{tarname} %{_mandir}/man1/%{tarname}.1.gz +%{python_sitearch}/%{tarname}.so %files -n %{libname} %defattr(-,root,root) other changes: -------------- ++++++ shiboken-1.1.1.tar.bz2 -> shiboken-1.1.2.tar.bz2 --- ApiExtractor/CMakeLists.txt +++ ApiExtractor/CMakeLists.txt @@ -7,8 +7,9 @@ if (NOT DISABLE_DOCSTRINGS) if (NOT LIBXSLT_FOUND OR NOT LIBXML2_FOUND) + set(DISABLE_DOCSTRINGS TRUE CACHE BOOL "Disable doc strings" PARENT_SCOPE) set(DISABLE_DOCSTRINGS TRUE) - message(WARNING "libxslt and/or libxml not found, disabling support to doc strings!") + message(WARNING "libxslt and/or libxml not found, disabling support for doc strings!") endif() endif() --- ApiExtractor/abstractmetalang.cpp +++ ApiExtractor/abstractmetalang.cpp @@ -783,6 +783,9 @@ if ((implementor == implementor->baseClass()) || (implementor == implementingClass() && (mods.size() > 0))) break; + foreach (const AbstractMetaClass* interface, implementor->interfaces()) { + mods += this->modifications(interface); + } implementor = implementor->baseClass(); } return mods; --- CMakeLists.txt +++ CMakeLists.txt @@ -12,7 +12,7 @@ set(shiboken_MAJOR_VERSION "1") set(shiboken_MINOR_VERSION "1") -set(shiboken_MICRO_VERSION "1") +set(shiboken_MICRO_VERSION "2") set(shiboken_VERSION "${shiboken_MAJOR_VERSION}.${shiboken_MINOR_VERSION}.${shiboken_MICRO_VERSION}") option(BUILD_TESTS "Build tests." TRUE) @@ -33,6 +33,18 @@ find_package(PythonInterpWithDebug) endif() +if (NOT PYTHON_SITE_PACKAGES) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; \\ + print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))" + OUTPUT_VARIABLE PYTHON_SITE_PACKAGES + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (NOT PYTHON_SITE_PACKAGES) + message(FATAL_ERROR "Could not detect Python module installation directory.") + elseif (APPLE) + message(STATUS "!!! The generated bindings will be installed on ${PYTHON_SITE_PACKAGES}, is it right!?") + endif() +endif() if(MSVC) set(CMAKE_CXX_FLAGS "/Zc:wchar_t- /GR /EHsc /DWIN32 /D_WINDOWS /D_SCL_SECURE_NO_WARNINGS") --- ChangeLog +++ ChangeLog @@ -1,3 +1,180 @@ +commit a3cecbab9735d40f97c0a031dd17ac594cf39e82 +Author: Nathan Smith <[email protected]> +Date: Tue Jul 3 17:55:04 2012 -0500 + + PYSIDE-83 Fix segfault calling shiboken.dump + + shiboken.dump would segfault when called on an object whose C++ object + had been deleted or whose parent C++ object had been deleted. This now + checks to see if the data pointers beneath the PyObject are NULL before + printing data. + + Change-Id: I89763a3ca3a5d25fad4142ff924692cd232c9c40 + Reviewed-by: Marcelo Lira <[email protected]> + +commit e1a91dd721c17727bea41b591336d1cacca6dea4 +Author: Nathan Smith <[email protected]> +Date: Tue Jul 3 17:35:27 2012 -0500 + + Fix and test case for bug PYSIDE-72. + + The address of the PyObject is used directly as the hash rather than a + member of that object. This avoids segfaults when the C++ object has + been deleted, rendering the child pointers NULL. + + Removed a test case verifying that hash(QObject()) != hash(QObject()) + because they in fact can be equal. The first QObject dies and is reaped + before the second QObject is created, meaning that the second QObject + may be allocated at the same address as the first QObject, giving them + both the same address. If a reference is held to the first object, + though, then they will get different hash values. + + Change-Id: I116463f88b837726a98720bae36770d53b13f4ee + Reviewed-by: Marcelo Lira <[email protected]> + +commit 7e5c76981d6bcb04b72a407a6bc4076170ee414e +Author: John Ehresman <[email protected]> +Date: Thu Jun 14 14:59:23 2012 -0400 + + Override all functions with the same name, not just one. + + This allows pyside to compile with Visual Studio 2008 when built + against qt 4.8. There are still test failures, however. + + Change-Id: I83da30211e5032b1352102f189cb93dfb741eb38 + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit f92ea511050786900ee9b648fdd7cefae13e3973 +Author: John Cummings <[email protected]> +Date: Thu Jun 14 15:30:27 2012 -0500 + + Update vector conversion + + Incorporate Hugo's comments from change Id2ea1a5f + + Change-Id: I5f0c93b7036f5d2908cd2ee2038eb570f9889b58 + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit 22b6e8243784aa57c820d01b73ed16e604d7bca8 +Author: John Cummings <[email protected]> +Date: Thu Jun 7 11:25:55 2012 -0500 + + Add typedef examples to minimal + + Add an example for a typedef of a template + Add an example for a typedef of a typedef + Add a python unit test for these examples + + Change-Id: Id2ea1a5f1e4b3d865c081625f2d5b7ed4c38bbdb + Reviewed-by: Marcelo Lira <[email protected]> + +commit f465efbff6830866c0a82b30193389bb97ab2210 +Author: John Cummings <[email protected]> +Date: Thu Jun 14 13:36:17 2012 -0500 + + Add test files back to cmake + + Change-Id: If4f2cd745fe0c6e81d876c0f890cd94dc73f5721 + Reviewed-by: Paulo Alcantara <[email protected]> + Reviewed-by: Marcelo Lira <[email protected]> + +commit 8bce7870aebd415a3d842cda3c29b82461802214 +Author: John Ehresman <[email protected]> +Date: Fri Mar 30 15:11:57 2012 -0400 + + Don't use it->second after erasing it + + Change-Id: I77bda667d4119a7982ec93175ff0b3153277ad8e + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit e40e993cecd1663636e2f0d33b3e2a6204d64984 +Author: John Ehresman <[email protected]> +Date: Thu Jun 7 20:44:19 2012 -0400 + + Find function modifications defined in the 2nd+ base class. + + Fixes bug PYSIDE-54 + + Change-Id: Ic5c341741170cc77e8ebb59c46c746211582ddeb + Reviewed-by: Marcelo Lira <[email protected]> + +commit 54cce10fa8a9942450c9e1a9d9a9d2a1b688f243 +Author: Hugo Parente Lima <[email protected]> +Date: Wed May 2 21:45:52 2012 -0300 + + Set a default hash function for all ObjectTypes. + + Fix bug PYSIDE-42 + + Change-Id: I1392374dcf0055309152082e674cc1e3e6472d4d + Reviewed-by: Paulo Alcantara <[email protected]> + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit 9a8eaf81a4694088cb2a5f3fcea753ea588cb7cf +Author: Paulo Alcantara <[email protected]> +Date: Wed May 2 20:24:56 2012 -0300 + + Fix compilation when there is no libxslt installed on the system. + + Signed-off-by: Paulo Alcantara <[email protected]> + + Change-Id: I7ea373535ff936b6a4fbf0071aff0a690925db15 + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit 1f7127acd36492cd37c7b86e09e62c51557c9ad3 +Author: John Ehresman <[email protected]> +Date: Tue Apr 17 15:18:45 2012 -0400 + + Install the shiboken module to site-packages + + Change-Id: Ia11858b90183ef6b599e1c0f299e730cd4ff9334 + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit f169a8c0e154ddd1a531e2aab51288ab1209ebb9 +Author: Roman Lacko <[email protected]> +Date: Mon Apr 30 23:36:11 2012 +0200 + + Fixed resolving of SOABI. SOABI is implemented on Linux, but not on Windows + + Change-Id: I472321506b53ff21ba608ebf72b0b7b458121387 + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit 8c5297bb10daf508f787646b66a2e4c21e4e15f6 +Author: John Ehresman <[email protected]> +Date: Tue Apr 17 12:30:49 2012 -0400 + + Don't use inline methods in dllexported classes to keep VC++ happy + + Change-Id: I2e954bedfe4699a621047a757b3dbd202655e97b + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit 815159e28d786d83c984670cd8867d5ce3d314f4 +Author: John Ehresman <[email protected]> +Date: Fri Mar 30 15:13:18 2012 -0400 + + Use SpooledTemporaryFile in 2.6+ os.tmpfile() fails on win32 if process doesn't have admin permissions + + Change-Id: Ic231d5faac08360a793ce33c091eef251d7b35e4 + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit 1a6bd4513e85eec3ad1648e545cd596cb6ab3858 +Author: Hugo Parente Lima <[email protected]> +Date: Fri Apr 27 14:41:26 2012 -0300 + + Version bump to 1.1.2. + + Change-Id: Ib7c918b91679240223ae8091c90d9069392b3423 + Reviewed-by: Hugo Parente Lima <[email protected]> + +commit 03650317cdf3c22e8f7353e3dfee03cd4030558d +Author: Hugo Parente Lima <[email protected]> +Date: Fri Apr 27 14:32:49 2012 -0300 + + Disable docstring generation if tools aren't found. + + Change-Id: I11d6b90c2ba924fbe182924e747fa39adc6981c6 + Reviewed-by: Hugo Parente Lima <[email protected]> + commit 49bc8fbb0803f91d391211356492fba9bc4e68dc Author: Jason McCampbell (Enthought, Inc) <[email protected]> Date: Thu Mar 15 16:07:22 2012 -0500 --- cmake/Modules/FindPython3InterpWithDebug.cmake +++ cmake/Modules/FindPython3InterpWithDebug.cmake @@ -30,7 +30,7 @@ vr = sys.version_info; \\ prefix = '-python%d.%d' % (vr[0], vr[1]); \\ suffix = prefix + '-dbg' if bool(sysconfig.get_config_var('Py_DEBUG')) else prefix; \\ - suffix = '.' + sysconfig.get_config_var('SOABI') if (vr.major == 3 and vr.minor >= 2) else suffix; \\ + suffix = '.' + sysconfig.get_config_var('SOABI') if (vr.major == 3 and vr.minor >= 2 and 'SOABI' in sysconfig.get_config_vars()) else suffix; \\ print(suffix)" OUTPUT_VARIABLE PYTHON_SUFFIX OUTPUT_STRIP_TRAILING_WHITESPACE) --- generator/shiboken/cppgenerator.cpp +++ generator/shiboken/cppgenerator.cpp @@ -666,9 +666,11 @@ } bool invalidateReturn = false; + QSet<int> invalidateArgs; foreach (FunctionModification funcMod, func->modifications()) { foreach (ArgumentModification argMod, funcMod.argument_mods) { - if (argMod.resetAfterUse) { + if (argMod.resetAfterUse && !invalidateArgs.contains(argMod.index)) { + invalidateArgs.insert(argMod.index); s << INDENT << "bool invalidateArg" << argMod.index; s << " = PyTuple_GET_ITEM(" PYTHON_ARGS ", " << argMod.index - 1 << ")->ob_refcnt == 1;" << endl; } else if (argMod.index == 0 && argMod.ownerships[TypeSystem::TargetLangCode] == TypeSystem::CppOwnership) { @@ -762,16 +764,18 @@ Indentation indentation(INDENT); s << INDENT << "Shiboken::Object::releaseOwnership(" << PYTHON_RETURN_VAR ".object());" << endl; } + foreach (int argIndex, invalidateArgs) { + s << INDENT << "if (invalidateArg" << argIndex << ')' << endl; + Indentation indentation(INDENT); + s << INDENT << "Shiboken::Object::invalidate(PyTuple_GET_ITEM(" PYTHON_ARGS ", "; + s << (argIndex - 1) << "));" << endl; + } + foreach (FunctionModification funcMod, func->modifications()) { foreach (ArgumentModification argMod, funcMod.argument_mods) { - if (argMod.resetAfterUse) { - s << INDENT << "if (invalidateArg" << argMod.index << ')' << endl; - Indentation indentation(INDENT); - s << INDENT << "Shiboken::Object::invalidate(PyTuple_GET_ITEM(" PYTHON_ARGS ", "; - s << (argMod.index - 1) << "));" << endl; - } else if (argMod.ownerships.contains(TypeSystem::NativeCode) - && argMod.index == 0 && argMod.ownerships[TypeSystem::NativeCode] == TypeSystem::CppOwnership) { + if (argMod.ownerships.contains(TypeSystem::NativeCode) + && argMod.index == 0 && argMod.ownerships[TypeSystem::NativeCode] == TypeSystem::CppOwnership) { s << INDENT << "if (Shiboken::Object::checkType(" PYTHON_RETURN_VAR "))" << endl; Indentation indent(INDENT); s << INDENT << "Shiboken::Object::releaseOwnership(" PYTHON_RETURN_VAR ");" << endl; @@ -3385,6 +3389,8 @@ if (!metaClass->typeEntry()->hashFunction().isEmpty()) tp_hash = '&' + cpythonBaseName(metaClass) + "_HashFunc"; + else if (isObjectType(metaClass)) + tp_hash = "&Shiboken::Object::hash"; const AbstractMetaFunction* callOp = metaClass->findFunction("operator()"); if (callOp && !callOp->isModifiedRemoved()) --- generator/shiboken/headergenerator.cpp +++ generator/shiboken/headergenerator.cpp @@ -215,7 +215,6 @@ && !f->isStatic() && f->name() == func->name()) { m_inheritedOverloads << f; - break; } } --- libshiboken/basewrapper.cpp +++ libshiboken/basewrapper.cpp @@ -748,6 +748,12 @@ return ObjectType::isUserType(pyObj->ob_type); } +Py_hash_t hash(PyObject* pyObj) +{ + assert(Shiboken::Object::checkType(pyObj)); + return reinterpret_cast<Py_hash_t>(pyObj); +} + static void setSequenceOwnership(PyObject* pyObj, bool owner) { if (PySequence_Check(pyObj)) { @@ -1315,16 +1321,21 @@ std::ostringstream s; std::list<SbkObjectType*> bases; - if (ObjectType::isUserType(Py_TYPE(self))) - bases = getCppBaseClasses(Py_TYPE(self)); - else - bases.push_back(reinterpret_cast<SbkObjectType*>(Py_TYPE(self))); + if (self->d && self->d->cptr) { + if (ObjectType::isUserType(Py_TYPE(self))) + bases = getCppBaseClasses(Py_TYPE(self)); + else + bases.push_back(reinterpret_cast<SbkObjectType*>(Py_TYPE(self))); - s << "C++ address....... "; - std::list<SbkObjectType*>::const_iterator it = bases.begin(); - for (int i = 0; it != bases.end(); ++it, ++i) - s << ((PyTypeObject*)*it)->tp_name << "/" << self->d->cptr[i] << ' '; - s << "\n"; + s << "C++ address....... "; + std::list<SbkObjectType*>::const_iterator it = bases.begin(); + for (int i = 0; it != bases.end(); ++it, ++i) + s << ((PyTypeObject*)*it)->tp_name << "/" << self->d->cptr[i] << ' '; + s << "\n"; + } + else { + s << "C++ address....... <<Deleted>>\n"; + } s << "hasOwnership...... " << bool(self->d->hasOwnership) << "\n" "containsCppWrapper " << self->d->containsCppWrapper << "\n" --- libshiboken/basewrapper.h +++ libshiboken/basewrapper.h @@ -231,6 +231,11 @@ LIBSHIBOKEN_API bool isUserType(PyObject* pyObj); /** + * Generic function used to make ObjectType hashable, the C++ pointer is used as hash value. + */ +LIBSHIBOKEN_API Py_hash_t hash(PyObject* pyObj); + +/** * Bind a C++ object to Python. * \param instanceType equivalent Python type for the C++ object. * \param hasOwnership if true, Python will try to delete the underlying C++ object when there's no more refs. --- shibokenmodule/CMakeLists.txt +++ shibokenmodule/CMakeLists.txt @@ -31,3 +31,4 @@ add_dependencies(shibokenmodule shiboken) +install(TARGETS shibokenmodule DESTINATION ${PYTHON_SITE_PACKAGES}) \ No newline at end of file --- tests/libminimal/CMakeLists.txt +++ tests/libminimal/CMakeLists.txt @@ -3,6 +3,7 @@ set(libminimal_SRC obj.cpp listuser.cpp +typedef.cpp ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) --- tests/libminimal/typedef.cpp +++ tests/libminimal/typedef.cpp @@ -0,0 +1,47 @@ +#include "typedef.h" + +// +// Test wrapping of a typedef +// +bool arrayFuncInt(std::vector<int> a) +{ + return a.empty(); +} + +bool arrayFuncIntTypedef(MyArray a) +{ + return arrayFuncInt(a); +} + +std::vector<int> arrayFuncIntReturn(int size) +{ + return std::vector<int>(size); +} + +MyArray arrayFuncIntReturnTypedef(int size) +{ + return arrayFuncIntReturn(size); +} + +// +// Test wrapping of a typedef of a typedef +// +bool arrayFunc(std::vector<int> a) +{ + return a.empty(); +} + +bool arrayFuncTypedef(MyArray a) +{ + return arrayFunc(a); +} + +std::vector<int> arrayFuncReturn(int size) +{ + return std::vector<int>(size); +} + +MyArray arrayFuncReturnTypedef(int size) +{ + return arrayFuncReturn(size); +} --- tests/libminimal/typedef.h +++ tests/libminimal/typedef.h @@ -0,0 +1,26 @@ +#ifndef TYPEDEF_H +#define TYPEDEF_H + +#include "libminimalmacros.h" + +#include <vector> + +// Test wrapping of a typedef +typedef std::vector<int> MyArrayInt; + +LIBMINIMAL_API bool arrayFuncInt(std::vector<int> a); +LIBMINIMAL_API bool arrayFuncIntTypedef(MyArrayInt a); + +LIBMINIMAL_API std::vector<int> arrayFuncIntReturn(int size); +LIBMINIMAL_API MyArrayInt arrayFuncIntReturnTypedef(int size); + +// Test wrapping of a typedef of a typedef +typedef MyArrayInt MyArray; + +LIBMINIMAL_API bool arrayFunc(std::vector<int> a); +LIBMINIMAL_API bool arrayFuncTypedef(MyArray a); + +LIBMINIMAL_API std::vector<int> arrayFuncReturn(int size); +LIBMINIMAL_API MyArray arrayFuncReturnTypedef(int size); + +#endif --- tests/libsample/CMakeLists.txt +++ tests/libsample/CMakeLists.txt @@ -28,6 +28,7 @@ overload.cpp overloadsort.cpp pairuser.cpp +pen.cpp photon.cpp point.cpp pointf.cpp @@ -36,6 +37,7 @@ reference.cpp sample.cpp samplenamespace.cpp +sbkdate.cpp simplefile.cpp size.cpp sometime.cpp --- tests/libsample/blackbox.cpp +++ tests/libsample/blackbox.cpp @@ -53,8 +53,9 @@ { map<int, ObjectType*>::iterator it = m_objects.find(ticket); if (it != m_objects.end()) { + ObjectType* second = it->second; m_objects.erase(it); - return it->second; + return second; } return 0; } @@ -82,8 +83,9 @@ { map<int, Point*>::iterator it = m_points.find(ticket); if (it != m_points.end()) { + Point* second = it->second; m_points.erase(it); - return it->second; + return second; } return 0; } --- tests/libsample/objecttype.cpp +++ tests/libsample/objecttype.cpp @@ -289,3 +289,17 @@ void* addr = new ObjectType(); return (std::size_t) addr; } + +OtherBase::~OtherBase() +{ +} + +ObjectTypeDerived::~ObjectTypeDerived() +{ +} + +bool +ObjectTypeDerived::event(Event* event) +{ + return true; +} --- tests/libsample/objecttype.h +++ tests/libsample/objecttype.h @@ -144,5 +144,19 @@ LIBSAMPLE_API unsigned int objectTypeHash(const ObjectType* objectType); +class LIBSAMPLE_API OtherBase { +public: + OtherBase() {}; + virtual ~OtherBase(); +}; + +class LIBSAMPLE_API ObjectTypeDerived: public ObjectType, public OtherBase { +public: + ObjectTypeDerived(): ObjectType(), OtherBase() {}; + + virtual bool event(Event* event); + virtual ~ObjectTypeDerived(); +}; + #endif // OBJECTTYPE_H --- tests/libsample/pen.cpp +++ tests/libsample/pen.cpp @@ -0,0 +1,61 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "pen.h" + +Color::Color() : m_null(true) +{ +} + +Color::Color(SampleNamespace::InValue arg) : m_null(false) +{ +} + +Color::Color(unsigned int arg) : m_null(false) +{ +} + +bool Color::isNull() const +{ + return m_null; +} + +Pen::Pen() : m_ctor(EmptyCtor) +{ +} + +Pen::Pen(SampleNamespace::Option option) : m_ctor(EnumCtor) +{ +} + +Pen::Pen(const Color& color) : m_ctor(ColorCtor) +{ +} + +Pen::Pen(const Pen& pen) : m_ctor(CopyCtor) +{ +} + +int Pen::ctorType() +{ + return m_ctor; +} --- tests/libsample/pen.h +++ tests/libsample/pen.h @@ -29,11 +29,11 @@ class LIBSAMPLE_API Color { public: - Color() : m_null(true) {} - Color(SampleNamespace::InValue arg) : m_null(false) {} - Color(unsigned int arg) : m_null(false) {} + Color(); + Color(SampleNamespace::InValue arg); + Color(unsigned int arg); - bool isNull() const { return m_null; } + bool isNull() const; private: bool m_null; }; @@ -43,12 +43,12 @@ public: enum { EmptyCtor, EnumCtor, ColorCtor, CopyCtor }; - Pen() : m_ctor(EmptyCtor) {} - Pen(SampleNamespace::Option option) : m_ctor(EnumCtor) {} - Pen(const Color& color) : m_ctor(ColorCtor) {} - Pen(const Pen& pen) : m_ctor(CopyCtor) {} + Pen(); + Pen(SampleNamespace::Option option); + Pen(const Color& color); + Pen(const Pen& pen); - int ctorType() { return m_ctor; } + int ctorType(); private: int m_ctor; }; --- tests/libsample/sbkdate.cpp +++ tests/libsample/sbkdate.cpp @@ -0,0 +1,42 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "sbkdate.h" + +SbkDate::SbkDate(int d, int m, int y) : m_d(d), m_m(m), m_y(y) +{ +} + +int SbkDate::day() const +{ + return m_d; +} + +int SbkDate::month() const +{ + return m_m; +} + +int SbkDate::year() const +{ + return m_y; +} --- tests/libsample/sbkdate.h +++ tests/libsample/sbkdate.h @@ -28,11 +28,11 @@ class LIBSAMPLE_API SbkDate { public: - SbkDate(int d, int m, int y) : m_d(d), m_m(m), m_y(y) {} + SbkDate(int d, int m, int y); - inline int day() const { return m_d; } - inline int month() const { return m_m; } - inline int year() const { return m_y; } + int day() const; + int month() const; + int year() const; private: int m_d; --- tests/minimalbinding/CMakeLists.txt +++ tests/minimalbinding/CMakeLists.txt @@ -19,6 +19,7 @@ COMMAND ${shibokengenerator_BINARY_DIR}/shiboken --project-file=${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt ${GENERATOR_EXTRA_FLAGS} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running generator for 'minimal' test binding..." +DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_minimal.xml libminimal ) include_directories(${CMAKE_CURRENT_SOURCE_DIR} --- tests/minimalbinding/global.h +++ tests/minimalbinding/global.h @@ -2,3 +2,4 @@ #include "val.h" #include "minbool.h" #include "listuser.h" +#include "typedef.h" --- tests/minimalbinding/typedef_test.py +++ tests/minimalbinding/typedef_test.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of the Shiboken Python Bindings Generator project. +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# +# Contact: PySide team <[email protected]> +# +# 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. +# # +# 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 + +import unittest +from minimal import * +from py3kcompat import IS_PY3K +import numpy as np + +if IS_PY3K: + import functools + reduce = functools.reduce + + +class TypedefTest(unittest.TestCase): + + def setUp(self): + self.the_size = 8 + + def test_arrayFuncInt(self): + none = () + full = range(self.the_size) + self.assertTrue(arrayFuncInt(none), "None is empty, arrayFuncInt should return true") + self.assertFalse(arrayFuncInt(full), "Full is NOT empty, arrayFuncInt should return false") + + self.assertTrue(arrayFuncInt(np.array(none)), "None is empty, arrayFuncInt should return true") + self.assertFalse(arrayFuncInt(np.array(full)), "Full is NOT empty, arrayFuncInt should return false") + + def test_arrayFuncIntTypedef(self): + none = () + full = (1, 2, 3) + self.assertTrue(arrayFuncIntTypedef(none), "None is empty, arrayFuncIntTypedef should return true") + self.assertFalse(arrayFuncIntTypedef(full), "Full is NOT empty, arrayFuncIntTypedef should return false") + + self.assertTrue(arrayFuncIntTypedef(np.array(none)), "None is empty, arrayFuncIntTypedef should return true") + self.assertFalse(arrayFuncIntTypedef(np.array(full)), "Full is NOT empty, arrayFuncIntTypedef should return false") + + def test_arrayFuncIntReturn(self): + none = arrayFuncIntReturn(0) + full = arrayFuncIntReturn(self.the_size) + self.assertTrue((len(none) == 0), "none should be empty") + self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + + def test_arrayFuncIntReturnTypedef(self): + none = arrayFuncIntReturnTypedef(0) + full = arrayFuncIntReturnTypedef(self.the_size) + self.assertTrue((len(none) == 0), "none should be empty") + self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + + def test_arrayFunc(self): + none = () + full = range(self.the_size) + self.assertTrue(arrayFunc(none), "None is empty, arrayFunc should return true") + self.assertFalse(arrayFunc(full), "Full is NOT empty, arrayFunc should return false") + + self.assertTrue(arrayFunc(np.array(none)), "None is empty, arrayFunc should return true") + self.assertFalse(arrayFunc(np.array(full)), "Full is NOT empty, arrayFunc should return false") + + def test_arrayFuncTypedef(self): + none = () + full = (1, 2, 3) + self.assertTrue(arrayFuncTypedef(none), "None is empty, arrayFuncTypedef should return true") + self.assertFalse(arrayFuncTypedef(full), "Full is NOT empty, arrayFuncTypedef should return false") + + self.assertTrue(arrayFuncTypedef(np.array(none)), "None is empty, arrayFuncTypedef should return true") + self.assertFalse(arrayFuncTypedef(np.array(full)), "Full is NOT empty, arrayFuncTypedef should return false") + + def test_arrayFuncReturn(self): + none = arrayFuncReturn(0) + full = arrayFuncReturn(self.the_size) + self.assertTrue((len(none) == 0), "none should be empty") + self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + + def test_arrayFuncReturnTypedef(self): + none = arrayFuncReturnTypedef(0) + full = arrayFuncReturnTypedef(self.the_size) + self.assertTrue((len(none) == 0), "none should be empty") + self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + + +if __name__ == '__main__': + unittest.main() --- tests/minimalbinding/typesystem_minimal.xml +++ tests/minimalbinding/typesystem_minimal.xml @@ -48,4 +48,46 @@ </value-type> <value-type name="ListUser"/> <value-type name="MinBoolUser"/> + + <container-type name="std::vector" type="vector"> + <include file-name="vector" location="global"/> + <conversion-rule> + <native-to-target> + %INTYPE::size_type vectorSize = %in.size(); + PyObject* %out = PyList_New((int) vectorSize); + for (%INTYPE::size_type idx = 0; idx < vectorSize; ++idx) { + %INTYPE_0 cppItem(%in[idx]); + PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); + } + return %out; + </native-to-target> + <target-to-native> + <add-conversion type="PySequence"> + Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); + int vectorSize = PySequence_Fast_GET_SIZE(seq.object()); + %out.reserve(vectorSize); + for (int idx = 0; idx < vectorSize; ++idx ) { + PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), idx); + %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); + %out.push_back(cppItem); + } + </add-conversion> + </target-to-native> + </conversion-rule> + </container-type> + <!-- Test wrapping of a typedef --> + <function signature="arrayFuncInt(std::vector<int>)" /> + <!-- Note manual expansion of the typedef --> + <function signature="arrayFuncIntTypedef(std::vector<int>)" /> + + <function signature="arrayFuncIntReturn(int)" /> + <function signature="arrayFuncIntReturnTypedef(int)" /> + + <!-- Test wrapping of a typedef of a typedef --> + <function signature="arrayFunc(std::vector<int>)" /> + <!-- Note manual expansion of the typedef --> + <function signature="arrayFuncTypedef(std::vector<int>)" /> + + <function signature="arrayFuncReturn(int)" /> + <function signature="arrayFuncReturnTypedef(int)" /> </typesystem> --- tests/otherbinding/objtypehashes_test.py +++ tests/otherbinding/objtypehashes_test.py @@ -0,0 +1,25 @@ +import unittest +from sample import * +from other import * +import shiboken + +class TestHashFuncs (unittest.TestCase): + + def testIt(self): + obj1 = HandleHolder() + obj2 = HandleHolder() + + hash1 = hash(obj1) + hash2 = hash(obj2) + self.assertNotEqual(hash1, hash2) + + # Now invalidate the object and test its hash. It shouldn't segfault. + shiboken.invalidate(obj1) + + hash1_2 = hash(obj1) + self.assertEqual(hash1_2, hash1) + + + +if __name__ == '__main__': + unittest.main() --- tests/samplebinding/CMakeLists.txt +++ tests/samplebinding/CMakeLists.txt @@ -50,6 +50,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttype_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypebyvalue_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypeholder_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypederived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypelayout_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypeptrlist_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypeoperators_wrapper.cpp @@ -57,6 +58,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/objtypereference_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/oddbooluser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/onlycopy_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/otherbase_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/overload_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/overload2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp --- tests/samplebinding/enum_test.py +++ tests/samplebinding/enum_test.py @@ -35,7 +35,7 @@ from py3kcompat import IS_PY3K, b def createTempFile(): - if IS_PY3K: + if sys.version_info >= (2, 6): import tempfile return tempfile.SpooledTemporaryFile(mode='rw') else: --- tests/samplebinding/ownership_invalidate_after_use_test.py +++ tests/samplebinding/ownership_invalidate_after_use_test.py @@ -29,7 +29,7 @@ import sys import unittest -from sample import ObjectType, Event +from sample import ObjectType, ObjectTypeDerived, Event class ExtObjectType(ObjectType): @@ -59,6 +59,16 @@ def invalidateEvent(self, ev): pass +class ExtObjectTypeDerived(ObjectTypeDerived): + def __init__(self): + ObjectTypeDerived.__init__(self) + self.type_of_last_event = None + self.last_event = None + def event(self, event): + self.last_event = event + self.type_of_last_event = event.eventType() + return True + class OwnershipInvalidateAfterUseTest(unittest.TestCase): '''Ownership tests for cases of invalidation of Python wrapper after use.''' @@ -82,6 +92,14 @@ obj.causeEvent(Event.BASIC_EVENT) self.assertFalse(obj.fail) + def testInvalidateAfterUseInDerived(self): + '''Invalidate was failing in a derived C++ class that also inherited + other base classes''' + eot = ExtObjectTypeDerived() + eot.causeEvent(Event.SOME_EVENT) + self.assertEqual(eot.type_of_last_event, Event.SOME_EVENT) + self.assertRaises(RuntimeError, eot.last_event.eventType) + if __name__ == '__main__': unittest.main() --- tests/samplebinding/typesystem_sample.xml +++ tests/samplebinding/typesystem_sample.xml @@ -727,6 +727,10 @@ </modify-argument> </modify-function> </object-type> + + <object-type name="OtherBase" /> + <object-type name="ObjectTypeDerived" /> + <object-type name="ObjectTypeLayout"> <modify-function signature="create()"> <modify-argument index="return"> --- tests/shibokenmodule/module_test.py +++ tests/shibokenmodule/module_test.py @@ -56,6 +56,12 @@ shiboken.dump(m) self.assertEqual(len(shiboken.getCppPointer(m)), 2) + # Don't crash even after deleting an object + shiboken.invalidate(obj) + shiboken.dump(obj) # deleted + shiboken.dump(p) # child deleted + shiboken.dump(obj2) # parent deleted + def testDelete(self): obj = ObjectType() child = ObjectType(obj)
