Skip to content

Commit 1fc1012

Browse files
committed
Remove traces of Python 2: libshiboken
A few leftovers from Python 2 compatibility that were around in our code base. Pick-to: 6.8 Change-Id: I38d97ef217186da1eb5a1d8c5be33884ae9a1cc8 Reviewed-by: Friedemann Kleint <[email protected]>
1 parent 66ca585 commit 1fc1012

File tree

6 files changed

+14
-50
lines changed

6 files changed

+14
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ using `setup.py build`:
9090
* `--ignore-git`, will skip the fetching and checkout steps for supermodule
9191
and all submodules.
9292
* `--limited-api=yes|no`, default yes if applicable. Set or clear the limited
93-
API flag. Ignored for Python 2.
93+
API flag.
9494
* `--module-subset`, allows for specifying the Qt modules to be built.
9595
A minimal set is: `--module-subset=Core,Gui,Test,Widgets`.
9696
* `--package-timestamp`, allows specifying the timestamp that will be used as

sources/shiboken6/libshiboken/pep384impl.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ static PyTypeObject *getFunctionType(void)
743743
"from types import FunctionType as result\n";
744744
return reinterpret_cast<PyTypeObject *>(PepRun_GetResult(prog));
745745
}
746-
#endif // Py_LIMITED_API || Python 2
746+
#endif // Py_LIMITED_API
747747

748748
/*****************************************************************************
749749
*
@@ -920,12 +920,6 @@ PyTypeObject *PepType_Type_tp_new(PyTypeObject *metatype, PyObject *args, PyObje
920920
*
921921
*/
922922

923-
#ifdef Py_LIMITED_API
924-
// We keep these definitions local, because they don't work in Python 2.
925-
# define PyUnicode_GET_LENGTH(op) PyUnicode_GetLength((PyObject *)(op))
926-
# define PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar((PyObject *)(u), (i))
927-
#endif // Py_LIMITED_API
928-
929923
PyObject *
930924
_Pep_PrivateMangle(PyObject *self, PyObject *name)
931925
{
@@ -934,15 +928,15 @@ _Pep_PrivateMangle(PyObject *self, PyObject *name)
934928
* This function is modelled after _Py_Mangle, but is optimized
935929
* a little for our purpose.
936930
*/
937-
if (PyUnicode_READ_CHAR(name, 0) != '_' ||
938-
PyUnicode_READ_CHAR(name, 1) != '_') {
931+
if (PyUnicode_ReadChar(name, 0) != '_' ||
932+
PyUnicode_ReadChar(name, 1) != '_') {
939933
Py_INCREF(name);
940934
return name;
941935
}
942-
const Py_ssize_t nlen = PyUnicode_GET_LENGTH(name);
936+
const Py_ssize_t nlen = PyUnicode_GetLength(name);
943937
/* Don't mangle __id__ or names with dots. */
944-
if ((PyUnicode_READ_CHAR(name, nlen-1) == '_' &&
945-
PyUnicode_READ_CHAR(name, nlen-2) == '_') ||
938+
if ((PyUnicode_ReadChar(name, nlen-1) == '_' &&
939+
PyUnicode_ReadChar(name, nlen-2) == '_') ||
946940
PyUnicode_FindChar(name, '.', 0, nlen, 1) != -1) {
947941
Py_INCREF(name);
948942
return name;
@@ -953,10 +947,10 @@ _Pep_PrivateMangle(PyObject *self, PyObject *name)
953947
// PYSIDE-1436: _Py_Mangle is no longer exposed; implement it always.
954948
// The rest of this function is our own implementation of _Py_Mangle.
955949
// Please compare the original function in compile.c .
956-
Py_ssize_t plen = PyUnicode_GET_LENGTH(privateobj.object());
950+
Py_ssize_t plen = PyUnicode_GetLength(privateobj.object());
957951
/* Strip leading underscores from class name */
958952
Py_ssize_t ipriv = 0;
959-
while (PyUnicode_READ_CHAR(privateobj.object(), ipriv) == '_')
953+
while (PyUnicode_ReadChar(privateobj.object(), ipriv) == '_')
960954
ipriv++;
961955
if (ipriv == plen) {
962956
Py_INCREF(name);

sources/shiboken6/libshiboken/pep384impl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ LIBSHIBOKEN_API void PepException_SetArgs(PyObject *ex, PyObject *args);
225225
// needed a debug Python.
226226
//
227227

228-
// PyUnicode_GetSize is deprecated in favor of PyUnicode_GetLength.
229-
#define PepUnicode_GetLength(op) PyUnicode_GetLength((PyObject *)(op))
230-
231228
// Unfortunately, we cannot ask this at runtime
232229
// #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
233230
// FIXME: Python 3.10: Replace _PepUnicode_AsString by PyUnicode_AsUTF8

sources/shiboken6/libshiboken/sbkpython.h

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,11 @@
1515
#if defined(slots) && (defined(__GNUC__) || defined(_MSC_VER) || defined(__clang__))
1616
# pragma push_macro("slots")
1717
# undef slots
18-
/*
19-
* Python 2 has function _Py_Mangle directly in Python.h .
20-
* This creates wrong language binding unless we define 'extern "C"' here.
21-
*/
22-
extern "C" {
23-
/*
24-
* Python 2 uses the "register" keyword, which is deprecated in C++ 11
25-
* and forbidden in C++17.
26-
*/
27-
# if defined(__clang__)
28-
# pragma clang diagnostic push
29-
# pragma clang diagnostic ignored "-Wdeprecated-register"
30-
# endif
3118

19+
extern "C" {
3220
# include <Python.h>
33-
34-
# if defined(__clang__)
35-
# pragma clang diagnostic pop
36-
# endif
3721
}
22+
3823
# include <structmember.h>
3924
// Now we have the usual variables from Python.h .
4025
# include "shibokenmacros.h"
@@ -45,21 +30,9 @@ extern "C" {
4530
#else
4631

4732
extern "C" {
48-
/*
49-
* Python 2 uses the "register" keyword, which is deprecated in C++ 11
50-
* and forbidden in C++17.
51-
*/
52-
# if defined(__clang__)
53-
# pragma clang diagnostic push
54-
# pragma clang diagnostic ignored "-Wdeprecated-register"
55-
# endif
56-
5733
# include <Python.h>
58-
59-
# if defined(__clang__)
60-
# pragma clang diagnostic pop
61-
# endif
6234
}
35+
6336
# include <structmember.h>
6437
// Now we have the usual variables from Python.h .
6538
# include "shibokenmacros.h"

sources/shiboken6/libshiboken/sbkstring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Py_ssize_t len(PyObject *str)
152152
return 0;
153153

154154
if (PyUnicode_Check(str))
155-
return PepUnicode_GetLength(str);
155+
return PyUnicode_GetLength(str);
156156

157157
if (PyBytes_Check(str))
158158
return PyBytes_GET_SIZE(str);

sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def function(self, func_name, func):
311311
ret = self.result_type()
312312
signature = get_sig(func, 'existence')
313313
sig = stringify(signature) if signature is not None else None
314-
if sig is not None and func_name not in ("next", "__next__", "__div__"):
314+
if sig is not None:
315315
with self.fmt.function(func_name, sig) as key:
316316
ret[key] = sig
317317
return ret

0 commit comments

Comments
 (0)