aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/libshiboken/sbkconverter_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/libshiboken/sbkconverter_p.h')
-rw-r--r--sources/shiboken6/libshiboken/sbkconverter_p.h117
1 files changed, 50 insertions, 67 deletions
diff --git a/sources/shiboken6/libshiboken/sbkconverter_p.h b/sources/shiboken6/libshiboken/sbkconverter_p.h
index 9e23fa54c..5d8c1977a 100644
--- a/sources/shiboken6/libshiboken/sbkconverter_p.h
+++ b/sources/shiboken6/libshiboken/sbkconverter_p.h
@@ -1,47 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 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
#ifndef SBK_CONVERTER_P_H
#define SBK_CONVERTER_P_H
#include "sbkpython.h"
#include "sbkconverter.h"
+#include "sbkcppstring.h"
#include "sbkstring.h"
#include <limits>
#include <typeinfo>
@@ -252,7 +217,7 @@ struct IntPrimitive : TwoPrimitive<INT>
{
static PyObject *toPython(const void *cppIn)
{
- return PyInt_FromLong(*reinterpret_cast<const INT *>(cppIn));
+ return PyLong_FromLong(*reinterpret_cast<const INT *>(cppIn));
}
static void toCpp(PyObject *pyIn, void *cppOut)
{
@@ -277,7 +242,7 @@ struct IntPrimitive : TwoPrimitive<INT>
}
static PythonToCppFunc isOtherConvertible(PyObject *pyIn)
{
- if (SbkNumber_Check(pyIn))
+ if (PyNumber_Check(pyIn))
return otherToCpp;
return nullptr;
}
@@ -313,12 +278,12 @@ struct Primitive<PY_LONG_LONG> : OnePrimitive<PY_LONG_LONG>
{
PY_LONG_LONG result = PyLong_AsLongLong(pyIn);
if (OverFlowChecker<PY_LONG_LONG>::check(result, pyIn))
- PyErr_SetObject(PyExc_OverflowError, 0);
+ PyErr_SetObject(PyExc_OverflowError, nullptr);
*reinterpret_cast<PY_LONG_LONG * >(cppOut) = result;
}
static PythonToCppFunc isConvertible(PyObject *pyIn)
{
- if (SbkNumber_Check(pyIn))
+ if (PyNumber_Check(pyIn))
return toCpp;
return nullptr;
}
@@ -345,7 +310,7 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG>
}
static PythonToCppFunc isConvertible(PyObject *pyIn)
{
- if (SbkNumber_Check(pyIn))
+ if (PyNumber_Check(pyIn))
return toCpp;
return nullptr;
}
@@ -362,11 +327,11 @@ struct FloatPrimitive : TwoPrimitive<FLOAT>
}
static void toCpp(PyObject *pyIn, void *cppOut)
{
- *reinterpret_cast<FLOAT *>(cppOut) = FLOAT(PyLong_AsLong(pyIn));
+ *reinterpret_cast<FLOAT *>(cppOut) = FLOAT(PyLong_AsDouble(pyIn));
}
static PythonToCppFunc isConvertible(PyObject *pyIn)
{
- if (PyInt_Check(pyIn) || PyLong_Check(pyIn))
+ if (PyLong_Check(pyIn) || PyLong_Check(pyIn))
return toCpp;
return nullptr;
}
@@ -376,7 +341,7 @@ struct FloatPrimitive : TwoPrimitive<FLOAT>
}
static PythonToCppFunc isOtherConvertible(PyObject *pyIn)
{
- if (SbkNumber_Check(pyIn))
+ if (PyNumber_Check(pyIn))
return otherToCpp;
return nullptr;
}
@@ -395,13 +360,13 @@ struct Primitive<bool> : OnePrimitive<bool>
}
static PythonToCppFunc isConvertible(PyObject *pyIn)
{
- if (SbkNumber_Check(pyIn))
+ if (PyNumber_Check(pyIn))
return toCpp;
return nullptr;
}
static void toCpp(PyObject *pyIn, void *cppOut)
{
- *reinterpret_cast<bool *>(cppOut) = PyInt_AS_LONG(pyIn) != 0;
+ *reinterpret_cast<bool *>(cppOut) = PyLong_AS_LONG(pyIn) != 0;
}
};
@@ -429,7 +394,7 @@ struct CharPrimitive : IntPrimitive<CHAR>
}
static PythonToCppFunc isOtherConvertible(PyObject *pyIn)
{
- if (SbkNumber_Check(pyIn))
+ if (PyNumber_Check(pyIn))
return otherToCpp;
return nullptr;
}
@@ -465,7 +430,7 @@ struct Primitive<const char *> : TwoPrimitive<const char *>
}
static void toCpp(PyObject *, void *cppOut)
{
- *((const char **)cppOut) = nullptr;
+ *reinterpret_cast<const char **>(cppOut) = nullptr;
}
static PythonToCppFunc isConvertible(PyObject *pyIn)
{
@@ -490,7 +455,7 @@ struct Primitive<std::string> : TwoPrimitive<std::string>
{
static PyObject *toPython(const void *cppIn)
{
- return Shiboken::String::fromCString(reinterpret_cast<const std::string *>(cppIn)->c_str());
+ return Shiboken::String::fromCppString(*reinterpret_cast<const std::string *>(cppIn));
}
static void toCpp(PyObject *, void *cppOut)
{
@@ -504,7 +469,7 @@ struct Primitive<std::string> : TwoPrimitive<std::string>
}
static void otherToCpp(PyObject *pyIn, void *cppOut)
{
- reinterpret_cast<std::string *>(cppOut)->assign(Shiboken::String::toCString(pyIn));
+ Shiboken::String::toCppString(pyIn, reinterpret_cast<std::string *>(cppOut));
}
static PythonToCppFunc isOtherConvertible(PyObject *pyIn)
{
@@ -514,9 +479,34 @@ struct Primitive<std::string> : TwoPrimitive<std::string>
}
};
+template <>
+struct Primitive<std::wstring> : TwoPrimitive<std::wstring>
+{
+ static PyObject *toPython(const void *cppIn)
+ {
+ return Shiboken::String::fromCppWString(*reinterpret_cast<const std::wstring *>(cppIn));
+ }
+ static void toCpp(PyObject *, void *cppOut)
+ {
+ reinterpret_cast<std::wstring *>(cppOut)->clear();
+ }
+ static PythonToCppFunc isConvertible(PyObject *pyIn)
+ {
+ return pyIn == Py_None ? toCpp : nullptr;
+ }
+ static void otherToCpp(PyObject *pyIn, void *cppOut)
+ {
+ Shiboken::String::toCppWString(pyIn, reinterpret_cast<std::wstring *>(cppOut));
+ }
+ static PythonToCppFunc isOtherConvertible(PyObject *pyIn)
+ {
+ return PyUnicode_Check(pyIn) ? otherToCpp : nullptr;
+ }
+};
+
// nullptr_t
template <>
-struct Primitive<std::nullptr_t> : TwoPrimitive<std::nullptr_t>
+struct Primitive<std::nullptr_t> : OnePrimitive<std::nullptr_t>
{
static PyObject *toPython(const void * /* cppIn */)
{
@@ -532,25 +522,18 @@ struct Primitive<std::nullptr_t> : TwoPrimitive<std::nullptr_t>
return toCpp;
return nullptr;
}
- static void otherToCpp(PyObject * /* pyIn */, void *cppOut)
- {
- *reinterpret_cast<std::nullptr_t *>(cppOut) = nullptr;
- }
- static PythonToCppFunc isOtherConvertible(PyObject *pyIn)
- {
- if (pyIn == nullptr)
- return otherToCpp;
- return nullptr;
- }
};
-namespace Shiboken {
-namespace Conversions {
+namespace Shiboken::Conversions {
+
SbkConverter *createConverterObject(PyTypeObject *type,
PythonToCppFunc toCppPointerConvFunc,
IsConvertibleToCppFunc toCppPointerCheckFunc,
CppToPythonFunc pointerToPythonFunc,
CppToPythonFunc copyToPythonFunc);
-} // namespace Conversions
-} // namespace Shiboken
+
+LIBSHIBOKEN_API void dumpConverters();
+
+} // namespace Shiboken::Conversions
+
#endif // SBK_CONVERTER_P_H