Commit Graph

2934 Commits

Author SHA1 Message Date
Georg Brandl 07e5681fd3 #2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich. 2008-03-21 20:21:46 +00:00
Raymond Hettinger c71d2a9afd Remove unnecessary traceback save/restore pair. 2008-03-19 22:47:48 +00:00
Raymond Hettinger 05387861ea Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh. 2008-03-19 17:45:19 +00:00
Raymond Hettinger de48d8406f Fix compiler warning. 2008-03-19 03:56:59 +00:00
Raymond Hettinger 6c0ff8aacd Issue: 2354: Add 3K warning for the cmp argument to list.sort() and sorted(). 2008-03-18 23:33:08 +00:00
Raymond Hettinger 9a47e6201f Speed-up isinstance() for one easy case. 2008-03-18 23:22:29 +00:00
Steven Bethard 6a644f92ef Add py3k warnings for code and method inequality comparisons. This should resolve issue 2373. The codeobject.c and methodobject.c changes are both just backports of the Python 3 code. 2008-03-18 22:08:20 +00:00
Steven Bethard b865f05a0f cell_compare needs to return -2 instead of NULL. 2008-03-18 19:03:50 +00:00
Steven Bethard ae42f33cdf Add py3k warnings for object, type, cell and dict comparisons. This should resolve issue2342 and partly resolve issue2373. 2008-03-18 17:26:10 +00:00
Brett Cannon 10ed0f50a9 Remove all traces of HAVE_STRERROR.
The removal of strerror.c led to the function check being removed from
configure.in.
2008-03-18 15:35:58 +00:00
Neal Norwitz b1d3d96374 Issue 2332: add new attribute names for instance method objects 2008-03-18 04:46:00 +00:00
Travis E. Oliphant 3781aef8f8 Finish backporting new buffer API to Python 2.6. Left to do: memoryview object and structmodule. But, these need to be finished in Python 3.0 first. No objects support the new buffer API in Python 2.6 as of yet, and except for the memoryview object, I don't think they will. 2008-03-18 04:44:57 +00:00
Guido van Rossum 6d91be3758 - Issue 2379: Raise a Py3K warning for __getitem__ or __getslice__ on
exception instances.
2008-03-18 04:42:22 +00:00
Jeffrey Yasskin 5de250e823 Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster. 2008-03-18 01:09:59 +00:00
Gregory P. Smith 887290d275 Fix the IOError message text when opening a file with an invalid filename.
Error reported by Ilan Schnell.
2008-03-18 00:20:01 +00:00
Neal Norwitz 419fd49abe Issue 2321: reduce memory usage (increase the memory that is returned
to the system) by using pymalloc for the data of unicode objects.

Will backport.
2008-03-17 20:22:43 +00:00
Eric Smith 9ff19b5434 Finished backporting PEP 3127, Integer Literal Support and Syntax.
Added 0b and 0o literals to tokenizer.
Modified PyOS_strtoul to support 0b and 0o inputs.
Modified PyLong_FromString to support guessing 0b and 0o inputs.
Renamed test_hexoct.py to test_int_literal.py and added binary tests.
Added upper and lower case 0b, 0O, and 0X tests to test_int_literal.py
2008-03-17 17:32:20 +00:00
Eric Smith 8113ca63b9 Issue 2264: empty float presentation type needs to have at least one digit past the decimal point.
Added "Z" format_char to PyOS_ascii_formatd to support empty float presentation type.
Renamed buf_size in PyOS_ascii_formatd to more accurately reflect it's meaning.
Modified format.__float__ to use the new "Z" format as the default.
Added test cases.
2008-03-17 11:01:01 +00:00
Mark Dickinson c23b8a7af9 Issue 705836: Fix struct.pack(">f", 1e40) to behave consistently
across platforms:  it should now raise OverflowError on all
platforms.  (Previously it raised OverflowError only on
non IEEE 754 platforms.)

Also fix the (already existing) test for this behaviour
so that it actually raises TestFailed instead of just
referencing it.
2008-03-14 14:23:37 +00:00
Guido van Rossum 5bdff60617 Fix the overflows in expandtabs(). "This time for sure!"
(Exploit at request.)
2008-03-11 21:18:06 +00:00
Jeffrey Yasskin 960b9b7a2f Move abc._Abstract into object by adding a new flag Py_TPFLAGS_IS_ABSTRACT,
which forbids constructing types that have it set. The effect is to speed

  ./python.exe -m timeit -s 'import abc' -s 'class Foo(object): __metaclass__ = abc.ABCMeta' 'Foo()'

up from 2.5us to 0.201us. This fixes issue 1762.
2008-02-28 04:45:36 +00:00
Eric Smith 4b051eecb9 Corrected assert to check for correct type in py3k. 2008-02-24 21:41:49 +00:00
Christian Heimes 09bde04154 Use PY_FORMAT_SIZE_T instead of z for string formatting. Thanks Neal. 2008-02-24 12:26:16 +00:00
Facundo Batista c11cecf3d0 Issue 1742669. Now %d accepts very big float numbers.
Thanks Gabriel Genellina.
2008-02-24 03:17:21 +00:00
Georg Brandl ad61bc8d9b #2067: file.__exit__() now calls subclasses' close() method. 2008-02-23 15:11:18 +00:00
Eric Smith 8a803dd94b Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it. 2008-02-20 23:39:28 +00:00
Eric Smith bc32fee029 Added code to correct combining str and unicode in ''.format(). Added test case. 2008-02-18 18:02:34 +00:00
Eric Smith a9f7d62480 Backport of PEP 3101, Advanced String Formatting, from py3k.
Highlights:
 - Adding PyObject_Format.
 - Adding string.Format class.
 - Adding __format__ for str, unicode, int, long, float, datetime.
 - Adding builtin format.
 - Adding ''.format and u''.format.
 - str/unicode fixups for formatters.

The files in Objects/stringlib that implement PEP 3101 (stringdefs.h,
unicodedefs.h, formatter.h, string_format.h) are identical in trunk
and py3k.  Any changes from here on should be made to trunk, and
changes will propogate to py3k).
2008-02-17 19:46:49 +00:00
Amaury Forgeot d'Arc 632fad3933 Prevent a crash with nested scopes, again caused by calling Py_DECREF when the pointer
is still present in the containing structure.
2008-02-16 20:55:24 +00:00
Amaury Forgeot d'Arc 60d6c7f0cc Issue #2115: __slot__ attributes setting was 10x slower.
Also correct a possible crash using ABCs.

This change is exactly the same as an optimisation
done 5 years ago, but on slot *access*:
http://svn.python.org/view?view=rev&rev=28297
2008-02-15 21:22:45 +00:00
Eric Smith 3f91437e5f In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long. It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long. 2008-02-15 12:14:32 +00:00
Christian Heimes 2f0da53d28 Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them. 2008-02-15 06:57:08 +00:00
Christian Heimes e247f0037f Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115 2008-02-14 22:40:11 +00:00
Christian Heimes 3b718a79af Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation. 2008-02-14 12:47:33 +00:00
Raymond Hettinger a37430a0ce dict.copy() rises from the ashes. Revert r60687. 2008-02-12 19:05:36 +00:00
Eric Smith 5e527ebee1 Added PyNumber_ToBase and supporting routines _PyInt_Format and
_PyLong_Format.  In longobject.c, changed long_format to
_PyLong_Format.  In intobject.c, changed uses of PyOS_snprintf to
_PyInt_Format instead.

_PyLong_Format is similar to py3k's routine of the same name, except
it has 2 additional parameters: addL and newstyle.  addL was existing
in long_format, and controls adding the trailing "L".  This is
unneeded in py3k.  newstyle is used to control whether octal prepends
"0" (the pre-2.6 style), or "0o" (the 3.0 sytle).

PyNumber_ToBase is needed for PEP 3127 (Integer Literal Support and
Syntax) and PEP 3101 (Advanced String Formatting).

This changeset does not need merging into py3k.
2008-02-10 01:36:53 +00:00
Raymond Hettinger 17a74c395e Add -3 warnings that set.copy(), dict.copy(), and defaultdict.copy() will go away in Py3.x 2008-02-09 04:37:49 +00:00
Raymond Hettinger 0913166da2 Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
2008-02-08 22:30:04 +00:00
Christian Heimes 48397d6c22 Use prefix decrement 2008-02-08 00:14:34 +00:00
Christian Heimes f75dbef208 Deallocate content of the dict free list on interpreter shutdown 2008-02-08 00:11:31 +00:00
Christian Heimes b4ee4a16f4 Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet. 2008-02-07 17:15:30 +00:00
Raymond Hettinger 55285ef44c Return ints instead of longs for tuple.count() and tuple.index(). 2008-02-07 02:12:52 +00:00
Raymond Hettinger 5b07ebce86 Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence. 2008-02-07 00:54:20 +00:00
Christian Heimes 5b970ad483 Unified naming convention for free lists and their limits. All free lists
in Object/ are named ``free_list``, the counter ``numfree`` and the upper
limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block.

The chances should make it easier to adjust Python for platforms with
less memory, e.g. mobile phones.
2008-02-06 13:33:44 +00:00
Christian Heimes 6075a82243 Limit free list of method and builtin function objects to 256 entries each. 2008-02-06 12:44:34 +00:00
Christian Heimes 422051a367 Patch #1953
I implemented the function sys._compact_freelists() and C API functions PyInt_/PyFloat_CompactFreeList() to compact the pre-allocated blocks of ints and floats. They allow the user to reduce the memory usage of a Python process that deals with lots of numbers.
The patch also renames sys._cleartypecache to sys._clear_type_cache
2008-02-04 18:00:12 +00:00
Jeffrey Yasskin a26cf9b760 Make int() and long() fall back to __trunc__(). See issue 2002. 2008-02-04 01:04:35 +00:00
Amaury Forgeot d'Arc cab3d98ca1 Ensure that PySet_Add() operates on a newly created frozenset, like PyTuple_SetItem does.
Add PyFrozenSet_Check(), which was not needed before; The list of Py*Set_Check* macros seems to be complete now.

Add missing NEWS entries about all this.
2008-02-03 22:51:43 +00:00
Raymond Hettinger 2d1aa3350a Simpler solution to handling non-IEEE 754 environments. 2008-02-02 05:11:40 +00:00
Raymond Hettinger f9859037fc Add protection from weirdness while scaling the mantissa to an integer. 2008-02-01 23:45:44 +00:00
Raymond Hettinger 1bcb99a9cb Fix int/long typecase. Add check for non-binary floating point. 2008-02-01 23:12:19 +00:00
Raymond Hettinger ffc667cbd5 labs() takes a long for an input. 2008-02-01 22:22:50 +00:00
Raymond Hettinger c9e928ae0f Integer ratio should return ints instead of longs whereever possible. 2008-02-01 22:15:52 +00:00
Raymond Hettinger 04c96d52a4 Issue #1996: float.as_integer_ratio() should return fraction in lowest terms. 2008-02-01 21:30:23 +00:00
Christian Heimes 796fc31585 The previous change was causing a segfault after multiple calls to Py_Initialize() and Py_Finalize(). 2008-01-30 18:58:29 +00:00
Christian Heimes 0d9244332b Fixed some references leaks in sys. 2008-01-30 17:21:22 +00:00
Christian Heimes 4d4f270941 Patch #1970 by Antoine Pitrou: Speedup unicode whitespace and linebreak detection. The speedup is about 25% for split() (571 / 457 usec) and 35% (175 / 127 usec )for splitlines() 2008-01-30 11:32:37 +00:00
Raymond Hettinger 7759a0cd76 Factor-out common code with a new macro 2008-01-28 21:47:42 +00:00
Raymond Hettinger ecdcb58950 Make PySet_Add() work with frozensets.
Works like PyTuple_SetItem() to build-up values in a brand new frozenset.
Also, PyFrozenSet_New() is now guaranteed to produce a distinct new frozenset.
2008-01-28 20:34:33 +00:00
Christian Heimes d7e1b2bd17 static PyObject* variables should use PyString_InternFromString() instead of PyObject_FromString() to store a python string in a function level static var. 2008-01-28 02:07:53 +00:00
Christian Heimes 908caac52e Added clear cache methods to clear the internal type lookup cache for ref leak test runs. 2008-01-27 23:34:59 +00:00
Jeffrey Yasskin 3ea7b41b58 Moved Rational._binary_float_to_ratio() to float.as_integer_ratio() because
it's useful outside of rational numbers.

This is my first C code that had to do anything significant. Please be more
careful when looking over it.
2008-01-27 23:08:46 +00:00
Neal Norwitz e7bb9188f4 Whitespace cleanup 2008-01-27 17:10:14 +00:00
Georg Brandl 0cdf9a36ec #1473257: add generator.gi_code attribute that refers to
the original code object backing the generator. Patch by Collin Winter.
2008-01-26 14:14:20 +00:00
Raymond Hettinger dee3f65d98 Revert PySet_Add() changes. 2008-01-26 09:31:11 +00:00
Raymond Hettinger d375723365 Update test code for change to PySet_Add(). 2008-01-26 08:41:13 +00:00
Raymond Hettinger 7c1be2a3b1 Make PySet_Add() work with frozensets. Works like PyTuple_SetItem() to build-up values in a brand new frozenset. 2008-01-26 08:19:06 +00:00
Thomas Wouters a97744c9d9 Use the right (portable) definition of the max of a Py_ssize_t. 2008-01-25 21:09:34 +00:00
Guido van Rossum 8d5cf4ed57 Rewrite the list_inline_repeat overflow check slightly differently. 2008-01-25 19:50:26 +00:00
Raymond Hettinger 3dbd4c536d Changes 54857 and 54840 broke code and were reverted in Py2.5 just before
it was released, but that reversion never made it to the Py2.6 head.
2008-01-25 19:24:46 +00:00
Christian Heimes 7f39c9fcbb Backport of several functions from Python 3.0 to 2.6 including PyUnicode_FromString, PyUnicode_Format and PyLong_From/AsSsize_t. The functions are partly required for the backport of the bytearray type and _fileio module. They should also make it easier to port C to 3.0.
First chapter of the Python 3.0 io framework back port: _fileio
The next step depends on a working bytearray type which itself depends on a backport of the nwe buffer API.
2008-01-25 12:18:43 +00:00
Neal Norwitz 5f95a79b2b Add prototypes to get the mathmodule.c to compile on OSF1 5.1 (Tru64)
and eliminate a compiler warning in floatobject.c.  There might be
a better way to go about this, but it should be good enough for now.
2008-01-25 08:04:16 +00:00
Guido van Rossum 37edeab778 Fix test67.py from issue #1303614. 2008-01-24 17:58:05 +00:00
Georg Brandl 96f2184de6 Indentation normalization. 2008-01-19 10:18:07 +00:00
Guido van Rossum 9ff1a44973 Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
2008-01-18 20:56:30 +00:00
Christian Heimes 4956d2b889 Silence Coverity false alerts with CIDs #172, #183, #184 2008-01-18 19:12:56 +00:00
Raymond Hettinger cbf8f6cffb Temporarily revert 59967 until GC can be added. 2008-01-15 05:39:59 +00:00
Raymond Hettinger c216df9288 Issue 1820: structseq objects did not work with the % formatting operator or isinstance(t, tuple).
Orignal patch (without tests) by Leif Walsh.
2008-01-15 03:02:37 +00:00
Christian Heimes c3b2a4afe8 Added more comments to the new structseq repr code and implemented several of Neal's suggestions. 2008-01-14 06:06:19 +00:00
Christian Heimes c94e2b5c12 Now that I've learnt about structseq objects I felt like converting sys.float_info to a structseq. It's
readonly and help(sys.float_info) explains the attributes nicely.
2008-01-14 04:13:37 +00:00
Christian Heimes 620fbe6632 I missed the most important file 2008-01-14 03:35:38 +00:00
Amaury Forgeot d'Arc e4c270c2a8 Re-apply patch #1700288 (first applied in r59931, rolled back in r59940)
now that ctypes uses a more supported method to create types:

Method cache optimization, by Armin Rigo, ported to 2.6 by Kevin Jacobs.
2008-01-14 00:29:41 +00:00
Georg Brandl d1c131a6e3 Back out r59931 - test_ctypes fails with it. 2008-01-13 15:04:05 +00:00
Georg Brandl 27e26ec418 Patch #1700288: Method cache optimization, by Armin Rigo, ported to
2.6 by Kevin Jacobs.
2008-01-12 13:47:57 +00:00
Georg Brandl dfe5dc8455 Make Python compile with --disable-unicode. 2008-01-07 18:16:36 +00:00
Jeffrey Yasskin 9871d8fe22 Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
 * Revert round to its 2.6 behavior (half away from 0).
 * Because round, floor, and ceil always return float again, it's no
   longer necessary to have them delegate to __xxx___, so I've ripped
   that out of their implementations and the Real ABC. This also helps
   in implementing types that work in both 2.6 and 3.0: you return int
   from the __xxx__ methods, and let it get enabled by the version
   upgrade.
 * Make pow(-1, .5) raise a ValueError again.
2008-01-05 08:47:13 +00:00
Jeffrey Yasskin 737c73f96f Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
2008-01-04 08:01:23 +00:00
Christian Heimes 8267d1dfe5 Bug #1481296: Fixed long(float('nan'))!=0L. 2008-01-04 00:37:34 +00:00
Christian Heimes 000a074c95 Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0
Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports
2008-01-03 22:16:32 +00:00
Jeffrey Yasskin 2f3c16be73 Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361,
r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new
documentation. The only significant difference is that round(x) returns a float
to preserve backward-compatibility. See http://bugs.python.org/issue1689.
2008-01-03 02:21:52 +00:00
Neal Norwitz 59a65facf2 Fix refleak 2007-12-31 23:48:47 +00:00
Georg Brandl 30b78048a6 Fix refleak introduced in r59576. 2007-12-20 21:03:02 +00:00
Guido van Rossum 0b7b6fdff3 Patch #1549 by Thomas Herve.
This changes the rules for when __hash__ is inherited slightly,
by allowing it to be inherited when one or more of __lt__, __le__,
__gt__, __ge__ are overridden, as long as __eq__ and __ne__ aren't.
2007-12-19 22:51:13 +00:00
Christian Heimes e93237dfcc #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available. 2007-12-19 02:37:44 +00:00
Christian Heimes 0a8143f646 Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
The patch unifies float("inf") and repr(float("inf")) on all platforms.
2007-12-18 23:22:54 +00:00
Raymond Hettinger fd7ed407d7 Give meaning to the oparg for BUILD_MAP: estimated size of the dictionary.
Allows dictionaries to be pre-sized (upto 255 elements) saving time lost
to re-sizes with their attendant mallocs and re-insertions.

Has zero effect on small dictionaries (5 elements or fewer), a slight
benefit for dicts upto 22 elements (because they had to resize once
anyway), and more benefit for dicts upto 255 elements (saving multiple
resizes during the build-up and reducing the number of collisions on
the first insertions).  Beyond 255 elements, there is no addional benefit.
2007-12-18 21:24:09 +00:00
Raymond Hettinger 6c87af5d87 Optimize PyList_AsTuple(). Improve cache performance by doing the
pointer copy and object increment in one pass.  For small lists,
save the overhead of the call to memcpy() -- this comes up in
calls like f(*listcomp).
2007-12-15 00:07:25 +00:00
Christian Heimes 90e10e79ea Fixed bug #1620: New @spam.getter property syntax modifies the property in place.
I added also the feature that a @prop.getter decorator does not overwrite the doc string of the property if it was given as an argument to property().
2007-12-14 02:35:23 +00:00
Christian Heimes f15c66e143 The new float repr causes too much trouble and pain. I'm disabling the feature until we have sorted out the issues on all machines. 64bit machines seem to have issues and Guido has reported even worse.
Guido: It's pretty bad actually -- repr(1e5) comes out as '1.0'... Ditto for
repr(1eN) for most N... Both in 2.6 and in 3.0...
2007-12-11 00:54:34 +00:00
Christian Heimes 284d927625 Backport of r59456:59458 from py3k to trunk
Issue #1580: New free format floating point representation based on "Floating-Point Printer Sample Code", by Robert G. Burger. For example repr(11./5) now returns '2.2' instead of '2.2000000000000002'.

Thanks to noam for the patch! I had to modify doubledigits.c slightly to support X64 and IA64 machines on Windows. I also added the new file to the three project files.
2007-12-10 22:28:56 +00:00