[Python-checkins] r64038 - in python/branches/tlee-ast-optimize: Doc/library/_ast.rst Doc/library/abc.rst Doc/library/ctypes.rst Doc/library/inspect.rst Doc/library/logging.rst Doc/library/parser.rst Doc/library/python.rst Doc/reference/simple_stmts.rst Doc/whatsnew/2.5.rst Doc/whatsnew/2.6.rst Include/Python.h Include/object.h Lib/UserDict.py Lib/_abcoll.py Lib/ctypes/__init__.py Lib/ctypes/test/test_errno.py Lib/ctypes/test/test_pep3118.py Lib/inspect.py Lib/test/test_inspect.py Lib/test/test_py3kwarn.py Lib/test/test_urllib2net.py Mac/Modules/MacOS.c Mac/Modules/ae/_AEmodule.c Mac/Modules/file/_Filemodule.c Misc/NEWS Modules/_ctypes/_ctypes.c Modules/_ctypes/callbacks.c Modules/_ctypes/callproc.c Modules/_ctypes/ctypes.h Modules/_ctypes/stgdict.c Modules/_heapqmodule.c Objects/abstract.c Python/ast.c configure configure.in pyconfig.h.in

thomas.lee python-checkins at python.org
Sun Jun 8 10:59:53 CEST 2008


Author: thomas.lee
Date: Sun Jun  8 10:59:51 2008
New Revision: 64038

Log:
Merged revisions 63957-64035 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r63961 | thomas.heller | 2008-06-06 03:29:38 +1000 (Fri, 06 Jun 2008) | 1 line
  
  Fix preprocessor statement.
........
  r63962 | thomas.heller | 2008-06-06 03:51:15 +1000 (Fri, 06 Jun 2008) | 3 lines
  
  Backport from py3k: Implement the new buffer interface from pep3118
  for ctypes instances.  Closes issue #2404.
........
  r63963 | thomas.heller | 2008-06-06 03:52:59 +1000 (Fri, 06 Jun 2008) | 3 lines
  
  Backport from py3k: Implement the new buffer interface from pep3118
  for ctypes instances.  Closes issue #2404.
........
  r63965 | benjamin.peterson | 2008-06-06 08:39:34 +1000 (Fri, 06 Jun 2008) | 2 lines
  
  use the more idomatic while True
........
  r63967 | benjamin.peterson | 2008-06-06 09:02:33 +1000 (Fri, 06 Jun 2008) | 2 lines
  
  revert 63965 for preformance reasons
........
  r63970 | andrew.kuchling | 2008-06-06 09:33:54 +1000 (Fri, 06 Jun 2008) | 1 line
  
  Document 'utc' parameter
........
  r63971 | andrew.kuchling | 2008-06-06 09:35:31 +1000 (Fri, 06 Jun 2008) | 1 line
  
  Add various items
........
  r63972 | andrew.kuchling | 2008-06-06 09:35:48 +1000 (Fri, 06 Jun 2008) | 1 line
  
  Grammar fix
........
  r63975 | neal.norwitz | 2008-06-06 14:47:01 +1000 (Fri, 06 Jun 2008) | 3 lines
  
  Aldo Cortesi confirmed this is still needed for OpenBSD 4.2 and 4.3.
  (I didn't regen configure, since I don't have a working autoconf.)
........
  r63976 | georg.brandl | 2008-06-06 17:34:50 +1000 (Fri, 06 Jun 2008) | 2 lines
  
  Markup fix.
........
  r63977 | thomas.heller | 2008-06-06 18:33:46 +1000 (Fri, 06 Jun 2008) | 31 lines
  
  Issue #1798: Add ctypes calling convention that allows safe access of errno.
  
  ctypes maintains thread-local storage that has space for two error
  numbers: private copies of the system 'errno' value and, on Windows,
  the system error code accessed by the GetLastError() and
  SetLastError() api functions.
    
  Foreign functions created with CDLL(..., use_errno=True), when called,
  swap the system 'errno' value with the private copy just before the
  actual function call, and swapped again immediately afterwards.  The
  'use_errno' parameter defaults to False, in this case 'ctypes_errno'
  is not touched.
  
  On Windows, foreign functions created with CDLL(...,
  use_last_error=True) or WinDLL(..., use_last_error=True) swap the
  system LastError value with the ctypes private copy.
  
  The values are also swapped immeditately before and after ctypes
  callback functions are called, if the callbacks are constructed using
  the new optional use_errno parameter set to True: CFUNCTYPE(...,
  use_errno=TRUE) or WINFUNCTYPE(..., use_errno=True).
  
  New ctypes functions are provided to access the ctypes private copies
  from Python:
  
  - ctypes.set_errno(value) and ctypes.set_last_error(value) store
    'value' in the private copy and returns the previous value.
  
  - ctypes.get_errno() and ctypes.get_last_error() returns the current
    ctypes private copies value.
........
  r63982 | georg.brandl | 2008-06-06 20:43:43 +1000 (Fri, 06 Jun 2008) | 2 lines
  
  Fix brackets.
........
  r63988 | thomas.heller | 2008-06-07 04:37:55 +1000 (Sat, 07 Jun 2008) | 3 lines
  
  Performance improvement: Use PyDict_Get/SetItem instead of
  PyDict_Get/SetItemString.
........
  r63989 | thomas.heller | 2008-06-07 04:42:11 +1000 (Sat, 07 Jun 2008) | 2 lines
  
  Add a reminder for the maintainer of whatsnew.
........
  r63991 | thomas.heller | 2008-06-07 06:05:15 +1000 (Sat, 07 Jun 2008) | 5 lines
  
  Document the new ctypes features.
  
  It would be great if someone could review both sematics, markup, and
  spelling, and correct the versionadded and versionchanges markers.
........
  r63997 | ronald.oussoren | 2008-06-07 07:31:33 +1000 (Sat, 07 Jun 2008) | 2 lines
  
  Fix build issue on OSX 10.4
........
  r63998 | raymond.hettinger | 2008-06-07 07:47:51 +1000 (Sat, 07 Jun 2008) | 1 line
  
  Issue 3501: Make heapq support both __le__ and __lt__.
........
  r64002 | travis.oliphant | 2008-06-07 08:33:21 +1000 (Sat, 07 Jun 2008) | 1 line
  
  Add long double check support to configure test.
........
  r64003 | travis.oliphant | 2008-06-07 08:39:47 +1000 (Sat, 07 Jun 2008) | 1 line
  
  Remove locking part of new buffer protocol.
........
  r64012 | facundo.batista | 2008-06-07 23:36:36 +1000 (Sat, 07 Jun 2008) | 4 lines
  
  
  Finished bug #2451.  Fixed the retrying part to make it 
  more robust.
........
  r64014 | georg.brandl | 2008-06-08 01:59:10 +1000 (Sun, 08 Jun 2008) | 3 lines
  
  Factor out docstring dedenting from inspect.getdoc() into inspect.cleandoc()
  to ease standalone use of the algorithm.
........
  r64015 | georg.brandl | 2008-06-08 02:04:01 +1000 (Sun, 08 Jun 2008) | 2 lines
  
  Revert unwanted changes.
........
  r64016 | georg.brandl | 2008-06-08 02:16:12 +1000 (Sun, 08 Jun 2008) | 2 lines
  
  Register IterableUserDict as a MutableMapping.
........
  r64018 | georg.brandl | 2008-06-08 03:03:28 +1000 (Sun, 08 Jun 2008) | 2 lines
  
  #3057: Fix the MutableMapping ABC to use the 2.6 dict interface.
........
  r64019 | georg.brandl | 2008-06-08 03:11:00 +1000 (Sun, 08 Jun 2008) | 2 lines
  
  Backport docs for abc module to 2.6.
........
  r64021 | georg.brandl | 2008-06-08 04:16:12 +1000 (Sun, 08 Jun 2008) | 2 lines
  
  X-ref to numbers module.
........
  r64022 | georg.brandl | 2008-06-08 04:17:37 +1000 (Sun, 08 Jun 2008) | 3 lines
  
  Document the "st" API, to avoid confusion with the "new" AST.
  Add a note about using the new AST module.
........
  r64028 | benjamin.peterson | 2008-06-08 06:44:48 +1000 (Sun, 08 Jun 2008) | 2 lines
  
  capitalization nit
........
  r64031 | benjamin.peterson | 2008-06-08 12:05:33 +1000 (Sun, 08 Jun 2008) | 2 lines
  
  change Py3k backquote warning to a SyntaxWarning and add a test
........


Added:
   python/branches/tlee-ast-optimize/Doc/library/_ast.rst
      - copied unchanged from r64031, /python/trunk/Doc/library/_ast.rst
   python/branches/tlee-ast-optimize/Doc/library/abc.rst
      - copied unchanged from r64031, /python/trunk/Doc/library/abc.rst
   python/branches/tlee-ast-optimize/Lib/ctypes/test/test_errno.py
      - copied unchanged from r64031, /python/trunk/Lib/ctypes/test/test_errno.py
   python/branches/tlee-ast-optimize/Lib/ctypes/test/test_pep3118.py
      - copied unchanged from r64031, /python/trunk/Lib/ctypes/test/test_pep3118.py
Modified:
   python/branches/tlee-ast-optimize/   (props changed)
   python/branches/tlee-ast-optimize/Doc/library/ctypes.rst
   python/branches/tlee-ast-optimize/Doc/library/inspect.rst
   python/branches/tlee-ast-optimize/Doc/library/logging.rst
   python/branches/tlee-ast-optimize/Doc/library/parser.rst
   python/branches/tlee-ast-optimize/Doc/library/python.rst
   python/branches/tlee-ast-optimize/Doc/reference/simple_stmts.rst
   python/branches/tlee-ast-optimize/Doc/whatsnew/2.5.rst
   python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst
   python/branches/tlee-ast-optimize/Include/Python.h
   python/branches/tlee-ast-optimize/Include/object.h
   python/branches/tlee-ast-optimize/Lib/UserDict.py
   python/branches/tlee-ast-optimize/Lib/_abcoll.py
   python/branches/tlee-ast-optimize/Lib/ctypes/__init__.py
   python/branches/tlee-ast-optimize/Lib/inspect.py
   python/branches/tlee-ast-optimize/Lib/test/test_inspect.py
   python/branches/tlee-ast-optimize/Lib/test/test_py3kwarn.py
   python/branches/tlee-ast-optimize/Lib/test/test_urllib2net.py
   python/branches/tlee-ast-optimize/Mac/Modules/MacOS.c
   python/branches/tlee-ast-optimize/Mac/Modules/ae/_AEmodule.c
   python/branches/tlee-ast-optimize/Mac/Modules/file/_Filemodule.c
   python/branches/tlee-ast-optimize/Misc/NEWS
   python/branches/tlee-ast-optimize/Modules/_ctypes/_ctypes.c
   python/branches/tlee-ast-optimize/Modules/_ctypes/callbacks.c
   python/branches/tlee-ast-optimize/Modules/_ctypes/callproc.c
   python/branches/tlee-ast-optimize/Modules/_ctypes/ctypes.h
   python/branches/tlee-ast-optimize/Modules/_ctypes/stgdict.c
   python/branches/tlee-ast-optimize/Modules/_heapqmodule.c
   python/branches/tlee-ast-optimize/Objects/abstract.c
   python/branches/tlee-ast-optimize/Python/ast.c
   python/branches/tlee-ast-optimize/configure
   python/branches/tlee-ast-optimize/configure.in
   python/branches/tlee-ast-optimize/pyconfig.h.in

Modified: python/branches/tlee-ast-optimize/Doc/library/ctypes.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/ctypes.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/ctypes.rst	Sun Jun  8 10:59:51 2008
@@ -1337,14 +1337,14 @@
 way is to instantiate one of the following classes:
 
 
-.. class:: CDLL(name, mode=DEFAULT_MODE, handle=None)
+.. class:: CDLL(name, mode=DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False)
 
    Instances of this class represent loaded shared libraries. Functions in these
    libraries use the standard C calling convention, and are assumed to return
    ``int``.
 
 
-.. class:: OleDLL(name, mode=DEFAULT_MODE, handle=None)
+.. class:: OleDLL(name, mode=DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False)
 
    Windows only: Instances of this class represent loaded shared libraries,
    functions in these libraries use the ``stdcall`` calling convention, and are
@@ -1354,7 +1354,7 @@
    failure, an :class:`WindowsError` is automatically raised.
 
 
-.. class:: WinDLL(name, mode=DEFAULT_MODE, handle=None)
+.. class:: WinDLL(name, mode=DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False)
 
    Windows only: Instances of this class represent loaded shared libraries,
    functions in these libraries use the ``stdcall`` calling convention, and are
@@ -1387,6 +1387,29 @@
 The *mode* parameter can be used to specify how the library is loaded.  For
 details, consult the ``dlopen(3)`` manpage, on Windows, *mode* is ignored.
 
+The *use_errno* parameter, when set to True, enables a ctypes
+mechanism that allows to access the system `errno` error number in a
+safe way.  `ctypes` maintains a thread-local copy of the systems
+`errno` variable; if you call foreign functions created with
+`use_errno=True` then the `errno` value before the function call is
+swapped with the ctypes private copy, the same happens immediately
+after the function call.
+
+The function `ctypes.get_errno()` returns the value of the ctypes
+private copy, and the function `ctypes.set_errno(value)` changes the
+ctypes private copy to `value` and returns the former value.
+
+The *use_last_error* parameter, when set to True, enables the same
+mechanism for the Windows error code which is managed by the
+GetLastError() and SetLastError() Windows api functions;
+`ctypes.get_last_error()` and `ctypes.set_last_error(value)` are used
+to request and change the ctypes private copy of the windows error
+code.
+
+.. versionchanged:: 2.6
+
+The `use_errno` and `use_last_error` parameters were added in Python
+2.6.
 
 .. data:: RTLD_GLOBAL
    :noindex:
@@ -1585,18 +1608,26 @@
 type and the argument types of the function.
 
 
-.. function:: CFUNCTYPE(restype, *argtypes)
+.. function:: CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False)
 
    The returned function prototype creates functions that use the standard C
    calling convention.  The function will release the GIL during the call.
+   If `use_errno` is set to True, the ctypes private copy of the system `errno`
+   variable is exchanged with the real `errno` value bafore and after the call;
+   `use_last_error` does the same for the Windows error code.
+
+   .. versionchanged:: 2.6
+
+   The optional `use_errno` and `use_last_error` parameters were added
+   in Python 2.6.
 
 
-.. function:: WINFUNCTYPE(restype, *argtypes)
+.. function:: WINFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False)
 
    Windows only: The returned function prototype creates functions that use the
    ``stdcall`` calling convention, except on Windows CE where :func:`WINFUNCTYPE`
    is the same as :func:`CFUNCTYPE`.  The function will release the GIL during the
-   call.
+   call. `use_errno` and `use_last_error` have the same meaning as above.
 
 
 .. function:: PYFUNCTYPE(restype, *argtypes)
@@ -1848,7 +1879,22 @@
 .. function:: GetLastError()
 
    Windows only: Returns the last error code set by Windows in the calling thread.
+   This function calls the Windows `GetLastError()` function directly,
+   it does not return the ctypes-private copy of the error code.
+
+.. function:: get_errno()
+
+   Returns the current value of the ctypes-private copy of the system
+   `errno` variable in the calling thread.
+
+   .. versionadded:: 2.6
+
+.. function:: get_last_error()
 
+   Windows only: returns the current value of the ctypes-private copy of the system
+   `LastError` variable in the calling thread.
+
+   .. versionadded:: 2.6
 
 .. function:: memmove(dst, src, count)
 
@@ -1901,6 +1947,22 @@
    other systems ``('ascii', 'strict')``.
 
 
+.. function:: set_errno(value)
+
+   Set the  current value of the ctypes-private copy of the system
+   `errno` variable in the calling thread to `value` and return the
+   previous value.
+
+   .. versionadded:: 2.6
+
+.. function:: set_last_error(value)
+
+   Windows only: set the current value of the ctypes-private copy of
+   the system `LastError` variable in the calling thread to `value`
+   and return the previous value.
+
+   .. versionadded:: 2.6
+
 .. function:: sizeof(obj_or_type)
 
    Returns the size in bytes of a ctypes type or instance memory buffer. Does the

Modified: python/branches/tlee-ast-optimize/Doc/library/inspect.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/inspect.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/inspect.rst	Sun Jun  8 10:59:51 2008
@@ -376,13 +376,9 @@
 Retrieving source code
 ----------------------
 
-
 .. function:: getdoc(object)
 
-   Get the documentation string for an object. All tabs are expanded to spaces.  To
-   clean up docstrings that are indented to line up with blocks of code, any
-   whitespace than can be uniformly removed from the second line onwards is
-   removed.
+   Get the documentation string for an object, cleaned up with :func:`cleandoc`.
 
 
 .. function:: getcomments(object)
@@ -429,6 +425,15 @@
    cannot be retrieved.
 
 
+.. function:: cleandoc(doc)
+
+   Clean up indentation from docstrings that are indented to line up with blocks
+   of code.  Any whitespace that can be uniformly removed from the second line
+   onwards is removed.  Also, all tabs are expanded to spaces.
+
+   .. versionadded:: 2.6
+
+
 .. _inspect-classes-functions:
 
 Classes and functions

Modified: python/branches/tlee-ast-optimize/Doc/library/logging.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/logging.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/logging.rst	Sun Jun  8 10:59:51 2008
@@ -1645,7 +1645,7 @@
 timed intervals.
 
 
-.. class:: TimedRotatingFileHandler(filename [,when [,interval [,backupCount[, encoding[, delay]]]]])
+.. class:: TimedRotatingFileHandler(filename [,when [,interval [,backupCount[, encoding[, delay[, utc]]]]]])
 
    Returns a new instance of the :class:`TimedRotatingFileHandler` class. The
    specified file is opened and used as the stream for logging. On rotating it also
@@ -1653,7 +1653,7 @@
    *interval*.
 
    You can use the *when* to specify the type of *interval*. The list of possible
-   values is, note that they are not case sensitive:
+   values is below.  Note that they are not case sensitive.
 
    +----------------+-----------------------+
    | Value          | Type of interval      |
@@ -1674,7 +1674,11 @@
    The system will save old log files by appending extensions to the filename.
    The extensions are date-and-time based, using the strftime format
    ``%Y-%m-%d_%H-%M-%S`` or a leading portion thereof, depending on the
-   rollover interval. If *backupCount* is nonzero, at most *backupCount* files
+   rollover interval. 
+   If the *utc* argument is true, times in UTC will be used; otherwise
+   local time is used.
+
+   If *backupCount* is nonzero, at most *backupCount* files
    will be kept, and if more would be created when rollover occurs, the oldest
    one is deleted. The deletion logic uses the interval to determine which
    files to delete, so changing the interval may leave old files lying around.

Modified: python/branches/tlee-ast-optimize/Doc/library/parser.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/parser.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/parser.rst	Sun Jun  8 10:59:51 2008
@@ -24,6 +24,17 @@
 code fragment as a string because parsing is performed in a manner identical to
 the code forming the application.  It is also faster.
 
+.. note::
+
+   From Python 2.5 onward, it's much more convenient to cut in at the Abstract
+   Syntax Tree (AST) generation and compilation stage, using the :mod:`ast`
+   module.
+
+   The :mod:`parser` module exports the names documented here also with "st"
+   replaced by "ast"; this is a legacy from the time when there was no other
+   AST and has nothing to do with the AST found in Python 2.5.  This is also the
+   reason for the functions' keyword arguments being called *ast*, not *st*.
+
 There are a few things to note about this module which are important to making
 use of the data structures created.  This is not a tutorial on editing the parse
 trees for Python code, but some examples of using the :mod:`parser` module are
@@ -34,9 +45,9 @@
 to :ref:`reference-index`.  The parser
 itself is created from a grammar specification defined in the file
 :file:`Grammar/Grammar` in the standard Python distribution.  The parse trees
-stored in the AST objects created by this module are the actual output from the
+stored in the ST objects created by this module are the actual output from the
 internal parser when created by the :func:`expr` or :func:`suite` functions,
-described below.  The AST objects created by :func:`sequence2ast` faithfully
+described below.  The ST objects created by :func:`sequence2st` faithfully
 simulate those structures.  Be aware that the values of the sequences which are
 considered "correct" will vary from one version of Python to another as the
 formal grammar for the language is revised.  However, transporting code from one
@@ -46,7 +57,7 @@
 language constructs.  The parse trees are not typically compatible from one
 version to another, whereas source code has always been forward-compatible.
 
-Each element of the sequences returned by :func:`ast2list` or :func:`ast2tuple`
+Each element of the sequences returned by :func:`st2list` or :func:`st2tuple`
 has a simple form.  Sequences representing non-terminal elements in the grammar
 always have a length greater than one.  The first element is an integer which
 identifies a production in the grammar.  These integers are given symbolic names
@@ -69,19 +80,19 @@
 terminal symbols are defined in the C header file :file:`Include/token.h` and
 the Python module :mod:`token`.
 
-The AST objects are not required to support the functionality of this module,
+The ST objects are not required to support the functionality of this module,
 but are provided for three purposes: to allow an application to amortize the
 cost of processing complex parse trees, to provide a parse tree representation
 which conserves memory space when compared to the Python list or tuple
 representation, and to ease the creation of additional modules in C which
 manipulate parse trees.  A simple "wrapper" class may be created in Python to
-hide the use of AST objects.
+hide the use of ST objects.
 
 The :mod:`parser` module defines functions for a few distinct purposes.  The
-most important purposes are to create AST objects and to convert AST objects to
+most important purposes are to create ST objects and to convert ST objects to
 other representations such as parse trees and compiled code objects, but there
 are also functions which serve to query the type of parse tree represented by an
-AST object.
+ST object.
 
 
 .. seealso::
@@ -94,20 +105,20 @@
       testing node values.
 
 
-.. _creating-asts:
+.. _creating-sts:
 
-Creating AST Objects
---------------------
+Creating ST Objects
+-------------------
 
-AST objects may be created from source code or from a parse tree. When creating
-an AST object from source, different functions are used to create the ``'eval'``
+ST objects may be created from source code or from a parse tree. When creating
+an ST object from source, different functions are used to create the ``'eval'``
 and ``'exec'`` forms.
 
 
 .. function:: expr(source)
 
    The :func:`expr` function parses the parameter *source* as if it were an input
-   to ``compile(source, 'file.py', 'eval')``.  If the parse succeeds, an AST object
+   to ``compile(source, 'file.py', 'eval')``.  If the parse succeeds, an ST object
    is created to hold the internal parse tree representation, otherwise an
    appropriate exception is thrown.
 
@@ -115,22 +126,22 @@
 .. function:: suite(source)
 
    The :func:`suite` function parses the parameter *source* as if it were an input
-   to ``compile(source, 'file.py', 'exec')``.  If the parse succeeds, an AST object
+   to ``compile(source, 'file.py', 'exec')``.  If the parse succeeds, an ST object
    is created to hold the internal parse tree representation, otherwise an
    appropriate exception is thrown.
 
 
-.. function:: sequence2ast(sequence)
+.. function:: sequence2st(sequence)
 
    This function accepts a parse tree represented as a sequence and builds an
    internal representation if possible.  If it can validate that the tree conforms
    to the Python grammar and all nodes are valid node types in the host version of
-   Python, an AST object is created from the internal representation and returned
+   Python, an ST object is created from the internal representation and returned
    to the called.  If there is a problem creating the internal representation, or
    if the tree cannot be validated, a :exc:`ParserError` exception is thrown.  An
-   AST object created this way should not be assumed to compile correctly; normal
-   exceptions thrown by compilation may still be initiated when the AST object is
-   passed to :func:`compileast`.  This may indicate problems not related to syntax
+   ST object created this way should not be assumed to compile correctly; normal
+   exceptions thrown by compilation may still be initiated when the ST object is
+   passed to :func:`compilest`.  This may indicate problems not related to syntax
    (such as a :exc:`MemoryError` exception), but may also be due to constructs such
    as the result of parsing ``del f(0)``, which escapes the Python parser but is
    checked by the bytecode compiler.
@@ -142,31 +153,31 @@
    symbols in the input tree.
 
 
-.. function:: tuple2ast(sequence)
+.. function:: tuple2st(sequence)
 
-   This is the same function as :func:`sequence2ast`.  This entry point is
+   This is the same function as :func:`sequence2st`.  This entry point is
    maintained for backward compatibility.
 
 
-.. _converting-asts:
+.. _converting-sts:
 
-Converting AST Objects
-----------------------
+Converting ST Objects
+---------------------
 
-AST objects, regardless of the input used to create them, may be converted to
+ST objects, regardless of the input used to create them, may be converted to
 parse trees represented as list- or tuple- trees, or may be compiled into
 executable code objects.  Parse trees may be extracted with or without line
 numbering information.
 
 
-.. function:: ast2list(ast[, line_info])
+.. function:: st2list(ast[, line_info])
 
-   This function accepts an AST object from the caller in *ast* and returns a
+   This function accepts an ST object from the caller in *ast* and returns a
    Python list representing the equivalent parse tree.  The resulting list
    representation can be used for inspection or the creation of a new parse tree in
    list form.  This function does not fail so long as memory is available to build
    the list representation.  If the parse tree will only be used for inspection,
-   :func:`ast2tuple` should be used instead to reduce memory consumption and
+   :func:`st2tuple` should be used instead to reduce memory consumption and
    fragmentation.  When the list representation is required, this function is
    significantly faster than retrieving a tuple representation and converting that
    to nested lists.
@@ -177,29 +188,29 @@
    This information is omitted if the flag is false or omitted.
 
 
-.. function:: ast2tuple(ast[, line_info])
+.. function:: st2tuple(ast[, line_info])
 
-   This function accepts an AST object from the caller in *ast* and returns a
+   This function accepts an ST object from the caller in *ast* and returns a
    Python tuple representing the equivalent parse tree.  Other than returning a
-   tuple instead of a list, this function is identical to :func:`ast2list`.
+   tuple instead of a list, this function is identical to :func:`st2list`.
 
    If *line_info* is true, line number information will be included for all
    terminal tokens as a third element of the list representing the token.  This
    information is omitted if the flag is false or omitted.
 
 
-.. function:: compileast(ast[, filename='<ast>'])
+.. function:: compilest(ast[, filename='<syntax-tree>'])
 
    .. index:: builtin: eval
 
-   The Python byte compiler can be invoked on an AST object to produce code objects
+   The Python byte compiler can be invoked on an ST object to produce code objects
    which can be used as part of an :keyword:`exec` statement or a call to the
    built-in :func:`eval` function. This function provides the interface to the
    compiler, passing the internal parse tree from *ast* to the parser, using the
    source file name specified by the *filename* parameter. The default value
-   supplied for *filename* indicates that the source was an AST object.
+   supplied for *filename* indicates that the source was an ST object.
 
-   Compiling an AST object may result in exceptions related to compilation; an
+   Compiling an ST object may result in exceptions related to compilation; an
    example would be a :exc:`SyntaxError` caused by the parse tree for ``del f(0)``:
    this statement is considered legal within the formal grammar for Python but is
    not a legal language construct.  The :exc:`SyntaxError` raised for this
@@ -209,15 +220,15 @@
    tree.
 
 
-.. _querying-asts:
+.. _querying-sts:
 
-Queries on AST Objects
-----------------------
+Queries on ST Objects
+---------------------
 
-Two functions are provided which allow an application to determine if an AST was
+Two functions are provided which allow an application to determine if an ST was
 created as an expression or a suite.  Neither of these functions can be used to
-determine if an AST was created from source code via :func:`expr` or
-:func:`suite` or from a parse tree via :func:`sequence2ast`.
+determine if an ST was created from source code via :func:`expr` or
+:func:`suite` or from a parse tree via :func:`sequence2st`.
 
 
 .. function:: isexpr(ast)
@@ -227,19 +238,19 @@
    When *ast* represents an ``'eval'`` form, this function returns true, otherwise
    it returns false.  This is useful, since code objects normally cannot be queried
    for this information using existing built-in functions.  Note that the code
-   objects created by :func:`compileast` cannot be queried like this either, and
+   objects created by :func:`compilest` cannot be queried like this either, and
    are identical to those created by the built-in :func:`compile` function.
 
 
 .. function:: issuite(ast)
 
-   This function mirrors :func:`isexpr` in that it reports whether an AST object
+   This function mirrors :func:`isexpr` in that it reports whether an ST object
    represents an ``'exec'`` form, commonly known as a "suite."  It is not safe to
    assume that this function is equivalent to ``not isexpr(ast)``, as additional
    syntactic fragments may be supported in the future.
 
 
-.. _ast-errors:
+.. _st-errors:
 
 Exceptions and Error Handling
 -----------------------------
@@ -255,12 +266,12 @@
    generally produced for validation failures rather than the built in
    :exc:`SyntaxError` thrown during normal parsing. The exception argument is
    either a string describing the reason of the failure or a tuple containing a
-   sequence causing the failure from a parse tree passed to :func:`sequence2ast`
-   and an explanatory string.  Calls to :func:`sequence2ast` need to be able to
+   sequence causing the failure from a parse tree passed to :func:`sequence2st`
+   and an explanatory string.  Calls to :func:`sequence2st` need to be able to
    handle either type of exception, while calls to other functions in the module
    will only need to be aware of the simple string values.
 
-Note that the functions :func:`compileast`, :func:`expr`, and :func:`suite` may
+Note that the functions :func:`compilest`, :func:`expr`, and :func:`suite` may
 throw exceptions which are normally thrown by the parsing and compilation
 process.  These include the built in exceptions :exc:`MemoryError`,
 :exc:`OverflowError`, :exc:`SyntaxError`, and :exc:`SystemError`.  In these
@@ -268,49 +279,49 @@
 Refer to the descriptions of each function for detailed information.
 
 
-.. _ast-objects:
+.. _st-objects:
 
-AST Objects
------------
+ST Objects
+----------
 
-Ordered and equality comparisons are supported between AST objects. Pickling of
-AST objects (using the :mod:`pickle` module) is also supported.
+Ordered and equality comparisons are supported between ST objects. Pickling of
+ST objects (using the :mod:`pickle` module) is also supported.
 
 
-.. data:: ASTType
+.. data:: STType
 
    The type of the objects returned by :func:`expr`, :func:`suite` and
-   :func:`sequence2ast`.
+   :func:`sequence2st`.
 
-AST objects have the following methods:
+ST objects have the following methods:
 
 
-.. method:: AST.compile([filename])
+.. method:: ST.compile([filename])
 
-   Same as ``compileast(ast, filename)``.
+   Same as ``compilest(st, filename)``.
 
 
-.. method:: AST.isexpr()
+.. method:: ST.isexpr()
 
-   Same as ``isexpr(ast)``.
+   Same as ``isexpr(st)``.
 
 
-.. method:: AST.issuite()
+.. method:: ST.issuite()
 
-   Same as ``issuite(ast)``.
+   Same as ``issuite(st)``.
 
 
-.. method:: AST.tolist([line_info])
+.. method:: ST.tolist([line_info])
 
-   Same as ``ast2list(ast, line_info)``.
+   Same as ``st2list(st, line_info)``.
 
 
-.. method:: AST.totuple([line_info])
+.. method:: ST.totuple([line_info])
 
-   Same as ``ast2tuple(ast, line_info)``.
+   Same as ``st2tuple(st, line_info)``.
 
 
-.. _ast-examples:
+.. _st-examples:
 
 Examples
 --------
@@ -338,27 +349,27 @@
    10
 
 The equivalent operation using the :mod:`parser` module is somewhat longer, and
-allows the intermediate internal parse tree to be retained as an AST object::
+allows the intermediate internal parse tree to be retained as an ST object::
 
    >>> import parser
-   >>> ast = parser.expr('a + 5')
-   >>> code = ast.compile('file.py')
+   >>> st = parser.expr('a + 5')
+   >>> code = st.compile('file.py')
    >>> a = 5
    >>> eval(code)
    10
 
-An application which needs both AST and code objects can package this code into
+An application which needs both ST and code objects can package this code into
 readily available functions::
 
    import parser
 
    def load_suite(source_string):
-       ast = parser.suite(source_string)
-       return ast, ast.compile()
+       st = parser.suite(source_string)
+       return st, st.compile()
 
    def load_expression(source_string):
-       ast = parser.expr(source_string)
-       return ast, ast.compile()
+       st = parser.expr(source_string)
+       return st, st.compile()
 
 
 Information Discovery
@@ -412,8 +423,8 @@
 
    >>> import parser
    >>> import pprint
-   >>> ast = parser.suite(open('docstring.py').read())
-   >>> tup = ast.totuple()
+   >>> st = parser.suite(open('docstring.py').read())
+   >>> tup = st.totuple()
    >>> pprint.pprint(tup)
    (257,
     (264,
@@ -670,8 +681,8 @@
 
        source = open(fileName).read()
        basename = os.path.basename(os.path.splitext(fileName)[0])
-       ast = parser.suite(source)
-       return ModuleInfo(ast.totuple(), basename)
+       st = parser.suite(source)
+       return ModuleInfo(st.totuple(), basename)
 
 This provides an easy-to-use interface to the documentation of a module.  If
 information is required which is not extracted by the code of this example, the

Modified: python/branches/tlee-ast-optimize/Doc/library/python.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/python.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/python.rst	Sun Jun  8 10:59:51 2008
@@ -18,6 +18,7 @@
    __main__.rst
    warnings.rst
    contextlib.rst
+   abc.rst
    atexit.rst
    traceback.rst
    __future__.rst

Modified: python/branches/tlee-ast-optimize/Doc/reference/simple_stmts.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/reference/simple_stmts.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/reference/simple_stmts.rst	Sun Jun  8 10:59:51 2008
@@ -375,8 +375,8 @@
 .. index:: statement: print
 
 .. productionlist::
-   print_stmt: "print" ([`expression` ("," `expression`)* [","]
-             : | ">>" `expression` [("," `expression`)+ [","])
+   print_stmt: "print" ([`expression` ("," `expression`)* [","]]
+             : | ">>" `expression` [("," `expression`)+ [","]])
 
 :keyword:`print` evaluates each expression in turn and writes the resulting
 object to standard output (see below).  If an object is not a string, it is

Modified: python/branches/tlee-ast-optimize/Doc/whatsnew/2.5.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/whatsnew/2.5.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/whatsnew/2.5.rst	Sun Jun  8 10:59:51 2008
@@ -2205,10 +2205,10 @@
 * MacOS X (10.3 and higher): dynamic loading of modules now uses the
   :cfunc:`dlopen` function instead of MacOS-specific functions.
 
-* MacOS X: a :option:`--enable-universalsdk` switch was added to the
+* MacOS X: an :option:`--enable-universalsdk` switch was added to the
   :program:`configure` script that compiles the interpreter as a universal binary
   able to run on both PowerPC and Intel processors. (Contributed by Ronald
-  Oussoren.)
+  Oussoren; :issue:`2573`.)
 
 * Windows: :file:`.dll` is no longer supported as a filename extension for
   extension modules.  :file:`.pyd` is now the only filename extension that will be

Modified: python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst	Sun Jun  8 10:59:51 2008
@@ -647,6 +647,7 @@
     >>> format(75.6564, '.2f')
     '75.66'
 
+
 .. seealso::
 
    :ref:`formatstrings`
@@ -1251,6 +1252,11 @@
 
   (Contributed by Alexander Belopolsky; :issue:`1686487`.)
 
+* A new built-in, ``next(*iterator*, [*default*])`` returns the next item
+  from the specified iterator.  If the *default* argument is supplied,
+  it will be returned if *iterator* has been exhausted; otherwise,
+  the :exc:`StopIteration` exception will be raised.  (:issue:`2719`)
+
 * Tuples now have an :meth:`index` method matching the list type's
   :meth:`index` method::
 
@@ -1554,6 +1560,7 @@
   :mod:`terminalcommand`.
 
   A number of old IRIX-specific modules were deprecated:
+  :mod:`al` and :mod:`AL`,
   :mod:`cd`,
   :mod:`cddb`,
   :mod:`cdplayer`,
@@ -1665,6 +1672,10 @@
 
   (Contributed by Raymond Hettinger.)
 
+* XXX Describe the new ctypes calling convention that allows safe
+  access to errno.
+  (Implemented by Thomas Heller; :issue:`1798`.)
+
 * The :mod:`ctypes` module now supports a :class:`c_bool` datatype
   that represents the C99 ``bool`` type.  (Contributed by David Remahl;
   :issue:`1649190`.)
@@ -1734,6 +1745,13 @@
   to drop the built-in in the 2.x series.  (Patched by
   Christian Heimes; :issue:`1739906`.)
 
+* When possible, the :mod:`getpass` module will now use
+  :file:`/dev/tty` (when available) to print
+  a prompting message and read the password, falling back to using
+  standard error and standard input.    If the password may be echoed to 
+  the terminal, a warning is printed before the prompt is displayed.
+  (Contributed by Gregory P. Smith.)
+
 * The :func:`glob.glob` function can now return Unicode filenames if
   a Unicode path was used and Unicode filenames are matched within the
   directory.  (:issue:`1001604`)
@@ -1753,6 +1771,10 @@
   This is more efficient than making a call to :func:`heappush` and then
   :func:`heappop`.
 
+  :mod:`heapq` is now implemented to only use less-than comparison,
+  instead of the less-than-or-equal comparison it previously used.
+  This makes :mod:`heapq`'s usage of a type match that of the 
+  :meth:`list.sort` method.
   (Contributed by Raymond Hettinger.)
 
 * An optional ``timeout`` parameter was added to the
@@ -1847,6 +1869,11 @@
   is true, opening of the log file is deferred until the first
   :meth:`emit` call is made.  (Contributed by Vinay Sajip.)
 
+  :class:`TimedRotatingFileHandler` also has a *utc* constructor 
+  parameter.  If the argument is true, UTC time will be used 
+  in determining when midnight occurs and in generating filenames;
+  otherwise local time will be used.
+
 * The :mod:`macfs` module has been removed.  This in turn required the
   :func:`macostools.touched` function to be removed because it depended on the
   :mod:`macfs` module.  (:issue:`1490190`)
@@ -2114,12 +2141,20 @@
   (Contributed by Neal Norwitz and Georg Brandl.)
 
   Information about the command-line arguments supplied to the Python
-  interpreter are available as attributes of a ``sys.flags`` named
-  tuple.  For example, the :attr:`verbose` attribute is true if Python
+  interpreter is available by reading attributes of a named
+  tuple available as ``sys.flags``.  For example, the :attr:`verbose`
+  attribute is true if Python
   was executed in verbose mode, :attr:`debug` is true in debugging mode, etc.
   These attributes are all read-only.
   (Contributed by Christian Heimes.)
 
+  A new function, :func:`getsizeof`, takes a Python object and returns 
+  the amount of memory used by the object, measured in bytes.  Built-in
+  objects return correct results; third-party extensions may not,
+  but can define a :meth:`__sizeof__` method to return the 
+  object's size.
+  (Contributed by Robert Schuppenies; :issue:`2898`.)
+
   It's now possible to determine the current profiler and tracer functions
   by calling :func:`sys.getprofile` and :func:`sys.gettrace`.
   (Contributed by Georg Brandl; :issue:`1648`.)
@@ -2205,6 +2240,10 @@
 
   (Contributed by Dwayne Bailey; :issue:`1581073`.)
 
+* The :mod:`threading` module's :class:`Thread` objects 
+  gained a :meth:`getIdent` method that returns the thread's 
+  identifier, a nonzero integer.  (Contributed by XXX; :issue:`2871`.)
+
 * The :mod:`timeit` module now accepts callables as well as strings
   for the statement being timed and for the setup code.
   Two convenience functions were added for creating
@@ -2214,6 +2253,24 @@
   the corresponding method. (Contributed by Erik Demaine;
   :issue:`1533909`.)
 
+* The :mod:`turtle` module for turtle graphics was greatly enhanced by
+  Gregor Lingl.  New features in the module include:
+
+  * Better animation of turtle movement and rotation.
+  * Control over turtle movement using the new delay(), 
+    tracer(), and speed() methods.
+  * The ability to set new shapes for the turtle, and to 
+    define a new coordinate system.
+  * Turtles now have an undo() method that can roll back actions.
+  * Simple support for reacting to input events such as mouse and keyboard
+    activity, making it possible to write simple games.
+  * A :file:`turtle.cfg` file can be used to customize the starting appearance 
+    of the turtle's screen.
+  * The module's docstrings can be replaced by new docstrings that have been
+    translated into another language.
+  
+  (:issue:`1513695`)
+
 * An optional ``timeout`` parameter was added to the
   :func:`urllib.urlopen` function and the
   :class:`urllib.ftpwrapper` class constructor, as well as the
@@ -2256,8 +2313,10 @@
   not necessarily correct for all applications.  Code using
   :mod:`xmlrpclib` should convert :class:`date` and :class:`time`
   instances. (:issue:`1330538`)  The code can also handle
-  dates before 1900.  (Contributed by Ralf Schmitt; :issue:`2014`.)
-
+  dates before 1900 (contributed by Ralf Schmitt; :issue:`2014`)
+  and 64-bit integers represented by using ``<i8>`` in XML-RPC responses
+  (contributed by XXX; :issue:`2985`).
+  
 * The :mod:`zipfile` module's :class:`ZipFile` class now has
   :meth:`extract` and :meth:`extractall` methods that will unpack
   a single file or all the files in the archive to the current directory, or
@@ -2273,9 +2332,14 @@
 
   (Contributed by Alan McIntyre; :issue:`467924`.)
 
-  Also, :mod:`zipfile` now supports using Unicode filenames
-  for archived files.  (Contributed by Alexey Borzenkov; :issue:`1734346`.)
+  The :meth:`open`, :meth:`read` and :meth:`extract` methods can now 
+  take either a filename or a :class:`ZipInfo` object.  This is useful when an
+  archive accidentally contains a duplicated filename.
+  (Contributed by Graham Horler; :issue:`1775025`.)
 
+  Finally, :mod:`zipfile` now supports using Unicode filenames
+  for archived files.  (Contributed by Alexey Borzenkov; :issue:`1734346`.)
+  
 .. ======================================================================
 .. whole new modules get described in subsections here
 
@@ -2470,10 +2534,8 @@
   results, and then compiles using these results for optimization.
   (Contributed by Gregory P. Smith.)
 
-
 .. ======================================================================
 
-
 Port-Specific Changes: Windows
 -----------------------------------
 
@@ -2518,6 +2580,16 @@
 
 .. ======================================================================
 
+Port-Specific Changes: MacOS X
+-----------------------------------
+
+* When compiling a framework build of Python, you can now specify the 
+  framework name to be used by providing the 
+  :option:`--with-framework-name=` option to the 
+  :program:`configure` script.
+
+.. ======================================================================
+
 
 .. _section-other:
 

Modified: python/branches/tlee-ast-optimize/Include/Python.h
==============================================================================
--- python/branches/tlee-ast-optimize/Include/Python.h	(original)
+++ python/branches/tlee-ast-optimize/Include/Python.h	Sun Jun  8 10:59:51 2008
@@ -1,4 +1,5 @@
-#ifndef Py_PYTHON_H #define Py_PYTHON_H
+#ifndef Py_PYTHON_H
+#define Py_PYTHON_H
 /* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */
 
 /* Include nearly all Python header files */

Modified: python/branches/tlee-ast-optimize/Include/object.h
==============================================================================
--- python/branches/tlee-ast-optimize/Include/object.h	(original)
+++ python/branches/tlee-ast-optimize/Include/object.h	Sun Jun  8 10:59:51 2008
@@ -183,7 +183,6 @@
 #define PyBUF_WRITABLE 0x0001
 /*  we used to include an E, backwards compatible alias  */
 #define PyBUF_WRITEABLE PyBUF_WRITABLE
-#define PyBUF_LOCK 0x0002
 #define PyBUF_FORMAT 0x0004
 #define PyBUF_ND 0x0008
 #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
@@ -194,25 +193,15 @@
 
 #define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
 #define PyBUF_CONTIG_RO (PyBUF_ND)
-#define PyBUF_CONTIG_LCK (PyBUF_ND | PyBUF_LOCK)
-#define PyBUF_CONTIG_XLCK (PyBUF_ND | PyBUF_LOCK | PyBUF_WRITABLE)
 
 #define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
 #define PyBUF_STRIDED_RO (PyBUF_STRIDES)
-#define PyBUF_STRIDED_LCK (PyBUF_STRIDES | PyBUF_LOCK)
-#define PyBUF_STRIDED_XLCK (PyBUF_STRIDES | PyBUF_LOCK | PyBUF_WRITABLE)
 
 #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
 #define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
-#define PyBUF_RECORDS_LCK (PyBUF_STRIDES | PyBUF_LOCK | PyBUF_FORMAT)
-#define PyBUF_RECORDS_XLCK (PyBUF_STRIDES | PyBUF_LOCK | PyBUF_WRITABLE \
-			    | PyBUF_FORMAT)
 
 #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
 #define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
-#define PyBUF_FULL_LCK (PyBUF_INDIRECT | PyBUF_LOCK | PyBUF_FORMAT)
-#define PyBUF_FULL_XLCK (PyBUF_INDIRECT | PyBUF_LOCK | PyBUF_WRITABLE \
-			 | PyBUF_FORMAT)
 
 
 #define PyBUF_READ  0x100

Modified: python/branches/tlee-ast-optimize/Lib/UserDict.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/UserDict.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/UserDict.py	Sun Jun  8 10:59:51 2008
@@ -79,6 +79,10 @@
     def __iter__(self):
         return iter(self.data)
 
+import _abcoll
+_abcoll.MutableMapping.register(IterableUserDict)
+
+
 class DictMixin:
     # Mixin defining all dictionary methods for classes that already have
     # a minimum dictionary interface including getitem, setitem, delitem,

Modified: python/branches/tlee-ast-optimize/Lib/_abcoll.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/_abcoll.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/_abcoll.py	Sun Jun  8 10:59:51 2008
@@ -329,14 +329,25 @@
         else:
             return True
 
+    def iterkeys(self):
+        return iter(self)
+
+    def itervalues(self):
+        for key in self:
+            yield self[key]
+
+    def iteritems(self):
+        for key in self:
+            yield (key, self[key])
+
     def keys(self):
-        return KeysView(self)
+        return list(self)
 
     def items(self):
-        return ItemsView(self)
+        return [(key, self[key]) for key in self]
 
     def values(self):
-        return ValuesView(self)
+        return [self[key] for key in self]
 
     def __eq__(self, other):
         return isinstance(other, Mapping) and \
@@ -363,8 +374,6 @@
         for key in self._mapping:
             yield key
 
-KeysView.register(type({}.keys()))
-
 
 class ItemsView(MappingView, Set):
 
@@ -381,8 +390,6 @@
         for key in self._mapping:
             yield (key, self._mapping[key])
 
-ItemsView.register(type({}.items()))
-
 
 class ValuesView(MappingView):
 
@@ -396,8 +403,6 @@
         for key in self._mapping:
             yield self._mapping[key]
 
-ValuesView.register(type({}.values()))
-
 
 class MutableMapping(Mapping):
 

Modified: python/branches/tlee-ast-optimize/Lib/ctypes/__init__.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/ctypes/__init__.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/ctypes/__init__.py	Sun Jun  8 10:59:51 2008
@@ -33,7 +33,9 @@
         DEFAULT_MODE = RTLD_GLOBAL
 
 from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL, \
-     FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI
+     FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI, \
+     FUNCFLAG_USE_ERRNO as _FUNCFLAG_USE_ERRNO, \
+     FUNCFLAG_USE_LASTERROR as _FUNCFLAG_USE_LASTERROR
 
 """
 WINOLEAPI -> HRESULT
@@ -73,8 +75,9 @@
     return create_string_buffer(init, size)
 
 _c_functype_cache = {}
-def CFUNCTYPE(restype, *argtypes):
-    """CFUNCTYPE(restype, *argtypes) -> function prototype.
+def CFUNCTYPE(restype, *argtypes, **kw):
+    """CFUNCTYPE(restype, *argtypes,
+                 use_errno=False, use_last_error=False) -> function prototype.
 
     restype: the result type
     argtypes: a sequence specifying the argument types
@@ -88,14 +91,21 @@
     prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal
     prototype((function name, dll object)[, paramflags]) -> foreign function exported by name
     """
+    flags = _FUNCFLAG_CDECL
+    if kw.pop("use_errno", False):
+        flags |= _FUNCFLAG_USE_ERRNO
+    if kw.pop("use_last_error", False):
+        flags |= _FUNCFLAG_USE_LASTERROR
+    if kw:
+        raise ValueError("unexpected keyword argument(s) %s" % kw.keys())
     try:
-        return _c_functype_cache[(restype, argtypes)]
+        return _c_functype_cache[(restype, argtypes, flags)]
     except KeyError:
         class CFunctionType(_CFuncPtr):
             _argtypes_ = argtypes
             _restype_ = restype
-            _flags_ = _FUNCFLAG_CDECL
-        _c_functype_cache[(restype, argtypes)] = CFunctionType
+            _flags_ = flags
+        _c_functype_cache[(restype, argtypes, flags)] = CFunctionType
         return CFunctionType
 
 if _os.name in ("nt", "ce"):
@@ -106,16 +116,23 @@
         _FUNCFLAG_STDCALL = _FUNCFLAG_CDECL
 
     _win_functype_cache = {}
-    def WINFUNCTYPE(restype, *argtypes):
+    def WINFUNCTYPE(restype, *argtypes, **kw):
         # docstring set later (very similar to CFUNCTYPE.__doc__)
+        flags = _FUNCFLAG_STDCALL
+        if kw.pop("use_errno", False):
+            flags |= _FUNCFLAG_USE_ERRNO
+        if kw.pop("use_last_error", False):
+            flags |= _FUNCFLAG_USE_LASTERROR
+        if kw:
+            raise ValueError("unexpected keyword argument(s) %s" % kw.keys())
         try:
-            return _win_functype_cache[(restype, argtypes)]
+            return _win_functype_cache[(restype, argtypes, flags)]
         except KeyError:
             class WinFunctionType(_CFuncPtr):
                 _argtypes_ = argtypes
                 _restype_ = restype
-                _flags_ = _FUNCFLAG_STDCALL
-            _win_functype_cache[(restype, argtypes)] = WinFunctionType
+                _flags_ = flags
+            _win_functype_cache[(restype, argtypes, flags)] = WinFunctionType
             return WinFunctionType
     if WINFUNCTYPE.__doc__:
         WINFUNCTYPE.__doc__ = CFUNCTYPE.__doc__.replace("CFUNCTYPE", "WINFUNCTYPE")
@@ -124,6 +141,7 @@
     from _ctypes import dlopen as _dlopen
 
 from _ctypes import sizeof, byref, addressof, alignment, resize
+from _ctypes import get_errno, set_errno
 from _ctypes import _SimpleCData
 
 def _check_size(typ, typecode=None):
@@ -313,12 +331,24 @@
     Calling the functions releases the Python GIL during the call and
     reacquires it afterwards.
     """
-    class _FuncPtr(_CFuncPtr):
-        _flags_ = _FUNCFLAG_CDECL
-        _restype_ = c_int # default, can be overridden in instances
+    _func_flags_ = _FUNCFLAG_CDECL
+    _func_restype_ = c_int
 
-    def __init__(self, name, mode=DEFAULT_MODE, handle=None):
+    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
+                 use_errno=False,
+                 use_last_error=False):
         self._name = name
+        flags = self._func_flags_
+        if use_errno:
+            flags |= _FUNCFLAG_USE_ERRNO
+        if use_last_error:
+            flags |= _FUNCFLAG_USE_LASTERROR
+
+        class _FuncPtr(_CFuncPtr):
+            _flags_ = flags
+            _restype_ = self._func_restype_
+        self._FuncPtr = _FuncPtr
+
         if handle is None:
             self._handle = _dlopen(self._name, mode)
         else:
@@ -348,9 +378,7 @@
     access Python API functions.  The GIL is not released, and
     Python exceptions are handled correctly.
     """
-    class _FuncPtr(_CFuncPtr):
-        _flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
-        _restype_ = c_int # default, can be overridden in instances
+    _func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
 
 if _os.name in ("nt", "ce"):
 
@@ -358,9 +386,7 @@
         """This class represents a dll exporting functions using the
         Windows stdcall calling convention.
         """
-        class _FuncPtr(_CFuncPtr):
-            _flags_ = _FUNCFLAG_STDCALL
-            _restype_ = c_int # default, can be overridden in instances
+        _func_flags_ = _FUNCFLAG_STDCALL
 
     # XXX Hm, what about HRESULT as normal parameter?
     # Mustn't it derive from c_long then?
@@ -384,9 +410,8 @@
         HRESULT error values are automatically raised as WindowsError
         exceptions.
         """
-        class _FuncPtr(_CFuncPtr):
-            _flags_ = _FUNCFLAG_STDCALL
-            _restype_ = HRESULT
+        _func_flags_ = _FUNCFLAG_STDCALL
+        _func_restype_ = HRESULT
 
 class LibraryLoader(object):
     def __init__(self, dlltype):
@@ -424,6 +449,7 @@
         GetLastError = windll.kernel32.GetLastError
     else:
         GetLastError = windll.coredll.GetLastError
+    from _ctypes import get_last_error, set_last_error
 
     def WinError(code=None, descr=None):
         if code is None:

Modified: python/branches/tlee-ast-optimize/Lib/inspect.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/inspect.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/inspect.py	Sun Jun  8 10:59:51 2008
@@ -368,6 +368,13 @@
         return None
     if not isinstance(doc, types.StringTypes):
         return None
+    return cleandoc(doc)
+
+def cleandoc(doc):
+    """Clean up indentation from docstrings.
+
+    Any whitespace that can be uniformly removed from the second line
+    onwards is removed."""
     try:
         lines = string.split(string.expandtabs(doc), '\n')
     except UnicodeError:

Modified: python/branches/tlee-ast-optimize/Lib/test/test_inspect.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_inspect.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_inspect.py	Sun Jun  8 10:59:51 2008
@@ -185,6 +185,10 @@
         self.assertEqual(inspect.getdoc(git.abuse),
                          'Another\n\ndocstring\n\ncontaining\n\ntabs')
 
+    def test_cleandoc(self):
+        self.assertEqual(inspect.cleandoc('An\n    indented\n    docstring.'),
+                         'An\nindented\ndocstring.')
+
     def test_getcomments(self):
         self.assertEqual(inspect.getcomments(mod), '# line 1\n')
         self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n')

Modified: python/branches/tlee-ast-optimize/Lib/test/test_py3kwarn.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_py3kwarn.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_py3kwarn.py	Sun Jun  8 10:59:51 2008
@@ -10,6 +10,12 @@
 
 class TestPy3KWarnings(unittest.TestCase):
 
+    def test_backquote(self):
+        expected = 'backquote not supported in 3.x; use repr()'
+        with catch_warning() as w:
+            exec "`2`" in {}
+        self.assertWarning(None, w, expected)
+
     def test_type_inequality_comparisons(self):
         expected = 'type inequality comparisons not supported in 3.x'
         with catch_warning() as w:

Modified: python/branches/tlee-ast-optimize/Lib/test/test_urllib2net.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_urllib2net.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_urllib2net.py	Sun Jun  8 10:59:51 2008
@@ -11,18 +11,24 @@
 import mimetools
 
 
-def _urlopen_with_retry(host, *args, **kwargs):
-    # Connecting to remote hosts is flaky.  Make it more robust
-    # by retrying the connection several times.
+def _retry_thrice(func, exc, *args, **kwargs):
     for i in range(3):
         try:
-            return urllib2.urlopen(host, *args, **kwargs)
-        except urllib2.URLError, last_exc:
+            return func(*args, **kwargs)
+        except exc, last_exc:
             continue
         except:
             raise
     raise last_exc
 
+def _wrap_with_retry_thrice(func, exc):
+    def wrapped(*args, **kwargs):
+        return _retry_thrice(func, exc, *args, **kwargs)
+    return wrapped
+
+# Connecting to remote hosts is flaky.  Make it more robust by retrying
+# the connection several times.
+_urlopen_with_retry = _wrap_with_retry_thrice(urllib2.urlopen, urllib2.URLError)
 
 
 class AuthTests(unittest.TestCase):
@@ -115,7 +121,7 @@
                 'file:'+sanepathname2url(os.path.abspath(TESTFN)),
                 ('file:///nonsensename/etc/passwd', None, urllib2.URLError),
                 ]
-            self._test_urls(urls, self._extra_handlers(), urllib2.urlopen)
+            self._test_urls(urls, self._extra_handlers(), retry=True)
         finally:
             os.remove(TESTFN)
 
@@ -147,13 +153,15 @@
 
 ##             self._test_urls(urls, self._extra_handlers()+[bauth, dauth])
 
-    def _test_urls(self, urls, handlers, urlopen=_urlopen_with_retry):
+    def _test_urls(self, urls, handlers, retry=True):
         import socket
         import time
         import logging
         debug = logging.getLogger("test_urllib2").debug
 
-        urllib2.install_opener(urllib2.build_opener(*handlers))
+        urlopen = urllib2.build_opener(*handlers).open
+        if retry:
+            urlopen = _wrap_with_retry_thrice(urlopen, urllib2.URLError)
 
         for url in urls:
             if isinstance(url, tuple):

Modified: python/branches/tlee-ast-optimize/Mac/Modules/MacOS.c
==============================================================================
--- python/branches/tlee-ast-optimize/Mac/Modules/MacOS.c	(original)
+++ python/branches/tlee-ast-optimize/Mac/Modules/MacOS.c	Sun Jun  8 10:59:51 2008
@@ -30,6 +30,9 @@
 #include <Carbon/Carbon.h>
 #include <ApplicationServices/ApplicationServices.h>
 
+#ifndef HAVE_MACOS105_SDK
+typedef SInt16	FSIORefNum;
+#endif
 
 static PyObject *MacOS_Error; /* Exception MacOS.Error */
 

Modified: python/branches/tlee-ast-optimize/Mac/Modules/ae/_AEmodule.c
==============================================================================
--- python/branches/tlee-ast-optimize/Mac/Modules/ae/_AEmodule.c	(original)
+++ python/branches/tlee-ast-optimize/Mac/Modules/ae/_AEmodule.c	Sun Jun  8 10:59:51 2008
@@ -7,6 +7,10 @@
 
 #include "pymactoolbox.h"
 
+#ifndef HAVE_OSX105_SDK
+typedef SInt32 SRefCon;
+#endif
+
 /* Macro to test whether a weak-loaded CFM function exists */
 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
         PyErr_SetString(PyExc_NotImplementedError, \

Modified: python/branches/tlee-ast-optimize/Mac/Modules/file/_Filemodule.c
==============================================================================
--- python/branches/tlee-ast-optimize/Mac/Modules/file/_Filemodule.c	(original)
+++ python/branches/tlee-ast-optimize/Mac/Modules/file/_Filemodule.c	Sun Jun  8 10:59:51 2008
@@ -7,6 +7,10 @@
 
 #include "pymactoolbox.h"
 
+#ifndef HAVE_MACOS105_SDK
+typedef SInt16	FSIORefNum;
+#endif
+
 /* Macro to test whether a weak-loaded CFM function exists */
 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
         PyErr_SetString(PyExc_NotImplementedError, \
@@ -193,10 +197,6 @@
 static void FSCatalogInfo_dealloc(FSCatalogInfoObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
-	FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
-	if (info->fileSec != NULL) {
-		CFRelease(info->fileSec);
-	}
 	self->ob_type->tp_free((PyObject *)self);
 }
 

Modified: python/branches/tlee-ast-optimize/Misc/NEWS
==============================================================================
--- python/branches/tlee-ast-optimize/Misc/NEWS	(original)
+++ python/branches/tlee-ast-optimize/Misc/NEWS	Sun Jun  8 10:59:51 2008
@@ -72,6 +72,14 @@
 Library
 -------
 
+- Factored out the indentation cleaning from inspect.getdoc() into
+  inspect.cleandoc() to ease standalone use.
+
+- Issue #1798: Add ctypes calling convention that allows safe access
+  to errno.
+
+- Issue #2404: ctypes objects support the new pep3118 buffer interface
+
 - Patch #2125: Add GetInteger and GetString methods for 
   msilib.Record objects.
 

Modified: python/branches/tlee-ast-optimize/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/tlee-ast-optimize/Modules/_ctypes/_ctypes.c	Sun Jun  8 10:59:51 2008
@@ -294,6 +294,36 @@
 
 /******************************************************************/
 /*
+  Allocate a memory block for a pep3118 format string, copy prefix (if
+  non-null) and suffix into it.  Returns NULL on failure, with the error
+  indicator set.  If called with a suffix of NULL the error indicator must
+  already be set.
+ */
+char *
+alloc_format_string(const char *prefix, const char *suffix)
+{
+	size_t len;
+	char *result;
+
+	if (suffix == NULL) {
+		assert(PyErr_Occurred());
+		return NULL;
+	}
+	len = strlen(suffix);
+	if (prefix)
+		len += strlen(prefix);
+	result = PyMem_Malloc(len + 1);
+	if (result == NULL)
+		return NULL;
+	if (prefix)
+		strcpy(result, prefix);
+	else
+		result[0] = '\0';
+	strcat(result, suffix);
+	return result;
+}
+
+/*
   StructType_Type - a meta type/class.  Creating a new class using this one as
   __metaclass__ will call the contructor StructUnionType_new.  It replaces the
   tp_dict member with a new instance of StgDict, and initializes the C
@@ -874,6 +904,16 @@
 		return NULL;
 	}
 
+	if (proto) {
+		StgDictObject *itemdict = PyType_stgdict(proto);
+		assert(itemdict);
+		stgdict->format = alloc_format_string("&", itemdict->format);
+		if (stgdict->format == NULL) {
+			Py_DECREF((PyObject *)stgdict);
+			return NULL;
+		}
+	}
+
 	/* create the new instance (which is a class,
 	   since we are a metatype!) */
 	result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds);
@@ -1244,9 +1284,10 @@
 	StgDictObject *itemdict;
 	PyObject *proto;
 	PyObject *typedict;
-	int length;
+	long length;
 
 	Py_ssize_t itemsize, itemalign;
+	char buf[32];
 
 	typedict = PyTuple_GetItem(args, 2);
 	if (!typedict)
@@ -1281,6 +1322,28 @@
 		return NULL;
 	}
 
+	assert(itemdict->format);
+	if (itemdict->format[0] == '(') {
+		sprintf(buf, "(%ld,", length);
+		stgdict->format = alloc_format_string(buf, itemdict->format+1);
+	} else {
+		sprintf(buf, "(%ld)", length);
+		stgdict->format = alloc_format_string(buf, itemdict->format);
+	}
+	if (stgdict->format == NULL) {
+		Py_DECREF((PyObject *)stgdict);
+		return NULL;
+	}
+	stgdict->ndim = itemdict->ndim + 1;
+	stgdict->shape = PyMem_Malloc(sizeof(Py_ssize_t *) * stgdict->ndim);
+	if (stgdict->shape == NULL) {
+		Py_DECREF((PyObject *)stgdict);
+		return NULL;
+	}
+	stgdict->shape[0] = length;
+	memmove(&stgdict->shape[1], itemdict->shape,
+		sizeof(Py_ssize_t) * (stgdict->ndim - 1));
+
 	itemsize = itemdict->size;
 	if (length * itemsize < 0) {
 		PyErr_SetString(PyExc_OverflowError,
@@ -1768,6 +1831,8 @@
 	PyTypeObject *result;
 	StgDictObject *stgdict;
 	PyObject *proto;
+	const char *proto_str;
+	Py_ssize_t proto_len;
 	PyMethodDef *ml;
 	struct fielddesc *fmt;
 
@@ -1778,17 +1843,34 @@
 		return NULL;
 
 	proto = PyObject_GetAttrString((PyObject *)result, "_type_"); /* new ref */
-	if (!proto
-	    || !PyBytes_Check(proto)
-	    || 1 != strlen(PyBytes_AS_STRING(proto))
-	    || !strchr(SIMPLE_TYPE_CHARS, PyBytes_AS_STRING(proto)[0])) {
+	if (!proto) {
+		PyErr_SetString(PyExc_AttributeError,
+				"class must define a '_type_' attribute");
+  error:
+		Py_XDECREF(proto);
+		Py_XDECREF(result);
+		return NULL;
+	}
+	if (PyString_Check(proto)) {
+		proto_str = PyBytes_AS_STRING(proto);
+		proto_len = PyBytes_GET_SIZE(proto);
+	} else {
+		PyErr_SetString(PyExc_TypeError,
+			"class must define a '_type_' string attribute");
+		goto error;
+	}
+	if (proto_len != 1) {
+		PyErr_SetString(PyExc_ValueError,
+				"class must define a '_type_' attribute "
+				"which must be a string of length 1");
+		goto error;
+	}
+	if (!strchr(SIMPLE_TYPE_CHARS, *proto_str)) {
 		PyErr_Format(PyExc_AttributeError,
 			     "class must define a '_type_' attribute which must be\n"
 			     "a single character string containing one of '%s'.",
 			     SIMPLE_TYPE_CHARS);
-		Py_XDECREF(proto);
-		Py_DECREF(result);
-		return NULL;
+		goto error;
 	}
 	fmt = getentry(PyBytes_AS_STRING(proto));
 	if (fmt == NULL) {
@@ -1810,6 +1892,16 @@
 	stgdict->size = fmt->pffi_type->size;
 	stgdict->setfunc = fmt->setfunc;
 	stgdict->getfunc = fmt->getfunc;
+#ifdef WORDS_BIGENDIAN
+	stgdict->format = alloc_format_string(">", proto_str);
+#else
+	stgdict->format = alloc_format_string("<", proto_str);
+#endif
+	if (stgdict->format == NULL) {
+		Py_DECREF(result);
+		Py_DECREF((PyObject *)stgdict);
+		return NULL;
+	}
 
 	stgdict->paramfunc = SimpleType_paramfunc;
 /*
@@ -1895,22 +1987,32 @@
 	if (type == &SimpleType_Type && fmt->setfunc_swapped && fmt->getfunc_swapped) {
 		PyObject *swapped = CreateSwappedType(type, args, kwds,
 						      proto, fmt);
+		StgDictObject *sw_dict;
 		if (swapped == NULL) {
 			Py_DECREF(result);
 			return NULL;
 		}
+		sw_dict = PyType_stgdict(swapped);
 #ifdef WORDS_BIGENDIAN
 		PyObject_SetAttrString((PyObject *)result, "__ctype_le__", swapped);
 		PyObject_SetAttrString((PyObject *)result, "__ctype_be__", (PyObject *)result);
 		PyObject_SetAttrString(swapped, "__ctype_be__", (PyObject *)result);
 		PyObject_SetAttrString(swapped, "__ctype_le__", swapped);
+		/* We are creating the type for the OTHER endian */
+		sw_dict->format = alloc_format_string("<", stgdict->format+1);
 #else
 		PyObject_SetAttrString((PyObject *)result, "__ctype_be__", swapped);
 		PyObject_SetAttrString((PyObject *)result, "__ctype_le__", (PyObject *)result);
 		PyObject_SetAttrString(swapped, "__ctype_le__", (PyObject *)result);
 		PyObject_SetAttrString(swapped, "__ctype_be__", swapped);
+		/* We are creating the type for the OTHER endian */
+		sw_dict->format = alloc_format_string(">", stgdict->format+1);
 #endif
 		Py_DECREF(swapped);
+		if (PyErr_Occurred()) {
+			Py_DECREF(result);
+			return NULL;
+		}
 	};
 
 	return (PyObject *)result;
@@ -2166,6 +2268,13 @@
 		return NULL;
 
 	stgdict->paramfunc = CFuncPtrType_paramfunc;
+	/* We do NOT expose the function signature in the format string.  It
+	   is impossible, generally, because the only requirement for the
+	   argtypes items is that they have a .from_param method - we do not
+	   know the types of the arguments (although, in practice, most
+	   argtypes would be a ctypes type).
+	*/
+	stgdict->format = alloc_format_string(NULL, "X{}");
 	stgdict->flags |= TYPEFLAG_ISPOINTER;
 
 	/* create the new instance (which is a class,
@@ -2386,15 +2495,29 @@
 	{ NULL },
 };
 
-static Py_ssize_t CData_GetBuffer(PyObject *_self, Py_ssize_t seg, void **pptr)
+static int CData_NewGetBuffer(PyObject *_self, Py_buffer *view, int flags)
 {
 	CDataObject *self = (CDataObject *)_self;
-	if (seg != 0) {
-		/* Hm. Must this set an exception? */
-		return -1;
-	}
-	*pptr = self->b_ptr;
-	return self->b_size;
+	StgDictObject *dict = PyObject_stgdict(_self);
+	Py_ssize_t i;
+
+	if (view == NULL) return 0;
+
+	view->buf = self->b_ptr;
+	view->len = self->b_size;
+	view->readonly = 0;
+	/* use default format character if not set */
+	view->format = dict->format ? dict->format : "B";
+	view->ndim = dict->ndim;
+	view->shape = dict->shape;
+	view->itemsize = self->b_size;
+	for (i = 0; i < view->ndim; ++i) {
+		view->itemsize /= dict->shape[i];
+	}
+	view->strides = NULL;
+	view->suboffsets = NULL;
+	view->internal = NULL;
+	return 0;
 }
 
 static Py_ssize_t CData_GetSegcount(PyObject *_self, Py_ssize_t *lenp)
@@ -2404,11 +2527,24 @@
 	return 1;
 }
 
+static Py_ssize_t CData_GetBuffer(PyObject *_self, Py_ssize_t seg, void **pptr)
+{
+	CDataObject *self = (CDataObject *)_self;
+	if (seg != 0) {
+		/* Hm. Must this set an exception? */
+		return -1;
+	}
+	*pptr = self->b_ptr;
+	return self->b_size;
+}
+
 static PyBufferProcs CData_as_buffer = {
-	CData_GetBuffer,
-	CData_GetBuffer,
-	CData_GetSegcount,
-	NULL,
+	(readbufferproc)CData_GetBuffer,
+	(writebufferproc)CData_GetBuffer,
+	(segcountproc)CData_GetSegcount,
+	(charbufferproc)NULL,
+	(getbufferproc)CData_NewGetBuffer,
+	(releasebufferproc)NULL,
 };
 
 /*
@@ -2497,7 +2633,7 @@
 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	&CData_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE, /* tp_flags */
 	"XXX to be provided",			/* tp_doc */
 	(traverseproc)CData_traverse,		/* tp_traverse */
 	(inquiry)CData_clear,			/* tp_clear */
@@ -3271,7 +3407,7 @@
 	thunk = AllocFunctionCallback(callable,
 				      dict->argtypes,
 				      dict->restype,
-				      dict->flags & FUNCFLAG_CDECL);
+				      dict->flags);
 	if (!thunk)
 		return NULL;
 
@@ -3824,7 +3960,7 @@
 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	&CData_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE, /* tp_flags */
 	"Function Pointer",			/* tp_doc */
 	(traverseproc)CFuncPtr_traverse,	/* tp_traverse */
 	(inquiry)CFuncPtr_clear,		/* tp_clear */
@@ -3967,7 +4103,7 @@
 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	&CData_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE, /* tp_flags */
 	"Structure base class",			/* tp_doc */
 	(traverseproc)CData_traverse,		/* tp_traverse */
 	(inquiry)CData_clear,			/* tp_clear */
@@ -4009,7 +4145,7 @@
 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	&CData_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE, /* tp_flags */
 	"Union base class",			/* tp_doc */
 	(traverseproc)CData_traverse,		/* tp_traverse */
 	(inquiry)CData_clear,			/* tp_clear */
@@ -4406,7 +4542,7 @@
 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	&CData_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE, /* tp_flags */
 	"XXX to be provided",			/* tp_doc */
 	(traverseproc)CData_traverse,		/* tp_traverse */
 	(inquiry)CData_clear,			/* tp_clear */
@@ -4643,7 +4779,7 @@
 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	&CData_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE, /* tp_flags */
 	"XXX to be provided",			/* tp_doc */
 	(traverseproc)CData_traverse,		/* tp_traverse */
 	(inquiry)CData_clear,			/* tp_clear */
@@ -5043,7 +5179,7 @@
 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	&CData_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER | Py_TPFLAGS_BASETYPE, /* tp_flags */
 	"XXX to be provided",			/* tp_doc */
 	(traverseproc)CData_traverse,		/* tp_traverse */
 	(inquiry)CData_clear,			/* tp_clear */
@@ -5394,6 +5530,8 @@
 	PyModule_AddObject(m, "FUNCFLAG_STDCALL", PyInt_FromLong(FUNCFLAG_STDCALL));
 #endif
 	PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL));
+	PyModule_AddObject(m, "FUNCFLAG_USE_ERRNO", PyInt_FromLong(FUNCFLAG_USE_ERRNO));
+	PyModule_AddObject(m, "FUNCFLAG_USE_LASTERROR", PyInt_FromLong(FUNCFLAG_USE_LASTERROR));
 	PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI));
 	PyModule_AddStringConstant(m, "__version__", "1.1.0");
 

Modified: python/branches/tlee-ast-optimize/Modules/_ctypes/callbacks.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/_ctypes/callbacks.c	(original)
+++ python/branches/tlee-ast-optimize/Modules/_ctypes/callbacks.c	Sun Jun  8 10:59:51 2008
@@ -189,12 +189,15 @@
 			      SETFUNC setfunc,
 			      PyObject *callable,
 			      PyObject *converters,
+			      int flags,
 			      void **pArgs)
 {
 	Py_ssize_t i;
 	PyObject *result;
 	PyObject *arglist = NULL;
 	Py_ssize_t nArgs;
+	PyObject *error_object = NULL;
+	int *space;
 #ifdef WITH_THREAD
 	PyGILState_STATE state = PyGILState_Ensure();
 #endif
@@ -271,8 +274,41 @@
 #define CHECK(what, x) \
 if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
 
+	if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
+		error_object = get_error_object(&space);
+		if (error_object == NULL)
+			goto Done;
+		if (flags & FUNCFLAG_USE_ERRNO) {
+			int temp = space[0];
+			space[0] = errno;
+			errno = temp;
+		}
+#ifdef MS_WIN32
+		if (flags & FUNCFLAG_USE_LASTERROR) {
+			int temp = space[1];
+			space[1] = GetLastError();
+			SetLastError(temp);
+		}
+#endif
+	}
+
 	result = PyObject_CallObject(callable, arglist);
 	CHECK("'calling callback function'", result);
+
+#ifdef MS_WIN32
+	if (flags & FUNCFLAG_USE_LASTERROR) {
+		int temp = space[1];
+		space[1] = GetLastError();
+		SetLastError(temp);
+	}
+#endif
+	if (flags & FUNCFLAG_USE_ERRNO) {
+		int temp = space[0];
+		space[0] = errno;
+		errno = temp;
+	}
+	Py_XDECREF(error_object);
+
 	if ((restype != &ffi_type_void) && result) {
 		PyObject *keep;
 		assert(setfunc);
@@ -322,6 +358,7 @@
 			  p->setfunc,
 			  p->callable,
 			  p->converters,
+			  p->flags,
 			  args);
 }
 
@@ -351,7 +388,7 @@
 CThunkObject *AllocFunctionCallback(PyObject *callable,
 				    PyObject *converters,
 				    PyObject *restype,
-				    int is_cdecl)
+				    int flags)
 {
 	int result;
 	CThunkObject *p;
@@ -371,6 +408,7 @@
 		goto error;
 	}
 
+	p->flags = flags;
 	for (i = 0; i < nArgs; ++i) {
 		PyObject *cnv = PySequence_GetItem(converters, i);
 		if (cnv == NULL)
@@ -398,7 +436,7 @@
 
 	cc = FFI_DEFAULT_ABI;
 #if defined(MS_WIN32) && !defined(_WIN32_WCE) && !defined(MS_WIN64)
-	if (is_cdecl == 0)
+	if ((flags & FUNCFLAG_CDECL) == 0)
 		cc = FFI_STDCALL;
 #endif
 	result = ffi_prep_cif(&p->cif, cc,

Modified: python/branches/tlee-ast-optimize/Modules/_ctypes/callproc.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/_ctypes/callproc.c	(original)
+++ python/branches/tlee-ast-optimize/Modules/_ctypes/callproc.c	Sun Jun  8 10:59:51 2008
@@ -83,7 +83,135 @@
 #define DONT_USE_SEH
 #endif
 
+/*
+  ctypes maintains thread-local storage that has space for two error numbers:
+  private copies of the system 'errno' value and, on Windows, the system error code
+  accessed by the GetLastError() and SetLastError() api functions.
+  
+  Foreign functions created with CDLL(..., use_errno=True), when called, swap
+  the system 'errno' value with the private copy just before the actual
+  function call, and swapped again immediately afterwards.  The 'use_errno'
+  parameter defaults to False, in this case 'ctypes_errno' is not touched.
+
+  On Windows, foreign functions created with CDLL(..., use_last_error=True) or
+  WinDLL(..., use_last_error=True) swap the system LastError value with the
+  ctypes private copy.
+
+  The values are also swapped immeditately before and after ctypes callback
+  functions are called, if the callbacks are constructed using the new
+  optional use_errno parameter set to True: CFUNCTYPE(..., use_errno=TRUE) or
+  WINFUNCTYPE(..., use_errno=True).
+
+  New ctypes functions are provided to access the ctypes private copies from
+  Python:
+
+  - ctypes.set_errno(value) and ctypes.set_last_error(value) store 'value' in
+    the private copy and returns the previous value.
+
+  - ctypes.get_errno() and ctypes.get_last_error() returns the current ctypes
+    private copies value.
+*/
+
+/*
+  This function creates and returns a thread-local Python object that has
+  space to store two integer error numbers; once created the Python object is
+  kept alive in the thread state dictionary as long as the thread itself.
+*/
+PyObject *
+get_error_object(int **pspace)
+{
+	PyObject *dict = PyThreadState_GetDict();
+	PyObject *errobj;
+	static PyObject *error_object_name;
+	if (dict == 0) {
+		PyErr_SetString(PyExc_RuntimeError,
+				"cannot get thread state");
+		return NULL;
+	}
+	if (error_object_name == NULL) {
+		error_object_name = PyString_InternFromString("ctypes.error_object");
+		if (error_object_name == NULL)
+			return NULL;
+	}
+	errobj = PyDict_GetItem(dict, error_object_name);
+	if (errobj)
+		Py_INCREF(errobj);
+	else {
+		void *space = PyMem_Malloc(sizeof(int) * 2);
+		if (space == NULL)
+			return NULL;
+		memset(space, 0, sizeof(int) * 2);
+		errobj = PyCObject_FromVoidPtr(space, PyMem_Free);
+		if (errobj == NULL)
+			return NULL;
+		if (-1 == PyDict_SetItem(dict, error_object_name,
+					 errobj)) {
+			Py_DECREF(errobj);
+			return NULL;
+		}
+	}
+	*pspace = (int *)PyCObject_AsVoidPtr(errobj);
+	return errobj;
+}
+
+static PyObject *
+get_error_internal(PyObject *self, PyObject *args, int index)
+{
+	int *space;
+	PyObject *errobj = get_error_object(&space);
+	PyObject *result;
+
+	if (errobj == NULL)
+		return NULL;
+	result = PyInt_FromLong(space[index]);
+	Py_DECREF(errobj);
+	return result;
+}
+
+static PyObject *
+set_error_internal(PyObject *self, PyObject *args, int index)
+{
+	int new_errno, old_errno;
+	PyObject *errobj;
+	int *space;
+
+	if (!PyArg_ParseTuple(args, "i", &new_errno))
+		return NULL;
+	errobj = get_error_object(&space);
+	if (errobj == NULL)
+		return NULL;
+	old_errno = space[index];
+	space[index] = new_errno;
+	Py_DECREF(errobj);
+	return PyInt_FromLong(old_errno);
+}
+
+static PyObject *
+get_errno(PyObject *self, PyObject *args)
+{
+	return get_error_internal(self, args, 0);
+}
+
+static PyObject *
+set_errno(PyObject *self, PyObject *args)
+{
+	return set_error_internal(self, args, 0);
+}
+
 #ifdef MS_WIN32
+
+static PyObject *
+get_last_error(PyObject *self, PyObject *args)
+{
+	return get_error_internal(self, args, 1);
+}
+
+static PyObject *
+set_last_error(PyObject *self, PyObject *args)
+{
+	return set_error_internal(self, args, 1);
+}
+
 PyObject *ComError;
 
 static TCHAR *FormatError(DWORD code)
@@ -625,6 +753,8 @@
 #ifdef WITH_THREAD
 	PyThreadState *_save = NULL; /* For Py_BLOCK_THREADS and Py_UNBLOCK_THREADS */
 #endif
+	PyObject *error_object = NULL;
+	int *space;
 	ffi_cif cif;
 	int cc;
 #ifdef MS_WIN32
@@ -656,11 +786,26 @@
 		return -1;
 	}
 
+	if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
+		error_object = get_error_object(&space);
+		if (error_object == NULL)
+			return -1;
+	}
 #ifdef WITH_THREAD
 	if ((flags & FUNCFLAG_PYTHONAPI) == 0)
 		Py_UNBLOCK_THREADS
 #endif
+	if (flags & FUNCFLAG_USE_ERRNO) {
+		int temp = space[0];
+		space[0] = errno;
+		errno = temp;
+	}
 #ifdef MS_WIN32
+	if (flags & FUNCFLAG_USE_LASTERROR) {
+		int temp = space[1];
+		space[1] = GetLastError();
+		SetLastError(temp);
+	}
 #ifndef DONT_USE_SEH
 	__try {
 #endif
@@ -675,7 +820,18 @@
 		;
 	}
 #endif
+	if (flags & FUNCFLAG_USE_LASTERROR) {
+		int temp = space[1];
+		space[1] = GetLastError();
+		SetLastError(temp);
+	}
 #endif
+	if (flags & FUNCFLAG_USE_ERRNO) {
+		int temp = space[0];
+		space[0] = errno;
+		errno = temp;
+	}
+	Py_XDECREF(error_object);
 #ifdef WITH_THREAD
 	if ((flags & FUNCFLAG_PYTHONAPI) == 0)
 		Py_BLOCK_THREADS
@@ -1666,15 +1822,46 @@
 	return result;
 }
 
+static PyObject *
+buffer_info(PyObject *self, PyObject *arg)
+{
+	StgDictObject *dict = PyType_stgdict(arg);
+	PyObject *shape;
+	Py_ssize_t i;
+
+	if (dict == NULL)
+		dict = PyObject_stgdict(arg);
+	if (dict == NULL) {
+		PyErr_SetString(PyExc_TypeError,
+				"not a ctypes type or object");
+		return NULL;
+	}
+	shape = PyTuple_New(dict->ndim);
+	for (i = 0; i < (int)dict->ndim; ++i)
+		PyTuple_SET_ITEM(shape, i, PyLong_FromSsize_t(dict->shape[i]));
+
+	if (PyErr_Occurred()) {
+		Py_DECREF(shape);
+		return NULL;
+	}
+	return Py_BuildValue("siN", dict->format, dict->ndim, shape);
+}
+
 PyMethodDef module_methods[] = {
+	{"get_errno", get_errno, METH_NOARGS},
+	{"set_errno", set_errno, METH_VARARGS},
 	{"POINTER", POINTER, METH_O },
 	{"pointer", pointer, METH_O },
 	{"_unpickle", unpickle, METH_VARARGS },
+	{"_buffer_info", buffer_info, METH_O,
+	 "Return buffer interface information (for testing only)"},
 	{"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},
 #ifdef CTYPES_UNICODE
 	{"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc},
 #endif
 #ifdef MS_WIN32
+	{"get_last_error", get_last_error, METH_NOARGS},
+	{"set_last_error", set_last_error, METH_VARARGS},
 	{"CopyComPointer", copy_com_pointer, METH_VARARGS, copy_com_pointer_doc},
 	{"FormatError", format_error, METH_VARARGS, format_error_doc},
 	{"LoadLibrary", load_library, METH_VARARGS, load_library_doc},

Modified: python/branches/tlee-ast-optimize/Modules/_ctypes/ctypes.h
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/_ctypes/ctypes.h	(original)
+++ python/branches/tlee-ast-optimize/Modules/_ctypes/ctypes.h	Sun Jun  8 10:59:51 2008
@@ -87,6 +87,7 @@
 	PyObject_VAR_HEAD
 	ffi_closure *pcl; /* the C callable */
 	ffi_cif cif;
+	int flags;
 	PyObject *converters;
 	PyObject *callable;
 	PyObject *restype;
@@ -185,7 +186,7 @@
 extern CThunkObject *AllocFunctionCallback(PyObject *callable,
 					   PyObject *converters,
 					   PyObject *restype,
-					   int stdcall);
+					   int flags);
 /* a table entry describing a predefined ctypes type */
 struct fielddesc {
 	char code;
@@ -235,6 +236,14 @@
 	PyObject *restype;	/* CDataObject or NULL */
 	PyObject *checker;
 	int flags;		/* calling convention and such */
+
+	/* pep3118 fields, pointers neeed PyMem_Free */
+	char *format;
+	int ndim;
+	Py_ssize_t *shape;
+/*	Py_ssize_t *strides;	*/ /* unused in ctypes */
+/*	Py_ssize_t *suboffsets;	*/ /* unused in ctypes */
+
 } StgDictObject;
 
 /****************************************************************
@@ -303,6 +312,8 @@
 #define FUNCFLAG_CDECL   0x1
 #define FUNCFLAG_HRESULT 0x2
 #define FUNCFLAG_PYTHONAPI 0x4
+#define FUNCFLAG_USE_ERRNO 0x8
+#define FUNCFLAG_USE_LASTERROR 0x10
 
 #define TYPEFLAG_ISPOINTER 0x100
 #define TYPEFLAG_HASPOINTER 0x200
@@ -415,11 +426,13 @@
 extern void _AddTraceback(char *, char *, int);
 
 extern PyObject *CData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr);
+extern char *alloc_format_string(const char *prefix, const char *suffix);
 
 /* XXX better name needed! */
 extern int IsSimpleSubType(PyObject *obj);
 
 extern PyObject *_pointer_type_cache;
+PyObject *get_error_object(int **pspace);
 
 #ifdef MS_WIN32
 extern PyObject *ComError;

Modified: python/branches/tlee-ast-optimize/Modules/_ctypes/stgdict.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/_ctypes/stgdict.c	(original)
+++ python/branches/tlee-ast-optimize/Modules/_ctypes/stgdict.c	Sun Jun  8 10:59:51 2008
@@ -6,6 +6,7 @@
 #include <ffi.h>
 #ifdef MS_WIN32
 #include <windows.h>
+#include <malloc.h>
 #endif
 #include "ctypes.h"
 
@@ -24,6 +25,9 @@
 {
 	if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0)
 		return -1;
+	self->format = NULL;
+	self->ndim = 0;
+	self->shape = NULL;
 	return 0;
 }
 
@@ -42,6 +46,8 @@
 StgDict_dealloc(StgDictObject *self)
 {
 	StgDict_clear(self);
+	PyMem_Free(self->format);
+	PyMem_Free(self->shape);
 	PyMem_Free(self->ffi_type_pointer.elements);
 	PyDict_Type.tp_dealloc((PyObject *)self);
 }
@@ -54,6 +60,10 @@
 
 	StgDict_clear(dst);
 	PyMem_Free(dst->ffi_type_pointer.elements);
+	PyMem_Free(dst->format);
+	dst->format = NULL;
+	PyMem_Free(dst->shape);
+	dst->shape = NULL;
 	dst->ffi_type_pointer.elements = NULL;
 
 	d = (char *)dst;
@@ -68,6 +78,20 @@
 	Py_XINCREF(dst->restype);
 	Py_XINCREF(dst->checker);
 
+	if (src->format) {
+		dst->format = PyMem_Malloc(strlen(src->format) + 1);
+		if (dst->format == NULL)
+			return -1;
+		strcpy(dst->format, src->format);
+	}
+	if (src->shape) {
+		dst->shape = PyMem_Malloc(sizeof(Py_ssize_t) * src->ndim);
+		if (dst->shape == NULL)
+			return -1;
+		memcpy(dst->shape, src->shape,
+		       sizeof(Py_ssize_t) * src->ndim);
+	}
+
 	if (src->ffi_type_pointer.elements == NULL)
 		return 0;
 	size = sizeof(ffi_type *) * (src->length + 1);
@@ -349,6 +373,11 @@
 		return -1;
 	}
 
+	if (stgdict->format) {
+		PyMem_Free(stgdict->format);
+		stgdict->format = NULL;
+	}
+
 	if (stgdict->ffi_type_pointer.elements)
 		PyMem_Free(stgdict->ffi_type_pointer.elements);
 
@@ -387,6 +416,15 @@
 		ffi_ofs = 0;
 	}
 
+	if (isStruct && !isPacked) {
+		stgdict->format = alloc_format_string(NULL, "T{");
+	} else {
+		/* PEP3118 doesn't support union, or packed structures (well,
+		   only standard packing, but we dont support the pep for
+		   that). Use 'B' for bytes. */
+		stgdict->format = alloc_format_string(NULL, "B");
+	}
+
 #define realdict ((PyObject *)&stgdict->dict)
 	for (i = 0; i < len; ++i) {
 		PyObject *name = NULL, *desc = NULL;
@@ -451,6 +489,24 @@
 			}
 		} else
 			bitsize = 0;
+		if (isStruct && !isPacked) {
+			char *fieldfmt = dict->format ? dict->format : "B";
+			char *fieldname = PyString_AsString(name);
+			char *ptr;
+			Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt);
+			char *buf = alloca(len + 2 + 1);
+
+			sprintf(buf, "%s:%s:", fieldfmt, fieldname);
+
+			ptr = stgdict->format;
+			stgdict->format = alloc_format_string(stgdict->format, buf);
+			PyMem_Free(ptr);
+
+			if (stgdict->format == NULL) {
+				Py_DECREF(pair);
+				return -1;
+			}
+		}
 		if (isStruct) {
 			prop = CField_FromDesc(desc, i,
 					       &field_size, bitsize, &bitofs,
@@ -481,6 +537,13 @@
 		Py_DECREF(prop);
 	}
 #undef realdict
+
+	if (isStruct && !isPacked) {
+		stgdict->format = alloc_format_string(stgdict->format, "}");
+		if (stgdict->format == NULL)
+			return -1;
+	}
+
 	if (!isStruct)
 		size = union_size;
 

Modified: python/branches/tlee-ast-optimize/Modules/_heapqmodule.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/_heapqmodule.c	(original)
+++ python/branches/tlee-ast-optimize/Modules/_heapqmodule.c	Sun Jun  8 10:59:51 2008
@@ -8,6 +8,25 @@
 
 #include "Python.h"
 
+/* Older implementations of heapq used Py_LE for comparisons.  Now, it uses
+   Py_LT so it will match min(), sorted(), and bisect().  Unfortunately, some
+   client code (Twisted for example) relied on Py_LE, so this little function
+   restores compatability by trying both.
+*/
+static int
+cmp_lt(PyObject *x, PyObject *y)
+{
+	int cmp;
+	cmp = PyObject_RichCompareBool(x, y, Py_LT);
+	if (cmp == -1 && PyErr_ExceptionMatches(PyExc_AttributeError)) {
+		PyErr_Clear();
+		cmp = PyObject_RichCompareBool(y, x, Py_LE);
+		if (cmp != -1)
+			cmp = 1 - cmp;
+	}
+	return cmp;
+}
+
 static int
 _siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
 {
@@ -28,7 +47,7 @@
 	while (pos > startpos){
 		parentpos = (pos - 1) >> 1;
 		parent = PyList_GET_ITEM(heap, parentpos);
-		cmp = PyObject_RichCompareBool(newitem, parent, Py_LT);
+		cmp = cmp_lt(newitem, parent);
 		if (cmp == -1) {
 			Py_DECREF(newitem);
 			return -1;
@@ -68,10 +87,9 @@
 		/* Set childpos to index of smaller child.   */
 		rightpos = childpos + 1;
 		if (rightpos < endpos) {
-			cmp = PyObject_RichCompareBool(
+			cmp = cmp_lt(
 				PyList_GET_ITEM(heap, childpos),
-				PyList_GET_ITEM(heap, rightpos),
-				Py_LT);
+				PyList_GET_ITEM(heap, rightpos));
 			if (cmp == -1) {
 				Py_DECREF(newitem);
 				return -1;
@@ -214,7 +232,7 @@
 		return item;
 	}
 
-	cmp = PyObject_RichCompareBool(PyList_GET_ITEM(heap, 0), item, Py_LT);
+	cmp = cmp_lt(PyList_GET_ITEM(heap, 0), item);
 	if (cmp == -1)
 		return NULL;
 	if (cmp == 0) {
@@ -313,7 +331,7 @@
 			else
 				goto sortit;
 		}
-		cmp = PyObject_RichCompareBool(sol, elem, Py_LT);
+		cmp = cmp_lt(sol, elem);
 		if (cmp == -1) {
 			Py_DECREF(elem);
 			goto fail;
@@ -368,7 +386,7 @@
 	while (pos > startpos){
 		parentpos = (pos - 1) >> 1;
 		parent = PyList_GET_ITEM(heap, parentpos);
-		cmp = PyObject_RichCompareBool(parent, newitem, Py_LT);
+		cmp = cmp_lt(parent, newitem);
 		if (cmp == -1) {
 			Py_DECREF(newitem);
 			return -1;
@@ -408,10 +426,9 @@
 		/* Set childpos to index of smaller child.   */
 		rightpos = childpos + 1;
 		if (rightpos < endpos) {
-			cmp = PyObject_RichCompareBool(
+			cmp = cmp_lt(
 				PyList_GET_ITEM(heap, rightpos),
-				PyList_GET_ITEM(heap, childpos),
-				Py_LT);
+				PyList_GET_ITEM(heap, childpos));
 			if (cmp == -1) {
 				Py_DECREF(newitem);
 				return -1;
@@ -484,7 +501,7 @@
 			else
 				goto sortit;
 		}
-		cmp = PyObject_RichCompareBool(elem, los, Py_LT);
+		cmp = cmp_lt(elem, los);
 		if (cmp == -1) {
 			Py_DECREF(elem);
 			goto fail;

Modified: python/branches/tlee-ast-optimize/Objects/abstract.c
==============================================================================
--- python/branches/tlee-ast-optimize/Objects/abstract.c	(original)
+++ python/branches/tlee-ast-optimize/Objects/abstract.c	Sun Jun  8 10:59:51 2008
@@ -685,12 +685,6 @@
 	      int readonly, int flags)
 {
 	if (view == NULL) return 0;
-	if (((flags & PyBUF_LOCK) == PyBUF_LOCK) &&
-	    readonly != 0) {
-		PyErr_SetString(PyExc_BufferError,
-				"Cannot lock this object.");
-		return -1;
-	}
 	if (((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) &&
 	    (readonly == 1)) {
 		PyErr_SetString(PyExc_BufferError,

Modified: python/branches/tlee-ast-optimize/Python/ast.c
==============================================================================
--- python/branches/tlee-ast-optimize/Python/ast.c	(original)
+++ python/branches/tlee-ast-optimize/Python/ast.c	Sun Jun  8 10:59:51 2008
@@ -1364,7 +1364,7 @@
     case BACKQUOTE: { /* repr */
         expr_ty expression;
         if (Py_Py3kWarningFlag) {
-            if (PyErr_WarnExplicit(PyExc_DeprecationWarning,
+            if (PyErr_WarnExplicit(PyExc_SyntaxWarning,
                                    "backquote not supported in 3.x; use repr()",
                                    c->c_filename, LINENO(n),
                                    NULL, NULL)) {

Modified: python/branches/tlee-ast-optimize/configure
==============================================================================
--- python/branches/tlee-ast-optimize/configure	(original)
+++ python/branches/tlee-ast-optimize/configure	Sun Jun  8 10:59:51 2008
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 63690 .
+# From configure.in Revision: 63955 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for python 2.6.
 #
@@ -2072,7 +2072,7 @@
   # On OpenBSD, select(2) is not available if _XOPEN_SOURCE is defined,
   # even though select is a POSIX function. Reported by J. Ribbens.
   # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish.
-  OpenBSD/2.* | OpenBSD/3.[0123456789] | OpenBSD/4.[0])
+  OpenBSD/2.* | OpenBSD/3.[0123456789] | OpenBSD/4.[0123])
     define_xopen_source=no
     # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
     # also defined. This can be overridden by defining _BSD_SOURCE
@@ -4659,6 +4659,7 @@
 
 
 		BASECFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${BASECFLAGS}"
+		CFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${CFLAGS}"
 	    fi
 
 	    ;;
@@ -12400,6 +12401,7 @@
 echo "${ECHO_T}$enable_toolbox_glue" >&6; }
 
 
+
 case $ac_sys_system/$ac_sys_release in
   Darwin/[01567]\..*)
     OTHER_LIBTOOL_OPT="-prebind -seg1addr 0x10000000"
@@ -12746,6 +12748,7 @@
 echo "${ECHO_T}$LINKFORSHARED" >&6; }
 
 
+
 { echo "$as_me:$LINENO: checking CFLAGSFORSHARED" >&5
 echo $ECHO_N "checking CFLAGSFORSHARED... $ECHO_C" >&6; }
 if test ! "$LIBRARY" = "$LDLIBRARY"
@@ -15309,6 +15312,58 @@
 	fi
 fi
 
+{ echo "$as_me:$LINENO: checking for OSX 10.5 SDK or later" >&5
+echo $ECHO_N "checking for OSX 10.5 SDK or later... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <Carbon/Carbon.h>
+int
+main ()
+{
+FSIORefNum fRef = 0
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_OSX105_SDK 1
+_ACEOF
+
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
 # Check for --with-doc-strings
 { echo "$as_me:$LINENO: checking for --with-doc-strings" >&5
 echo $ECHO_N "checking for --with-doc-strings... $ECHO_C" >&6; }

Modified: python/branches/tlee-ast-optimize/configure.in
==============================================================================
--- python/branches/tlee-ast-optimize/configure.in	(original)
+++ python/branches/tlee-ast-optimize/configure.in	Sun Jun  8 10:59:51 2008
@@ -248,7 +248,7 @@
   # On OpenBSD, select(2) is not available if _XOPEN_SOURCE is defined,
   # even though select is a POSIX function. Reported by J. Ribbens.
   # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish.
-  OpenBSD/2.* | OpenBSD/3.@<:@0123456789@:>@ | OpenBSD/4.@<:@0@:>@) 
+  OpenBSD/2.* | OpenBSD/3.@<:@0123456789@:>@ | OpenBSD/4.@<:@0123@:>@) 
     define_xopen_source=no
     # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
     # also defined. This can be overridden by defining _BSD_SOURCE
@@ -918,6 +918,7 @@
 
 
 		BASECFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${BASECFLAGS}"
+		CFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${CFLAGS}"
 	    fi
 
 	    ;;
@@ -1320,6 +1321,17 @@
 AC_CHECK_SIZEOF(long long, 8)
 fi
 
+AC_MSG_CHECKING(for long double support)
+have_long_double=no
+AC_TRY_COMPILE([], [long double x; x = (long double)0.;], [
+  AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define this if you have the type long double.])
+  have_long_double=yes
+])
+AC_MSG_RESULT($have_long_double)
+if test "$have_long_long" = yes ; then
+AC_CHECK_SIZEOF(long double, 12)
+fi
+
 AC_MSG_CHECKING(for _Bool support)
 have_c99_bool=no
 AC_TRY_COMPILE([], [_Bool x; x = (_Bool)0;], [
@@ -1456,6 +1468,7 @@
 esac
 AC_MSG_RESULT($enable_toolbox_glue)
 
+
 AC_SUBST(OTHER_LIBTOOL_OPT)
 case $ac_sys_system/$ac_sys_release in
   Darwin/@<:@01567@:>@\..*) 
@@ -1781,6 +1794,7 @@
 fi
 AC_MSG_RESULT($LINKFORSHARED)
 
+
 AC_SUBST(CFLAGSFORSHARED)
 AC_MSG_CHECKING(CFLAGSFORSHARED)
 if test ! "$LIBRARY" = "$LDLIBRARY"
@@ -2297,6 +2311,13 @@
 	fi
 fi
 
+AC_MSG_CHECKING(for OSX 10.5 SDK or later)
+AC_TRY_COMPILE([#include <Carbon/Carbon.h>], FSIORefNum fRef = 0,
+  AC_DEFINE(HAVE_OSX105_SDK, 1, Define if compiling using MacOS X 10.5 SDK or later.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
 # Check for --with-doc-strings
 AC_MSG_CHECKING(for --with-doc-strings)
 AC_ARG_WITH(doc-strings,

Modified: python/branches/tlee-ast-optimize/pyconfig.h.in
==============================================================================
--- python/branches/tlee-ast-optimize/pyconfig.h.in	(original)
+++ python/branches/tlee-ast-optimize/pyconfig.h.in	Sun Jun  8 10:59:51 2008
@@ -426,6 +426,9 @@
 /* Define to 1 if you have the `openpty' function. */
 #undef HAVE_OPENPTY
 
+/* Define if compiling using MacOS X 10.5 SDK or later. */
+#undef HAVE_OSX105_SDK
+
 /* Define to 1 if you have the `pathconf' function. */
 #undef HAVE_PATHCONF
 
@@ -489,9 +492,6 @@
 /* Define if you have readline 4.2 */
 #undef HAVE_RL_COMPLETION_MATCHES
 
-/* Define when using libedit's readline emulation */
-#undef HAVE_RL_DISPM_VFUNC
-
 /* Define if you have readline 4.0 */
 #undef HAVE_RL_PRE_INPUT_HOOK
 


More information about the Python-checkins mailing list