aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2026-09-16 15:30:57 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2026-09-25 14:32:24 +0000
commitefb55681b7e9e2c5af3ab09455de995f1b9ac54d (patch)
treee4662fc9faf703ab732ab9993b140cfc3dd3225e
parentc7193cee5d80c1a30f06b586730ca11220853f01 (diff)
libshiboken: Add class helper macros LIBSHIBOKEN_DISABLE_COPY(_MOVE)
Modeled after the equivalent Qt header qtclasshelpermacros.h and its macros. They make the intent of the class clearer. Change-Id: Ie766672cfaacb2528bf386c0883179cbab197b4c Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r--sources/shiboken6/libshiboken/CMakeLists.txt3
-rw-r--r--sources/shiboken6/libshiboken/autodecref.h5
-rw-r--r--sources/shiboken6/libshiboken/basewrapper_p.h7
-rw-r--r--sources/shiboken6/libshiboken/bindingmanager.h6
-rw-r--r--sources/shiboken6/libshiboken/gilstate.h6
-rw-r--r--sources/shiboken6/libshiboken/helper.h6
-rw-r--r--sources/shiboken6/libshiboken/sbkarrayconverter.h6
-rw-r--r--sources/shiboken6/libshiboken/sbkerrors.h11
-rw-r--r--sources/shiboken6/libshiboken/shibokenclasshelpermacros.h17
-rw-r--r--sources/shiboken6/libshiboken/threadstatesaver.h6
10 files changed, 38 insertions, 35 deletions
diff --git a/sources/shiboken6/libshiboken/CMakeLists.txt b/sources/shiboken6/libshiboken/CMakeLists.txt
index 95ccf0ea3..bb7212de3 100644
--- a/sources/shiboken6/libshiboken/CMakeLists.txt
+++ b/sources/shiboken6/libshiboken/CMakeLists.txt
@@ -90,7 +90,7 @@ sbktypefactory.cpp sbktypefactory.h
sbkwindows.h
shiboken.h
shibokenbuffer.cpp shibokenbuffer.h
-shibokenmacros.h
+shibokenmacros.h shibokenclasshelpermacros.h
threadstatesaver.cpp threadstatesaver.h
voidptr.cpp voidptr.h
@@ -208,6 +208,7 @@ install(FILES
sbktypefactory.h
shiboken.h
shibokenmacros.h
+ shibokenclasshelpermacros.h
threadstatesaver.h
shibokenbuffer.h
sbkpep.h
diff --git a/sources/shiboken6/libshiboken/autodecref.h b/sources/shiboken6/libshiboken/autodecref.h
index 292fe98af..8fab8edc6 100644
--- a/sources/shiboken6/libshiboken/autodecref.h
+++ b/sources/shiboken6/libshiboken/autodecref.h
@@ -6,6 +6,7 @@
#define AUTODECREF_H
#include "sbkpython.h"
+#include "shibokenclasshelpermacros.h"
#include <utility>
@@ -19,9 +20,9 @@ namespace Shiboken
struct AutoDecRef
{
public:
- AutoDecRef(const AutoDecRef &) = delete;
+ LIBSHIBOKEN_DISABLE_COPY(AutoDecRef)
+
AutoDecRef(AutoDecRef &&o) noexcept : m_pyObj{std::exchange(o.m_pyObj, nullptr)} {}
- AutoDecRef &operator=(const AutoDecRef &) = delete;
AutoDecRef &operator=(AutoDecRef &&o) noexcept
{
m_pyObj = std::exchange(o.m_pyObj, nullptr);
diff --git a/sources/shiboken6/libshiboken/basewrapper_p.h b/sources/shiboken6/libshiboken/basewrapper_p.h
index 5f2c86876..179b2efd4 100644
--- a/sources/shiboken6/libshiboken/basewrapper_p.h
+++ b/sources/shiboken6/libshiboken/basewrapper_p.h
@@ -6,6 +6,7 @@
#define BASEWRAPPER_P_H
#include "sbkpython.h"
+#include "shibokenclasshelpermacros.h"
#include "basewrapper.h"
#include <unordered_map>
@@ -50,11 +51,9 @@ extern "C"
*/
struct SbkObjectPrivate
{
+ LIBSHIBOKEN_DISABLE_COPY_MOVE(SbkObjectPrivate)
+
SbkObjectPrivate() noexcept = default;
- SbkObjectPrivate(const SbkObjectPrivate &) = delete;
- SbkObjectPrivate(SbkObjectPrivate &&o) = delete;
- SbkObjectPrivate &operator=(const SbkObjectPrivate &) = delete;
- SbkObjectPrivate &operator=(SbkObjectPrivate &&o) = delete;
/// Pointer to the C++ class.
void ** cptr;
diff --git a/sources/shiboken6/libshiboken/bindingmanager.h b/sources/shiboken6/libshiboken/bindingmanager.h
index b9ac63c4f..0c358be5c 100644
--- a/sources/shiboken6/libshiboken/bindingmanager.h
+++ b/sources/shiboken6/libshiboken/bindingmanager.h
@@ -6,6 +6,7 @@
#define BINDINGMANAGER_H
#include "sbkpython.h"
+#include "shibokenclasshelpermacros.h"
#include "shibokenmacros.h"
#include "sbkdestructorentry.h"
@@ -26,10 +27,7 @@ using ObjectVisitor = void (*)(SbkObject *, void *);
class LIBSHIBOKEN_API BindingManager
{
public:
- BindingManager(const BindingManager &) = delete;
- BindingManager(BindingManager &&) = delete;
- BindingManager &operator=(const BindingManager &) = delete;
- BindingManager &operator=(BindingManager &&) = delete;
+ LIBSHIBOKEN_DISABLE_COPY_MOVE(BindingManager)
static BindingManager &instance();
diff --git a/sources/shiboken6/libshiboken/gilstate.h b/sources/shiboken6/libshiboken/gilstate.h
index 571dd13e2..d3a557180 100644
--- a/sources/shiboken6/libshiboken/gilstate.h
+++ b/sources/shiboken6/libshiboken/gilstate.h
@@ -6,6 +6,7 @@
#define GILSTATE_H
#include <shibokenmacros.h>
+#include "shibokenclasshelpermacros.h"
#include "sbkpython.h"
namespace Shiboken
@@ -14,10 +15,7 @@ namespace Shiboken
class LIBSHIBOKEN_API GilState
{
public:
- GilState(const GilState &) = delete;
- GilState(GilState &&) = delete;
- GilState &operator=(const GilState &) = delete;
- GilState &operator=(GilState &&) = delete;
+ LIBSHIBOKEN_DISABLE_COPY_MOVE(GilState)
explicit GilState(bool acquire=true);
~GilState();
diff --git a/sources/shiboken6/libshiboken/helper.h b/sources/shiboken6/libshiboken/helper.h
index 20b882acd..213803ce3 100644
--- a/sources/shiboken6/libshiboken/helper.h
+++ b/sources/shiboken6/libshiboken/helper.h
@@ -7,6 +7,7 @@
#include "sbkpython.h"
#include "shibokenmacros.h"
+#include "shibokenclasshelpermacros.h"
#include <iosfwd>
@@ -58,10 +59,7 @@ template<class T>
class ArrayPointer
{
public:
- ArrayPointer(const ArrayPointer &) = delete;
- ArrayPointer(ArrayPointer &&) = delete;
- ArrayPointer &operator=(const ArrayPointer &) = delete;
- ArrayPointer &operator=(ArrayPointer &&) = delete;
+ LIBSHIBOKEN_DISABLE_COPY_MOVE(ArrayPointer)
explicit ArrayPointer(Py_ssize_t size) : data(new T[size]) {}
T &operator[](Py_ssize_t pos) { return data[pos]; }
diff --git a/sources/shiboken6/libshiboken/sbkarrayconverter.h b/sources/shiboken6/libshiboken/sbkarrayconverter.h
index b153eb52c..5e9390831 100644
--- a/sources/shiboken6/libshiboken/sbkarrayconverter.h
+++ b/sources/shiboken6/libshiboken/sbkarrayconverter.h
@@ -7,6 +7,7 @@
#include "sbkpython.h"
#include "shibokenmacros.h"
+#include "shibokenclasshelpermacros.h"
extern "C" {
struct SbkArrayConverter;
@@ -38,10 +39,7 @@ template <class T>
class ArrayHandle
{
public:
- ArrayHandle(const ArrayHandle &) = delete;
- ArrayHandle& operator=(const ArrayHandle &) = delete;
- ArrayHandle(ArrayHandle &&) = delete;
- ArrayHandle& operator=(ArrayHandle &&) = delete;
+ LIBSHIBOKEN_DISABLE_COPY_MOVE(ArrayHandle)
ArrayHandle() = default;
~ArrayHandle() { destroy(); }
diff --git a/sources/shiboken6/libshiboken/sbkerrors.h b/sources/shiboken6/libshiboken/sbkerrors.h
index a0eac6954..94497135a 100644
--- a/sources/shiboken6/libshiboken/sbkerrors.h
+++ b/sources/shiboken6/libshiboken/sbkerrors.h
@@ -7,6 +7,7 @@
#include "sbkpython.h"
#include "shibokenmacros.h"
+#include "shibokenclasshelpermacros.h"
#include <memory>
@@ -25,10 +26,7 @@ namespace Shiboken
struct LIBSHIBOKEN_API PythonContextMarker
{
public:
- PythonContextMarker(const PythonContextMarker &) = delete;
- PythonContextMarker(PythonContextMarker &&) = delete;
- PythonContextMarker &operator=(const PythonContextMarker &) = delete;
- PythonContextMarker &operator=(PythonContextMarker &&) = delete;
+ LIBSHIBOKEN_DISABLE_COPY_MOVE(PythonContextMarker)
explicit PythonContextMarker();
~PythonContextMarker();
@@ -44,10 +42,7 @@ struct ErrorStore;
class Stash
{
public:
- Stash(const Stash &) = delete;
- Stash &operator=(const Stash &) = delete;
- Stash(Stash &&) = delete;
- Stash &operator=(Stash &&) = delete;
+ LIBSHIBOKEN_DISABLE_COPY_MOVE(Stash)
LIBSHIBOKEN_API Stash();
LIBSHIBOKEN_API ~Stash();
diff --git a/sources/shiboken6/libshiboken/shibokenclasshelpermacros.h b/sources/shiboken6/libshiboken/shibokenclasshelpermacros.h
new file mode 100644
index 000000000..9f6122d1a
--- /dev/null
+++ b/sources/shiboken6/libshiboken/shibokenclasshelpermacros.h
@@ -0,0 +1,17 @@
+// Copyright (C) 2026 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// Qt-Security score:significant reason:default
+
+#ifndef SHIBOKENCLASSHELPERMACROS_H
+#define SHIBOKENCLASSHELPERMACROS_H
+
+#define LIBSHIBOKEN_DISABLE_COPY(Class) \
+ Class(const Class &) = delete;\
+ Class &operator=(const Class &) = delete;
+
+#define LIBSHIBOKEN_DISABLE_COPY_MOVE(Class) \
+ LIBSHIBOKEN_DISABLE_COPY(Class) \
+ Class(Class &&) = delete; \
+ Class &operator=(Class &&) = delete;
+
+#endif // SHIBOKENCLASSHELPERMACROS_H
diff --git a/sources/shiboken6/libshiboken/threadstatesaver.h b/sources/shiboken6/libshiboken/threadstatesaver.h
index 4278b32bc..6d15c9624 100644
--- a/sources/shiboken6/libshiboken/threadstatesaver.h
+++ b/sources/shiboken6/libshiboken/threadstatesaver.h
@@ -7,6 +7,7 @@
#include "sbkpython.h"
#include <shibokenmacros.h>
+#include "shibokenclasshelpermacros.h"
namespace Shiboken
{
@@ -14,10 +15,7 @@ namespace Shiboken
class LIBSHIBOKEN_API ThreadStateSaver
{
public:
- ThreadStateSaver(const ThreadStateSaver &) = delete;
- ThreadStateSaver(ThreadStateSaver &&) = delete;
- ThreadStateSaver &operator=(const ThreadStateSaver &) = delete;
- ThreadStateSaver &operator=(ThreadStateSaver &&) = delete;
+ LIBSHIBOKEN_DISABLE_COPY_MOVE(ThreadStateSaver)
ThreadStateSaver();
~ThreadStateSaver();