]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 59680-59695 via svnmerge from
authorChristian Heimes <christian@cheimes.de>
Fri, 4 Jan 2008 03:06:10 +0000 (03:06 +0000)
committerChristian Heimes <christian@cheimes.de>
Fri, 4 Jan 2008 03:06:10 +0000 (03:06 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r59686 | guido.van.rossum | 2008-01-04 00:54:04 +0100 (Fri, 04 Jan 2008) | 2 lines

  Bug #1301: fixed a bad assert in _tkinter.
........
  r59687 | raymond.hettinger | 2008-01-04 01:01:15 +0100 (Fri, 04 Jan 2008) | 3 lines

  Finish-up the struct module optimizations started at the Iceland NFS sprint.
........
  r59688 | christian.heimes | 2008-01-04 01:04:52 +0100 (Fri, 04 Jan 2008) | 1 line

  Fixed #1687: plistlib.py restricts <integer> to Python int when writing
........
  r59689 | christian.heimes | 2008-01-04 01:37:34 +0100 (Fri, 04 Jan 2008) | 1 line

  Bug #1481296: Fixed long(float('nan'))!=0L.
........
  r59691 | andrew.kuchling | 2008-01-04 02:15:50 +0100 (Fri, 04 Jan 2008) | 1 line

  Markup fixes; grammar tweaks
........
  r59692 | andrew.kuchling | 2008-01-04 02:16:12 +0100 (Fri, 04 Jan 2008) | 1 line

  Add items
........
  r59694 | christian.heimes | 2008-01-04 02:48:50 +0100 (Fri, 04 Jan 2008) | 1 line

  Fixed math.copysign() on Windows
........
  r59695 | christian.heimes | 2008-01-04 03:03:25 +0100 (Fri, 04 Jan 2008) | 1 line

  Filled in some XXX comments
........

Doc/library/msvcrt.rst
Doc/whatsnew/2.6.rst
Lib/plat-mac/plistlib.py
Lib/test/regrtest.py
Lib/test/test_long.py
Modules/_struct.c
Modules/_tkinter.c
Modules/mathmodule.c
Objects/longobject.c

index 9fa49daf27f79873767199a7d8cf32ca34feb6e6..a30578829400b75d329b3b778bd07b94c6018aae 100644 (file)
@@ -101,9 +101,9 @@ Console I/O
    
 .. function:: getwch()
 
-   Wide char variant of `func:getch`, returns unicode.
+   Wide char variant of :func:`getch`, returning a Unicode value.
    
-   ..versionadded:: 2.6
+   .. versionadded:: 2.6
    
 
 .. function:: getche()
@@ -114,9 +114,9 @@ Console I/O
 
 .. function:: getwche()
 
-   Wide char variant of `func:getche`, returns unicode.
+   Wide char variant of :func:`getche`, returning a Unicode value.
    
-   ..versionadded:: 2.6
+   .. versionadded:: 2.6
 
 
 .. function:: putch(char)
@@ -126,9 +126,9 @@ Console I/O
    
 .. function:: putwch(unicode_char)
 
-   Wide char variant of `func:putch`, accepts unicode.
+   Wide char variant of :func:`putch`, accepting a Unicode value.
    
-   ..versionadded:: 2.6
+   .. versionadded:: 2.6
    
 
 .. function:: ungetch(char)
@@ -139,9 +139,9 @@ Console I/O
    
 .. function:: ungetwch(unicode_char)
 
-   Wide char variant of `func:ungetch`, accepts unicode.
+   Wide char variant of :func:`ungetch`, accepting a Unicode value.
    
-   ..versionadded:: 2.6
+   .. versionadded:: 2.6
 
 
 .. _msvcrt-other:
index 4a8eb76f1af240864bb30b3fca487e845e4c83a6..7bd9cbd50e28431ce573de58175d3051a13012bb 100644 (file)
@@ -552,6 +552,14 @@ Here are all of the changes that Python 2.6 makes to the core Python language.
 
   .. Patch 1507
 
+* More floating-point features were also added.  The :func:`float` function
+  will now turn the strings ``+nan`` and ``-nan`` into the corresponding
+  IEEE 754 Not a Number values, and ``+inf`` and ``-inf`` into 
+  positive or negative infinity.  This works on any platform with 
+  IEEE 754 semantics.  (Contributed by Christian Heimes.)
+
+  .. Patch 1635.
+
 * Changes to the :class:`Exception` interface
   as dictated by :pep:`352` continue to be made.  For 2.6, 
   the :attr:`message` attribute is being deprecated in favor of the
@@ -1055,14 +1063,35 @@ Changes to Python's build process and to the C API include:
   ``"mant_dig"`` (number of digits in the mantissa), ``"epsilon"``
   (smallest difference between 1.0 and the next largest value
   representable), and several others.
+  (Contributed by Christian Heimes.)
 
   .. Issue 1534
 
+* Python's C API now includes two functions for case-insensitive string
+  comparisions, ``PyOS_stricmp(char*, char*)``
+  and ``PyOS_strnicmp(char*, char*, Py_ssize_t)``.
+  (Contributed by Christian Heimes.)
+
+  .. Issue 1635
+
+* Some macros were renamed.  :cmacro:`Py_Size()` became :cmacro:`Py_SIZE()`,
+  :cmacro:`Py_Type()` became :cmacro:`Py_TYPE()`, and
+  :cmacro:`Py_Refcnt()` became :cmacro:`Py_REFCNT()`.  Macros for backward
+  compatibility are still available for Python 2.6.
+
+  .. Issue 1629: XXX why was this done?
+
 .. ======================================================================
 
 
-Port-Specific Changes
----------------------
+Port-Specific Changes: Windows
+-----------------------------------
+
+* The :mod:`msvcrt` module now supports 
+  both the normal and wide char variants of the console I/O
+  API.  The :func:`getwch` function reads a keypress and returns a Unicode 
+  value, as does the :func:`getwche` function.  The :func:`putwch` function
+  takes a Unicode character and writes it to the console.
 
 Platform-specific changes go here.
 
@@ -1089,9 +1118,15 @@ Some of the more notable changes are:
 Porting to Python 2.6
 =====================
 
-This section lists previously described changes that may require changes to your
+This section lists previously described changes, and a few
+esoteric bugfixes, that may require changes to your
 code:
 
+* The :method:`__init__` method of :class:`collections.deque`
+  now clears any existing contents of the deque
+  before adding elements from the iterable.  This change makes the
+  behavior match that of ``list.__init__()``.  
+
 * The :mod:`socket` module exception :exc:`socket.error` now inherits
   from :exc:`IOError`.  Previously it wasn't a subclass of
   :exc:`StandardError` but now it is, through :exc:`IOError`.
index 72dfa2e414e0e6623bf980e5fdc4a7d5bfb8f4fb..2a80e845f4bb4c71e2f4a36aed2bc57836c75da5 100644 (file)
@@ -242,8 +242,8 @@ class PlistWriter(DumbXMLWriter):
                 self.simpleElement("true")
             else:
                 self.simpleElement("false")
-        elif isinstance(value, int):
-            self.simpleElement("integer", str(value))
+        elif isinstance(value, (int, long)):
+            self.simpleElement("integer", "%d" % value)
         elif isinstance(value, float):
             self.simpleElement("real", repr(value))
         elif isinstance(value, dict):
index bd79c97be0fba213de8f13c86149d3010e77c3c6..790d769c97a496cc52f7e91ddbae76dbface5e85 100755 (executable)
@@ -771,8 +771,8 @@ def dash_R_cleanup(fs, ps, pic, abcs):
     dircache.reset()
     linecache.clearcache()
     mimetypes._default_mime_types()
-    struct._cache.clear()
     filecmp._cache.clear()
+    struct._clearcache()
     doctest.master = None
 
     # Collect cyclic trash.
index 8be8bff249a6253c13e329e6affa11a8f0159efc..223ef7cae655fd0070baaf8fe18323568f3a2e39 100644 (file)
@@ -537,6 +537,10 @@ class LongTest(unittest.TestCase):
         # conversion to string should fail
         self.assertRaises(ValueError, format, 3, "s")
 
+    def test_nan_inf(self):
+        self.assertRaises(OverflowError, long, float('inf'))
+        self.assertEqual(long(float('nan')), 0L)
+
 def test_main():
     test_support.run_unittest(LongTest)
 
index 3c02bc9982db26ac3128c374259bf37fbcc752c6..278b03537c2744fb73ec4a9605d5ee17ba17b565 100644 (file)
@@ -1464,11 +1464,28 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds)
 
        assert(PyStruct_Check(self));
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:Struct", kwlist,
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:Struct", kwlist,
                                         &o_format))
                return -1;
 
-       Py_INCREF(o_format);
+       if (PyUnicode_Check(o_format)) {
+               o_format = PyUnicode_AsASCIIString(o_format);
+               if (o_format == NULL)
+                       return -1;
+       }
+       /* XXX support buffer interface, too */
+       else {
+               Py_INCREF(o_format);
+       }
+
+       if (!PyString_Check(o_format)) {
+               Py_DECREF(o_format);
+               PyErr_Format(PyExc_TypeError,
+                            "Struct() argument 1 must be bytes, not %.200s",
+                            Py_TYPE(o_format)->tp_name);
+               return -1;
+       }
+
        Py_XDECREF(soself->s_format);
        soself->s_format = o_format;
 
@@ -1861,12 +1878,226 @@ PyTypeObject PyStructType = {
        PyObject_Del,           /* tp_free */
 };
 
+
+/* ---- Standalone functions  ---- */
+
+#define MAXCACHE 100
+static PyObject *cache = NULL;
+
+static PyObject *
+cache_struct(PyObject *fmt)
+{
+       PyObject * s_object;
+
+       if (cache == NULL) {
+               cache = PyDict_New();
+               if (cache == NULL)
+                       return NULL;
+       }
+
+       s_object = PyDict_GetItem(cache, fmt);
+       if (s_object != NULL) {
+               Py_INCREF(s_object);
+               return s_object;
+       }
+
+       s_object = PyObject_CallFunctionObjArgs((PyObject *)(&PyStructType), fmt, NULL);
+       if (s_object != NULL) {
+               if (PyDict_Size(cache) >= MAXCACHE)
+                       PyDict_Clear(cache);
+               /* Attempt to cache the result */
+               if (PyDict_SetItem(cache, fmt, s_object) == -1)
+                       PyErr_Clear();
+       }
+       return s_object;
+}
+
+PyDoc_STRVAR(clearcache_doc,
+"Clear the internal cache.");
+
+static PyObject *
+clearcache(PyObject *self)
+{
+       if (cache != NULL)
+               PyDict_Clear(cache);
+       Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(calcsize_doc,
+"Return size of C struct described by format string fmt.");
+
+static PyObject *
+calcsize(PyObject *self, PyObject *fmt)
+{
+       Py_ssize_t n;
+       PyObject *s_object = cache_struct(fmt);
+       if (s_object == NULL)
+               return NULL;
+       n = ((PyStructObject *)s_object)->s_size;
+       Py_DECREF(s_object);
+       return PyLong_FromSsize_t(n);
+}
+
+PyDoc_STRVAR(pack_doc,
+"Return string containing values v1, v2, ... packed according to fmt.");
+
+static PyObject *
+pack(PyObject *self, PyObject *args)
+{
+       PyObject *s_object, *fmt, *newargs, *result;
+       Py_ssize_t n = PyTuple_GET_SIZE(args);
+
+       if (n == 0) {
+               PyErr_SetString(PyExc_TypeError, "missing format argument");
+               return NULL;
+       }
+       fmt = PyTuple_GET_ITEM(args, 0);
+       newargs = PyTuple_GetSlice(args, 1, n);
+       if (newargs == NULL)
+               return NULL;
+
+       s_object = cache_struct(fmt);
+       if (s_object == NULL) {
+               Py_DECREF(newargs);
+               return NULL;
+       }
+       result = s_pack(s_object, newargs);
+       Py_DECREF(newargs);
+       Py_DECREF(s_object);
+       return result;
+}
+
+PyDoc_STRVAR(pack_into_doc,
+"Pack the values v1, v2, ... according to fmt.\n\
+Write the packed bytes into the writable buffer buf starting at offset.");
+
+static PyObject *
+pack_into(PyObject *self, PyObject *args)
+{
+       PyObject *s_object, *fmt, *newargs, *result;
+       Py_ssize_t n = PyTuple_GET_SIZE(args);
+
+       if (n == 0) {
+               PyErr_SetString(PyExc_TypeError, "missing format argument");
+               return NULL;
+       }
+       fmt = PyTuple_GET_ITEM(args, 0);
+       newargs = PyTuple_GetSlice(args, 1, n);
+       if (newargs == NULL)
+               return NULL;
+
+       s_object = cache_struct(fmt);
+       if (s_object == NULL) {
+               Py_DECREF(newargs);
+               return NULL;
+       }
+       result = s_pack_into(s_object, newargs);
+       Py_DECREF(newargs);
+       Py_DECREF(s_object);
+       return result;
+}
+
+PyDoc_STRVAR(unpack_doc,
+"Unpack the string containing packed C structure data, according to fmt.\n\
+Requires len(string) == calcsize(fmt).");
+
+static PyObject *
+unpack(PyObject *self, PyObject *args)
+{
+       PyObject *s_object, *fmt, *inputstr, *result;
+
+       if (!PyArg_UnpackTuple(args, "unpack", 2, 2, &fmt, &inputstr))
+               return NULL;
+
+       s_object = cache_struct(fmt);
+       if (s_object == NULL)
+               return NULL;
+       result = s_unpack(s_object, inputstr);
+       Py_DECREF(s_object);
+       return result;
+}
+
+PyDoc_STRVAR(unpack_from_doc,
+"Unpack the buffer, containing packed C structure data, according to\n\
+fmt, starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).");
+
+static PyObject *
+unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
+{
+       PyObject *s_object, *fmt, *newargs, *result;
+       Py_ssize_t n = PyTuple_GET_SIZE(args);
+
+       if (n == 0) {
+               PyErr_SetString(PyExc_TypeError, "missing format argument");
+               return NULL;
+       }
+       fmt = PyTuple_GET_ITEM(args, 0);
+       newargs = PyTuple_GetSlice(args, 1, n);
+       if (newargs == NULL)
+               return NULL;
+
+       s_object = cache_struct(fmt);
+       if (s_object == NULL) {
+               Py_DECREF(newargs);
+               return NULL;
+       }
+       result = s_unpack_from(s_object, newargs, kwds);
+       Py_DECREF(newargs);
+       Py_DECREF(s_object);
+       return result;
+}
+
+static struct PyMethodDef module_functions[] = {
+       {"_clearcache", (PyCFunction)clearcache,        METH_NOARGS,    clearcache_doc},
+       {"calcsize",    calcsize,       METH_O,         calcsize_doc},
+       {"pack",        pack,           METH_VARARGS,   pack_doc},
+       {"pack_into",   pack_into,      METH_VARARGS,   pack_into_doc},
+       {"unpack",      unpack,         METH_VARARGS,   unpack_doc},
+       {"unpack_from", (PyCFunction)unpack_from,       
+                       METH_VARARGS|METH_KEYWORDS,     unpack_from_doc},
+       {NULL,   NULL}          /* sentinel */
+};
+
+
 /* Module initialization */
 
+PyDoc_STRVAR(module_doc,
+"Functions to convert between Python values and C structs.\n\
+Python strings are used to hold the data representing the C struct\n\
+and also as format strings to describe the layout of data in the C struct.\n\
+\n\
+The optional first format char indicates byte order, size and alignment:\n\
+ @: native order, size & alignment (default)\n\
+ =: native order, std. size & alignment\n\
+ <: little-endian, std. size & alignment\n\
+ >: big-endian, std. size & alignment\n\
+ !: same as >\n\
+\n\
+The remaining chars indicate types of args and must match exactly;\n\
+these can be preceded by a decimal repeat count:\n\
+  x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;\n\
+  h:short; H:unsigned short; i:int; I:unsigned int;\n\
+  l:long; L:unsigned long; f:float; d:double.\n\
+Special cases (preceding decimal count indicates length):\n\
+  s:string (array of char); p: pascal string (with count byte).\n\
+Special case (only available in native format):\n\
+  P:an integer type that is wide enough to hold a pointer.\n\
+Special case (not in native mode unless 'long long' in platform C):\n\
+  q:long long; Q:unsigned long long\n\
+Whitespace between formats is ignored.\n\
+\n\
+The variable struct.error is an exception raised on errors.\n");
+
 PyMODINIT_FUNC
 init_struct(void)
 {
-       PyObject *m = Py_InitModule("_struct", NULL);
+       PyObject *ver, *m;
+
+       ver = PyString_FromString("0.2");
+       if (ver == NULL)
+               return;
+
+       m = Py_InitModule3("_struct", module_functions, module_doc);
        if (m == NULL)
                return;
 
@@ -1947,6 +2178,8 @@ init_struct(void)
        Py_INCREF((PyObject*)&PyStructType);
        PyModule_AddObject(m, "Struct", (PyObject*)&PyStructType);
 
+       PyModule_AddObject(m, "__version__", ver);
+
        PyModule_AddIntConstant(m, "_PY_STRUCT_RANGE_CHECKING", 1);
 #ifdef PY_STRUCT_OVERFLOW_MASKING
        PyModule_AddIntConstant(m, "_PY_STRUCT_OVERFLOW_MASKING", 1);
index 0e9390404309621ccbda7d0a2027409c631eca22..97f85f939c66db72ef10cc0fe626d82326a0102a 100644 (file)
@@ -898,10 +898,12 @@ AsObj(PyObject *value)
                /* This #ifdef assumes that Tcl uses UCS-2.
                   See TCL_UTF_MAX test above. */
 #if defined(Py_UNICODE_WIDE) && TCL_UTF_MAX == 3
-               Tcl_UniChar *outbuf;
+               Tcl_UniChar *outbuf = NULL;
                Py_ssize_t i;
-               assert(size < size * sizeof(Tcl_UniChar));
-               outbuf = (Tcl_UniChar*)ckalloc(size * sizeof(Tcl_UniChar));
+               size_t allocsize = ((size_t)size) * sizeof(Tcl_UniChar);
+               if (allocsize >= size)
+                       outbuf = (Tcl_UniChar*)ckalloc(allocsize);
+               /* Else overflow occurred, and we take the next exit */
                if (!outbuf) {
                        PyErr_NoMemory();
                        return NULL;
index 8992baed837c5e220e8c1eb13404dac7787e1c3a..62f9f0b5bf62567843d2a1c6a400ff9ea062f06a 100644 (file)
@@ -133,14 +133,16 @@ FUNC1(cos, cos,
       "cos(x)\n\nReturn the cosine of x (measured in radians).")
 FUNC1(cosh, cosh,
       "cosh(x)\n\nReturn the hyperbolic cosine of x.")
-#if defined(MS_WINDOWS) || defined(HAVE_COPYSIGN)
+
 #ifdef MS_WINDOWS
-FUNC2(copysign, _copysign,
-#else
-FUNC2(copysign, copysign,
+#  define copysign _copysign
+#  define HAVE_COPYSIGN 1
 #endif
-    "copysign(x,y)\n\nReturn x with the sign of y.");
+#ifdef HAVE_COPYSIGN
+FUNC2(copysign, copysign,
+      "copysign(x,y)\n\nReturn x with the sign of y.");
 #endif
+
 FUNC1(exp, exp,
       "exp(x)\n\nReturn e raised to the power of x.")
 FUNC1(fabs, fabs,
@@ -383,7 +385,7 @@ static PyMethodDef math_methods[] = {
        {"atan",        math_atan,      METH_O,         math_atan_doc},
        {"atan2",       math_atan2,     METH_VARARGS,   math_atan2_doc},
        {"ceil",        math_ceil,      METH_O,         math_ceil_doc},
-#if defined(MS_WINDOWS) || defined(HAVE_COPYSIGN)
+#ifdef HAVE_COPYSIGN
        {"copysign",    math_copysign,  METH_VARARGS,   math_copysign_doc},
 #endif
        {"cos",         math_cos,       METH_O,         math_cos_doc},
index dc459fd01ea0c516d40ffa68e061fa6209a9140c..40aaba1e181e71dc3e3067bd435c5f33d454b7ce 100644 (file)
@@ -254,6 +254,9 @@ PyLong_FromDouble(double dval)
                        "cannot convert float infinity to int");
                return NULL;
        }
+       if (Py_IS_NAN(dval)) {
+               return PyLong_FromLong(0L);
+       }
        if (dval < 0.0) {
                neg = 1;
                dval = -dval;