diff options
Diffstat (limited to 'sources/shiboken2')
5 files changed, 73 insertions, 64 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index be285693e..75fd6af5b 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -1278,7 +1278,9 @@ void AbstractMetaBuilderPrivate::fixReturnTypeOfConversionOperator(AbstractMetaF if (!retType) return; - metaFunction->replaceType(new AbstractMetaType(retType)); + auto metaType = new AbstractMetaType(retType); + metaType->decideUsagePattern(); + metaFunction->replaceType(metaType); } AbstractMetaFunctionList AbstractMetaBuilderPrivate::classFunctionList(const ScopeModelItem &scopeItem, diff --git a/sources/shiboken2/doc/gettingstarted.rst b/sources/shiboken2/doc/gettingstarted.rst index caeb5a909..321db9545 100644 --- a/sources/shiboken2/doc/gettingstarted.rst +++ b/sources/shiboken2/doc/gettingstarted.rst @@ -12,8 +12,8 @@ General Requirements ^^^^^^^^^^^^^^^^^^^^ * **Python**: 3.5+ and 2.7 - * **Qt:** 5.12+ is recommended - * **libclang:** The libclang library, recommended: version 6 for Shiboken2 5.12. + * **Qt:** 5.12+ (5.15 is recommended) + * **libclang:** The libclang library, recommended: version 10 for Shiboken2 5.15. Prebuilt versions of it can be `downloaded here`_. * **CMake:** 3.1+ is needed. @@ -24,15 +24,26 @@ Simple build If you need only Shiboken Generator, a simple build run would look like this:: + # For the required libraries (this will also build the shiboken2 python module) + python setup.py install --qmake=/path/to/qmake \ + --build-tests \ + --verbose-build \ + --internal-build-type=shiboken2 + + # For the executable python setup.py install --qmake=/path/to/qmake \ --build-tests \ - --parallel=8 \ --verbose-build \ --internal-build-type=shiboken2-generator The same can be used for the module, changing the value of ``internal-build-type`` to ``shiboken2-module``. +.. warning:: If you are planning to use PySide too, for examples like + 'scriptableapplication' you need to have build it as well. The main issue is + that your PySide and Shiboken needs to be build using the same dependencies + from Qt and libclang. + Using the wheels ---------------- diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 434b03dc7..11a6c193e 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -1622,20 +1622,39 @@ void CppGenerator::writeConverterRegister(QTextStream &s, const AbstractMetaClas s << Qt::endl; - QStringList cppSignature; - if (!classContext.forSmartPointer()) { - cppSignature = metaClass->qualifiedCppName().split(QLatin1String("::"), - Qt::SkipEmptyParts); - } else { - cppSignature = classContext.preciseType()->cppSignature().split(QLatin1String("::"), - Qt::SkipEmptyParts); - } - while (!cppSignature.isEmpty()) { - QString signature = cppSignature.join(QLatin1String("::")); + auto writeConversions = [&s, this](const QString &signature) + { s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "\");\n"; s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "*\");\n"; s << INDENT << "Shiboken::Conversions::registerConverterName(converter, \"" << signature << "&\");\n"; - cppSignature.removeFirst(); + }; + + auto writeConversionsForType = [writeConversions](const QString &fullTypeName) + { + QStringList lst = fullTypeName.split(QLatin1String("::"), + Qt::SkipEmptyParts); + while (!lst.isEmpty()) { + QString signature = lst.join(QLatin1String("::")); + writeConversions(signature); + lst.removeFirst(); + } + }; + + if (!classContext.forSmartPointer()) { + writeConversionsForType(metaClass->qualifiedCppName()); + } else { + const QString &smartPointerType = classContext.preciseType()->instantiations().at(0)->cppSignature(); + const QString &smartPointerName = classContext.preciseType()->typeEntry()->name(); + + QStringList lst = smartPointerType.split(QLatin1String("::"), + Qt::SkipEmptyParts); + while (!lst.isEmpty()) { + QString signature = lst.join(QLatin1String("::")); + writeConversions(QStringLiteral("%1<%2>").arg(smartPointerName, signature)); + lst.removeFirst(); + } + + writeConversionsForType(smartPointerType); } s << INDENT << "Shiboken::Conversions::registerConverterName(converter, typeid(::"; diff --git a/sources/shiboken2/tests/libsmart/smart_sharedptr.h b/sources/shiboken2/tests/libsmart/smart_sharedptr.h index 84184e1f8..65a489c68 100644 --- a/sources/shiboken2/tests/libsmart/smart_sharedptr.h +++ b/sources/shiboken2/tests/libsmart/smart_sharedptr.h @@ -29,19 +29,9 @@ #ifndef SMART_SHARED_PTR_H #define SMART_SHARED_PTR_H -#include "libsmartmacros.h" +#include <memory> -template <class T> -class RefData { -public: - RefData(T *ptr) : m_refCount(1), m_heldPtr(ptr) {} - ~RefData() { delete m_heldPtr; } - int inc() { return ++m_refCount; } - int dec() { return --m_refCount; } - int useCount() { return m_refCount; } - int m_refCount; - T *m_heldPtr; -}; +#include "libsmartmacros.h" struct SharedPtrBase { @@ -57,84 +47,70 @@ class SharedPtr : public SharedPtrBase { public: SharedPtr() { logDefaultConstructor(this); } - SharedPtr(T *v) + SharedPtr(T *v) : mPtr(v) { logConstructor(this, v); - if (v) - m_refData = new RefData<T>(v); } - SharedPtr(const SharedPtr<T> &other) : m_refData(other.m_refData) + SharedPtr(const SharedPtr<T> &other) : mPtr(other.mPtr) { - logCopyConstructor(this, other.m_refData); - if (m_refData) - m_refData->inc(); + logCopyConstructor(this, data()); } - SharedPtr<T> &operator=(const SharedPtr<T>& other) + template<class X> + SharedPtr(const SharedPtr<X> &other) : mPtr(other.mPtr) { - if (this != &other) { - logAssignment(this, other.m_refData); - if (m_refData && m_refData->dec() == 0) - delete m_refData; - m_refData = other.m_refData; - if (m_refData) - m_refData->inc(); - } + logCopyConstructor(this, data()); + } + + SharedPtr& operator=(const SharedPtr& other) + { + mPtr = other.mPtr; return *this; } T *data() const { - return m_refData ? m_refData->m_heldPtr : nullptr; + return mPtr.get(); } int useCount() const { - return m_refData ? m_refData->useCount() : 0; + return mPtr.use_count(); } void dummyMethod1() { + } + bool isNull() const + { + return mPtr.get() == nullptr; } T& operator*() const { // Crashes if smart pointer is empty (just like std::shared_ptr). - return *(m_refData->m_heldPtr); + return *mPtr; } T *operator->() const { - return m_refData ? m_refData->m_heldPtr : nullptr; + return mPtr.get(); } bool operator!() const { - return !m_refData || !m_refData->m_heldPtr; - } - - bool isNull() const - { - return !m_refData || !m_refData->m_heldPtr; - } - - operator bool() const - { - return m_refData && m_refData->m_heldPtr; + return !mPtr; } ~SharedPtr() { - if (m_refData) - logDestructor(this, m_refData->useCount() - 1); - if (m_refData && m_refData->dec() == 0) - delete m_refData; + if (mPtr.use_count() >= 1) + logDestructor(this, mPtr.use_count() - 1); } -private: - RefData<T> *m_refData = nullptr; + std::shared_ptr<T> mPtr; }; #endif // SMART_SHARED_PTR_H diff --git a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml index 8fb3082a0..46cb08267 100644 --- a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml @@ -34,6 +34,7 @@ </conversion-rule> </container-type> + <custom-type name="std::shared_ptr" /> <!-- Used in tests to check what C++ objects are allocated. --> <object-type name="Registry" /> |