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