Changeset 391 for python/trunk/Doc/whatsnew/2.5.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/whatsnew/2.5.rst
r2 r391 871 871 ======================================== 872 872 873 A wide-ranging change to Python's C API, using a new :c type:`Py_ssize_t` type874 definition instead of :c type:`int`, will permit the interpreter to handle more873 A wide-ranging change to Python's C API, using a new :c:type:`Py_ssize_t` type 874 definition instead of :c:type:`int`, will permit the interpreter to handle more 875 875 data on 64-bit platforms. This change doesn't affect Python's capacity on 32-bit 876 876 platforms. 877 877 878 Various pieces of the Python interpreter used C's :c type:`int` type to store878 Various pieces of the Python interpreter used C's :c:type:`int` type to store 879 879 sizes or counts; for example, the number of items in a list or tuple were stored 880 in an :c type:`int`. The C compilers for most 64-bit platforms still define881 :c type:`int` as a 32-bit type, so that meant that lists could only hold up to880 in an :c:type:`int`. The C compilers for most 64-bit platforms still define 881 :c:type:`int` as a 32-bit type, so that meant that lists could only hold up to 882 882 ``2**31 - 1`` = 2147483647 items. (There are actually a few different 883 883 programming models that 64-bit C compilers can use -- see 884 884 http://www.unix.org/version2/whatsnew/lp64_wp.html for a discussion -- but the 885 most commonly available model leaves :c type:`int` as 32 bits.)885 most commonly available model leaves :c:type:`int` as 32 bits.) 886 886 887 887 A limit of 2147483647 items doesn't really matter on a 32-bit platform because 888 888 you'll run out of memory before hitting the length limit. Each list item 889 889 requires space for a pointer, which is 4 bytes, plus space for a 890 :c type:`PyObject` representing the item. 2147483647\*4 is already more bytes890 :c:type:`PyObject` representing the item. 2147483647\*4 is already more bytes 891 891 than a 32-bit address space can contain. 892 892 … … 895 895 unreasonable that Python programmers might construct lists that large. 896 896 Therefore, the Python interpreter had to be changed to use some type other than 897 :c type:`int`, and this will be a 64-bit type on 64-bit platforms. The change897 :c:type:`int`, and this will be a 64-bit type on 64-bit platforms. The change 898 898 will cause incompatibilities on 64-bit machines, so it was deemed worth making 899 899 the transition now, while the number of 64-bit users is still relatively small. … … 903 903 This change most strongly affects authors of C extension modules. Python 904 904 strings and container types such as lists and tuples now use 905 :c type:`Py_ssize_t` to store their size. Functions such as906 :c func:`PyList_Size` now return :ctype:`Py_ssize_t`. Code in extension modules907 may therefore need to have some variables changed to :c type:`Py_ssize_t`.908 909 The :c func:`PyArg_ParseTuple` and :cfunc:`Py_BuildValue` functions have a new910 conversion code, ``n``, for :c type:`Py_ssize_t`. :cfunc:`PyArg_ParseTuple`'s911 ``s#`` and ``t#`` still output :c type:`int` by default, but you can define the912 macro :c macro:`PY_SSIZE_T_CLEAN` before including :file:`Python.h` to make913 them return :c type:`Py_ssize_t`.905 :c:type:`Py_ssize_t` to store their size. Functions such as 906 :c:func:`PyList_Size` now return :c:type:`Py_ssize_t`. Code in extension modules 907 may therefore need to have some variables changed to :c:type:`Py_ssize_t`. 908 909 The :c:func:`PyArg_ParseTuple` and :c:func:`Py_BuildValue` functions have a new 910 conversion code, ``n``, for :c:type:`Py_ssize_t`. :c:func:`PyArg_ParseTuple`'s 911 ``s#`` and ``t#`` still output :c:type:`int` by default, but you can define the 912 macro :c:macro:`PY_SSIZE_T_CLEAN` before including :file:`Python.h` to make 913 them return :c:type:`Py_ssize_t`. 914 914 915 915 :pep:`353` has a section on conversion guidelines that extension authors should … … 955 955 956 956 A corresponding :attr:`nb_index` slot was added to the C-level 957 :c type:`PyNumberMethods` structure to let C extensions implement this protocol.958 :c func:`PyNumber_Index(obj)` can be used in extension code to call the957 :c:type:`PyNumberMethods` structure to let C extensions implement this protocol. 958 :c:func:`PyNumber_Index(obj)` can be used in extension code to call the 959 959 :meth:`__index__` function and retrieve its result. 960 960 … … 1180 1180 1181 1181 * The :mod:`re` module got a 1 or 2% speedup by switching to Python's allocator 1182 functions instead of the system's :c func:`malloc` and :cfunc:`free`.1182 functions instead of the system's :c:func:`malloc` and :c:func:`free`. 1183 1183 (Contributed by Jack Diederich at the NeedForSpeed sprint.) 1184 1184 … … 1204 1204 1205 1205 * Importing now caches the paths tried, recording whether they exist or not so 1206 that the interpreter makes fewer :c func:`open` and :cfunc:`stat` calls on1206 that the interpreter makes fewer :c:func:`open` and :c:func:`stat` calls on 1207 1207 startup. (Contributed by Martin von Löwis and Georg Brandl.) 1208 1208 … … 1339 1339 .. XXX need to provide some more detail here 1340 1340 1341 .. index:: 1342 single: universal newlines; What's new 1343 1341 1344 * The :mod:`fileinput` module was made more flexible. Unicode filenames are now 1342 1345 supported, and a *mode* parameter that defaults to ``"r"`` was added to the 1343 :func:`input` function to allow opening files in binary or universal-newline 1344 mode. Another new parameter, *openhook*, lets you use a function other than 1345 :func:`open` to open the input files. Once you're iterating over the set of 1346 files, the :class:`FileInput` object's new :meth:`fileno` returns the file 1347 descriptor for the currently opened file. (Contributed by Georg Brandl.) 1346 :func:`input` function to allow opening files in binary or :term:`universal 1347 newlines` mode. Another new parameter, *openhook*, lets you use a function 1348 other than :func:`open` to open the input files. Once you're iterating over 1349 the set of files, the :class:`FileInput` object's new :meth:`fileno` returns 1350 the file descriptor for the currently opened file. (Contributed by Georg 1351 Brandl.) 1348 1352 1349 1353 * In the :mod:`gc` module, the new :func:`get_count` function returns a 3-tuple … … 1460 1464 On FreeBSD, the :func:`os.stat` function now returns times with nanosecond 1461 1465 resolution, and the returned object now has :attr:`st_gen` and 1462 :attr:`st_birthtime`. The :attr:`st_flags` memberis also available, if the1466 :attr:`st_birthtime`. The :attr:`st_flags` attribute is also available, if the 1463 1467 platform supports it. (Contributed by Antti Louko and Diego Pettenò.) 1464 1468 … … 1569 1573 1570 1574 This information is also available to C extensions via the 1571 :c func:`Py_GetBuildInfo` function that returns a string of build information1575 :c:func:`Py_GetBuildInfo` function that returns a string of build information 1572 1576 like this: ``"trunk:45355:45356M, Apr 13 2006, 07:42:19"``. (Contributed by 1573 1577 Barry Warsaw.) … … 1691 1695 1692 1696 Type constructors for the various C types are provided: :func:`c_int`, 1693 :func:`c_float`, :func:`c_double`, :func:`c_char_p` (equivalent to :c type:`char1697 :func:`c_float`, :func:`c_double`, :func:`c_char_p` (equivalent to :c:type:`char 1694 1698 \*`), and so forth. Unlike Python's types, the C versions are all mutable; you 1695 1699 can assign to their :attr:`value` attribute to change the wrapped value. Python … … 1721 1725 interpreter lock before calling a function, because the lock must be held when 1722 1726 calling into the interpreter's code. There's a :class:`py_object()` type 1723 constructor that will create a :c type:`PyObject \*` pointer. A simple usage::1727 constructor that will create a :c:type:`PyObject \*` pointer. A simple usage:: 1724 1728 1725 1729 import ctypes … … 1766 1770 1767 1771 ElementTree represents an XML document as a tree of element nodes. The text 1768 content of the document is stored as the :attr:` .text` and :attr:`.tail`1772 content of the document is stored as the :attr:`text` and :attr:`tail` 1769 1773 attributes of (This is one of the major differences between ElementTree and 1770 1774 the Document Object Model; in the DOM there are many different types of node, … … 2088 2092 2089 2093 * The largest change to the C API came from :pep:`353`, which modifies the 2090 interpreter to use a :c type:`Py_ssize_t` type definition instead of2091 :c type:`int`. See the earlier section :ref:`pep-353` for a discussion of this2094 interpreter to use a :c:type:`Py_ssize_t` type definition instead of 2095 :c:type:`int`. See the earlier section :ref:`pep-353` for a discussion of this 2092 2096 change. 2093 2097 … … 2114 2118 the various AST nodes in :file:`Parser/Python.asdl`. A Python script reads this 2115 2119 file and generates a set of C structure definitions in 2116 :file:`Include/Python-ast.h`. The :c func:`PyParser_ASTFromString` and2117 :c func:`PyParser_ASTFromFile`, defined in :file:`Include/pythonrun.h`, take2120 :file:`Include/Python-ast.h`. The :c:func:`PyParser_ASTFromString` and 2121 :c:func:`PyParser_ASTFromFile`, defined in :file:`Include/pythonrun.h`, take 2118 2122 Python source as input and return the root of an AST representing the contents. 2119 This AST can then be turned into a code object by :c func:`PyAST_Compile`. For2123 This AST can then be turned into a code object by :c:func:`PyAST_Compile`. For 2120 2124 more information, read the source code, and then ask questions on python-dev. 2121 2125 … … 2139 2143 Note that this change means extension modules must be more careful when 2140 2144 allocating memory. Python's API has many different functions for allocating 2141 memory that are grouped into families. For example, :c func:`PyMem_Malloc`,2142 :c func:`PyMem_Realloc`, and :cfunc:`PyMem_Free` are one family that allocates2143 raw memory, while :c func:`PyObject_Malloc`, :cfunc:`PyObject_Realloc`, and2144 :c func:`PyObject_Free` are another family that's supposed to be used for2145 memory that are grouped into families. For example, :c:func:`PyMem_Malloc`, 2146 :c:func:`PyMem_Realloc`, and :c:func:`PyMem_Free` are one family that allocates 2147 raw memory, while :c:func:`PyObject_Malloc`, :c:func:`PyObject_Realloc`, and 2148 :c:func:`PyObject_Free` are another family that's supposed to be used for 2145 2149 creating Python objects. 2146 2150 2147 2151 Previously these different families all reduced to the platform's 2148 :c func:`malloc` and :cfunc:`free` functions. This meant it didn't matter if2149 you got things wrong and allocated memory with the :c func:`PyMem` function but2150 freed it with the :c func:`PyObject` function. With 2.5's changes to obmalloc,2152 :c:func:`malloc` and :c:func:`free` functions. This meant it didn't matter if 2153 you got things wrong and allocated memory with the :c:func:`PyMem` function but 2154 freed it with the :c:func:`PyObject` function. With 2.5's changes to obmalloc, 2151 2155 these families now do different things and mismatches will probably result in a 2152 2156 segfault. You should carefully test your C extension modules with Python 2.5. 2153 2157 2154 * The built-in set types now have an official C API. Call :c func:`PySet_New`2155 and :c func:`PyFrozenSet_New` to create a new set, :cfunc:`PySet_Add` and2156 :c func:`PySet_Discard` to add and remove elements, and :cfunc:`PySet_Contains`2157 and :c func:`PySet_Size` to examine the set's state. (Contributed by Raymond2158 * The built-in set types now have an official C API. Call :c:func:`PySet_New` 2159 and :c:func:`PyFrozenSet_New` to create a new set, :c:func:`PySet_Add` and 2160 :c:func:`PySet_Discard` to add and remove elements, and :c:func:`PySet_Contains` 2161 and :c:func:`PySet_Size` to examine the set's state. (Contributed by Raymond 2158 2162 Hettinger.) 2159 2163 2160 2164 * C code can now obtain information about the exact revision of the Python 2161 interpreter by calling the :c func:`Py_GetBuildInfo` function that returns a2165 interpreter by calling the :c:func:`Py_GetBuildInfo` function that returns a 2162 2166 string of build information like this: ``"trunk:45355:45356M, Apr 13 2006, 2163 2167 07:42:19"``. (Contributed by Barry Warsaw.) … … 2165 2169 * Two new macros can be used to indicate C functions that are local to the 2166 2170 current file so that a faster calling convention can be used. 2167 :c func:`Py_LOCAL(type)` declares the function as returning a value of the2171 :c:func:`Py_LOCAL(type)` declares the function as returning a value of the 2168 2172 specified *type* and uses a fast-calling qualifier. 2169 :c func:`Py_LOCAL_INLINE(type)` does the same thing and also requests the2170 function be inlined. If :c func:`PY_LOCAL_AGGRESSIVE` is defined before2173 :c:func:`Py_LOCAL_INLINE(type)` does the same thing and also requests the 2174 function be inlined. If :c:func:`PY_LOCAL_AGGRESSIVE` is defined before 2171 2175 :file:`python.h` is included, a set of more aggressive optimizations are enabled 2172 2176 for the module; you should benchmark the results to find out if these … … 2174 2178 the NeedForSpeed sprint.) 2175 2179 2176 * :c func:`PyErr_NewException(name, base, dict)` can now accept a tuple of base2180 * :c:func:`PyErr_NewException(name, base, dict)` can now accept a tuple of base 2177 2181 classes as its *base* argument. (Contributed by Georg Brandl.) 2178 2182 2179 * The :c func:`PyErr_Warn` function for issuing warnings is now deprecated in2180 favour of :c func:`PyErr_WarnEx(category, message, stacklevel)` which lets you2183 * The :c:func:`PyErr_Warn` function for issuing warnings is now deprecated in 2184 favour of :c:func:`PyErr_WarnEx(category, message, stacklevel)` which lets you 2181 2185 specify the number of stack frames separating this function and the caller. A 2182 *stacklevel* of 1 is the function calling :c func:`PyErr_WarnEx`, 2 is the2186 *stacklevel* of 1 is the function calling :c:func:`PyErr_WarnEx`, 2 is the 2183 2187 function above that, and so forth. (Added by Neal Norwitz.) 2184 2188 … … 2187 2191 Martin von Löwis, Skip Montanaro.) 2188 2192 2189 * The :c func:`PyRange_New` function was removed. It was never documented, never2193 * The :c:func:`PyRange_New` function was removed. It was never documented, never 2190 2194 used in the core code, and had dangerously lax error checking. In the unlikely 2191 2195 case that your extensions were using it, you can replace it by something like … … 2204 2208 2205 2209 * MacOS X (10.3 and higher): dynamic loading of modules now uses the 2206 :c func:`dlopen` function instead of MacOS-specific functions.2210 :c:func:`dlopen` function instead of MacOS-specific functions. 2207 2211 2208 2212 * MacOS X: an :option:`--enable-universalsdk` switch was added to the … … 2260 2264 checking. 2261 2265 2262 * C API: Many functions now use :c type:`Py_ssize_t` instead of :ctype:`int` to2266 * C API: Many functions now use :c:type:`Py_ssize_t` instead of :c:type:`int` to 2263 2267 allow processing more data on 64-bit machines. Extension code may need to make 2264 2268 the same change to avoid warnings and to support 64-bit machines. See the … … 2266 2270 2267 2271 * C API: The obmalloc changes mean that you must be careful to not mix usage 2268 of the :c func:`PyMem_\*` and :cfunc:`PyObject_\*` families of functions. Memory2269 allocated with one family's :c func:`\*_Malloc` must be freed with the2270 corresponding family's :c func:`\*_Free` function.2272 of the :c:func:`PyMem_\*` and :c:func:`PyObject_\*` families of functions. Memory 2273 allocated with one family's :c:func:`\*_Malloc` must be freed with the 2274 corresponding family's :c:func:`\*_Free` function. 2271 2275 2272 2276 .. ======================================================================
Note:
See TracChangeset
for help on using the changeset viewer.