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

Skip to content

Commit 84d66a0

Browse files
author
Thomas Heller
committed
Remove all the Python 2.3 compatibility markers (the Python 3 ctypes
version is not compatible with Python 2.x anymore). Remove backwards compatibility code.
1 parent e5095e1 commit 84d66a0

15 files changed

Lines changed: 0 additions & 177 deletions

File tree

Lib/ctypes/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
######################################################################
2-
# This file should be kept compatible with Python 2.3, see PEP 291. #
3-
######################################################################
41
"""create and manipulate C data types in Python"""
52

63
import os as _os, sys as _sys

Lib/ctypes/_endian.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
######################################################################
2-
# This file should be kept compatible with Python 2.3, see PEP 291. #
3-
######################################################################
41
import sys
52
from ctypes import *
63

Lib/ctypes/macholib/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
######################################################################
2-
# This file should be kept compatible with Python 2.3, see PEP 291. #
3-
######################################################################
41
"""
52
Enough Mach-O to make your head spin.
63

Lib/ctypes/macholib/dyld.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
######################################################################
2-
# This file should be kept compatible with Python 2.3, see PEP 291. #
3-
######################################################################
41
"""
52
dyld emulation
63
"""

Lib/ctypes/macholib/dylib.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
######################################################################
2-
# This file should be kept compatible with Python 2.3, see PEP 291. #
3-
######################################################################
41
"""
52
Generic dylib path manipulation
63
"""

Lib/ctypes/macholib/framework.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
######################################################################
2-
# This file should be kept compatible with Python 2.3, see PEP 291. #
3-
######################################################################
41
"""
52
Generic framework path manipulation
63
"""

Lib/ctypes/util.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
######################################################################
2-
# This file should be kept compatible with Python 2.3, see PEP 291. #
3-
######################################################################
41
import sys, os
52

63
# find_library(name) returns the pathname of a library, or None.

Lib/ctypes/wintypes.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
######################################################################
2-
# This file should be kept compatible with Python 2.3, see PEP 291. #
3-
######################################################################
4-
51
# The most useful windows datatypes
62
from ctypes import *
73

Modules/_ctypes/_ctypes.c

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*****************************************************************
2-
This file should be kept compatible with Python 2.3, see PEP 291.
3-
*****************************************************************/
4-
5-
61
/*
72
ToDo:
83
@@ -365,11 +360,7 @@ CDataType_repeat(PyObject *self, Py_ssize_t length)
365360
{
366361
if (length < 0)
367362
return PyErr_Format(PyExc_ValueError,
368-
#if (PY_VERSION_HEX < 0x02050000)
369-
"Array length must be >= 0, not %d",
370-
#else
371363
"Array length must be >= 0, not %zd",
372-
#endif
373364
length);
374365
return CreateArrayType(self, length);
375366
}
@@ -1112,9 +1103,6 @@ static PyObject *
11121103
c_wchar_p_from_param(PyObject *type, PyObject *value)
11131104
{
11141105
PyObject *as_parameter;
1115-
#if (PYTHON_API_VERSION < 1012)
1116-
# error not supported
1117-
#endif
11181106
if (value == Py_None) {
11191107
Py_INCREF(Py_None);
11201108
return Py_None;
@@ -1176,9 +1164,6 @@ static PyObject *
11761164
c_char_p_from_param(PyObject *type, PyObject *value)
11771165
{
11781166
PyObject *as_parameter;
1179-
#if (PYTHON_API_VERSION < 1012)
1180-
# error not supported
1181-
#endif
11821167
if (value == Py_None) {
11831168
Py_INCREF(Py_None);
11841169
return Py_None;
@@ -1241,9 +1226,6 @@ c_void_p_from_param(PyObject *type, PyObject *value)
12411226
{
12421227
StgDictObject *stgd;
12431228
PyObject *as_parameter;
1244-
#if (PYTHON_API_VERSION < 1012)
1245-
# error not supported
1246-
#endif
12471229

12481230
/* None */
12491231
if (value == Py_None) {
@@ -1388,20 +1370,11 @@ c_void_p_from_param(PyObject *type, PyObject *value)
13881370
"wrong type");
13891371
return NULL;
13901372
}
1391-
#if (PYTHON_API_VERSION >= 1012)
13921373

13931374
static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_O };
13941375
static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_O };
13951376
static PyMethodDef c_wchar_p_method = { "from_param", c_wchar_p_from_param, METH_O };
13961377

1397-
#else
1398-
#error
1399-
static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_VARARGS };
1400-
static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_VARARGS };
1401-
static PyMethodDef c_wchar_p_method = { "from_param", c_wchar_p_from_param, METH_VARARGS };
1402-
1403-
#endif
1404-
14051378
static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject *kwds,
14061379
PyObject *proto, struct fielddesc *fmt)
14071380
{
@@ -1608,27 +1581,11 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
16081581
}
16091582

16101583
if (ml) {
1611-
#if (PYTHON_API_VERSION >= 1012)
16121584
PyObject *meth;
16131585
int x;
16141586
meth = PyDescr_NewClassMethod(result, ml);
16151587
if (!meth)
16161588
return NULL;
1617-
#else
1618-
#error
1619-
PyObject *meth, *func;
1620-
int x;
1621-
func = PyCFunction_New(ml, NULL);
1622-
if (!func)
1623-
return NULL;
1624-
meth = PyObject_CallFunctionObjArgs(
1625-
(PyObject *)&PyClassMethod_Type,
1626-
func, NULL);
1627-
Py_DECREF(func);
1628-
if (!meth) {
1629-
return NULL;
1630-
}
1631-
#endif
16321589
x = PyDict_SetItemString(result->tp_dict,
16331590
ml->ml_name,
16341591
meth);
@@ -1810,11 +1767,7 @@ converters_from_argtypes(PyObject *ob)
18101767
Py_XDECREF(converters);
18111768
Py_DECREF(ob);
18121769
PyErr_Format(PyExc_TypeError,
1813-
#if (PY_VERSION_HEX < 0x02050000)
1814-
"item %d in _argtypes_ has no from_param method",
1815-
#else
18161770
"item %zd in _argtypes_ has no from_param method",
1817-
#endif
18181771
i+1);
18191772
return NULL;
18201773
}
@@ -2017,11 +1970,7 @@ unique_key(CDataObject *target, Py_ssize_t index)
20171970
size_t bytes_left;
20181971

20191972
assert(sizeof(string) - 1 > sizeof(Py_ssize_t) * 2);
2020-
#if (PY_VERSION_HEX < 0x02050000)
2021-
cp += sprintf(cp, "%x", index);
2022-
#else
20231973
cp += sprintf(cp, "%x", Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
2024-
#endif
20251974
while (target->b_base) {
20261975
bytes_left = sizeof(string) - (cp - string) - 1;
20271976
/* Hex format needs 2 characters per byte */
@@ -2030,11 +1979,7 @@ unique_key(CDataObject *target, Py_ssize_t index)
20301979
"ctypes object structure too deep");
20311980
return NULL;
20321981
}
2033-
#if (PY_VERSION_HEX < 0x02050000)
2034-
cp += sprintf(cp, ":%x", (int)target->b_index);
2035-
#else
20361982
cp += sprintf(cp, ":%x", Py_SAFE_DOWNCAST(target->b_index, Py_ssize_t, int));
2037-
#endif
20381983
target = target->b_base;
20391984
}
20401985
return PyUnicode_FromStringAndSize(string, cp-string);
@@ -3237,11 +3182,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
32373182
message is misleading. See unittests/test_paramflags.py
32383183
*/
32393184
PyErr_Format(PyExc_TypeError,
3240-
#if (PY_VERSION_HEX < 0x02050000)
3241-
"call takes exactly %d arguments (%d given)",
3242-
#else
32433185
"call takes exactly %d arguments (%zd given)",
3244-
#endif
32453186
inargs_index, actual_args);
32463187
goto error;
32473188
}
@@ -3967,11 +3908,7 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
39673908
if (cache == NULL)
39683909
return NULL;
39693910
}
3970-
#if (PY_VERSION_HEX < 0x02050000)
3971-
key = Py_BuildValue("(Oi)", itemtype, length);
3972-
#else
39733911
key = Py_BuildValue("(On)", itemtype, length);
3974-
#endif
39753912
if (!key)
39763913
return NULL;
39773914
result = PyDict_GetItem(cache, key);
@@ -4093,32 +4030,6 @@ static PyNumberMethods Simple_as_number = {
40934030
(inquiry)Simple_bool, /* nb_bool */
40944031
};
40954032

4096-
#if (PY_VERSION_HEX < 0x02040000)
4097-
/* Only in Python 2.4 and up */
4098-
static PyObject *
4099-
PyTuple_Pack(int n, ...)
4100-
{
4101-
int i;
4102-
PyObject *o;
4103-
PyObject *result;
4104-
PyObject **items;
4105-
va_list vargs;
4106-
4107-
va_start(vargs, n);
4108-
result = PyTuple_New(n);
4109-
if (result == NULL)
4110-
return NULL;
4111-
items = ((PyTupleObject *)result)->ob_item;
4112-
for (i = 0; i < n; i++) {
4113-
o = va_arg(vargs, PyObject *);
4114-
Py_INCREF(o);
4115-
items[i] = o;
4116-
}
4117-
va_end(vargs);
4118-
return result;
4119-
}
4120-
#endif
4121-
41224033
/* "%s(%s)" % (self.__class__.__name__, self.value) */
41234034
static PyObject *
41244035
Simple_repr(CDataObject *self)

Modules/_ctypes/_ctypes_test.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
/*****************************************************************
2-
This file should be kept compatible with Python 2.3, see PEP 291.
3-
*****************************************************************/
4-
5-
61
#include <Python.h>
72

8-
/*
9-
Backwards compatibility:
10-
Python2.2 used LONG_LONG instead of PY_LONG_LONG
11-
*/
12-
#if defined(HAVE_LONG_LONG) && !defined(PY_LONG_LONG)
13-
#define PY_LONG_LONG LONG_LONG
14-
#endif
15-
163
#ifdef MS_WIN32
174
#include <windows.h>
185
#endif

0 commit comments

Comments
 (0)