[Python-3000-checkins] r56342 - in python/branches/py3k-struni: 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

thomas.heller python-3000-checkins at python.org
Fri Jul 13 13:49:15 CEST 2007


Author: thomas.heller
Date: Fri Jul 13 13:49:15 2007
New Revision: 56342

Modified:
   python/branches/py3k-struni/Lib/ctypes/__init__.py
   python/branches/py3k-struni/Lib/ctypes/_endian.py
   python/branches/py3k-struni/Lib/ctypes/macholib/__init__.py
   python/branches/py3k-struni/Lib/ctypes/macholib/dyld.py
   python/branches/py3k-struni/Lib/ctypes/macholib/dylib.py
   python/branches/py3k-struni/Lib/ctypes/macholib/framework.py
   python/branches/py3k-struni/Lib/ctypes/util.py
   python/branches/py3k-struni/Lib/ctypes/wintypes.py
   python/branches/py3k-struni/Modules/_ctypes/_ctypes.c
   python/branches/py3k-struni/Modules/_ctypes/_ctypes_test.c
   python/branches/py3k-struni/Modules/_ctypes/callbacks.c
   python/branches/py3k-struni/Modules/_ctypes/callproc.c
   python/branches/py3k-struni/Modules/_ctypes/cfield.c
   python/branches/py3k-struni/Modules/_ctypes/malloc_closure.c
   python/branches/py3k-struni/Modules/_ctypes/stgdict.c
Log:
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.


Modified: python/branches/py3k-struni/Lib/ctypes/__init__.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/__init__.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/__init__.py	Fri Jul 13 13:49:15 2007
@@ -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

Modified: python/branches/py3k-struni/Lib/ctypes/_endian.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/_endian.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/_endian.py	Fri Jul 13 13:49:15 2007
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 import sys
 from ctypes import *
 

Modified: python/branches/py3k-struni/Lib/ctypes/macholib/__init__.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/macholib/__init__.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/macholib/__init__.py	Fri Jul 13 13:49:15 2007
@@ -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.
 

Modified: python/branches/py3k-struni/Lib/ctypes/macholib/dyld.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/macholib/dyld.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/macholib/dyld.py	Fri Jul 13 13:49:15 2007
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 """
 dyld emulation
 """

Modified: python/branches/py3k-struni/Lib/ctypes/macholib/dylib.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/macholib/dylib.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/macholib/dylib.py	Fri Jul 13 13:49:15 2007
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 """
 Generic dylib path manipulation
 """

Modified: python/branches/py3k-struni/Lib/ctypes/macholib/framework.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/macholib/framework.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/macholib/framework.py	Fri Jul 13 13:49:15 2007
@@ -1,6 +1,3 @@
-######################################################################
-#  This file should be kept compatible with Python 2.3, see PEP 291. #
-######################################################################
 """
 Generic framework path manipulation
 """

Modified: python/branches/py3k-struni/Lib/ctypes/util.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/util.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/util.py	Fri Jul 13 13:49:15 2007
@@ -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.

Modified: python/branches/py3k-struni/Lib/ctypes/wintypes.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/wintypes.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/wintypes.py	Fri Jul 13 13:49:15 2007
@@ -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 *
 

Modified: python/branches/py3k-struni/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/py3k-struni/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/py3k-struni/Modules/_ctypes/_ctypes.c	Fri Jul 13 13:49:15 2007
@@ -1,8 +1,3 @@
-/*****************************************************************
-  This file should be kept compatible with Python 2.3, see PEP 291.
- *****************************************************************/
-
-
 /*
   ToDo:
 
@@ -365,11 +360,7 @@
 {
 	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 @@
 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 @@
 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 @@
 {
 	StgDictObject *stgd;
 	PyObject *as_parameter;
-#if (PYTHON_API_VERSION < 1012)
-# error not supported
-#endif
 
 /* None */
 	if (value == Py_None) {
@@ -1388,20 +1370,11 @@
 			"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 @@
 		}
 			
 		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 @@
 	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 @@
 	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 @@
 					"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 @@
 		   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 @@
 		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 @@
 	(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)

Modified: python/branches/py3k-struni/Modules/_ctypes/_ctypes_test.c
==============================================================================
--- python/branches/py3k-struni/Modules/_ctypes/_ctypes_test.c	(original)
+++ python/branches/py3k-struni/Modules/_ctypes/_ctypes_test.c	Fri Jul 13 13:49:15 2007
@@ -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

Modified: python/branches/py3k-struni/Modules/_ctypes/callbacks.c
==============================================================================
--- python/branches/py3k-struni/Modules/_ctypes/callbacks.c	(original)
+++ python/branches/py3k-struni/Modules/_ctypes/callbacks.c	Fri Jul 13 13:49:15 2007
@@ -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>

Modified: python/branches/py3k-struni/Modules/_ctypes/callproc.c
==============================================================================
--- python/branches/py3k-struni/Modules/_ctypes/callproc.c	(original)
+++ python/branches/py3k-struni/Modules/_ctypes/callproc.c	Fri Jul 13 13:49:15 2007
@@ -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 @@
 	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 @@
 	}
 	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;
 	}

Modified: python/branches/py3k-struni/Modules/_ctypes/cfield.c
==============================================================================
--- python/branches/py3k-struni/Modules/_ctypes/cfield.c	(original)
+++ python/branches/py3k-struni/Modules/_ctypes/cfield.c	Fri Jul 13 13:49:15 2007
@@ -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 @@
 
 	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 @@
 	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 @@
 		++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;

Modified: python/branches/py3k-struni/Modules/_ctypes/malloc_closure.c
==============================================================================
--- python/branches/py3k-struni/Modules/_ctypes/malloc_closure.c	(original)
+++ python/branches/py3k-struni/Modules/_ctypes/malloc_closure.c	Fri Jul 13 13:49:15 2007
@@ -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

Modified: python/branches/py3k-struni/Modules/_ctypes/stgdict.c
==============================================================================
--- python/branches/py3k-struni/Modules/_ctypes/stgdict.c	(original)
+++ python/branches/py3k-struni/Modules/_ctypes/stgdict.c	Fri Jul 13 13:49:15 2007
@@ -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 @@
 		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;
 		}


More information about the Python-3000-checkins mailing list