]> granicus.if.org Git - python/commitdiff
Remove all the Python 2.3 compatibility markers (the Python 3 ctypes
authorThomas Heller <theller@ctypes.org>
Fri, 13 Jul 2007 11:49:15 +0000 (11:49 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 13 Jul 2007 11:49:15 +0000 (11:49 +0000)
version is not compatible with Python 2.x anymore).
Remove backwards compatibility code.

15 files changed:
Lib/ctypes/__init__.py
Lib/ctypes/_endian.py
Lib/ctypes/macholib/__init__.py
Lib/ctypes/macholib/dyld.py
Lib/ctypes/macholib/dylib.py
Lib/ctypes/macholib/framework.py
Lib/ctypes/util.py
Lib/ctypes/wintypes.py
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes_test.c
Modules/_ctypes/callbacks.c
Modules/_ctypes/callproc.c
Modules/_ctypes/cfield.c
Modules/_ctypes/malloc_closure.c
Modules/_ctypes/stgdict.c

index 86678ea766cdc63d2fda97f14a820966433bc7ee..f62c345428ad68e03fdb3361911d6f67ac912507 100644 (file)
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 """create and manipulate C data types in Python"""
 
 import os as _os, sys as _sys
index 138b248788d22215873462aee08bb3071602732d..b48bda5c4f20acd0002d4b98b5429351a4d505e7 100644 (file)
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 import sys
 from ctypes import *
 
index 36149d28a1506c56346c127b277702f1e8123fb2..5621defccd61d1c4b0c64b8e136ef4357052dcb3 100644 (file)
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 """
 Enough Mach-O to make your head spin.
 
index c5a41deafdb6c1aa224933ef173ec95c56f1d4c3..837da4d4dfdfa45a32398ef08520a96e31323d09 100644 (file)
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 """
 dyld emulation
 """
index ea3dd38bdfb864fff8fe84687cf5572c49be742a..aa107507bd4a9a8bd61cdfdc008855ccc09d6c10 100644 (file)
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 """
 Generic dylib path manipulation
 """
index dd7fb2f296a895ab628686c36c3f2c15f0fc198d..ad6ed554ba0c221a0673e077f451fc7fbac25f24 100644 (file)
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 """
 Generic framework path manipulation
 """
index 8a9b706a7d51dd2ae79db497f9f492adaa9136f3..2aebc07009bf55040c2f61e1694e8b59471a113e 100644 (file)
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 import sys, os
 
 # find_library(name) returns the pathname of a library, or None.
index e97b31dabc1260f4d4e262170e276c2c9d206a34..fdd08a0541e03b5812be609064bae5c5de5d60d0 100644 (file)
@@ -1,7 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
-
 # The most useful windows datatypes
 from ctypes import *
 
index 5b114804e5bcc96b89003851cd518e42523c27a3..35f087df7ed71be0099f07ea97a4df378737bdc9 100644 (file)
@@ -1,8 +1,3 @@
-/*****************************************************************
-  This file should be kept compatible with Python 2.3, see PEP 291.
- *****************************************************************/
-
-
 /*
   ToDo:
 
@@ -365,11 +360,7 @@ CDataType_repeat(PyObject *self, Py_ssize_t length)
 {
        if (length < 0)
                return PyErr_Format(PyExc_ValueError,
-#if (PY_VERSION_HEX < 0x02050000)
-                                   "Array length must be >= 0, not %d",
-#else
                                    "Array length must be >= 0, not %zd",
-#endif
                                    length);
        return CreateArrayType(self, length);
 }
@@ -1112,9 +1103,6 @@ static PyObject *
 c_wchar_p_from_param(PyObject *type, PyObject *value)
 {
        PyObject *as_parameter;
-#if (PYTHON_API_VERSION < 1012)
-# error not supported
-#endif
        if (value == Py_None) {
                Py_INCREF(Py_None);
                return Py_None;
@@ -1176,9 +1164,6 @@ static PyObject *
 c_char_p_from_param(PyObject *type, PyObject *value)
 {
        PyObject *as_parameter;
-#if (PYTHON_API_VERSION < 1012)
-# error not supported
-#endif
        if (value == Py_None) {
                Py_INCREF(Py_None);
                return Py_None;
@@ -1241,9 +1226,6 @@ c_void_p_from_param(PyObject *type, PyObject *value)
 {
        StgDictObject *stgd;
        PyObject *as_parameter;
-#if (PYTHON_API_VERSION < 1012)
-# error not supported
-#endif
 
 /* None */
        if (value == Py_None) {
@@ -1388,20 +1370,11 @@ c_void_p_from_param(PyObject *type, PyObject *value)
                        "wrong type");
        return NULL;
 }
-#if (PYTHON_API_VERSION >= 1012)
 
 static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_O };
 static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_O };
 static PyMethodDef c_wchar_p_method = { "from_param", c_wchar_p_from_param, METH_O };
 
-#else
-#error
-static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_VARARGS };
-static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_VARARGS };
-static PyMethodDef c_wchar_p_method = { "from_param", c_wchar_p_from_param, METH_VARARGS };
-
-#endif
-
 static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject *kwds,
                                   PyObject *proto, struct fielddesc *fmt)
 {
@@ -1608,27 +1581,11 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                }
                        
                if (ml) {
-#if (PYTHON_API_VERSION >= 1012)
                        PyObject *meth;
                        int x;
                        meth = PyDescr_NewClassMethod(result, ml);
                        if (!meth)
                                return NULL;
-#else
-#error
-                       PyObject *meth, *func;
-                       int x;
-                       func = PyCFunction_New(ml, NULL);
-                       if (!func)
-                               return NULL;
-                       meth = PyObject_CallFunctionObjArgs(
-                               (PyObject *)&PyClassMethod_Type,
-                               func, NULL);
-                       Py_DECREF(func);
-                       if (!meth) {
-                               return NULL;
-                       }
-#endif
                        x = PyDict_SetItemString(result->tp_dict,
                                                 ml->ml_name,
                                                 meth);
@@ -1810,11 +1767,7 @@ converters_from_argtypes(PyObject *ob)
        Py_XDECREF(converters);
        Py_DECREF(ob);
        PyErr_Format(PyExc_TypeError,
-#if (PY_VERSION_HEX < 0x02050000)
-                    "item %d in _argtypes_ has no from_param method",
-#else
                     "item %zd in _argtypes_ has no from_param method",
-#endif
                     i+1);
        return NULL;
 }
@@ -2017,11 +1970,7 @@ unique_key(CDataObject *target, Py_ssize_t index)
        size_t bytes_left;
 
        assert(sizeof(string) - 1 > sizeof(Py_ssize_t) * 2);
-#if (PY_VERSION_HEX < 0x02050000)
-       cp += sprintf(cp, "%x", index);
-#else
        cp += sprintf(cp, "%x", Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
-#endif
        while (target->b_base) {
                bytes_left = sizeof(string) - (cp - string) - 1;
                /* Hex format needs 2 characters per byte */
@@ -2030,11 +1979,7 @@ unique_key(CDataObject *target, Py_ssize_t index)
                                        "ctypes object structure too deep");
                        return NULL;
                }
-#if (PY_VERSION_HEX < 0x02050000)
-               cp += sprintf(cp, ":%x", (int)target->b_index);
-#else
                cp += sprintf(cp, ":%x", Py_SAFE_DOWNCAST(target->b_index, Py_ssize_t, int));
-#endif
                target = target->b_base;
        }
        return PyUnicode_FromStringAndSize(string, cp-string);
@@ -3237,11 +3182,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
                   message is misleading.  See unittests/test_paramflags.py
                 */
                PyErr_Format(PyExc_TypeError,
-#if (PY_VERSION_HEX < 0x02050000)
-                            "call takes exactly %d arguments (%d given)",
-#else
                             "call takes exactly %d arguments (%zd given)",
-#endif
                             inargs_index, actual_args);
                goto error;
        }
@@ -3967,11 +3908,7 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
                if (cache == NULL)
                        return NULL;
        }
-#if (PY_VERSION_HEX < 0x02050000)
-       key = Py_BuildValue("(Oi)", itemtype, length);
-#else
        key = Py_BuildValue("(On)", itemtype, length);
-#endif
        if (!key)
                return NULL;
        result = PyDict_GetItem(cache, key);
@@ -4093,32 +4030,6 @@ static PyNumberMethods Simple_as_number = {
        (inquiry)Simple_bool, /* nb_bool */
 };
 
-#if (PY_VERSION_HEX < 0x02040000)
-/* Only in Python 2.4 and up */
-static PyObject *
-PyTuple_Pack(int n, ...)
-{
-       int i;
-       PyObject *o;
-       PyObject *result;
-       PyObject **items;
-       va_list vargs;
-
-       va_start(vargs, n);
-       result = PyTuple_New(n);
-       if (result == NULL)
-               return NULL;
-       items = ((PyTupleObject *)result)->ob_item;
-       for (i = 0; i < n; i++) {
-               o = va_arg(vargs, PyObject *);
-               Py_INCREF(o);
-               items[i] = o;
-       }
-       va_end(vargs);
-       return result;
-}
-#endif
-
 /* "%s(%s)" % (self.__class__.__name__, self.value) */
 static PyObject *
 Simple_repr(CDataObject *self)
index 8a198a71f0b6e003affcb0a6d635edd9bf800fd6..39d92328a1582308cd144d8b5d8ebc2a224adcf5 100644 (file)
@@ -1,18 +1,5 @@
-/*****************************************************************
-  This file should be kept compatible with Python 2.3, see PEP 291.
- *****************************************************************/
-
-
 #include <Python.h>
 
-/*
-  Backwards compatibility:
-  Python2.2 used LONG_LONG instead of PY_LONG_LONG
-*/
-#if defined(HAVE_LONG_LONG) && !defined(PY_LONG_LONG)
-#define PY_LONG_LONG LONG_LONG
-#endif
-
 #ifdef MS_WIN32
 #include <windows.h>
 #endif
index 497599b8d1107c4c5db0be6023380a0f0fa56de4..82f6cc1ee812c9b8c5617fa5cfdc4fc978359de1 100644 (file)
@@ -1,9 +1,4 @@
-/*****************************************************************
-  This file should be kept compatible with Python 2.3, see PEP 291.
- *****************************************************************/
-
 #include "Python.h"
-#include "compile.h" /* required only for 2.3, as it seems */
 #include "frameobject.h"
 
 #include <ffi.h>
index 6380b1ab5fb4adc6e27cfeb7354807eb8ea2af61..35453d569013e1769b593ef3969799c11f5c66a4 100644 (file)
@@ -1,8 +1,3 @@
-/*****************************************************************
-  This file should be kept compatible with Python 2.3, see PEP 291.
- *****************************************************************/
-
-
 /*
  * History: First version dated from 3/97, derived from my SCMLIB version
  * for win16.
@@ -1525,11 +1520,7 @@ resize(PyObject *self, PyObject *args)
        Py_ssize_t size;
 
        if (!PyArg_ParseTuple(args,
-#if (PY_VERSION_HEX < 0x02050000)
-                             "Oi:resize",
-#else
                              "On:resize",
-#endif
                              &obj, &size))
                return NULL;
 
@@ -1541,11 +1532,7 @@ resize(PyObject *self, PyObject *args)
        }
        if (size < dict->size) {
                PyErr_Format(PyExc_ValueError,
-#if PY_VERSION_HEX < 0x02050000
-                            "minimum size is %d",
-#else
                             "minimum size is %zd",
-#endif
                             dict->size);
                return NULL;
        }
index 8a0dfe7ce2d0c23e0ddeac2cfad9fb43e42d95aa..da7e0fcd281f439e0571a68960918853481f6485 100644 (file)
@@ -1,7 +1,3 @@
-/*****************************************************************
-  This file should be kept compatible with Python 2.3, see PEP 291.
- *****************************************************************/
-
 #include "Python.h"
 
 #include <ffi.h>
@@ -268,19 +264,11 @@ CField_repr(CFieldObject *self)
 
        if (bits)
                result = PyUnicode_FromFormat(
-#if (PY_VERSION_HEX < 0x02050000)
-                       "<Field type=%s, ofs=%d:%d, bits=%d>",
-#else
                        "<Field type=%s, ofs=%zd:%zd, bits=%zd>",
-#endif
                        name, self->offset, size, bits);
        else
                result = PyUnicode_FromFormat(
-#if (PY_VERSION_HEX < 0x02050000)
-                       "<Field type=%s, ofs=%d, size=%d>",
-#else
                        "<Field type=%s, ofs=%zd, size=%zd>",
-#endif
                        name, self->offset, size);
        return result;
 }
@@ -1276,11 +1264,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
        size = PyUnicode_GET_SIZE(value);
        if (size > length) {
                PyErr_Format(PyExc_ValueError,
-#if (PY_VERSION_HEX < 0x02050000)
-                            "string too long (%d, maximum length %d)",
-#else
                             "string too long (%zd, maximum length %zd)",
-#endif
                             size, length);
                Py_DECREF(value);
                return NULL;
@@ -1349,11 +1333,7 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
                ++size;
        } else if (size > length) {
                PyErr_Format(PyExc_ValueError,
-#if (PY_VERSION_HEX < 0x02050000)
-                            "string too long (%d, maximum length %d)",
-#else
                             "string too long (%zd, maximum length %zd)",
-#endif
                             size, length);
                Py_DECREF(value);
                return NULL;
index 4cd5dd6f5a23a2301811791aebefa6588ef782e4..29e9f4c4b2898efb6a85729411e0d705fdb9b039 100644 (file)
@@ -1,7 +1,3 @@
-/*****************************************************************
-  This file should be kept compatible with Python 2.3, see PEP 291.
- *****************************************************************/
-
 #include <Python.h>
 #include <ffi.h>
 #ifdef MS_WIN32
index c35a5154e965d58790d9b85e360448e0fa62f988..b4a6e87f8c4874bd8b3c82dac30421b263db0023 100644 (file)
@@ -1,7 +1,3 @@
-/*****************************************************************
-  This file should be kept compatible with Python 2.3, see PEP 291.
- *****************************************************************/
-
 #include "Python.h"
 #include <ffi.h>
 #ifdef MS_WIN32
@@ -402,11 +398,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
                if (dict == NULL) {
                        Py_DECREF(pair);
                        PyErr_Format(PyExc_TypeError,
-#if (PY_VERSION_HEX < 0x02050000)
-                                    "second item in _fields_ tuple (index %d) must be a C type",
-#else
                                     "second item in _fields_ tuple (index %zd) must be a C type",
-#endif
                                     i);
                        return -1;
                }