aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h5
-rw-r--r--sources/pyside2/PySide2/QtQml/typesystem_qml.xml18
-rw-r--r--sources/shiboken2/doc/typesystem_codeinjection.rst5
-rw-r--r--sources/shiboken2/generator/shiboken2/headergenerator.cpp6
4 files changed, 27 insertions, 7 deletions
diff --git a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h
index e94ea043f..536348aa3 100644
--- a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h
+++ b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h
@@ -73,11 +73,6 @@ int qmlRegisterType(PyObject *pyObj, const char *uri, int versionMajor, int vers
// Volatile Bool Ptr type definition.
-typedef struct {
- PyObject_HEAD
- volatile bool flag;
-} QtQml_VolatileBoolObject;
-
PyAPI_FUNC(PyTypeObject *) QtQml_VolatileBoolTypeF(void);
#define VolatileBool_Check(op) (Py_TYPE(op) == QtQml_VolatileBoolTypeF())
diff --git a/sources/pyside2/PySide2/QtQml/typesystem_qml.xml b/sources/pyside2/PySide2/QtQml/typesystem_qml.xml
index 57979f63f..0a12d44cf 100644
--- a/sources/pyside2/PySide2/QtQml/typesystem_qml.xml
+++ b/sources/pyside2/PySide2/QtQml/typesystem_qml.xml
@@ -44,10 +44,22 @@
<load-typesystem name="QtNetwork/typesystem_network.xml" generate="no"/>
<load-typesystem name="QtGui/typesystem_gui.xml" generate="no"/>
+ <inject-code class="target" position="declaration">
+ // Volatile Bool Ptr type definition.
+
+ typedef struct {
+ PyObject_HEAD
+ volatile bool flag;
+ } QtQml_VolatileBoolObject;
+ </inject-code>
+
+ <inject-code class="native" position="beginning">
+ #include "pysideqmlregistertype.h"
+ </inject-code>
+
<!-- This is to inform the generator that the VolatileBool python type exists -->
<custom-type name="VolatileBool"/>
<primitive-type name="bool volatile" target-lang-api-name="VolatileBool">
- <include file-name="pysideqmlregistertype.h" location="local"/>
<!-- No conversion rules are specified here, because the generator does not handle
pointer to primitive types without function adjustment.
See commit ff0b861b59b41387e771d9cd565e13de8b2750d1 or search for changePStr
@@ -85,7 +97,6 @@
<enum-type identified-by-value="QML_HAS_ATTACHED_PROPERTIES">
<extra-includes>
<include file-name="QtQml" location="global"/>
- <include file-name="pysideqmlregistertype.h" location="local"/>
</extra-includes>
</enum-type>
@@ -159,6 +170,9 @@
<enum-type name="Status"/>
</object-type>
<object-type name="QQmlIncubationController">
+ <extra-includes>
+ <include file-name="pysideqmlregistertype.h" location="local"/>
+ </extra-includes>
<modify-function signature="incubateWhile(volatile bool*,int)" allow-thread="yes">
<modify-argument index="1">
<!-- The replace type is needed to use the VolatileBool_Check macro instead of
diff --git a/sources/shiboken2/doc/typesystem_codeinjection.rst b/sources/shiboken2/doc/typesystem_codeinjection.rst
index 684630dd4..4ca77aa54 100644
--- a/sources/shiboken2/doc/typesystem_codeinjection.rst
+++ b/sources/shiboken2/doc/typesystem_codeinjection.rst
@@ -114,6 +114,8 @@ The following table describes the semantics of ``inject-code`` tag as used on
| | |end |Insert code at the end of the module initialization function |
| | | |(``initMODULENAME()``), but before the checking that emits a |
| | | |fatal error in case of problems importing the module. |
+ | | +-----------+--------------------------------------------------------------+
+ | | |declaration|Insert code into module header. |
+---------------+------+-----------+--------------------------------------------------------------+
@@ -400,3 +402,6 @@ to prevent bad custom code to pass unnoticed.
(...)
// Start of ``MODULENAME_module_wrapper.cpp``
+
+In addition, code can be injected into the module header by specifying ``target``
+and ``declaration``. This is useful for type definitions.
diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
index 8b3fe1653..cd99d76be 100644
--- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
@@ -391,6 +391,12 @@ bool HeaderGenerator::finishGeneration()
QString protectedEnumSurrogates;
QTextStream protEnumsSurrogates(&protectedEnumSurrogates);
+ const auto snips = TypeDatabase::instance()->defaultTypeSystemType()->codeSnips();
+ if (!snips.isEmpty()) {
+ writeCodeSnips(macrosStream, snips, TypeSystem::CodeSnipPositionDeclaration,
+ TypeSystem::TargetLangCode);
+ }
+
Indentation indent(INDENT);
macrosStream << "// Type indices\nenum : int {\n";