diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-12-19 09:15:57 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-12-19 11:12:39 +0100 |
| commit | 5ef2f78f7d0172683d6ae63314530844c48c548e (patch) | |
| tree | e053a85d31754e4158990c815a967b2ae8e8d6ec | |
| parent | 7c670b40b9fc2681260d0fdbcc275afd9bf6c2e8 (diff) | |
Clean up include statements
- Remove some unused include statements
- Replace C-headers (string.h) by the C++ versions (cstring)
- Use WIN32_LEAN_AND_MEAN for windows.h
Task-number: PYSIDE-2155
Change-Id: I8085e36f336d227218abb6c06cdd52d24c0761f4
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
14 files changed, 55 insertions, 50 deletions
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index dc855ae35..6783aea3d 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -1516,7 +1516,6 @@ return %CONVERTTOPYTHON[QVariant](ret); // @snippet qthread_pthread_cleanup #ifdef Q_OS_UNIX -# include <stdio.h> # include <pthread.h> static void qthread_pthread_cleanup(void *arg) { diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangdebugutils.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangdebugutils.cpp index 93618cf0f..80f439e49 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/clangdebugutils.cpp +++ b/sources/shiboken6/ApiExtractor/clangparser/clangdebugutils.cpp @@ -7,8 +7,6 @@ #include <QtCore/QDebug> #include <QtCore/QString> -#include <string.h> - #ifndef QT_NO_DEBUG_STREAM #ifdef Q_OS_WIN @@ -19,7 +17,7 @@ const char pathSep = '/'; static const char *baseName(const char *fileName) { - const char *b = strrchr(fileName, pathSep); + const char *b = std::strrchr(fileName, pathSep); return b ? b + 1 : fileName; } diff --git a/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp index 4145c8dec..8c3eeb592 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp +++ b/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp @@ -19,7 +19,6 @@ #include <clang-c/Index.h> -#include <string.h> #include <algorithm> #include <iterator> diff --git a/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.cpp b/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.cpp index d7b716c6a..29f5ec2b5 100644 --- a/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.cpp @@ -15,28 +15,29 @@ using namespace Qt::StringLiterals; void TestRemoveOperatorMethod::testRemoveOperatorMethod() { - const char cppCode[] = "\ - #include <stdint.h>\n\ - \n\ - struct Char {};\n\ - struct ByteArray {};\n\ - struct String {};\n\ - \n\ - struct A {\n\ - A& operator>>(char&);\n\ - A& operator>>(char*);\n\ - A& operator>>(short&);\n\ - A& operator>>(unsigned short&);\n\ - A& operator>>(int&);\n\ - A& operator>>(unsigned int&);\n\ - A& operator>>(int64_t&);\n\ - A& operator>>(uint64_t&);\n\ - A& operator>>(float&);\n\ - A& operator>>(double&);\n\ - A& operator>>(Char&);\n\ - A& operator>>(ByteArray&);\n\ - A& operator>>(String&);\n\ - };\n"; + const char cppCode[] = R"(#include <cstdint> + +struct Char {}; +struct ByteArray {}; +struct String {}; + +struct A { + A& operator>>(char&); + A& operator>>(char*); + A& operator>>(short&); + A& operator>>(unsigned short&); + A& operator>>(int&); + A& operator>>(unsigned int&); + A& operator>>(int64_t&); + A& operator>>(uint64_t&); + A& operator>>(float&); + A& operator>>(double&); + A& operator>>(Char&); + A& operator>>(ByteArray&); + A& operator>>(String&); +}; +)"; + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='char'/>\n\ diff --git a/sources/shiboken6/libshiboken/debugfreehook.cpp b/sources/shiboken6/libshiboken/debugfreehook.cpp index 1a80a2514..ee9434423 100644 --- a/sources/shiboken6/libshiboken/debugfreehook.cpp +++ b/sources/shiboken6/libshiboken/debugfreehook.cpp @@ -6,8 +6,11 @@ #include "gilstate.h" #if defined(_WIN32) && defined(_DEBUG) -#include <crtdbg.h> -#include <windows.h> +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include <crtdbg.h> +# include <windows.h> #endif #ifdef __GLIBC__ diff --git a/sources/shiboken6/libshiboken/helper.cpp b/sources/shiboken6/libshiboken/helper.cpp index a9ab9eca2..378511010 100644 --- a/sources/shiboken6/libshiboken/helper.cpp +++ b/sources/shiboken6/libshiboken/helper.cpp @@ -18,6 +18,9 @@ # ifndef NOMINMAX # define NOMINMAX # endif +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include <windows.h> #else # include <pthread.h> diff --git a/sources/shiboken6/libshiboken/signature/signature_globals.cpp b/sources/shiboken6/libshiboken/signature/signature_globals.cpp index d0ea86fc6..a32e72c14 100644 --- a/sources/shiboken6/libshiboken/signature/signature_globals.cpp +++ b/sources/shiboken6/libshiboken/signature/signature_globals.cpp @@ -201,12 +201,12 @@ static int init_phase_2(safe_globals_struc *p, PyMethodDef *methods) #ifndef _WIN32 //////////////////////////////////////////////////////////////////////////// // a stack trace for linux-like platforms -#include <stdio.h> +#include <cstdio> #if defined(__GLIBC__) # include <execinfo.h> #endif #include <signal.h> -#include <stdlib.h> +#include <cstdlib> #include <unistd.h> static void handler(int sig) { @@ -219,7 +219,7 @@ static void handler(int sig) { // print out all the frames to stderr #endif - fprintf(stderr, "Error: signal %d:\n", sig); + std::fprintf(stderr, "Error: signal %d:\n", sig); #if defined(__GLIBC__) backtrace_symbols_fd(array, size, STDERR_FILENO); #endif diff --git a/sources/shiboken6/tests/libsample/bucket.cpp b/sources/shiboken6/tests/libsample/bucket.cpp index 87a42118a..40f92d97e 100644 --- a/sources/shiboken6/tests/libsample/bucket.cpp +++ b/sources/shiboken6/tests/libsample/bucket.cpp @@ -5,11 +5,14 @@ #include <iostream> #ifdef _WIN32 // _WIN32 is defined by all Windows 32 and 64 bit compilers, but not by others. -#include <windows.h> -#define SLEEP(x) Sleep(x) +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include <windows.h> +# define SLEEP(x) Sleep(x) #else -#include <unistd.h> -#define SLEEP(x) usleep(x) +# include <unistd.h> +# define SLEEP(x) usleep(x) #endif Bucket::Bucket() : m_locked(false) diff --git a/sources/shiboken6/tests/libsample/functions.cpp b/sources/shiboken6/tests/libsample/functions.cpp index 210daec7c..fdb179913 100644 --- a/sources/shiboken6/tests/libsample/functions.cpp +++ b/sources/shiboken6/tests/libsample/functions.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "functions.h" -#include <string.h> +#include <cstring> #include <algorithm> #include <iostream> #include <numeric> @@ -66,7 +66,7 @@ char* makeCString() { char* string = new char[strlen(__FUNCTION__) + 1]; - strcpy(string, __FUNCTION__); + std::strcpy(string, __FUNCTION__); return string; } diff --git a/sources/shiboken6/tests/libsample/objecttype.h b/sources/shiboken6/tests/libsample/objecttype.h index 221fb7eea..260061995 100644 --- a/sources/shiboken6/tests/libsample/objecttype.h +++ b/sources/shiboken6/tests/libsample/objecttype.h @@ -10,8 +10,6 @@ #include "libsamplemacros.h" -#include <stddef.h> - struct Event { enum EventType { diff --git a/sources/shiboken6/tests/libsample/samplenamespace.cpp b/sources/shiboken6/tests/libsample/samplenamespace.cpp index 265dcea52..119a8b673 100644 --- a/sources/shiboken6/tests/libsample/samplenamespace.cpp +++ b/sources/shiboken6/tests/libsample/samplenamespace.cpp @@ -3,7 +3,7 @@ #include <iostream> #include <cstdlib> -#include <time.h> +#include <ctime> #include "samplenamespace.h" namespace SampleNamespace @@ -51,7 +51,7 @@ getNumber(Option opt) retval = rand() % 100; break; case UnixTime: - retval = (int) time(nullptr); + retval = (int) std::time(nullptr); break; default: retval = 0; diff --git a/sources/shiboken6/tests/libsample/simplefile.cpp b/sources/shiboken6/tests/libsample/simplefile.cpp index e0e42e268..81ef849ae 100644 --- a/sources/shiboken6/tests/libsample/simplefile.cpp +++ b/sources/shiboken6/tests/libsample/simplefile.cpp @@ -1,8 +1,8 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include <stdlib.h> -#include <string.h> +#include <cstdlib> +#include <cstring> #include <fstream> #include "simplefile.h" @@ -51,9 +51,9 @@ SimpleFile::open() if ((p->m_descriptor = fopen(p->m_filename, "rb")) == nullptr) return false; - fseek(p->m_descriptor, 0, SEEK_END); + std::fseek(p->m_descriptor, 0, SEEK_END); p->m_size = ftell(p->m_descriptor); - rewind(p->m_descriptor); + std::rewind(p->m_descriptor); return true; } @@ -62,7 +62,7 @@ void SimpleFile::close() { if (p->m_descriptor) { - fclose(p->m_descriptor); + std::fclose(p->m_descriptor); p->m_descriptor = nullptr; } } diff --git a/sources/shiboken6/tests/libsample/simplefile.h b/sources/shiboken6/tests/libsample/simplefile.h index 765b46095..6bc75b926 100644 --- a/sources/shiboken6/tests/libsample/simplefile.h +++ b/sources/shiboken6/tests/libsample/simplefile.h @@ -5,7 +5,6 @@ #define SIMPLEFILE_H #include "libsamplemacros.h" -#include <stdio.h> class SimpleFile_p; diff --git a/sources/shiboken6/tests/libsample/sometime.cpp b/sources/shiboken6/tests/libsample/sometime.cpp index 8a3802deb..daeae6df4 100644 --- a/sources/shiboken6/tests/libsample/sometime.cpp +++ b/sources/shiboken6/tests/libsample/sometime.cpp @@ -2,7 +2,8 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "sometime.h" -#include <stdio.h> + +#include <cstdio> void Time::setTime() @@ -46,7 +47,8 @@ Time::toString() const if (m_is_null) return Str(); char buffer[13]; - snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d.%03d", m_hour, m_minute, m_second, m_msec); + std::snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d.%03d", + m_hour, m_minute, m_second, m_msec); return Str(buffer); } |
