Commit Graph

2905 Commits

Author SHA1 Message Date
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
Skip Montanaro 26015494f2 When splitting, avoid making a copy of the string if the split doesn't find
anything (issue 1538).
2007-12-08 15:33:24 +00:00
Skip Montanaro 4e3ebe0bae Note that open() is the preferred way to open files (issue 1510). 2007-12-08 14:37:43 +00:00
Raymond Hettinger 4e2f714031 Fix Issue 1045.
Factor-out common calling code by simplifying the length_hint API.
Speed-up the function by caching the PyObject_String for the attribute lookup.
2007-12-06 00:56:53 +00:00
Christian Heimes fe4826f6ac merge -r59315:59316 from py3k: Fix issue #1553: An errornous __length_hint__ can make list() raise a SystemError 2007-12-05 12:49:14 +00:00
Guido van Rossum e227263a6c Shut up a compiler warning. 2007-12-03 22:02:10 +00:00
Christian Heimes 44eeaec173 Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)
2007-12-03 20:01:02 +00:00
Nick Coghlan ef01d822aa Implement PEP 366 2007-12-03 12:55:17 +00:00
Christian Heimes dfdfaab1c5 Feature #1534
Added PyFloat_GetMax(), PyFloat_GetMin() and PyFloat_GetInfo() to the float API.
Added a dictionary sys.float_info with information about the internal floating point type to the sys module.
2007-12-01 11:20:10 +00:00
Georg Brandl ede3a3218e Spaces vs. Tabs. 2007-11-29 18:33:01 +00:00
Guido van Rossum 31645ba4a0 Fix bug #1517, a segfault in lookdict(). 2007-11-29 18:25:12 +00:00
Guido van Rossum 715ec1818d Patch # 1507 by Mark Dickinson. Make complex(x, -0) retain the sign of
the imaginary part (as long as it's not complex).
Backport candidate?
2007-11-27 22:38:36 +00:00
Amaury Forgeot d'Arc ce7d10ccc4 Issue #1445: Fix a SystemError when accessing the ``cell_contents``
attribute of an empty cell object.  Now a ValueError is raised.
2007-11-24 13:44:17 +00:00
Christian Heimes e8954f8ce7 Backport of the PCbuild9 directory from the py3k branch.
I've finished the last task for the PCbuild9 directory today. I don't think there is much left to do. Now you can all play around with the shiny new VS 2008 and try the PGO builds. I was able to get a speed improvement of about 10% on py3k.
Have fun! :)
2007-11-22 11:21:16 +00:00
Guido van Rossum 64c06e327d Backport of _abccoll.py by Benjamin Arangueren, issue 1383.
With some changes of my own thrown in (e.g. backport of r58107).
2007-11-22 00:55:51 +00:00
Amaury Forgeot d'Arc 5087980c1e The incremental decoder for utf-7 must preserve its state between calls.
Solves issue1460.

Might not be a backport candidate: a new API function was added,
and some code may rely on details in utf-7.py.
2007-11-20 23:31:27 +00:00
Facundo Batista 6f7e6fb7a2 Made _ParseTupleFinds only defined to unicodeobject.c 2007-11-16 19:16:15 +00:00
Facundo Batista 292a069b88 Fix for stupid error (I need to remember to do a full 'make clean + make'
cycle before the tests...). Sorry.
2007-11-16 18:41:24 +00:00
Facundo Batista 57d5669f4b Now in find, rfind, index, and rindex, you can use None as defaults,
as usual with slicing (both with str and unicode strings).  This
fixes issue 1259.

For str only the stringobject.c file was modified.  But for unicode,
I needed to repeat in the four functions a lot of code, so created
a new function that does part of the job for them (and placed it in
find.h, following a suggestion of Barry).

Also added tests for this behaviour.
2007-11-16 18:04:14 +00:00
Andrew M. Kuchling abfe45368c Re-word sentence 2007-11-12 01:25:21 +00:00
Christian Heimes 3d4c316f17 Added new decorator syntax to property.__doc__
Guido prefers _x over __x.
2007-11-12 01:15:40 +00:00
Guido van Rossum d1ef78942a Issue 1416. Add getter, setter, deleter methods to properties that can be
used as decorators to create fully-populated properties.
2007-11-10 22:12:24 +00:00
Raymond Hettinger 34448790db Optimize common case for dict.fromkeys(). 2007-11-09 23:14:44 +00:00
Raymond Hettinger e8d58ba6bb Reposition the decref (spotted by eagle-eye norwitz). 2007-11-08 18:47:51 +00:00
Raymond Hettinger 1760c8a017 Add set.isdisjoint() 2007-11-08 02:52:43 +00:00
Raymond Hettinger cdcf887999 Optimize dict.fromkeys() with dict inputs. Useful for resetting bag/muliset counts for example. 2007-11-07 02:26:17 +00:00
Guido van Rossum 9b847b432c Add missing "return NULL" in overflow check in PyObject_Repr(). 2007-11-06 23:32:56 +00:00
Guido van Rossum 1c1ac38157 Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
2007-10-29 22:15:05 +00:00
Armin Rigo a1e42e11d5 Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.

Backport candidate, possibly.
2007-10-17 18:46:37 +00:00
Brett Cannon 77ae87c11e Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.

Closes issue1238.
2007-10-10 00:07:50 +00:00