summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Darn! Don't divide by zero. Bad fix. :-)Guido van Rossum2002-10-111-1/+1
|
* Backport listobject.c 2.137 and tupleobject.c 2.75:Guido van Rossum2002-10-112-0/+6
| | | | Add checks for size overflow on list*n, list+list, tuple+tuple.
* Backport 2.193:Guido van Rossum2002-10-111-10/+4
| | | | | | | | | PyObject_Init[Var] is almost always called from the PyObject_NEW[_VAR] macros. The 'op' argument is then the result from PyObject_MALLOC, and that can of course be NULL. In that case, PyObject_Init[Var] would raise a SystemError with "NULL object passed to PyObject_Init[Var]". But there's nothing the caller of the macro can do about this. So PyObject_Init[Var] should call just PyErr_NoMemory.
* Backport stringobject.c 2.194 and unicodeobject.c 2.172:Guido van Rossum2002-10-112-4/+12
| | | | | | | | | | | | Fix a nasty endcase reported by Armin Rigo in SF bug 618623: '%2147483647d' % -123 segfaults. This was because an integer overflow in a comparison caused the string resize to be skipped. After fixing the overflow, this could call _PyString_Resize() with a negative size, so I (1) test for that and raise MemoryError instead; (2) also added a test for negative newsize to _PyString_Resize(), raising SystemError as for all bad arguments. An identical bug existed in unicodeobject.c, of course.
* New in 2.2.2!Guido van Rossum2002-10-111-1/+0
| | | | | | | | | | | | | | | | | | | | | | In inherit_slots(), get rid of the COPYSLOT(tp_dictoffset). Copying the offset from a non-dominant base makes no sense: either the non-dominant base has a nonzero tp_dictoffset, and then we should have already copied it from the dominant base (at the very end of inherit_special()), or the non-dominant base has no tp_dictoffset and for some reason type_new() decided not to add one. The tp_dictoffset from a non-dominant base is likely to conflict with the instance layout of the dominant base, so copying the tp_dictoffset from the non-dominant base would be a really bad idea in that case. This bug can only be triggered by multiple inheritance from an extension class that doesn't set tp_dictoffset and a new-style user-level class that does have one. There are no such extension classes in the distribution, but there are 3rd party ones. (Zope3 now has one, that's how I found this. :-) I've asked a few heavy users of new-style classes, extension classes and metaclasses (David Abrahams and Kevin Jacobs), and neither of them found any problems in their test suite after applying this fix, so I assume it's safe.
* Backport the relevant part of 2.192:Guido van Rossum2002-10-111-1/+2
| | | | | | | | | | | The string formatting code has a test to switch to Unicode when %s sees a Unicode argument. Unfortunately this test was also executed for %r, because %s and %r share almost all of their code. This meant that, if u is a unicode object while repr(u) is an 8-bit string containing ASCII characters, '%r' % u is a *unicode* string containing only ASCII characters! Fixed by executing the test only for %s.
* Backport, at the reqest of Kevin Jacobs:Guido van Rossum2002-10-071-0/+4
| | | | | | | | | | | - Changed new-style class instantiation so that when C's __new__ method returns something that's not a C instance, its __init__ is not called. [SF bug #537450] XXX This is arguably a semantic change, but it's hard to imagine a reason for wanting to depend on the old behavior. If problems with this are reported within a week of the release of 2.2.2 beta 1, we may revert this change.
* Backport:Michael W. Hudson2002-10-071-1/+55
| | | | | | | | | | | | | | 2002/08/11 12:23:04 lemburg Python/bltinmodule.c 2.262 2002/08/11 12:23:04 lemburg Objects/unicodeobject.c 2.162 2002/08/11 12:23:03 lemburg Misc/NEWS 1.461 2002/08/11 12:23:03 lemburg Lib/test/test_unicode.py 1.65 2002/08/11 12:23:03 lemburg Include/unicodeobject.h 2.39 Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level. u'%c' will now raise a ValueError in case the argument is an integer outside the valid range of Unicode code point ordinals. Closes SF bug #593581.
* Backport 2.103:Raymond Hettinger2002-10-051-2/+2
| | | | Made conversion failure error messages consistent between types.
* Backport 2.63 and 2.60:Raymond Hettinger2002-10-051-27/+24
| | | | | | | | | | | | Call me anal, but there was a particular phrase that was speading to comments everywhere that bugged me: /* Foo is inlined */ instead of /* Inline Foo */. Somehow the "is inlined" phrase always confused me for half a second (thinking, "No it isn't" until I added the missing "here"). The new phrase is hopefully unambiguous. Close SF bug 563740. complex() now finds __complex__() in new style classes. Made conversion failure error messages consistent between types. Added related unittests.
* Fix typo in xreadlines() docstring. This does not apply to the trunk.Fred Drake2002-09-251-1/+1
| | | | Closes SF bug #614542.
* unicode_memchr(): Squashed compiler wng (signed-vs-unsigned comparison).Tim Peters2002-09-241-1/+1
|
* Backport the UTF-8 codec from 2.3 and add a work-around to let theMarc-André Lemburg2002-09-241-101/+118
| | | | | | | | UTF-8 decoder accept broken UTF-8 sequences which encode lone high surrogates (the pre-2.2.2 versions forgot to generate the UTF-8 prefix \xed for these). Fixes SF bug #610783: Lone surrogates cause bad .pyc files.
* backport theller's checkin ofMichael W. Hudson2002-09-241-1/+2
| | | | | | | | | | revision 2.102 of abstract.c Better isinstance error message. Closes SF patch # 560250. Bugfix candidate IMO.
* backport bwarsaw's checkin ofMichael W. Hudson2002-09-241-10/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | revision 2.101 of abstract.c abstract_get_bases(): Clarify exactly what the return values and states can be for this function, and ensure that only AttributeErrors are masked. Any other exception raised via the equivalent of getattr(cls, '__bases__') should be propagated up. abstract_issubclass(): If abstract_get_bases() returns NULL, we must call PyErr_Occurred() to see if an exception is being propagated, and return -1 or 0 as appropriate. This is the specific fix for a problem whereby if getattr(derived, '__bases__') raised an exception, an "undetected error" would occur (under a debug build). This nasty situation was uncovered when writing a security proxy extension type for the Zope3 project, where the security proxy raised a Forbidden exception on getattr of __bases__. PyObject_IsInstance(), PyObject_IsSubclass(): After both calls to abstract_get_bases(), where we're setting the TypeError if the return value is NULL, we must first check to see if an exception occurred, and /not/ mask an existing exception. Neil Schemenauer should double check that these changes don't break his ExtensionClass examples (there aren't any test cases for those examples and abstract_get_bases() was added by him in response to problems with ExtensionClass). Neil, please add test cases if possible! I belive this is a bug fix candidate for Python 2.2.2. ---- Whitespace normalization made this a pest to backport... Did a test case ever get added for this?
* Fix cast from backport.Marc-André Lemburg2002-09-241-1/+1
|
* Backport from trunk:Guido van Rossum2002-09-232-2/+4
| | | | | | | | unicodeobject.c 2.169 stringobject.c 2.189 Fix warnings on 64-bit platforms about casts from pointers to ints. Two of these were real bugs.
* Backport 2.93 from trunk:Guido van Rossum2002-09-231-3/+30
| | | | | | Insert an overflow check when the sequence repetition count is outside the range of ints. The old code would pass random truncated bits to sq_repeat() on a 64-bit machine.
* Backport 2.166 from trunk:Guido van Rossum2002-09-231-3/+9
| | | | | | | | | Fix SF bug 599128, submitted by Inyeol Lee: .replace() would do the wrong thing for a unicode subclass when there were zero string replacements. The example given in the SF bug report was only one way to trigger this; replacing a string of length >= 2 that's not found is another. The code would actually write outside allocated memory if replacement string was longer than the search string.
* Fix some endcase bugs in unicode rfind()/rindex() and endswith().Guido van Rossum2002-08-202-6/+6
| | | | | | These were reported and fixed by Inyeol Lee in SF bug 595350. The endswith() bug is already fixed in 2.3; I'll fix the others in 2.3 next.
* Backport:Guido van Rossum2002-08-141-6/+6
| | | | | PyType_Ready(): initialize the base class a bit earlier, so that if we copy the metatype from the base, the base actually has one!
* Backport:Guido van Rossum2002-08-131-2/+4
| | | | | | | | Add an improvement wrinkle to Neil Schemenauer's change to int_mul (rev. 2.79.6.3). The other type is only disqualified from sq_repeat when it has the CHECKTYPES flag. This means that for extension types that only support "old-style" numeric ops, such as Zope 2's ExtensionClass, sq_repeat still trumps nb_multiply.
* Only call sq_repeat if the object does not have a nb_multiply slot. OneNeil Schemenauer2002-08-091-6/+8
| | | | | | | example of where this changes behavior is when a new-style instance defines '__mul__' and '__rmul__' and is multiplied by an int. Before the change the '__rmul__' method is never called, even if the int is the left operand.
* Remove calls to 2.1 GC API (they are noops).Neil Schemenauer2002-08-052-15/+6
|
* SF 582071 clarified the .split() method's docstring to note that sep=NoneRaymond Hettinger2002-08-051-2/+2
| | | | will trigger splitting on any whitespace.
* Backport:Guido van Rossum2002-08-011-5/+3
| | | | | | | | | | | | | Tim found that once test_longexp has run, test_sort takes very much longer to run than normal. A profiler run showed that this was due to PyFrame_New() taking up an unreasonable amount of time. A little thinking showed that this was due to the while loop clearing the space available for the stack. The solution is to only clear the local variables (and cells and free variables), not the space available for the stack, since anything beyond the stack top is considered to be garbage anyway. Also, use memset() instead of a while loop counting backwards. This should be a time savings for normal code too! (By a probably unmeasurable amount. :-)
* Backport:Guido van Rossum2002-08-011-0/+18
| | | | | | | | SF patch 588728 (Nathan Srebro). The __delete__ method wrapper for descriptors was not supported (I added a test, too.)
* SF patch #587889, fix memory leak of tp_docNeal Norwitz2002-07-301-0/+1
|
* Patch #554716: Use __va_copy where available.Martin v. Löwis2002-07-282-0/+8
|
* The object returned by tp_new() may not have a tp_init.Jeremy Hylton2002-07-161-1/+2
| | | | | | If the object is an ExtensionClass, for example, the slot is not even defined. So we must check that the type has the slot (implied by HAVE_CLASS) before calling tp_init().
* Attempting to resurrect a dying instance of a new-style class in aTim Peters2002-07-111-1/+2
| | | | | | | | | __del__ method died with Fatal Python error: GC object already in linked list in both release and debug builds. Fixed that. Added a new test that dies without the fix.
* SF bug 578752: COUNT_ALLOCS vs heap typesTim Peters2002-07-081-0/+9
| | | | | | | | Repair segfaults and infinite loops in COUNT_ALLOCS builds in the presence of new-style (heap-allocated) classes/types. Note: test_gc fails in a COUNT_ALLOCS build now, because it expects a new-style class to get garbage collected.
* Fix SF Bug 572567: Memory leak in object comparisonRaymond Hettinger2002-06-241-0/+1
|
* Backport:Guido van Rossum2002-06-181-0/+5
| | | | | | | | Patch from SF bug 570483 (Tim Northover). In a fresh interpreter, type.mro(tuple) would segfault, because PyType_Ready() isn't called for tuple yet. To fix, call PyType_Ready(type) if type->tp_dict is NULL.
* Backport:Guido van Rossum2002-06-141-1/+2
| | | | | | | Inexplicably, recurse_down_subclasses() was comparing the object gotten from a weak reference to NULL instead of to None. This caused the following assert() to fail (but only in 2.2 in the debug build -- I have to find a better test case).
* SF # 533070 Silence AIX C Compiler WarningsNeal Norwitz2002-06-131-1/+1
| | | | Warning caused by using &func. & is not necessary.
* Backport:Guido van Rossum2002-06-131-1/+17
| | | | | | | Fix for SF bug 532646. This is a little simpler than what Neal suggested there, based upon a better analysis (__getattr__ is a red herring). [This might be a 2.1 bugfix candidate we well, if people care]
* Backport two patches that belong together:Guido van Rossum2002-06-101-29/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (2.150) In the recent python-dev thread "Bizarre new test failure", we discovered that subtype_traverse must traverse the type if it is a heap type, because otherwise some cycles involving a type and its instance would not be collected. Simplest example: while 1: class C(object): pass C.ref = C() This program grows without bounds before this fix. (It grows ever slower since it spends ever more time in the collector.) Simply adding the right visit() call to subtype_traverse() revealed other problems. With MvL's help we re-learned that type_clear() doesn't have to clear *all* references, only the ones that may not be cleared by other means. Careful analysis (see comments in the code) revealed that only tp_mro needs to be cleared. (The previous checkin to this file adds a test for tp_mro==NULL to _PyType_Lookup() that's essential to prevent crashes due to tp_mro being NULL when subtype_dealloc() tries to look for a __del__ method.) The same kind of analysis also revealed that subtype_clear() doesn't need to clear the instance dict. With this fix, a useful property of the collector is once again guaranteed: a single gc.collect() call will clear out all garbage. (It didn't always before, which put us on the track of this bug.) (2.151) Undo the last chunk of the previous patch, putting back a useful assert into PyType_Ready(): now that we're not clearing tp_dict, we can assert that it's non-NULL again.
* Backport:Guido van Rossum2002-06-101-19/+17
| | | | | | | | | | Three's a charm: yet another fix for SF bug 551412. Thinking again about the test case, slot_nb_power gets called on behalf of its second argument, but with a non-None modulus it wouldn't check this, and believes it is called on behalf of its first argument. Fix this properly, and get rid of the code in _PyType_Lookup() that tries to call _PyType_Ready(). But do leave a check for a NULL tp_mro there, because this can still legitimately occur.
* Backport to 2.2.x:Guido van Rossum2002-06-041-45/+109
| | | | | | | | | | | | | Address SF bug 519621: slots weren't traversed by GC. While I was at it, I added a tp_clear handler and changed the tp_dealloc handler to use the clear_slots helper for the tp_clear handler. Also set mp->flags = READONLY for the __weakref__ pseudo-slot. [Note that I am *not* backporting the part of that patch that tightened the __slot__ rules.]
* Backport to 2.2.x:Guido van Rossum2002-06-031-1/+11
| | | | | | Address the residual issue with the fix for SF 551412 in _PyType_Lookup(). Decided to clear the error condition in the unfortunate but unlikely case that PyType_Ready() fails.
* Fix for SF bug 551412. When _PyType_Lookup() is called on a typeGuido van Rossum2002-05-241-0/+6
| | | | | whose tp_mro hasn't been initialized, it would dump core. Fix this by checking for NULL and calling PyType_Ready(). Backport from 2.3.
* Closes: #556025 seg fault when doing list(xrange(1e9))Neal Norwitz2002-05-231-3/+12
| | | | | | | | | A MemoryError is now raised when the list cannot be created. There is a test, but as the comment says, it really only works for 32 bit systems. I don't know how to improve the test for other systems (ie, 64 bit or systems where the data size != addressable size, e.g. 64 bit data, but 48 bit addressable memory)
* Backport from 2.3:Guido van Rossum2002-05-131-7/+15
| | | | | | | Jim Fulton reported a segfault in dir(). A heavily proxied object returned a proxy for __class__ whose __bases__ was also a proxy. The merge_class_dict() helper for dir() assumed incorrectly that __bases__ would always be a tuple and used the in-line tuple API on the proxy.
* Backport checkin:Walter Dörwald2002-05-131-0/+6
| | | | | | | Add #ifdef PY_USING_UNICODE sections, so that stringobject.c compiles again with --disable-unicode. Fixes SF bug http://www.python.org/sf/554912
* Close SF bug 551673. Backport Skip Montanaro's checkin of 2.112.Raymond Hettinger2002-05-121-1/+1
| | | | | Clarifies message when raising TypeError to indicate that float() accepts strings or numbers.
* Fix attribute access for the xrange objects. The tp_getattr and tp_getattroFred Drake2002-05-021-31/+38
| | | | | | handlers were both set, but were not compatible. This change uses only the tp_getattro handler with a more "modern" approach. This fixes SF bug #551285.
* backport tim_one's patch:Anthony Baxter2002-04-303-32/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Repair widespread misuse of _PyString_Resize. Since it's clear people don't understand how this function works, also beefed up the docs. The most common usage error is of this form (often spread out across gotos): if (_PyString_Resize(&s, n) < 0) { Py_DECREF(s); s = NULL; goto outtahere; } The error is that if _PyString_Resize runs out of memory, it automatically decrefs the input string object s (which also deallocates it, since its refcount must be 1 upon entry), and sets s to NULL. So if the "if" branch ever triggers, it's an error to call Py_DECREF(s): s is already NULL! A correct way to write the above is the simpler (and intended) if (_PyString_Resize(&s, n) < 0) goto outtahere; Bugfix candidate. Original patch(es): python/dist/src/Objects/fileobject.c:2.161 python/dist/src/Objects/stringobject.c:2.161 python/dist/src/Objects/unicodeobject.c:2.147
* backport gvanrossum's patch:Anthony Baxter2002-04-261-0/+8
| | | | | | | | | | | | | | | Make sure that tp_free frees the int the same way as tp_dealloc would. This fixes the problem that Barry reported on python-dev: >>> 23000 .__class__ = bool crashes in the deallocator. This was because int inherited tp_free from object, which uses the default allocator. 2.2. Bugfix candidate. (trivial change in backport: "freefunc" -> "destructor") Original patch(es): python/dist/src/Objects/intobject.c:2.82
* Backport checkin:Walter Dörwald2002-04-222-70/+191
| | | | | | | | | | Apply patch diff.txt from SF feature request http://www.python.org/sf/444708 This adds the optional argument for str.strip to unicode.strip too and makes it possible to call str.strip with a unicode argument and unicode.strip with a str argument.