Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CTK pragma macros and fix "PythonQtInstanceWrapper.h" -Wold-style-cast warnings #837

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jcfr
Copy link
Member

@jcfr jcfr commented Oct 1, 2018

The macros were adapted from ITK and allow to avoid warnings like the following:

/path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h: In member function ‘PythonQtClassInfo* PythonQtInstanceWrapperStruct::classInfo()’:
/path/to/Slicer-build/python-install/include/python2.7/object.h:115:49: warning: use of old-style cast [-Wold-style-cast]
 #define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
                                                 ^
/path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h:68:37: note: in expansion of macro ‘Py_TYPE’
   {  return ((PythonQtClassWrapper*)Py_TYPE(this))->_classInfo; }
                                     ^

…-cast warnings

The macros were adapted from ITK and allow to avoid warnings like the following:

/path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h: In member function ‘PythonQtClassInfo* PythonQtInstanceWrapperStruct::classInfo()’:
/path/to/Slicer-build/python-install/include/python2.7/object.h:115:49: warning: use of old-style cast [-Wold-style-cast]
 #define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
                                                 ^
/path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h:68:37: note: in expansion of macro ‘Py_TYPE’
   {  return ((PythonQtClassWrapper*)Py_TYPE(this))->_classInfo; }
                                     ^
@jcfr
Copy link
Member Author

jcfr commented Oct 1, 2018

Since the can be of general use in the remaining of CTK (and also user code) I added them to ctkMacro.h.

  • We could also introduce a header named "ctkPythonQt.h" that would systematically be included (instead of PythonQt.h), this header would then be used everywhere in CTK/Slicer/...

  • or we could work in fixing PythonQt ...

@jcfr
Copy link
Member Author

jcfr commented Oct 1, 2018

for reference, here is the email sent to the pythonqt discussion forum (not yet visible):


Hi Florian,

Would you accept a patch like the following to systematically ignore old-style cast warnings ?

That would be very helpful and avoid user code to maintain their own guard headers.

diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h
index 00f0b07..bd20c76 100644
--- a/src/PythonQtPythonInclude.h
+++ b/src/PythonQtPythonInclude.h
@@ -44,6 +44,15 @@
 #define PYTHONQT_RESTORE_KEYWORDS
 #endif
 
+// Ignore "old-style-cast" warnings  associated with use of macro like Py_TYPE
+// provided by pythonX.Y/object.h
+#if defined( __GNUC__ )
+#if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 9 ) || ( __GNUC__ >= 7 )
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+#endif
+
 // If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link
 // release Python DLL if it is available by undefining _DEBUG while
 // including Python.h
@@ -59,6 +68,12 @@
 #include <Python.h>
 #endif
 
+#if defined( __GNUC__ )
+#if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 9 ) || ( __GNUC__ >= 7 )
+#pragma GCC diagnostic pop
+#endif
+#endif
+

Example of warnings:

/path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h: In member function ‘PythonQtClassInfo* PythonQtInstanceWrapperStruct::classInfo()’:
/path/to/Slicer-build/python-install/include/python2.7/object.h:115:49: warning: use of old-style cast [-Wold-style-cast]
 #define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
                                                 ^
/path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h:68:37: note: in expansion of macro ‘Py_TYPE’
   {  return ((PythonQtClassWrapper*)Py_TYPE(this))->_classInfo; }
                                     ^
/path/to/Slicer-build/python-install/include/python2.7/object.h:115:60: warning: use of old-style cast [-Wold-style-cast]
 #define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
                                                            ^
/path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h:68:37: note: in expansion of macro ‘Py_TYPE’
   {  return ((PythonQtClassWrapper*)Py_TYPE(this))->_classInfo; }
                                     ^
/path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h: In member function ‘PythonQtDynamicClassInfo* PythonQtInstanceWrapperStruct::dynamicClassInfo()’:
/path/to/Slicer-build/python-install/include/python2.7/object.h:115:49: warning: use of old-style cast [-Wold-style-cast]
 #define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
                                                 ^

@jcfr
Copy link
Member Author

jcfr commented Oct 1, 2018

It turns out that (1) the patch was incorrect and (2) updating PythonQtPythonInclude.h by pushing/poping context is not working.

Instead the following should be done:

diff --git a/src/PythonQt.h b/src/PythonQt.h
index fd2e28e..643d984 100644
--- a/src/PythonQt.h
+++ b/src/PythonQt.h
@@ -42,6 +42,15 @@
 */
 //----------------------------------------------------------------------------------
 
+// Ignore "old-style-cast" warnings  associated with use of macro like Py_TYPE
+// provided by pythonX.Y/object.h
+#if defined( __GNUC__ )
+#if ( __GNUC__ > 4 ) || (( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 ))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+#endif
+
 #include "PythonQtPythonInclude.h"
 #include "PythonQtUtils.h"
 #include "PythonQtSystem.h"
@@ -51,6 +60,13 @@
 #include "PythonQtObjectPtr.h"
 #include "PythonQtStdIn.h"
 #include "PythonQtThreadSupport.h"
+
+#if defined( __GNUC__ )
+#if ( __GNUC__ > 4 ) || (( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 ))
+#pragma GCC diagnostic pop
+#endif
+#endif
+
 #include <QObject>
 #include <QVariant>
 #include <QList>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant