Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8fa8ee3

Browse files
Issue #18701: Remove support of old CPython versions (<3.0) from C code.
1 parent 5c03d20 commit 8fa8ee3

13 files changed

Lines changed: 4 additions & 58 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Core and Builtins
2828
Library
2929
-------
3030

31+
- Issue #18701: Remove support of old CPython versions (<3.0) from C code.
32+
3133
- Issue #18756: Improve error reporting in os.urandom() when the failure
3234
is due to something else than /dev/urandom not existing (for example,
3335
exhausting the file descriptor limit).

Modules/_ctypes/_ctypes.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,7 @@ CDataType_from_buffer(PyObject *type, PyObject *args)
428428
StgDictObject *dict = PyType_stgdict(type);
429429
assert (dict);
430430

431-
if (!PyArg_ParseTuple(args,
432-
#if (PY_VERSION_HEX < 0x02050000)
433-
"O|i:from_buffer",
434-
#else
435-
"O|n:from_buffer",
436-
#endif
437-
&obj, &offset))
431+
if (!PyArg_ParseTuple(args, "O|n:from_buffer", &obj, &offset))
438432
return NULL;
439433

440434
if (-1 == PyObject_AsWriteBuffer(obj, &buffer, &buffer_len))
@@ -447,11 +441,7 @@ CDataType_from_buffer(PyObject *type, PyObject *args)
447441
}
448442
if (dict->size > buffer_len - offset) {
449443
PyErr_Format(PyExc_ValueError,
450-
#if (PY_VERSION_HEX < 0x02050000)
451-
"Buffer size too small (%d instead of at least %d bytes)",
452-
#else
453444
"Buffer size too small (%zd instead of at least %zd bytes)",
454-
#endif
455445
buffer_len, dict->size + offset);
456446
return NULL;
457447
}
@@ -484,13 +474,7 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args)
484474
StgDictObject *dict = PyType_stgdict(type);
485475
assert (dict);
486476

487-
if (!PyArg_ParseTuple(args,
488-
#if (PY_VERSION_HEX < 0x02050000)
489-
"O|i:from_buffer",
490-
#else
491-
"O|n:from_buffer",
492-
#endif
493-
&obj, &offset))
477+
if (!PyArg_ParseTuple(args, "O|n:from_buffer", &obj, &offset))
494478
return NULL;
495479

496480
if (-1 == PyObject_AsReadBuffer(obj, (const void**)&buffer, &buffer_len))
@@ -504,11 +488,7 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args)
504488

505489
if (dict->size > buffer_len - offset) {
506490
PyErr_Format(PyExc_ValueError,
507-
#if (PY_VERSION_HEX < 0x02050000)
508-
"Buffer size too small (%d instead of at least %d bytes)",
509-
#else
510491
"Buffer size too small (%zd instead of at least %zd bytes)",
511-
#endif
512492
buffer_len, dict->size + offset);
513493
return NULL;
514494
}

Modules/_sqlite/cache.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* 3. This notice may not be removed or altered from any source distribution.
2222
*/
2323

24-
#include "sqlitecompat.h"
2524
#include "cache.h"
2625
#include <limits.h>
2726

Modules/_sqlite/connection.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "cursor.h"
3030
#include "prepare_protocol.h"
3131
#include "util.h"
32-
#include "sqlitecompat.h"
3332

3433
#include "pythread.h"
3534

Modules/_sqlite/cursor.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "cursor.h"
2525
#include "module.h"
2626
#include "util.h"
27-
#include "sqlitecompat.h"
2827

2928
PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self);
3029

Modules/_sqlite/prepare_protocol.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* 3. This notice may not be removed or altered from any source distribution.
2222
*/
2323

24-
#include "sqlitecompat.h"
2524
#include "prepare_protocol.h"
2625

2726
int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* args, PyObject* kwargs)

Modules/_sqlite/row.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "row.h"
2525
#include "cursor.h"
26-
#include "sqlitecompat.h"
2726

2827
void pysqlite_row_dealloc(pysqlite_Row* self)
2928
{

Modules/_sqlite/statement.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "microprotocols.h"
2828
#include "prepare_protocol.h"
2929
#include "util.h"
30-
#include "sqlitecompat.h"
3130

3231
/* prototypes */
3332
static int pysqlite_check_remaining_sql(const char* tail);

Modules/_sre.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ static char copyright[] =
7070
/* enables copy/deepcopy handling (work in progress) */
7171
#undef USE_BUILTIN_COPY
7272

73-
#if PY_VERSION_HEX < 0x01060000
74-
#define PyObject_DEL(op) PyMem_DEL((op))
75-
#endif
76-
7773
/* -------------------------------------------------------------------- */
7874

7975
#if defined(_MSC_VER)
@@ -1993,10 +1989,8 @@ join_list(PyObject* list, PyObject* string)
19931989
/* join list elements */
19941990

19951991
PyObject* joiner;
1996-
#if PY_VERSION_HEX >= 0x01060000
19971992
PyObject* function;
19981993
PyObject* args;
1999-
#endif
20001994
PyObject* result;
20011995

20021996
joiner = PySequence_GetSlice(string, 0, 0);
@@ -2008,7 +2002,6 @@ join_list(PyObject* list, PyObject* string)
20082002
return joiner;
20092003
}
20102004

2011-
#if PY_VERSION_HEX >= 0x01060000
20122005
function = PyObject_GetAttrString(joiner, "join");
20132006
if (!function) {
20142007
Py_DECREF(joiner);
@@ -2024,12 +2017,6 @@ join_list(PyObject* list, PyObject* string)
20242017
result = PyObject_CallObject(function, args);
20252018
Py_DECREF(args); /* also removes list */
20262019
Py_DECREF(function);
2027-
#else
2028-
result = call(
2029-
"string", "join",
2030-
PyTuple_Pack(2, list, joiner)
2031-
);
2032-
#endif
20332020
Py_DECREF(joiner);
20342021

20352022
return result;
@@ -2136,7 +2123,6 @@ pattern_findall(PatternObject* self, PyObject* args, PyObject* kw)
21362123

21372124
}
21382125

2139-
#if PY_VERSION_HEX >= 0x02020000
21402126
static PyObject*
21412127
pattern_finditer(PatternObject* pattern, PyObject* args, PyObject* kw)
21422128
{
@@ -2158,7 +2144,6 @@ pattern_finditer(PatternObject* pattern, PyObject* args, PyObject* kw)
21582144

21592145
return iterator;
21602146
}
2161-
#endif
21622147

21632148
static PyObject*
21642149
pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
@@ -2581,10 +2566,8 @@ static PyMethodDef pattern_methods[] = {
25812566
pattern_split_doc},
25822567
{"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS,
25832568
pattern_findall_doc},
2584-
#if PY_VERSION_HEX >= 0x02020000
25852569
{"finditer", (PyCFunction) pattern_finditer, METH_VARARGS|METH_KEYWORDS,
25862570
pattern_finditer_doc},
2587-
#endif
25882571
{"scanner", (PyCFunction) pattern_scanner, METH_VARARGS|METH_KEYWORDS},
25892572
{"__copy__", (PyCFunction) pattern_copy, METH_NOARGS},
25902573
{"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O},

Objects/stringlib/unicodedefs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@
2424
#define STRINGLIB_CHECK PyUnicode_Check
2525
#define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact
2626

27-
#if PY_VERSION_HEX < 0x03000000
28-
#define STRINGLIB_TOSTR PyObject_Unicode
29-
#define STRINGLIB_TOASCII PyObject_Repr
30-
#else
3127
#define STRINGLIB_TOSTR PyObject_Str
3228
#define STRINGLIB_TOASCII PyObject_ASCII
33-
#endif
3429

3530
#define STRINGLIB_WANT_CONTAINS_OBJ 1
3631

0 commit comments

Comments
 (0)