Commit Graph

192 Commits

Author SHA1 Message Date
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
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
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
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
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
Skip Montanaro 2c7ca9bb11 Correct grammar. 2008-07-07 11:16:14 +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
Christian Heimes 593daf545b Renamed PyString to PyBytes 2008-05-26 12:51:38 +00:00
Neal Norwitz fddc469876 Prevent namespace pollution, add static for internal functions 2008-04-15 03:46:21 +00:00
Raymond Hettinger c71d2a9afd Remove unnecessary traceback save/restore pair. 2008-03-19 22:47:48 +00:00
Raymond Hettinger de48d8406f Fix compiler warning. 2008-03-19 03:56:59 +00:00
Raymond Hettinger 9a47e6201f Speed-up isinstance() for one easy case. 2008-03-18 23:22:29 +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
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
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 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
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
Jeffrey Yasskin a26cf9b760 Make int() and long() fall back to __trunc__(). See issue 2002. 2008-02-04 01:04:35 +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
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
Thomas Wouters bbaff4c7e8 Properly indent two lines. (Spotted because it caused merge conflicts in the
py3k branch ;)
2007-09-18 23:27:30 +00:00
Guido van Rossum b55911378f Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.

I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
2007-09-10 22:36:02 +00:00
Brett Cannon 1e534b5425 Fix a crasher where Python code managed to infinitely recurse in C code without
ever going back out to Python code in PyObject_Call().  Required introducing a
static RuntimeError instance so that normalizing an exception there is no
reliance on a recursive call that would put the exception system over the
recursion check itself.
2007-09-07 04:18:30 +00:00
Raymond Hettinger de33c62466 Silence compiler warning 2007-02-07 23:49:03 +00:00
Raymond Hettinger 4da5bf644a Bug #1575169: operator.isSequenceType() now returns False for subclasses of dict. 2007-02-07 22:24:07 +00:00
Armin Rigo 7ccbca93a2 Forward-port of r52136,52138: a review of overflow-detecting code.
* unified the way intobject, longobject and mystrtoul handle
  values around -sys.maxint-1.

* in general, trying to entierely avoid overflows in any computation
  involving signed ints or longs is extremely involved.  Fixed a few
  simple cases where a compiler might be too clever (but that's all
  guesswork).

* more overflow checks against bad data in marshal.c.

* 2.5 specific: fixed a number of places that were still confusing int
  and Py_ssize_t.  Some of them could potentially have caused
  "real-world" breakage.

* list.pop(x): fixing overflow issues on x was messy.  I just reverted
  to PyArg_ParseTuple("n"), which does the right thing.  (An obscure
  test was trying to give a Decimal to list.pop()... doesn't make
  sense any more IMHO)

* trying to write a few tests...
2006-10-04 12:17:45 +00:00
Neal Norwitz 271a8689e9 Subclasses of int/long are allowed to define an __index__. 2006-08-15 06:29:03 +00:00
Neal Norwitz 8a87f5d37e Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments.  This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward.  I don't want this to hold up release if possible.
2006-08-12 17:03:09 +00:00
Georg Brandl b0061c8e93 Remove "non-mapping" and "non-sequence" from TypeErrors raised by
PyMapping_Size and PySequence_Size.

Because len() tries first sequence, then mapping size, it will always
raise a "non-mapping object has no len" error which is confusing.
2006-08-08 11:56:21 +00:00
Armin Rigo 53c1692f6a Fix for an obscure bug introduced by revs 46806 and 46808, with a test.
The problem of checking too eagerly for recursive calls is the
following: if a RuntimeError is caused by recursion, and if code needs
to normalize it immediately (as in the 2nd test), then
PyErr_NormalizeException() needs a call to the RuntimeError class to
instantiate it, and this hits the recursion limit again...  causing
PyErr_NormalizeException() to never finish.

Moved this particular recursion check to slot_tp_call(), which is not
involved in instantiating built-in exceptions.

Backport candidate.
2006-06-21 21:58:50 +00:00
Georg Brandl ccff785258 Patch #1507676: improve exception messages in abstract.c, object.c and typeobject.c. 2006-06-18 22:17:29 +00:00
Brett Cannon 6946ea0be0 Fix bug introduced in rev. 46806 by not having variable declaration at the top of a block. 2006-06-09 22:45:54 +00:00
Brett Cannon 22565aac3b An object with __call__ as an attribute, when called, will have that attribute checked for __call__ itself, and will continue to look until it finds an object without the attribute. This can lead to an infinite recursion.
Closes bug #532646, again.  Will be backported.
2006-06-09 22:31:23 +00:00
Brett Cannon ea229bd1ed Fix coding style guide bug. 2006-06-06 18:08:16 +00:00
Skip Montanaro 54e964d253 C++ compilation cleanup: Migrate declaration of
_PyObject_Call(Function|Method)_SizeT into Include/abstract.h.  This gets
them under the umbrella of the extern "C" { ... } block in that file.
2006-04-18 00:27:46 +00:00
Martin v. Löwis 5cb6936672 Make Py_BuildValue, PyObject_CallFunction and
PyObject_CallMethod aware of PY_SSIZE_T_CLEAN.
2006-04-14 09:08:42 +00:00
Armin Rigo 314861c568 Minor bugs in the __index__ code (PEP 357), with tests. 2006-03-30 14:04:02 +00:00
Neal Norwitz badc086543 Stop duplicating code and handle slice indices consistently and correctly
wrt to ssize_t.
2006-03-23 06:03:08 +00:00
Neal Norwitz 29892cc386 Update function name to reflect params and stop casting to long to avoid losing data 2006-03-20 01:55:26 +00:00
Guido van Rossum 38fff8c4e4 Checking in the code for PEP 357.
This was mostly written by Travis Oliphant.
I've inspected it all; Neal Norwitz and MvL have also looked at it
(in an earlier incarnation).
2006-03-07 18:50:55 +00:00
Neal Norwitz 1fc4b776d4 Change some sequnce APIs to use Py_ssize_t. 2006-03-04 18:49:58 +00:00
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Martin v. Löwis eb079f1c25 Use Py_ssize_t for counts and sizes.
Convert Py_ssize_t using PyInt_FromSsize_t
2006-02-16 14:32:27 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00