Commit Graph

3266 Commits

Author SHA1 Message Date
Mark Dickinson 777e4ff503 Eliminate some locale-dependent calls to isspace and tolower. 2009-05-03 20:59:48 +00:00
Mark Dickinson 85e269b37d Remove unnecessary uses of context in PyGetSetDef. See issue #5880. 2009-05-03 20:39:06 +00:00
Mark Dickinson d4b5c98fa6 Remove unnecessary use of context for long getters.
(Related to issue #5880).
2009-05-02 17:55:01 +00:00
Eric Smith 27f204dc29 Keep py3k and trunk code in sync. 2009-05-02 09:58:09 +00:00
Georg Brandl ca87fa5a5b #5889: remove comma at the end of a list that some C compilers don't like. 2009-05-01 08:51:37 +00:00
Eric Smith 9139cc6a3b Issue #1588: Add complex.__format__. 2009-04-30 00:58:58 +00:00
Mark Dickinson df108ca324 Remove format_float and use _PyOS_double_to_string instead. 2009-04-29 21:56:53 +00:00
Eric Smith cac7af6863 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors. 2009-04-27 19:04:37 +00:00
Mark Dickinson 6d6b220215 Backport r71967 changes from py3k to trunk.
(Internal plumbing changes for float parsing.)
2009-04-26 16:04:05 +00:00
Mark Dickinson 944c6aedd0 Reset errno before both calls to PyOS_ascii_strtod, not just one. 2009-04-26 14:00:08 +00:00
Martin v. Löwis 99f277933e Issue #4971: Fix titlecase for characters that are their own
titlecase, but not their own uppercase.
2009-04-26 00:53:18 +00:00
Eric Smith 068f06568b Issue #5835, deprecate PyOS_ascii_formatd.
If anyone wants to clean up the documentation, feel free. It's my first documentation foray, and it's not that great.

Will port to py3k with a different strategy.
2009-04-25 21:40:15 +00:00
Walter Dörwald 5d98ec76bb Issue #5828 (Invalid behavior of unicode.lower): Fixed bogus logic in
makeunicodedata.py and regenerated the Unicode database (This fixes
u'\u1d79'.lower() == '\x00').
2009-04-25 14:03:16 +00:00
Mark Dickinson 0a6501bf56 Fix typo in complex parsing code; expand tests. 2009-04-25 09:47:00 +00:00
Benjamin Peterson 5083dc552b fix a segfault when setting __class__ in __del__ #5283 2009-04-25 00:41:22 +00:00
Mark Dickinson 90d47cb46c Fix missing 'return NULL' 2009-04-24 13:14:07 +00:00
Mark Dickinson 95bc980d9e Issue #5816:
- simplify parsing and printing of complex numbers
 - make complex(repr(z)) round-tripping work for complex
   numbers involving nans, infs, or negative zeros
 - don't accept some of the stranger complex strings
   that were previously allowed---e.g., complex('1..1j')
2009-04-24 12:46:53 +00:00
Eric Smith ebafbb705c Fixed issue 5782: formatting with commas didn't work if no specifier type code was given. 2009-04-22 16:20:47 +00:00
Eric Smith aca19e6a74 Backport of some of the work in r71665 to trunk. This reworks much of
int, long, and float __format__(), and it keeps their implementation
in sync with py3k.

Also added PyOS_double_to_string. This is the "fallback" version
that's also available in trunk, and should be kept in sync with that
code. I'll add an issue to document PyOS_double_to_string in the C
API.

There are many internal cleanups. Externally visible changes include:

- Implement PEP 378, Format Specifier for Thousands Separator, for
  floats, ints, and longs.

- Issue #5515: 'n' formatting for ints, longs, and floats handles
  leading zero formatting poorly.

- Issue #5772: For float.__format__, don't add a trailing ".0" if
  we're using no type code and we have an exponent.
2009-04-22 13:29:05 +00:00
Mark Dickinson 6736cf8d20 Issue #3166: Make long -> float (and int -> float) conversions
correctly rounded, using round-half-to-even.  This ensures that the
value of float(n) doesn't depend on whether we're using 15-bit digits
or 30-bit digits for Python longs.
2009-04-20 21:13:33 +00:00
Benjamin Peterson 8cfa8e613f make errors consistent 2009-04-19 02:40:43 +00:00
Benjamin Peterson 308c6ba002 initialize weakref some weakref types 2009-04-19 02:32:42 +00:00
Benjamin Peterson 01c6e6fb35 many more types to initialize (I had to expose some of them) 2009-04-18 22:15:26 +00:00
Benjamin Peterson 5ce73759bf initalize -> initialize 2009-04-18 20:25:25 +00:00
Benjamin Peterson d4d400cb8a try to initalize all builtin types with PyType_Ready to avoid problems like #5787 2009-04-18 20:12:47 +00:00
Benjamin Peterson d672001b03 rename internal bytes_ functions to bytearray 2009-04-18 15:31:34 +00:00
Georg Brandl f5fd523981 "not subscriptable" should be a bit more understandable than "unsubscriptable". 2009-04-18 08:26:21 +00:00
Benjamin Peterson 99d36f1563 call __float__ on str subclasses #5759
tests by R. David Murray
2009-04-15 21:26:36 +00:00
Eric Smith 8c023248ed Fixed incorrect object passed into format_float_internal(). This was resulting in a conversion being done twice. 2009-04-13 00:29:50 +00:00
Georg Brandl 517cfdcfd9 Whitespace normalization. 2009-04-05 13:16:35 +00:00
Georg Brandl d3eaa745a9 #5615: make it possible to configure --without-threads again. 2009-04-05 11:07:14 +00:00
Antoine Pitrou 789be0c0a0 Issue #2396: backport the memoryview object. 2009-04-02 21:18:34 +00:00
Mark Dickinson 48e3fd240f sys.long_info attributes should be ints, not longs 2009-04-02 18:39:37 +00:00
Georg Brandl 42827e91ee Fix a wrong struct field assignment (docstring as closure). 2009-03-31 01:25:15 +00:00
Mark Dickinson d4814bfa23 Issue #532631: Apply floatformat changes to unicodeobject.c
as well as stringobject.c.
2009-03-29 16:24:29 +00:00
Mark Dickinson 174e909842 Issue #532631: Add paranoid check to avoid potential buffer overflow
on systems with sizeof(int) > 4.
2009-03-29 16:17:16 +00:00
Mark Dickinson 2e648ecc7d Issue #532631: Replace confusing fabs(x)/1e25 >= 1e25 test
with fabs(x) >= 1e50, and fix documentation.
2009-03-29 14:37:51 +00:00
Antoine Pitrou 1fba62427c The tracking statistics were actually too pessimistic 2009-03-23 19:17:00 +00:00
Antoine Pitrou f8387af262 Issue #4688: Add a heuristic so that tuples and dicts containing only
untrackable objects are not tracked by the garbage collector. This can
reduce the size of collections and therefore the garbage collection overhead
on long-running programs, depending on their particular use of datatypes.

(trivia: this makes the "binary_trees" benchmark from the Computer Language
Shootout 40% faster)
2009-03-23 18:41:45 +00:00
Mark Dickinson 0b666bfdf9 Issue #5512: speed up the long division algorithm for Python longs.
The basic algorithm remains the same; the most significant speedups
come from the following three changes:

  (1) normalize by shifting instead of multiplying and dividing
  (2) the old algorithm usually did an unnecessary extra iteration of
      the outer loop; remove this.  As a special case, this means that
      long divisions with a single-digit result run twice as fast as
      before.
  (3) make inner loop much tighter.

Various benchmarks show speedups of between 50% and 150% for long
integer divisions and modulo operations.
2009-03-23 18:25:13 +00:00
Hirokazu Yamamoto 52a3492efb There is no macro named SIZEOF_SSIZE_T. Should use SIZEOF_SIZE_T instead. 2009-03-21 10:32:52 +00:00
Mark Dickinson efc82f7e8e Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Backport of r70459.
2009-03-20 15:51:55 +00:00
Benjamin Peterson 6ffe852f90 fix strange errors when setting attributes on tracebacks #4034 2009-03-18 20:52:15 +00:00
Mark Dickinson 6b265f1bf8 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
sizeof(Py_UNICODE) == 2, PyUnicode_FromWideChar now converts
each character outside the BMP to the appropriate surrogate pair.

Thanks Victor Stinner for the patch.

(backport of r70452 from py3k to trunk)
2009-03-18 16:07:26 +00:00
Georg Brandl ed4cefbedd Fix a small nit in the error message if bool() falls back on __len__ and it returns the wrong type: it would tell the user that __nonzero__ should return bool or int. 2009-03-15 21:43:38 +00:00
Benjamin Peterson 1706c644ae fix tuple.index() error message #5495 2009-03-15 14:38:55 +00:00
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
Nick Coghlan 53663a695e Issue 2235: __hash__ is once again inherited by default, but inheritance can be blocked explicitly so that collections.Hashable remains meaningful 2008-07-15 14:27:37 +00:00
Eric Smith d0c841243c Added '#' formatting to integers. This adds the 0b, 0o, or 0x prefix for bin, oct, hex. There's still one failing case, and I need to finish the docs. I hope to finish those today. 2008-07-15 10:10:07 +00:00
Robert Schuppenies 9be2ec109b Added additional __sizeof__ implementations and addressed comments made in
Issue3122.
2008-07-10 15:24:04 +00:00
Nick Coghlan 524b7773cc Issue 2517: Allow unicode messages in Exceptions again by correctly bypassing the instance dictionary when looking up __unicode__ on new-style classes 2008-07-08 14:08:04 +00:00
Skip Montanaro 2c7ca9bb11 Correct grammar. 2008-07-07 11:16:14 +00:00
Gregory P. Smith 2fe77060eb - Issue #2862: Make int and float freelist management consistent with other
freelists.  Changes their CompactFreeList apis into ClearFreeList apis and
  calls them via gc.collect().
2008-07-06 03:35:58 +00:00
Mark Dickinson bf9f4d8015 Issue 3188: accept float('infinity') as well as float('inf'). This
makes the float constructor behave in the same way as specified
by various other language standards, including C99, IEEE 754r,
and the IBM Decimal standard.
2008-07-05 11:33:52 +00:00
Raymond Hettinger a27474c345 Issue 3230: Do not the set specific size macro. 2008-06-28 22:16:53 +00:00
Robert Schuppenies 161b92103c Corrected inconsistencies in sizeof tests and addressed issue pointed
out by Jean Brouwers.
2008-06-26 15:20:35 +00:00
Raymond Hettinger 9c437af4eb Revert 64424, 64438, and 64439. 2008-06-24 22:46:07 +00:00
Eric Smith 5dce7e9a83 Fixed formatting with thousands separator and padding. Resolves issue 3140. 2008-06-24 11:11:59 +00:00
Eric Smith 9ea1e36957 Typo in comment. 2008-06-24 06:05:30 +00:00
Eric Smith 65fe47b931 Modified interface to _Py_[String|Unicode]InsertThousandsGrouping, in anticipation of fixing issue 3140. 2008-06-24 00:42:10 +00:00
Andrew M. Kuchling d897264464 Docstring typo 2008-06-21 13:29:12 +00:00
Hye-Shik Chang 30fa13f3a0 Fix build on FreeBSD gcc. 2008-06-21 11:15:30 +00:00
Raymond Hettinger e0e711446b Issue 3008: hex/oct/bin can show floats exactly. 2008-06-21 06:39:53 +00:00
Mark Dickinson 1ec2fcd16e Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now
returns (0, 0, 1) instead of (0, -1, 1), and slice(None, 10, -1).indices(10)
returns (9, 9, -1) instead of (9, 10, -1).
2008-06-20 14:53:43 +00:00
Raymond Hettinger e3ae655edf Make bin() implementation parallel oct() and hex() so that int/long subclasses can override or so that other classes can support. 2008-06-20 04:18:15 +00:00
Amaury Forgeot d'Arc a8919fe631 Issue 3110: Crash with weakref subclass,
seen after a "import multiprocessing.reduction"

An instance of a weakref subclass can have attributes.
If such a weakref holds the only strong reference to the object,
deleting the weakref will delete the object. In this case,
the callback must not be called, because the ref object is being deleted!
2008-06-16 19:12:42 +00:00
Robert Schuppenies 73e9ffc811 Fixed: sys.getsizeof does not take the actual length of the tuples into account. 2008-06-13 13:29:37 +00:00
Raymond Hettinger 4267be6478 Multi-arg form for set.difference() and set.difference_update(). 2008-06-11 10:30:54 +00:00
Gregory P. Smith 9d53457e59 Merge in release25-maint r60793:
Added checks for integer overflows, contributed by Google. Some are
 only available if asserts are left in the code, in cases where they
 can't be triggered from Python code.
2008-06-11 07:41:16 +00:00
Raymond Hettinger 610a93ea26 Handle the case with zero arguments. 2008-06-11 00:44:47 +00:00
Gregory P. Smith b7fea62cca Rename bytesobject.c back to stringobject.c to keep with the PyString theme.
Part of reverting most of r63675 per the mailing list discussion.
2008-06-10 21:23:22 +00:00
Gregory P. Smith 99a3dce92d More reverting of r63675 per the mailing list discussions. This restores
occurances of PyBytes_ in the code to their original PyString_ names.  The
bytesobject.c file will be renamed back to stringobject.c in a future checkin.
2008-06-10 17:42:36 +00:00
Robert Schuppenies 901c997de0 Issue 3048: Fixed sys.getsizeof for unicode objects. 2008-06-10 10:10:31 +00:00
Alexandre Vassalotti 602d8db2bc Added better pickling support to xrange objects.
Cleaned up the unit test.
2008-06-10 04:01:23 +00:00
Alexandre Vassalotti 1f2f61a78f Issue 2582: Fix pickling of xrange objects. 2008-06-10 03:34:53 +00:00
Raymond Hettinger 5c4d3d0e4c Let set.intersection() and set.intersection_update() take multiple input arguments. 2008-06-09 13:07:27 +00:00
Raymond Hettinger ee4bcad68e Let set.union() and set.update() accept multiple inputs. 2008-06-09 08:33:37 +00:00
Gregory P. Smith dd96db63f6 This reverts r63675 based on the discussion in this thread:
http://mail.python.org/pipermail/python-dev/2008-June/079988.html

Python 2.6 should stick with PyString_* in its codebase.  The PyBytes_* names
in the spirit of 3.0 are available via a #define only.  See the email thread.
2008-06-09 04:58:54 +00:00
Travis E. Oliphant 0144f27602 Remove locking part of new buffer protocol. 2008-06-06 22:39:47 +00:00
Alexandre Vassalotti 80af6da748 Fixed complex.__getnewargs__() to not emit another complex object. 2008-06-04 20:41:44 +00:00
Georg Brandl 7a6de8b0f4 Some style nits. Also clarify in the docstrings what __sizeof__ does. 2008-06-01 16:42:16 +00:00
Robert Schuppenies 51df064767 Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes. 2008-06-01 16:16:17 +00:00
Martin v. Löwis 99815892f6 New environment variable PYTHONIOENCODING. 2008-06-01 07:20:46 +00:00
Eric Smith dc13b79a38 Refactor and clean up str.format() code (and helpers) in advance of optimizations. 2008-05-30 18:10:04 +00:00
Georg Brandl 30fadc1799 #2999: fix name of third parameter in unicode.replace()'s docstring. 2008-05-30 07:54:16 +00:00
Raymond Hettinger d99bee7c9f Issue 2855: Fix obscure crasher by slowing down the entire module. Mimics what was done to dictionaries in r59223. 2008-05-30 06:49:47 +00:00
Georg Brandl f18a707205 Revert #2990 patch; it's not necessary as Armin showed. 2008-05-29 14:35:39 +00:00
Georg Brandl 5ec330cb2f #2990: prevent inconsistent state while updating method cache. 2008-05-28 15:41:36 +00:00
Georg Brandl 74a1deaab3 #2989: add PyType_Modified(). 2008-05-28 11:21:39 +00:00
Christian Heimes 44720838eb Renamed bytesobject.c to bytearrayobject.c
Renamed stringobject.c to bytesobject.c
Fixed Windows builds
2008-05-26 13:01:01 +00:00
Christian Heimes 593daf545b Renamed PyString to PyBytes 2008-05-26 12:51:38 +00:00
Christian Heimes 3497f94476 First step of the C API rename:
renamed Include/bytesobject.h to Include/bytearrayobject.h
renamed Include/stringobject.h to Include/bytesobject.h
added Include/stringobject.h with aliases
2008-05-26 12:29:14 +00:00
Georg Brandl 88659b0ab2 #2592: delegate nb_index and the floor/truediv slots in weakref.proxy. 2008-05-20 08:40:43 +00:00
Georg Brandl dffbf5f542 Revert copy_reg -> copyreg rename. 2008-05-20 07:49:57 +00:00
Georg Brandl a9916b55de #2353: raise Py3k warning in file.xreadlines(). 2008-05-17 22:11:54 +00:00
Alexandre Vassalotti ea0b22a167 Patch by Quentin Gallet-Gilles: Renaming leftovers for 2.6.
This fixes the omissions of configparser, copyreg, queue and
socketserver renaming.
2008-05-16 18:03:52 +00:00
Georg Brandl ecf9091f59 Don't allow keyword arguments to reversed(). 2008-05-16 13:24:29 +00:00
Georg Brandl 5ffad6646e Make generator repr consistent with function and code object repr. 2008-05-16 09:34:48 +00:00
Georg Brandl c91210c06b #2863: add gen.__name__ and add this name to generator repr(). 2008-05-15 15:08:32 +00:00
Georg Brandl 913835763a #2831: add start argument to enumerate(). Patch by Scott Dial and me. 2008-05-13 19:04:54 +00:00
Georg Brandl ecbbd94e71 #2809 followup: even better split docstring. 2008-05-11 20:53:55 +00:00