aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2')
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp4
-rw-r--r--sources/shiboken2/libshiboken/bindingmanager.cpp12
-rw-r--r--sources/shiboken2/shiboken_version.py2
3 files changed, 15 insertions, 3 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 1ebe38fbc..670427d3f 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -1770,7 +1770,7 @@ void CppGenerator::writeSmartPointerConverterFunctions(QTextStream &s, const Abs
// TODO: Missing conversion to smart pointer pointer type:
s << "// Register smartpointer conversion for all derived classes\n";
- const auto classes = getBaseClasses(targetClass);
+ const auto classes = getAllAncestors(targetClass);
for (auto k : classes) {
if (smartPointerTypeEntry->matchesInstantiation(k->typeEntry())) {
if (auto smartTargetType = findSmartPointerInstantiation(k->typeEntry())) {
@@ -4016,7 +4016,7 @@ void CppGenerator::writeSmartPointerConverterInitialization(QTextStream &s, cons
if (!klass)
return;
- const auto classes = getBaseClasses(klass);
+ const auto classes = getAllAncestors(klass);
if (classes.isEmpty())
return;
diff --git a/sources/shiboken2/libshiboken/bindingmanager.cpp b/sources/shiboken2/libshiboken/bindingmanager.cpp
index 5d69e923f..13e0f9e7e 100644
--- a/sources/shiboken2/libshiboken/bindingmanager.cpp
+++ b/sources/shiboken2/libshiboken/bindingmanager.cpp
@@ -49,6 +49,7 @@
#include <cstddef>
#include <fstream>
+#include <mutex>
#include <unordered_map>
namespace Shiboken
@@ -141,6 +142,11 @@ struct BindingManager::BindingManagerPrivate {
using DestructorEntries = std::vector<DestructorEntry>;
WrapperMap wrapperMapper;
+ // Guard wrapperMapper mainly for QML which calls into the generated
+ // QObject::metaObject() and elsewhere from threads without GIL, causing
+ // crashes for example in retrieveWrapper(). std::shared_mutex was rejected due to:
+ // https://stackoverflow.com/questions/50972345/when-is-stdshared-timed-mutex-slower-than-stdmutex-and-when-not-to-use-it
+ std::recursive_mutex wrapperMapLock;
Graph classHierarchy;
DestructorEntries deleteInMainThread;
bool destroying;
@@ -156,6 +162,7 @@ bool BindingManager::BindingManagerPrivate::releaseWrapper(void *cptr, SbkObject
// The wrapper argument is checked to ensure that the correct wrapper is released.
// Returns true if the correct wrapper is found and released.
// If wrapper argument is NULL, no such check is performed.
+ std::lock_guard<std::recursive_mutex> guard(wrapperMapLock);
auto iter = wrapperMapper.find(cptr);
if (iter != wrapperMapper.end() && (wrapper == nullptr || iter->second == wrapper)) {
wrapperMapper.erase(iter);
@@ -167,6 +174,7 @@ bool BindingManager::BindingManagerPrivate::releaseWrapper(void *cptr, SbkObject
void BindingManager::BindingManagerPrivate::assignWrapper(SbkObject *wrapper, const void *cptr)
{
assert(cptr);
+ std::lock_guard<std::recursive_mutex> guard(wrapperMapLock);
auto iter = wrapperMapper.find(cptr);
if (iter == wrapperMapper.end())
wrapperMapper.insert(std::make_pair(cptr, wrapper));
@@ -193,6 +201,7 @@ BindingManager::~BindingManager()
* the BindingManager is being destroyed the interpreter is alredy
* shutting down. */
if (Py_IsInitialized()) { // ensure the interpreter is still valid
+ std::lock_guard<std::recursive_mutex> guard(m_d->wrapperMapLock);
while (!m_d->wrapperMapper.empty()) {
Object::destroy(m_d->wrapperMapper.begin()->second, const_cast<void *>(m_d->wrapperMapper.begin()->first));
}
@@ -208,6 +217,7 @@ BindingManager &BindingManager::instance() {
bool BindingManager::hasWrapper(const void *cptr)
{
+ std::lock_guard<std::recursive_mutex> guard(m_d->wrapperMapLock);
return m_d->wrapperMapper.find(cptr) != m_d->wrapperMapper.end();
}
@@ -268,6 +278,7 @@ void BindingManager::addToDeletionInMainThread(const DestructorEntry &e)
SbkObject *BindingManager::retrieveWrapper(const void *cptr)
{
+ std::lock_guard<std::recursive_mutex> guard(m_d->wrapperMapLock);
auto iter = m_d->wrapperMapper.find(cptr);
if (iter == m_d->wrapperMapper.end())
return nullptr;
@@ -357,6 +368,7 @@ SbkObjectType *BindingManager::resolveType(void **cptr, SbkObjectType *type)
std::set<PyObject *> BindingManager::getAllPyObjects()
{
std::set<PyObject *> pyObjects;
+ std::lock_guard<std::recursive_mutex> guard(m_d->wrapperMapLock);
const WrapperMap &wrappersMap = m_d->wrapperMapper;
auto it = wrappersMap.begin();
for (; it != wrappersMap.end(); ++it)
diff --git a/sources/shiboken2/shiboken_version.py b/sources/shiboken2/shiboken_version.py
index 34caf4590..80dd16ae0 100644
--- a/sources/shiboken2/shiboken_version.py
+++ b/sources/shiboken2/shiboken_version.py
@@ -39,7 +39,7 @@
major_version = "5"
minor_version = "15"
-patch_version = "9"
+patch_version = "10"
# For example: "a", "b", "rc"
# (which means "alpha", "beta", "release candidate").