Eric Smith
6f42edb682
Issue 5237, Allow auto-numbered replacement fields in str.format() strings.
...
For simple uses for str.format(), this makes the typing easier. Hopfully this
will help in the adoption of str.format().
For example:
'The {} is {}'.format('sky', 'blue')
You can mix and matcth auto-numbering and named replacement fields:
'The {} is {color}'.format('sky', color='blue')
But you can't mix and match auto-numbering and specified numbering:
'The {0} is {}'.format('sky', 'blue')
ValueError: cannot switch from manual field specification to automatic field numbering
Will port to 3.1.
2009-03-14 11:57:26 +00:00
Benjamin Peterson
9c1f7b2b04
fix funky indentation
2009-03-08 00:21:17 +00:00
Hirokazu Yamamoto
a3e6c9763c
Fixed memory leak on failure.
2009-03-05 09:34:14 +00:00
Mark Dickinson
b646487687
Replace long with twodigits, to avoid depending
...
on sizeof(digit) < sizeof(long)
2009-02-25 20:29:50 +00:00
Mark Dickinson
3e4caeb3bf
Issue #5341 : Fix a variety of spelling errors.
2009-02-21 20:27:01 +00:00
Eric Smith
e9fb6863da
Issue #5247 : Improve error message when unknown format codes are used when using str.format() with str, unicode, long, int, and float arguments.
2009-02-20 14:02:36 +00:00
Mark Dickinson
bcf6b18eb7
A few more minor fixes in longobject.c
2009-02-15 15:48:39 +00:00
Mark Dickinson
2ffb26fb83
Issue #5260 : Various portability and standards compliance fixes, optimizations
...
and cleanups in Objects/longobject.c. The most significant change is that
longs now use less memory: average savings are 2 bytes per long on 32-bit
systems and 6 bytes per long on 64-bit systems. (This memory saving already
exists in py3k.)
2009-02-15 10:13:41 +00:00
Antoine Pitrou
9e8a250ed9
Fix compiler warning (gcc)
2009-02-13 13:57:40 +00:00
Antoine Pitrou
76a4b896c4
Issue #5186 : Reduce hash collisions for objects with no __hash__ method by
...
rotating the object pointer by 4 bits to the right.
2009-02-13 13:52:33 +00:00
Georg Brandl
cbb4958cd8
Fix warnings GCC emits where the argument of PyErr_Format is a single variable.
2009-02-13 11:06:59 +00:00
Mark Dickinson
4015f62e39
Issue #5175 : PyLong_AsUnsignedLongLong now raises OverflowError for
...
negative arguments. Previously, it raised TypeError.
Thanks Lisandro Dalcin.
2009-02-10 15:46:50 +00:00
Kristján Valur Jónsson
6a743d3694
Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
2009-02-10 13:32:24 +00:00
Mark Dickinson
10fe877dcd
Issue #789290 : make sure that hash(2**63) == hash(2.**63) on 64-bit
...
platforms. The previous code was fragile, depending on the twin
accidents that:
(1) in C, casting the double value 2.**63 to long returns the integer
value -2**63, and
(2) in Python, hash(-2**63) == hash(2**63).
There's already a test for this in test_hash.
2009-02-08 14:42:28 +00:00
Mark Dickinson
b91d2f5bd3
Remove redundant assignment in _PyObject_LengthHint
2009-02-08 13:58:10 +00:00
Kristján Valur Jónsson
fd4c872726
issue 4804: Provide checks for the format string of strftime, and for the "mode" string of fopen on Windows. These strings are user provided from python and so we can avoid invoking the C runtime invalid parameter handler by first checking that they are valid.
2009-02-04 10:05:25 +00:00
Raymond Hettinger
d6fc2623c5
Validate that __length_hint__ returns a usable result.
2009-02-03 02:23:19 +00:00
Raymond Hettinger
b516370bcb
Issue 1242657: list(obj) can swallow KeyboardInterrupt.
2009-02-02 21:50:13 +00:00
Benjamin Peterson
1c5d21d644
fix indentation in comment
2009-01-31 22:33:02 +00:00
Benjamin Peterson
be1399e39a
fix indentation; looks like all I managed to do the first time is make things uglier
2009-01-31 22:03:19 +00:00
Benjamin Peterson
d17fec74e5
fix indentation
2009-01-31 21:47:42 +00:00
Benjamin Peterson
857ce15791
completely detabify unicodeobject.c
2009-01-31 16:29:18 +00:00
Mark Dickinson
a0eae0398c
Fix comment.
2009-01-26 21:40:08 +00:00
Mark Dickinson
6ffa4a2a7d
Fix undefined behaviour (left shift of negative value) in long_hash. Also,
...
rewrap a line of length > 79, and update comments.
2009-01-26 21:36:30 +00:00
Mark Dickinson
1afe6ddd07
No need for carry to be type twodigits in _PyLong_AsByteArray; digit is large enough.
...
This change should silence a compiler warning on Windows.
2009-01-25 22:12:31 +00:00
Hirokazu Yamamoto
1e234e8c19
Fixed compile error on windows.
2009-01-25 17:46:48 +00:00
Benjamin Peterson
78821ddf8c
fix building the core with --disable-unicode
...
I changed some bytearray methods to use strings instead of unicode like bytes_repr
Also, bytearray.fromhex() can take strings as well as unicode
2009-01-25 17:15:10 +00:00
Mark Dickinson
ff84aa87b4
Issue #4393 : fix 3 classes of potential portability problems in longobject.c:
...
- fix some places where counters into ob_digit were declared as
int instead of Py_ssize_t
- add (twodigit) casts where necessary
- fix code in _PyLong_AsByteArray that uses << on negative values
2009-01-24 15:27:44 +00:00
Benjamin Peterson
e548d2487d
fix url
2009-01-20 18:58:27 +00:00
Amaury Forgeot d'Arc
59ce042766
#4077 : No need to append \n when calling Py_FatalError
...
+ fix a declaration to make it match the one in pythonrun.h
2009-01-17 20:18:59 +00:00
Amaury Forgeot d'Arc
bd55c52565
#4930 : Slightly cleaner (and faster) code in type creation:
...
compare slots by address, not by name.
2009-01-17 17:11:50 +00:00
Antoine Pitrou
c2f02216b6
Issue #4935 : The overflow checking code in the expandtabs() method common
...
to str, bytes and bytearray could be optimized away by the compiler, letting
the interpreter segfault instead of raising an error.
2009-01-13 23:13:52 +00:00
Amaury Forgeot d'Arc
a40d573664
#3720 : Interpreter crashes when an evil iterator removes its own next function.
...
Now the slot is filled with a function that always raises.
Will not backport: extensions compiled with 2.6.x would not run on 2.6.0.
2009-01-12 23:36:55 +00:00
Martin v. Löwis
b90304acb9
Issue #4850 : Change COUNT_ALLOCS variables to Py_ssize_t.
2009-01-07 18:40:40 +00:00
Antoine Pitrou
aa687902f2
Issue #3680 : Reference cycles created through a dict, set or deque iterator did not get collected.
2009-01-01 14:11:22 +00:00
Nick Coghlan
180e400766
Issue #4701 : implicitly call PyType_Ready from PyObject_Hash
2008-12-30 01:18:48 +00:00
Benjamin Peterson
fe231b07e4
#4764 set IOError.filename when trying to open a directory on POSIX platforms
2008-12-29 17:47:42 +00:00
Georg Brandl
6425a2fa8f
Backport r67974:
...
#4759 : allow None as first argument of bytearray.translate(), for consistency with bytes.translate().
Also fix segfault for bytearray.translate(x, None) -- will backport this part to 3.0 and 2.6.
2008-12-28 11:54:53 +00:00
Alexandre Vassalotti
034e08ce8d
Remove unnecessary casts related to unicode_decode_call_errorhandler.
...
Make the _PyUnicode_Resize macro a static function.
These changes are needed to avoid breaking strict aliasing rules.
2008-12-27 06:36:10 +00:00
Benjamin Peterson
f09925da67
add py3k warnings to frame.f_exc_*
2008-12-22 20:16:25 +00:00
Mark Dickinson
1a707981c8
Issue #3439 : add bit_length method to int and long.
...
Thanks Fredrik Johansson and Victor Stinner for code,
Raymond Hettinger for review.
2008-12-17 16:14:37 +00:00
Amaury Forgeot d'Arc
3538a3107a
#3632 : the "pyo" macro from gdbinit can now run when the GIL is released.
...
Patch by haypo.
2008-12-15 22:29:14 +00:00
Antoine Pitrou
ae5beceb35
Issue #4509 : bugs in bytearray with exports (buffer protocol)
2008-12-06 21:29:24 +00:00
Mark Dickinson
826f3fefe5
Issue #4445 : save 3 bytes (on average, on a typical machine) per
...
string allocation.
2008-12-05 21:55:28 +00:00
Raymond Hettinger
7989a4dccb
Backport r67478
2008-12-03 15:42:10 +00:00
Amaury Forgeot d'Arc
2a1fd05971
Fix a small typo in docstring
2008-11-29 02:03:32 +00:00
Benjamin Peterson
46cc6d1102
make sure that bytearray methods return a new bytearray even if there is no change
...
Fixes #4348
Reviewed by Brett
2008-11-19 21:49:09 +00:00
Benjamin Peterson
273c233c78
when __getattr__ is a descriptor, call it correctly; fixes #4230
...
patch from Ziga Seilnacht
2008-11-17 22:39:09 +00:00
Amaury Forgeot d'Arc
d78b9dcbc3
#4069 : aSet.remove(otherSet) would always report the empty frozenset([]) as the missing key.
...
Now it correctly refers to the initial otherset.
Reviewed by Raymond. Will backport to 2.6.
2008-10-07 20:32:10 +00:00
Andrew M. Kuchling
a4127173f8
Punctuation fix; expand dict.update docstring to be clearer
2008-10-04 21:51:59 +00:00
Andrew M. Kuchling
efeb43eb31
Docstring change for *partition: use same tense as other docstrings.
...
Hyphenate left- and right-justified.
Fix 'registerd' typo
2008-10-04 01:05:56 +00:00
Andrew M. Kuchling
d810cdf849
Docstring changes: Specify exceptions raised
2008-10-04 01:04:24 +00:00
Andrew M. Kuchling
b15d6fb9a7
Docstring change: Specify exception raised
2008-10-04 01:03:42 +00:00
Andrew M. Kuchling
bd7c4ca569
Use correct capitalization of NaN
2008-10-04 01:02:29 +00:00
Andrew M. Kuchling
d7b7dde98e
Mention exception in docstring
2008-10-03 16:29:19 +00:00
Christian Heimes
32a66a0410
Fixed a couple more C99 comments and one occurence of inline.
2008-10-02 19:47:50 +00:00
Christian Heimes
25584b1b74
Fixed a comment to C89 style as of http://drj11.wordpress.com/2008/10/02/python-and-bragging-about-c89/
2008-10-02 18:33:41 +00:00
Amaury Forgeot d'Arc
fc5ea39289
#3967 : Correct a crash in count() and find() methods of string-like objects.
...
For example:
"".count("xxxx", sys.maxint, 0)
Reviewed by Benjamin Peterson.
Will port to 2.5 and 3.0.
2008-09-26 22:34:08 +00:00
Amaury Forgeot d'Arc
17617a07d1
#3965 : on Windows, open() crashes if the filename or the mode is invalid,
...
and if the filename is a unicode string.
Reviewed by Martin von Loewis.
2008-09-25 20:52:56 +00:00
Martin v. Löwis
e86b07cc9a
Bug #3951 : Py_USING_MEMORY_DEBUGGER should not be enabled by default.
2008-09-25 04:12:50 +00:00
Andrew MacIntyre
8c47cabbe9
should use macro'ed symbols not direct
...
Part of source_os2emx.patch in issue 3868
Reviewed by Amaury Forgeot d'Arc
2008-09-22 14:10:54 +00:00
Martin v. Löwis
9fa5a2828c
Issue #3642 : Suppress warning in obmalloc when size_t is
...
larger than uint. Reverts r65975. Reviewed by Brett Cannon.
2008-09-11 06:53:30 +00:00
Martin v. Löwis
24329ba176
Issue #3811 : The Unicode database was updated to 5.1.
...
Reviewed by Fredrik Lundh and Marc-Andre Lemburg.
2008-09-10 13:38:12 +00:00
Benjamin Peterson
97179b0f58
Fix #3634 invalid return value from _weakref.ref(Exception).__init__
...
Reviewers: Amaury, Antoine, Benjamin
2008-09-09 20:55:01 +00:00
Georg Brandl
98064078f7
Fix varname in docstring. #3822 .
2008-09-09 19:26:00 +00:00
Amaury Forgeot d'Arc
d3ffb8974f
#3777 : long(4.2) returned an int, and broke backward compatibility.
...
the __long__ slot is allowed to return either int or long, but the behaviour of
float objects should not change between 2.5 and 2.6.
Reviewed by Benjamin Peterson
2008-09-09 07:24:30 +00:00
Amaury Forgeot d'Arc
3571fbfed7
Issue #3751 : str.rpartition would perform a left-partition when called with
...
a unicode argument.
will backport.
2008-09-01 19:52:00 +00:00
Antoine Pitrou
d4ae97bc38
#3668 : When PyArg_ParseTuple correctly parses a s* format, but raises an
...
exception afterwards (for a subsequent parameter), the user code will
not call PyBuffer_Release() and memory will leak.
Reviewed by Amaury Forgeot d'Arc.
2008-08-29 18:39:48 +00:00
Antoine Pitrou
0668c62677
Issue #2534 : speed up isinstance() and issubclass() by 50-70%, so as to
...
match Python 2.5 speed despite the __instancecheck__ / __subclasscheck__
mechanism. In the process, fix a bug where isinstance() and issubclass(),
when given a tuple of classes as second argument, were looking up
__instancecheck__ / __subclasscheck__ on the tuple rather than on each
type object.
Reviewed by Benjamin Peterson and Raymond Hettinger.
2008-08-26 22:42:08 +00:00
Benjamin Peterson
712ee92309
generate py3k warnings on __getslice__, __delslice__, and __setslice__
...
Reviewer: Brett Cannon
2008-08-24 18:10:20 +00:00
Neal Norwitz
18aa388ca0
Fix:
...
* crashes on memory allocation failure found with failmalloc
* memory leaks found with valgrind
* compiler warnings in opt mode which would lead to invalid memory reads
* problem using wrong name in decimal module reported by pychecker
Update the valgrind suppressions file with new leaks that are small/one-time
leaks we don't care about (ie, they are too hard to fix).
TBR=barry
TESTED=./python -E -tt ./Lib/test/regrtest.py -uall (both debug and opt modes)
in opt mode:
valgrind -q --leak-check=yes --suppressions=Misc/valgrind-python.supp \
./python -E -tt ./Lib/test/regrtest.py -uall,-bsddb,-compiler \
-x test_logging test_ssl test_multiprocessing
valgrind -q --leak-check=yes --suppressions=Misc/valgrind-python.supp \
./python -E -tt ./Lib/test/regrtest.py test_multiprocessing
for i in `seq 1 4000` ; do
LD_PRELOAD=~/local/lib/libfailmalloc.so FAILMALLOC_INTERVAL=$i \
./python -c pass
done
At least some of these fixes should probably be backported to 2.5.
2008-08-24 05:04:52 +00:00
Christian Heimes
7d4c3177d5
Silenced compiler warning
...
Objects/stringlib/find.h:97: warning: 'stringlib_contains_obj' defined but not used
Reviewed by Benjamin Peterson
2008-08-22 19:47:25 +00:00
Christian Heimes
fb1813cb8d
Changed type of numarenas from uint to size_t to silence a GCC warning on 64bit OSes. Reviewed by Benjamin Peterson.
2008-08-22 19:34:15 +00:00
Mark Dickinson
5c2bb1a7d4
issue 3633: Solaris allows fullwidth Unicode digits in isxdigit, so
...
rewrite float.fromhex to only allow ASCII hex digits on all platforms.
(Tests for this are already present, but the test_float failures
on Solaris hadn't been noticed before.)
Reviewed by Antoine Pitrou.
2008-08-21 21:38:38 +00:00
Eric Smith
e5bdccc77b
Backport of r63826.
...
Optimization of str.format() for cases with str, unicode, int, long,
and float arguments. This gives about 30% speed improvement for the
simplest (but most common) cases. This patch skips the __format__
dispatch, and also avoids creating an object to hold the format_spec.
Unfortunately there's a complication in 2.6 with int, long, and float
because they always expect str format_specs. So in the unicode
version of this optimization, just check for unicode objects. int,
float, long, and str can be added later, if needed.
2008-08-18 14:27:38 +00:00
Amaury Forgeot d'Arc
313bda12e8
Fix a refleak in bytearray.split and bytearray.rsplit, detected by
...
regrtest.py -R:: test_bytes
2008-08-17 21:05:18 +00:00
Martin v. Löwis
64034f994c
Fix memory leak: Always DECREF obj in PyBuffer_Release.
2008-08-14 20:12:06 +00:00
Martin v. Löwis
241b8345ea
Make obj an owned reference in Py_buffer; this checkin
...
was missing from the patch for #3139 .
2008-08-14 15:54:27 +00:00
Martin v. Löwis
f91d46a17d
Issue #3139 : Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
...
by denying s# to parse objects that have a releasebuffer procedure,
and introducing s*.
More module might need to get converted to use s*.
2008-08-12 14:49:50 +00:00
Nick Coghlan
48361f5cbf
Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
2008-08-11 15:45:58 +00:00
Georg Brandl
1e13ea94a3
- Issue #3537 : Fix an assertion failure when an empty but presized dict
...
object was stored in the freelist.
2008-08-11 09:07:59 +00:00
Brett Cannon
0563a8ffd1
Change the warning emitted for using the buffer() object; memoryview() in 3.0
...
is not an equivalent.
2008-08-08 04:15:53 +00:00
Mark Dickinson
b646757e01
Issue #1481296 : (again!) Make conversion of a float NaN to an int or
...
long raise ValueError instead of returning 0. Also, change the error
message for conversion of an infinity to an integer, replacing 'long' by
'integer', so that it's appropriate for both long(float('inf')) and
int(float('inf')).
2008-08-04 21:30:09 +00:00
Antoine Pitrou
92a6240198
Preemptively backport the relevant parts of r65420
2008-08-02 21:58:05 +00:00
Amaury Forgeot d'Arc
06847b13ca
Correct a crash when two successive unicode allocations fail with a MemoryError:
...
the freelist contained half-initialized objects with freed pointers.
The comment
/* XXX UNREF/NEWREF interface should be more symmetrical */
was copied from tupleobject.c, and appears in some other places.
I sign the petition.
2008-07-31 23:39:05 +00:00
Neal Norwitz
e7d8be80ba
Security patches from Apple: prevent int overflow when allocating memory
2008-07-31 17:17:14 +00:00
Benjamin Peterson
c0bf76d3cf
backport r64751
2008-07-30 17:45:10 +00:00
Antoine Pitrou
4982d5d04a
#2242 : utf7 decoding crashes on bogus input on some Windows/MSVC versions
2008-07-25 17:45:59 +00:00
Raymond Hettinger
7f59b5cc03
Convert from long to Py_ssize_t.
2008-07-24 07:04:55 +00:00
Gregory P. Smith
0470bab697
Issue #2620 : Overflow checking when allocating or reallocating memory
...
was not always being done properly in some python types and extension
modules. PyMem_MALLOC, PyMem_REALLOC, PyMem_NEW and PyMem_RESIZE have
all been updated to perform better checks and places in the code that
would previously leak memory on the error path when such an allocation
failed have been fixed.
2008-07-22 04:46:32 +00:00
Amaury Forgeot d'Arc
e4921fec01
Issue2378: pdb would delete free variables when stepping into a class statement.
...
The problem was introduced by r53954, the correction is to restore the symmetry between
PyFrame_FastToLocals and PyFrame_LocalsToFast
2008-07-21 22:00:38 +00:00
Neal Norwitz
c86b54cb03
Fix a couple of names in error messages that were wrong
2008-07-20 19:35:23 +00:00
Eric Smith
d6c393ab2b
Backed out r65069, pending fixing it in Windows.
2008-07-17 19:49:47 +00:00
Eric Smith
454816d8bd
Issue 3382: Make '%F' and float.__format__('F') convert results to upper case.
2008-07-17 17:48:39 +00:00
Georg Brandl
3238a3e329
Backport part of r65043.
2008-07-16 23:17:46 +00:00
Georg Brandl
3e75846cf6
Use _getbytevalue() in init too.
2008-07-16 23:10:05 +00:00
Georg Brandl
3e483f643d
#3156 : fix consistency in what type bytearray methods accept as items.
...
Also rename confusing "item" parameters to "index".
2008-07-16 22:57:41 +00:00
Eric Smith
4cb965ca91
Renamed a parameter in calc_number_widths, for consistency with the same parameter in fill_non_digits.
2008-07-16 18:29:51 +00:00
Eric Smith
a5fa5a218d
Complete issue 3083: add alternate (#) formatting to bin, oct, hex in str.format().
2008-07-16 00:11:49 +00:00
Mark Dickinson
7103aa42c0
Issue #3008 : add instance method float.hex and class method float.fromhex
...
to convert floats to and from hexadecimal strings respectively.
2008-07-15 19:08:33 +00:00