aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/libshiboken/helper.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2022-12-14 14:12:02 +0100
committerFriedemann Kleint <[email protected]>2022-12-15 08:23:11 +0100
commitcf540671a591c446d1d573fc5812aa64102774c6 (patch)
treeaad8f2f53cc72fda1196b0a09e7d4bf5fbdf2def /sources/shiboken6/libshiboken/helper.cpp
parent4315cfb44eaa8abd57c685390c6b9d3aff09ba0f (diff)
shiboken6: Move parts of the typenameOf() function into libshiboken
The static function causes conflicts with UNITY_BUILDs. Task-number: PYSIDE-2151 Task-number: PYSIDE-661 Change-Id: Ib0f1ceeb9d393721eab987a0c0419d0a5d0fec45 Reviewed-by: Cristian Maureira-Fredes <[email protected]> Reviewed-by: Qt CI Bot <[email protected]>
Diffstat (limited to 'sources/shiboken6/libshiboken/helper.cpp')
-rw-r--r--sources/shiboken6/libshiboken/helper.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/sources/shiboken6/libshiboken/helper.cpp b/sources/shiboken6/libshiboken/helper.cpp
index 8f836316e..a9ab9eca2 100644
--- a/sources/shiboken6/libshiboken/helper.cpp
+++ b/sources/shiboken6/libshiboken/helper.cpp
@@ -6,10 +6,13 @@
#include "sbkstring.h"
#include "sbkstaticstrings.h"
+#include <algorithm>
+
#include <iomanip>
#include <iostream>
-
+#include <cstring>
#include <cstdarg>
+#include <cctype>
#ifdef _WIN32
# ifndef NOMINMAX
@@ -20,8 +23,6 @@
# include <pthread.h>
#endif
-#include <algorithm>
-
static void formatPyTypeObject(const PyTypeObject *obj, std::ostream &str)
{
if (obj) {
@@ -442,4 +443,26 @@ ThreadId mainThreadId()
return _mainThreadId;
}
+const char *typeNameOf(const char *typeIdName)
+{
+ auto size = std::strlen(typeIdName);
+#if defined(Q_CC_MSVC) // MSVC: "class QPaintDevice * __ptr64"
+ if (auto *lastStar = strchr(typeName, '*')) {
+ // MSVC: "class QPaintDevice * __ptr64"
+ while (*--lastStar == ' ') {
+ }
+ size = lastStar - typeName + 1;
+ }
+#else // g++, Clang: "QPaintDevice *" -> "P12QPaintDevice"
+ if (size > 2 && typeIdName[0] == 'P' && std::isdigit(typeIdName[1])) {
+ ++typeIdName;
+ --size;
+ }
+#endif
+ char *result = new char[size + 1];
+ result[size] = '\0';
+ std::memcpy(result, typeIdName, size);
+ return result;
+}
+
} // namespace Shiboken