diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-02-28 10:51:06 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-02-28 18:04:22 +0000 |
commit | 099f3f46ca9ec1362f211278df4b3e4949b0a339 (patch) | |
tree | 6580c38554168eabcaf2defb82d200bf4c841c1d /sources/shiboken2/ApiExtractor/abstractmetalang.cpp | |
parent | da7b579c1f0e40d5a895cc2b3a6cbf4ed88de890 (diff) |
shiboken: Add allow-thread attribute to type system and class entries
In the typesystem parser, add the allow-thread attribute to root and
complex type entry.
Rewrite the handling of allow-thread (cached) in AbstractMetaFunction
similar to the exception handling (store the modification in
AbstractMetaFunction and go down the class hierarchy if it is
unspecified).
Change-Id: I00e6e2ab25208fda63ec20522814cbfccbb8c42d
Fixes: PYSIDE-931
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/abstractmetalang.cpp')
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index 660bbdff1..a10a15b08 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -550,6 +550,7 @@ AbstractMetaFunction *AbstractMetaFunction::copy() const cpy->setType(type()->copy()); cpy->setConstant(isConstant()); cpy->setExceptionSpecification(m_exceptionSpecification); + cpy->setAllowThreadModification(m_allowThreadModification); cpy->setExceptionHandlingModification(m_exceptionHandlingModification); for (AbstractMetaArgument *arg : m_arguments) @@ -773,28 +774,40 @@ bool AbstractMetaFunction::autoDetectAllowThread() const return !maybeGetter; } -bool AbstractMetaFunction::allowThread() const +static inline TypeSystem::AllowThread allowThreadMod(const AbstractMetaClass *klass) { - using AllowThread = TypeSystem::AllowThread; + return klass->typeEntry()->allowThread(); +} - if (m_cachedAllowThread < 0) { - AllowThread allowThread = AllowThread::Auto; - // Find a modification that specifies allowThread - const FunctionModificationList &modifications = this->modifications(declaringClass()); - for (const FunctionModification &modification : modifications) { - if (modification.allowThread() != AllowThread::Unspecified) { - allowThread = modification.allowThread(); - break; - } - } +static inline bool hasAllowThreadMod(const AbstractMetaClass *klass) +{ + return allowThreadMod(klass) != TypeSystem::AllowThread::Unspecified; +} - m_cachedAllowThread = allowThread == AllowThread::Allow - || (allowThread == AllowThread::Auto && autoDetectAllowThread()) ? 1 : 0; +bool AbstractMetaFunction::allowThread() const +{ + auto allowThreadModification = m_allowThreadModification; + // If there is no modification on the function, check for a base class. + if (m_class && allowThreadModification == TypeSystem::AllowThread::Unspecified) { + if (auto base = recurseClassHierarchy(m_class, hasAllowThreadMod)) + allowThreadModification = allowThreadMod(base); + } - if (m_cachedAllowThread == 0) - qCDebug(lcShiboken).noquote() << msgDisallowThread(this); + bool result = true; + switch (allowThreadModification) { + case TypeSystem::AllowThread::Disallow: + result = false; + break; + case TypeSystem::AllowThread::Allow: + break; + case TypeSystem::AllowThread::Auto: + case TypeSystem::AllowThread::Unspecified: + result = autoDetectAllowThread(); + break; } - return m_cachedAllowThread > 0; + if (!result) + qCDebug(lcShiboken).noquote() << msgDisallowThread(this); + return result; } TypeSystem::Ownership AbstractMetaFunction::ownership(const AbstractMetaClass *cls, TypeSystem::Language language, int key) const |