summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
...
* 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.
* Backport the following changes:Walter Dörwald2002-04-222-21/+84
| | | | | | | | | | | | | | | | | | | | Misc/NEWS 1.387->1.388 Lib/test/string_tests.py 1.10->1.11, 1.12->1.14, Lib/test/test_unicode.py 1.50->1.51, 1.53->1.54, 1.55->1.56 Lib/test/test_string.py 1.15->1.16 Lib/string.py 1.61->1.63 Lib/test/test_userstring.py 1.5->1.6, 1.11, 1.12 Objects/stringobject.c 2.156->2.159 Objects/unicodeobject.c 2.137->2.139 Doc/lib/libstdtypes.tec 1.87->1.88 Add a method zfill to str, unicode and UserString and change Lib/string.py accordingly (see SF patch http://www.python.org/sf/536241) This also adds Guido's fix to test_userstring.py and the subinstance checks in test_string.py and test_unicode.py.
* backport fix for SF buf #505315 from trunkJeremy Hylton2002-04-201-5/+5
|
* backport gvanrossum's patch:Anthony Baxter2002-04-181-1/+6
| | | | | | | | Deprecate % as well. The message for deprecation of //, % and divmod is the same in all three cases (mostly because // calls divmod :-). Original patches were: python/dist/src/Objects/complexobject.c:2.59
* backport gvanrossum's patch:Anthony Baxter2002-04-181-0/+5
| | | | | | | | | | | | | | SF bug #543387. Complex numbers implement divmod() and //, neither of which makes one lick of sense. Unfortunately this is documented, so I'm adding a deprecation warning now, so we can delete this silliness, oh, around 2005 or so. Bugfix candidate (At least for 2.2.2, I think.) Original patches were: python/dist/src/Objects/complexobject.c:2.58
* backport gvanrossum's patch:Anthony Baxter2002-04-181-15/+86
| | | | | | | | | | | | | | | | | | | | | Partially implement SF feature request 444708. Add optional arg to string methods strip(), lstrip(), rstrip(). The optional arg specifies characters to delete. Also for UserString. Still to do: - Misc/NEWS - LaTeX docs (I did the docstrings though) - Unicode methods, and Unicode support in the string methods. Original patches were: python/dist/src/Objects/stringobject.c:2.156
* backport gvanrossum's patch:Anthony Baxter2002-04-181-0/+5
| | | | | | | | | | | | | SF bug #541883 (Vincent Fiack). A stupid bug in object_set_class(): didn't check for value==NULL before checking its type. Bugfix candidate. Original patches were: python/dist/src/Objects/typeobject.c:2.142
* Darn. Of course the warning that Tim killed on the trunk must also beGuido van Rossum2002-04-181-1/+2
| | | | killed in the branch.
* backport gvanrossum's patch:Anthony Baxter2002-04-181-2/+6
| | | | | | | | | | | SF bug 544647. PyNumber_InPlaceMultiply insisted on calling sq_inplace_repeat if it existed, even if nb_inplace_multiply also existed and the arguments weren't right for sq_inplace_repeat. Change this to only use sq_inplace_repeat if nb_inplace_multiply isn't defined. Bugfix candidate.
* backport tim_one's patch:Anthony Baxter2002-04-181-1/+1
| | | | | | SF bug 543840: complex(string) accepts strings with \0 complex_subtype_from_string(): this stopped parsing at the first 0 byte, as if that were the end of the input string.
* Backport rev 2.143 (note: some earlier bugfix candidates still TBD).Guido van Rossum2002-04-181-7/+11
| | | | | | | | | | | | | SF bug 542984. Change type_get_doc (the get function for __doc__) to look in tp_dict more often, and if it finds a descriptor in tp_dict, to call it (with a NULL instance). This means you can add a __doc__ descriptor to a new-style class that returns instance docs when called on an instance, and class docs when called on a class -- or the same docs in either case, but lazily computed. I'll also check this into the 2.2 maintenance branch.
* SF bug 543148: Memory leak with stackframes + inspect.Tim Peters2002-04-131-2/+17
| | | | | | | | Put a bound on the number of frameobjects that can live in the frameobject free_list. Also fixed on the trunk. I don't intend to backport to 2.1 (too much work -- lots of cyclic structures leak there).
* SF bug 538827: Python open w/ MSVC6: bad error msgs.Tim Peters2002-04-081-1/+14
| | | | | | | open_the_file: Some (not all) flavors of Windows set errno to EINVAL when passed a syntactically invalid filename. Python turned that into an incomprehensible complaint about the mode string. Fixed by special-casing MSVC.
* - A type can now inherit its metatype from its base type. Previously,Guido van Rossum2002-04-081-6/+6
| | | | | | when PyType_Ready() was called, if ob_type was found to be NULL, it was always set to &PyType_Type; now it is set to base->ob_type, where base is tp_base, defaulting to &PyObject_Type.
* Backport half a patch from the trunk. This inherits tp_is_gc from aGuido van Rossum2002-04-051-0/+1
| | | | base class.