Skip to content

Commit 90220d9

Browse files
mrbean-bremenjcfr
authored andcommitted
[Backport] Replace NULL with nullptr
(cherry-picked and adapted from MeVisLab/pythonqt@c00ebf4) It replaces occurrences of NULL with nullptr, switches from usage of "0" to nullptr where a pointer is expected and fixes indentation of comments in type structure (e.g PythonQtSlotFunction_Type) It replaces comment "/* tp_print */" with "/* tp_vectorcall_offset */". Starting with Python 3.0, the slot was unused. Then it was renamed in Python 3.8 to support the new "vectorcall" protocol. See https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_vectorcall_offset and https://peps.python.org/pep-0590/#changes-to-the-pytypeobject-struct It resolves conflicts in PythonQt.cpp maintaining changes introduced in this fork.
1 parent e5fcf56 commit 90220d9

30 files changed

+859
-864
lines changed

src/PythonQt.cpp

Lines changed: 79 additions & 79 deletions
Large diffs are not rendered by default.

src/PythonQt.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ template<class T1, class T2> int PythonQtUpcastingOffset() {
144144
typedef QObject* PythonQtQObjectCreatorFunctionCB();
145145

146146
//! helper template to create a derived QObject class
147-
template<class T> QObject* PythonQtCreateObject() { return new T(); };
147+
template<class T> QObject* PythonQtCreateObject() { return new T(); }
148148

149149
//! Helper define to convert from QString to Python C-API
150150
#ifdef PY3K
@@ -260,7 +260,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
260260

261261
//! Overwrite default handling of stdin using a custom callback. It internally backup
262262
//! the original 'sys.stdin' into 'sys.pythonqt_original_stdin'
263-
void setRedirectStdInCallback(PythonQtInputChangedCB* callback, void * callbackData = 0);
263+
void setRedirectStdInCallback(PythonQtInputChangedCB* callback, void * callbackData = nullptr);
264264

265265
//! Enable or disable stdin custom callback. It resets 'sys.stdin' using either 'sys.pythonqt_stdin'
266266
//! or 'sys.pythonqt_original_stdin'
@@ -331,7 +331,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
331331
//! registers a QObject derived class to PythonQt (this is implicitly called by addObject as well)
332332
/* Since Qt4 does not offer a way to detect if a given classname is derived from QObject and thus has a QMetaObject,
333333
you MUST register all your QObject derived classes here when you want them to be detected in signal and slot calls */
334-
void registerClass(const QMetaObject* metaobject, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL);
334+
void registerClass(const QMetaObject* metaobject, const char* package = nullptr, PythonQtQObjectCreatorFunctionCB* wrapperCreator = nullptr, PythonQtShellSetInstanceWrapperCB* shell = nullptr);
335335

336336
//! add a wrapper object for the given QMetaType typeName, also does an addClassDecorators() to add constructors for variants
337337
//! (ownership of wrapper is passed to PythonQt)
@@ -341,7 +341,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
341341
All slots that take a pointer to typeName as the first argument will be callable from Python on
342342
a variant object that contains such a type.
343343
*/
344-
void registerCPPClass(const char* typeName, const char* parentTypeName = NULL, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL);
344+
void registerCPPClass(const char* typeName, const char* parentTypeName = nullptr, const char* package = nullptr, PythonQtQObjectCreatorFunctionCB* wrapperCreator = nullptr, PythonQtShellSetInstanceWrapperCB* shell = nullptr);
345345

346346
//! as an alternative to registerClass, you can tell PythonQt the names of QObject derived classes
347347
//! and it will register the classes when it first sees a pointer to such a derived class
@@ -377,7 +377,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
377377

378378
//! evaluates the given script code and returns the result value
379379
QVariant evalScript(PyObject* object, const QString& script, int start = Py_file_input);
380-
380+
381381
//! evaluates the given script code in context of given globals and locals and returns the result value
382382
QVariant evalScript(const QString& script, PyObject* globals, PyObject* locals, int start);
383383

@@ -548,7 +548,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
548548
//! the default importer allows to import files from anywhere QFile can read from,
549549
//! including the Qt resource system using ":". Keep in mind that you need to extend
550550
//! "sys.path" with ":" to be able to import from the Qt resources.
551-
void installDefaultImporter() { setImporter(NULL); }
551+
void installDefaultImporter() { setImporter(nullptr); }
552552

553553
//! set paths that the importer should ignore
554554
void setImporterIgnorePaths(const QStringList& paths);
@@ -731,7 +731,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject {
731731
//! registers a QObject derived class to PythonQt (this is implicitly called by addObject as well)
732732
/* Since Qt4 does not offer a way to detect if a given classname is derived from QObject and thus has a QMetaObject,
733733
you MUST register all your QObject derived classes here when you want them to be detected in signal and slot calls */
734-
void registerClass(const QMetaObject* metaobject, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL, PyObject* module = NULL, int typeSlots = 0);
734+
void registerClass(const QMetaObject* metaobject, const char* package = nullptr, PythonQtQObjectCreatorFunctionCB* wrapperCreator = nullptr, PythonQtShellSetInstanceWrapperCB* shell = nullptr, PyObject* module = nullptr, int typeSlots = 0);
735735

736736
//! add a wrapper object for the given QMetaType typeName, also does an addClassDecorators() to add constructors for variants
737737
//! (ownership of wrapper is passed to PythonQt)
@@ -741,7 +741,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject {
741741
All slots that take a pointer to typeName as the first argument will be callable from Python on
742742
a variant object that contains such a type.
743743
*/
744-
void registerCPPClass(const char* typeName, const char* parentTypeName = NULL, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL, PyObject* module = NULL, int typeSlots = 0);
744+
void registerCPPClass(const char* typeName, const char* parentTypeName = nullptr, const char* package = nullptr, PythonQtQObjectCreatorFunctionCB* wrapperCreator = nullptr, PythonQtShellSetInstanceWrapperCB* shell = nullptr, PyObject* module = nullptr, int typeSlots = 0);
745745

746746
//! as an alternative to registerClass, you can tell PythonQt the names of QObject derived classes
747747
//! and it will register the classes when it first sees a pointer to such a derived class
@@ -760,7 +760,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject {
760760
static PyObject* createNewPythonQtEnumWrapper(const char* enumName, PyObject* parentObject);
761761

762762
//! helper method that creates a PythonQtInstanceWrapper object and registers it in the object map
763-
PythonQtInstanceWrapper* createNewPythonQtInstanceWrapper(QObject* obj, PythonQtClassInfo* info, void* wrappedPtr = NULL);
763+
PythonQtInstanceWrapper* createNewPythonQtInstanceWrapper(QObject* obj, PythonQtClassInfo* info, void* wrappedPtr = nullptr);
764764

765765
//! get the class info for a meta object (if available)
766766
PythonQtClassInfo* getClassInfo(const QMetaObject* meta);
@@ -799,13 +799,13 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject {
799799
//! get the dynamic meta object for the given wrapper. It will contain the signals/slots that have been added in Python
800800
const QMetaObject* getDynamicMetaObject(PythonQtInstanceWrapper* wrapper, const QMetaObject* prototypeMetaObject);
801801

802-
//! recursively creates the dynamic meta object chain down to the Qt class wrapper.
802+
//! recursively creates the dynamic meta object chain down to the Qt class wrapper.
803803
const QMetaObject* setupDynamicMetaObjectChain(PythonQtClassWrapper* type, const QMetaObject* prototypeMetaObject);
804804

805805
//! builds and returns the dynamic meta object for the given type, derived from prototypeMetaObject.
806806
const QMetaObject* buildDynamicMetaObject(PythonQtClassWrapper* type, const QMetaObject* prototypeMetaObject);
807807

808-
//! redirected from shell classes, tries to call the given meta call on the Python wrapper.
808+
//! redirected from shell classes, tries to call the given meta call on the Python wrapper.
809809
int handleMetaCall(QObject* object, PythonQtInstanceWrapper* wrapper, QMetaObject::Call call, int id, void** args);
810810

811811
//! calls the given method on Python function with same name.
@@ -816,7 +816,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject {
816816
void setupSharedLibrarySuffixes();
817817

818818
//! create a new pythonqt class wrapper and place it in the pythonqt module
819-
void createPythonQtClassWrapper(PythonQtClassInfo* info, const char* package, PyObject* module = NULL);
819+
void createPythonQtClassWrapper(PythonQtClassInfo* info, const char* package, PyObject* module = nullptr);
820820

821821
//! get/create new package module (the returned object is a borrowed reference)
822822
PyObject* packageByName(const char* name);

src/PythonQtBoolResult.cpp

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -66,54 +66,54 @@ static int PythonQtBoolResult_nonzero(PyObject *obj)
6666

6767
// we override nb_nonzero, so that one can do 'if' expressions to test for a NULL ptr
6868
static PyNumberMethods PythonQtBoolResult_as_number = {
69-
0, /* nb_add */
70-
0, /* nb_subtract */
71-
0, /* nb_multiply */
69+
nullptr, /* nb_add */
70+
nullptr, /* nb_subtract */
71+
nullptr, /* nb_multiply */
7272
#ifndef PY3K
73-
0, /* nb_divide */
73+
nullptr, /* nb_divide */
7474
#endif
75-
0, /* nb_remainder */
76-
0, /* nb_divmod */
77-
0, /* nb_power */
78-
0, /* nb_negative */
79-
0, /* nb_positive */
80-
0, /* nb_absolute */
75+
nullptr, /* nb_remainder */
76+
nullptr, /* nb_divmod */
77+
nullptr, /* nb_power */
78+
nullptr, /* nb_negative */
79+
nullptr, /* nb_positive */
80+
nullptr, /* nb_absolute */
8181
PythonQtBoolResult_nonzero, /* nb_nonzero / nb_bool in Py3K */
82-
0, /* nb_invert */
83-
0, /* nb_lshift */
84-
0, /* nb_rshift */
85-
0, /* nb_and */
86-
0, /* nb_xor */
87-
0, /* nb_or */
88-
#ifndef PY3K
89-
0, /* nb_coerce */
82+
nullptr, /* nb_invert */
83+
nullptr, /* nb_lshift */
84+
nullptr, /* nb_rshift */
85+
nullptr, /* nb_and */
86+
nullptr, /* nb_xor */
87+
nullptr, /* nb_or */
88+
#ifndef PY3K
89+
nullptr, /* nb_coerce */
9090
#endif
91-
0, /* nb_int */
92-
0, /* nb_long / nb_reserved in Py3K */
93-
0, /* nb_float */
91+
nullptr, /* nb_int */
92+
nullptr, /* nb_long / nb_reserved in Py3K */
93+
nullptr, /* nb_float */
9494
#ifndef PY3K
95-
0, /* nb_oct */
96-
0, /* nb_hex */
95+
nullptr, /* nb_oct */
96+
nullptr, /* nb_hex */
9797
#endif
98-
0, /* nb_inplace_add */
99-
0, /* nb_inplace_subtract */
100-
0, /* nb_inplace_multiply */
98+
nullptr, /* nb_inplace_add */
99+
nullptr, /* nb_inplace_subtract */
100+
nullptr, /* nb_inplace_multiply */
101101
#ifndef PY3K
102-
0, /* nb_inplace_divide */
102+
nullptr, /* nb_inplace_divide */
103103
#endif
104-
0, /* nb_inplace_remainder */
105-
0, /* nb_inplace_power */
106-
0, /* nb_inplace_lshift */
107-
0, /* nb_inplace_rshift */
108-
0, /* nb_inplace_and */
109-
0, /* nb_inplace_xor */
110-
0, /* nb_inplace_or */
111-
0, /* nb_floor_divide */
112-
0, /* nb_true_divide */
113-
0, /* nb_inplace_floor_divide */
114-
0, /* nb_inplace_true_divide */
104+
nullptr, /* nb_inplace_remainder */
105+
nullptr, /* nb_inplace_power */
106+
nullptr, /* nb_inplace_lshift */
107+
nullptr, /* nb_inplace_rshift */
108+
nullptr, /* nb_inplace_and */
109+
nullptr, /* nb_inplace_xor */
110+
nullptr, /* nb_inplace_or */
111+
nullptr, /* nb_floor_divide */
112+
nullptr, /* nb_true_divide */
113+
nullptr, /* nb_inplace_floor_divide */
114+
nullptr, /* nb_inplace_true_divide */
115115
#ifdef PY3K
116-
0, /* nb_index in Py3K */
116+
nullptr, /* nb_index in Py3K */
117117
#endif
118118
};
119119

@@ -122,37 +122,37 @@ PyTypeObject PythonQtBoolResult_Type = {
122122
"BoolResult",
123123
sizeof(PythonQtBoolResultObject),
124124
0,
125-
0, /* tp_dealloc */
126-
0, /* tp_print */
127-
0, /* tp_getattr */
128-
0, /* tp_setattr */
129-
0,
125+
nullptr, /* tp_dealloc */
126+
0, /* tp_vectorcall_offset */
127+
nullptr, /* tp_getattr */
128+
nullptr, /* tp_setattr */
129+
nullptr,
130130
(reprfunc)PythonQtBoolResult_repr, /* tp_repr */
131131
&PythonQtBoolResult_as_number, /* tp_as_number */
132-
0, /* tp_as_sequence */
133-
0, /* tp_as_mapping */
134-
0, /* tp_hash */
135-
0, /* tp_call */
136-
0, /* tp_str */
137-
0, /* tp_getattro */
138-
0, /* tp_setattro */
139-
0, /* tp_as_buffer */
132+
nullptr, /* tp_as_sequence */
133+
nullptr, /* tp_as_mapping */
134+
nullptr, /* tp_hash */
135+
nullptr, /* tp_call */
136+
nullptr, /* tp_str */
137+
nullptr, /* tp_getattro */
138+
nullptr, /* tp_setattro */
139+
nullptr, /* tp_as_buffer */
140140
Py_TPFLAGS_DEFAULT,/* tp_flags */
141-
"Result object that is useful for bool* arguments", /* tp_doc */
142-
0, /* tp_traverse */
143-
0, /* tp_clear */
144-
0, /* tp_richcompare */
145-
0, /* tp_weaklistoffset */
146-
0, /* tp_iter */
147-
0, /* tp_iternext */
148-
0, /* tp_methods */
149-
0, /* tp_members */
150-
0, /* tp_getset */
151-
0, /* tp_base */
152-
0, /* tp_dict */
153-
0, /* tp_descr_get */
154-
0, /* tp_descr_set */
155-
0, /* tp_dictoffset */
141+
"Result object that is useful for bool* arguments", /* tp_doc */
142+
nullptr, /* tp_traverse */
143+
nullptr, /* tp_clear */
144+
nullptr, /* tp_richcompare */
145+
0, /* tp_weaklistoffset */
146+
nullptr, /* tp_iter */
147+
nullptr, /* tp_iternext */
148+
nullptr, /* tp_methods */
149+
nullptr, /* tp_members */
150+
nullptr, /* tp_getset */
151+
nullptr, /* tp_base */
152+
nullptr, /* tp_dict */
153+
nullptr, /* tp_descr_get */
154+
nullptr, /* tp_descr_set */
155+
0, /* tp_dictoffset */
156156
(initproc)&PythonQtBoolResult_init, /* tp_init */
157157
};
158158

0 commit comments

Comments
 (0)