[PyQt] [PATCH v2 1/6] Add SIP_NULLPTR/SIP_OVERRIDE compatibility macros
Stefan Brüns
stefan.bruens at rwth-aachen.de
Mon Oct 1 02:58:44 BST 2018
To allow using nullptr throughout the generated code while staying
backwards compatible for C and older C++ compilers, use SIP_NULLPTR
as a proxy. Likewise for override/SIP_OVERRIDE.
Signed-off-by: Stefan Brüns <stefan.bruens at rwth-aachen.de>
---
sipgen/gencode.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/sipgen/gencode.c b/sipgen/gencode.c
index ca76761..98a84b5 100644
--- a/sipgen/gencode.c
+++ b/sipgen/gencode.c
@@ -301,6 +301,7 @@ static void generatePreprocLine(int linenr, const char *fname, FILE *fp);
static int hasOptionalArgs(overDef *od);
static int emptyIfaceFile(sipSpec *pt, ifaceFileDef *iff);
static void declareLimitedAPI(int py_debug, moduleDef *mod, FILE *fp);
+static void declareCompatDefines(FILE *fp);
static int generatePluginSignalsTable(sipSpec *pt, classDef *cd,
const char *pyqt_prefix, FILE *fp);
static int generatePyQt5ClassPlugin(sipSpec *pt, classDef *cd, FILE *fp);
@@ -608,6 +609,9 @@ static void generateInternalAPIHeader(sipSpec *pt, moduleDef *mod,
"#include <QThread>\n"
);
+ /* Define macros for forward/backwards compatibility */
+ declareCompatDefines(fp);
+
/* Define the qualifiers. */
noIntro = TRUE;
@@ -1165,6 +1169,9 @@ static void generateCompositeCpp(sipSpec *pt, const char *codeDir,
"}\n"
);
+ /* Define macros for forward/backwards compatibility */
+ declareCompatDefines(fp);
+
generateModDocstring(pt->module, fp);
generateModInitStart(pt->module, TRUE, fp);
generateModDefinition(pt->module, "NULL", fp);
@@ -15473,6 +15480,31 @@ static void declareLimitedAPI(int py_debug, moduleDef *mod, FILE *fp)
}
+/*
+ *
+ * Add some convenience macros to make code forward/backwards compatible.
+ */
+static void declareCompatDefines(FILE *fp)
+{
+ prcode(fp,
+"\n"
+"#ifndef SIP_NULLPTR\n"
+"#if __cplusplus >= 201103L\n"
+"#define SIP_NULLPTR nullptr\n"
+"#define SIP_OVERRIDE override\n"
+"#elif defined _MSVC_LANG\n"
+"#define SIP_NULLPTR nullptr\n"
+"#define SIP_OVERRIDE override\n"
+"#else\n"
+"#define SIP_NULLPTR 0\n"
+"#define SIP_OVERRIDE\n"
+"#endif\n"
+"#endif\n"
+"\n"
+ );
+}
+
+
/*
* Generate the PyQt4/5 signals table.
*/
--
2.19.0
More information about the PyQt
mailing list