summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Check for trailing backslash. Fixes #593656.Martin v. Löwis2002-08-141-5/+8
|
* Patch #505705: Remove eval in pickle and cPickle.Martin v. Löwis2002-08-141-3/+157
|
* Allow more docstrings to be removed during compilationNeal Norwitz2002-08-132-14/+18
|
* Fixed error in new comment.Tim Peters2002-08-131-4/+3
|
* k_mul(): The fix for (ah+al)*(bh+bl) spilling 1 bit beyond the allocatedTim Peters2002-08-131-8/+44
| | | | | | | | | | space is no longer needed, so removed the code. It was only possible when a degenerate (ah->ob_size == 0) split happened, but after that fix went in I added k_lopsided_mul(), which saves the body of k_mul() from seeing a degenerate split. So this removes code, and adds a honking long comment block explaining why spilling out of bounds isn't possible anymore. Note: ff we end up spilling out of bounds anyway <wink>, an assert in v_iadd() is certain to trigger.
* Allow docstrings to be removed during compilation for *SLOT macro and friendsNeal Norwitz2002-08-131-3/+5
|
* Allow docstrings to be removed during compilationNeal Norwitz2002-08-131-3/+3
|
* Add an improvement wrinkle to Neil Schemenauer's change to int_mulGuido van Rossum2002-08-131-2/+4
| | | | | | | (rev. 2.86). 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.
* Fix comment for PyLong_AsUnsignedLong() to say that the return valueGuido van Rossum2002-08-131-1/+1
| | | | is an *unsigned* long.
* k_lopsided_mul(): This allocated more space for bslice than necessary.Tim Peters2002-08-121-1/+1
|
* Added new function k_lopsided_mul(), which is much more efficient thanTim Peters2002-08-121-10/+72
| | | | | | | | k_mul() when inputs have vastly different sizes, and a little more efficient when they're close to a factor of 2 out of whack. I consider this done now, although I'll set up some more correctness tests to run overnight.
* k_mul(): Moved an assert down. In a debug build, interrupting aTim Peters2002-08-121-2/+2
| | | | | multiply via Ctrl+C could cause a NULL-pointer dereference due to the assert.
* k_mul(): Heh -- I checked in two fixes for the last problem. Only keepTim Peters2002-08-121-2/+2
| | | | the good one <wink>. Also checked in a test-aid by mistake.
* k_mul(): White-box testing turned up that (ah+al)*(bh+bl) can, in rareTim Peters2002-08-121-3/+11
| | | | | | | | | cases, overflow the allocated result object by 1 bit. In such cases, it would have been brought back into range if we subtracted al*bl and ah*bh from it first, but I don't want to do that because it hurts cache behavior. Instead we just ignore the excess bit when it appears -- in effect, this is forcing unsigned mod BASE**(asize + bsize) arithmetic in a case where that doesn't happen all by itself.
* Fix MSVC warnings.Guido van Rossum2002-08-121-2/+2
|
* Refactor how __dict__ and __weakref__ interact with __slots__.Guido van Rossum2002-08-121-55/+147
| | | | | | | | | | | | | | | | | | | | | | | 1. You can now have __dict__ and/or __weakref__ in your __slots__ (before only __weakref__ was supported). This is treated differently than before: it merely sets a flag that the object should support the corresponding magic. 2. Dynamic types now always have descriptors __dict__ and __weakref__ thrust upon them. If the type in fact does not support one or the other, that descriptor's __get__ method will raise AttributeError. 3. (This is the reason for all this; it fixes SF bug 575229, reported by Cesar Douady.) Given this code: class A(object): __slots__ = [] class B(object): pass class C(A, B): __slots__ = [] the class object for C was broken; its size was less than that of B, and some descriptors on B could cause a segfault. C now correctly inherits __weakrefs__ and __dict__ from B, even though A is the "primary" base (C.__base__ is A). 4. Some code cleanup, and a few comments added.
* x_mul(): Made life easier for C optimizers in the "grade school"Tim Peters2002-08-121-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | algorithm. MSVC 6 wasn't impressed <wink>. Something odd: the x_mul algorithm appears to get substantially worse than quadratic time as the inputs grow larger: bits in each input x_mul time k_mul time ------------------ ---------- ---------- 15360 0.01 0.00 30720 0.04 0.01 61440 0.16 0.04 122880 0.64 0.14 245760 2.56 0.40 491520 10.76 1.23 983040 71.28 3.69 1966080 459.31 11.07 That is, x_mul is perfectly quadratic-time until a little burp at 2.56->10.76, and after that goes to hell in a hurry. Under Karatsuba, doubling the input size "should take" 3 times longer instead of 4, and that remains the case throughout this range. I conclude that my "be nice to the cache" reworkings of k_mul() are paying.
* k_mul() and long_mul(): I'm confident that the Karatsuba algorithm isTim Peters2002-08-121-9/+30
| | | | | | | | correct now, so added some final comments, did some cleanup, and enabled it for all long-int multiplies. The KARAT envar no longer matters, although I left some #if 0'ed code in there for my own use (temporary). k_mul() is still much slower than x_mul() if the inputs have very differenent sizes, and that still needs to be addressed.
* k_mul: Rearranged computation for better cache use. Ignored overflowTim Peters2002-08-121-60/+50
| | | | | | | | | (it's possible, but should be harmless -- this requires more thought, and allocating enough space in advance to prevent it requires exactly as much thought, to know exactly how much that is -- the end result certainly fits in the allocated space -- hmm, but that's really all the thought it needs! borrows/carries out of the high digits really are harmless).
* x_mul(): This failed to normalize its result.Tim Peters2002-08-121-6/+18
| | | | | | | | | | | | | | | | | | | | | | k_mul(): This didn't allocate enough result space when one input had more than twice as many bits as the other. This was partly hidden by that x_mul() didn't normalize its result. The Karatsuba recurrence is pretty much hosed if the inputs aren't roughly the same size. If one has at least twice as many bits as the other, we get a degenerate case where the "high half" of the smaller input is 0. Added a special case for that, for speed, but despite that it helped, this can still be much slower than the "grade school" method. It seems to take a really wild imbalance to trigger that; e.g., a 2**22-bit input times a 1000-bit input on my box runs about twice as slow under k_mul than under x_mul. This still needs to be addressed. I'm also not sure that allocating a->ob_size + b->ob_size digits is enough, given that this is computing k = (ah+al)*(bh+bl) instead of k = (ah-al)*(bl-bh); i.e., it's certainly enough for the final result, but it's vaguely possible that adding in the "artificially" large k may overflow that temporarily. If so, an assert will trigger in the debug build, but we'll probably compute the right result anyway(!).
* Introduced helper functions v_iadd and v_isub, for in-place digit-vectorTim Peters2002-08-121-29/+75
| | | | | | | addition and subtraction. Reworked the tail end of k_mul() to use them. This saves oodles of one-shot longobject allocations (this is a triply- recursive routine, so saving one allocation in the body saves 3**n allocations at depth n; we actually save 2 allocations in the body).
* k_mul(): Repaired another typo in another comment.Tim Peters2002-08-121-1/+1
|
* k_mul(): Repaired typo in comment.Tim Peters2002-08-121-1/+1
|
* Cautious introduction of a patch that started fromTim Peters2002-08-121-85/+264
| | | | | | | | SF 560379: Karatsuba multiplication. Lots of things were changed from that. This needs a lot more testing, for correctness and speed, the latter especially when bit lengths are unbalanced. For now, the Karatsuba code gets invoked if and only if envar KARAT exists.
* int_lshift(): Simplified/sped overflow-checking.Tim Peters2002-08-111-4/+2
|
* Use a better check for overflow from a<<b.Guido van Rossum2002-08-111-2/+4
|
* Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.Marc-André Lemburg2002-08-111-1/+55
| | | | | | | 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.
* Implement stage B0 of PEP 237: add warnings for operations thatGuido van Rossum2002-08-113-3/+41
| | | | | | | | | | currently return inconsistent results for ints and longs; in particular: hex/oct/%u/%o/%x/%X of negative short ints, and x<<n that either loses bits or changes sign. (No warnings for repr() of a long, though that will also change to lose the trailing 'L' eventually.) This introduces some warnings in the test suite; I'll take care of those later.
* Fixed new typos, added a little info about ~sort versus "hint"s.Tim Peters2002-08-101-4/+10
|
* Disallow class assignment completely unless both old and new are heapGuido van Rossum2002-08-101-6/+9
| | | | | types. This prevents nonsense like 2.__class__ = bool or True.__class__ = int.
* 1. Combined the base and length arrays into a single array of structs.Tim Peters2002-08-102-53/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is friendlier for caches. 2. Cut MIN_GALLOP to 7, but added a per-sort min_gallop vrbl that adapts the "get into galloping mode" threshold higher when galloping isn't paying, and lower when it is. There's no known case where this hurts. It's (of course) neutral for /sort, \sort and =sort. It also happens to be neutral for !sort. It cuts a tiny # of compares in 3sort and +sort. For *sort, it reduces the # of compares to better than what this used to do when MIN_GALLOP was hardcoded to 10 (it did about 0.1% more *sort compares before, but given how close we are to the limit, this is "a lot"!). %sort used to do about 1.5% more compares, and ~sort about 3.6% more. Here are exact counts: i *sort 3sort +sort %sort ~sort !sort 15 449235 33019 33016 51328 188720 65534 before 448885 33016 33007 50426 182083 65534 after 0.08% 0.01% 0.03% 1.79% 3.65% 0.00% %ch from after 16 963714 65824 65809 103409 377634 131070 962991 65821 65808 101667 364341 131070 0.08% 0.00% 0.00% 1.71% 3.65% 0.00% 17 2059092 131413 131362 209130 755476 262142 2057533 131410 131361 206193 728871 262142 0.08% 0.00% 0.00% 1.42% 3.65% 0.00% 18 4380687 262440 262460 421998 1511174 524286 4377402 262437 262459 416347 1457945 524286 0.08% 0.00% 0.00% 1.36% 3.65% 0.00% 19 9285709 524581 524634 848590 3022584 1048574 9278734 524580 524633 837947 2916107 1048574 0.08% 0.00% 0.00% 1.27% 3.65% 0.00% 20 19621118 1048960 1048942 1715806 6045418 2097150 19606028 1048958 1048941 1694896 5832445 2097150 0.08% 0.00% 0.00% 1.23% 3.65% 0.00% 3. Added some key asserts I overlooked before. 4. Updated the doc file.
* The samplesort-vs-mergesort #-of-comparisons comparisons were capturedTim Peters2002-08-101-24/+24
| | | | | | | | before %sort was introduced. Redid them (the numbers change, but the conclusions don't). Also did the samplesort counts with the released 2.2.1, as they're slightly different under the last CVS 2.3 samplesort (some higher, some lower -- CVS had been changed to stop doing the special-case business on recursive samplesort calls).
* Add support for the iterator protocol to weakref proxy objects.Fred Drake2002-08-091-38/+64
| | | | Part of fixing SF bug #591704.
* Unicode replace() method with empty pattern argument should fail, likeGuido van Rossum2002-08-091-0/+5
| | | | it does for 8-bit strings.
* 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.
* Repaired a braino in the description of bad minrun values.Tim Peters2002-08-091-3/+3
|
* Major speedup for new-style class creation. Turns out there was someGuido van Rossum2002-08-091-0/+22
| | | | | | | | | | | | trampolining going on with the tp_new descriptor, where the inherited PyType_GenericNew was overwritten with the much slower slot_tp_new which would end up calling tp_new_wrapper which would eventually call PyType_GenericNew. Add a special case for this to update_one_slot(). XXX Hope there isn't a loophole in this. I'll buy the first person to point out a bug in the reasoning a beer. Backport candidate (but I won't do it).
* Moved special case for tuples from iterobject.c toRaymond Hettinger2002-08-092-25/+123
| | | | | | tupleobject.c. Makes the code in iterobject.c cleaner and speeds-up the general case by not checking for tuples everytime. SF Patch #592065.
* Significant speedup in new-style object creation: in slot_tp_new(),Guido van Rossum2002-08-081-1/+8
| | | | | | | | | intern the string "__new__" so we can call PyObject_GetAttr() rather than PyObject_GetAttrString(). (Though it's a mystery why slot_tp_new is being called when a class doesn't define __new__. I'll look into that tomorrow.) 2.2 backport candidate (but I won't do it).
* A modest speedup of object deallocation. call_finalizer() did ratherGuido van Rossum2002-08-081-66/+70
| | | | | | | | | | | | | | | a lot of work: it had to save and restore the current exception around a call to lookup_maybe(), because that could fail in rare cases, and most objects don't have a __del__ method, so the whole exercise was usually a waste of time. Changed this to cache the __del__ method in the type object just like all other special methods, in a new slot tp_del. So now subtype_dealloc() can test whether tp_del is NULL and skip the whole exercise if it is. The new slot doesn't need a new flag bit: subtype_dealloc() is only called if the type was dynamically allocated by type_new(), so it's guaranteed to have all current slots. Types defined in C cannot fill in tp_del with a function of their own, so there's no corresponding "wrapper". (That functionality is already available through tp_dealloc.)
* Added info about highwater heap-memory use for the sortperf.py tests; + aTim Peters2002-08-081-3/+31
| | | | couple of minor edits elsewhere.
* PyList_Reverse(): This was leaking a reference to Py_None on every call.Tim Peters2002-08-081-1/+4
| | | | | I believe I introduced this bug when I refactored the reversal code so that the mergesort could use it too. It's not a problem on the 2.2 branch.
* Fix a subtle bug in the trashcan code I added yesterday toGuido van Rossum2002-08-071-2/+3
| | | | | | | | | | | | | | | | | | | | | | | subtype_dealloc(). When call_finalizer() failed, it would return without going through the trashcan end macro, thereby unbalancing the trashcan nesting level counter, and thereby defeating the test case (slottrash() in test_descr.py). This in turn meant that the assert in the GC_UNTRACK macro wasn't triggered by the slottrash() test despite a bug in the code: _PyTrash_destroy_chain() calls the dealloc routine with an object that's untracked, and the assert in the GC_UNTRACK macro would fail on this; but because of an earlier test that resurrects an object, causing call_finalizer() to fail and the trashcan nesting level to be unbalanced, so _PyTrash_destroy_chain() was never called. Calling the slottrash() test in isolation *did* trigger the assert, however. So the fix is twofold: (1) call the GC_UnTrack() function instead of the GC_UNTRACK macro, because the function is safe when the object is already untracked; (2) when call_finalizer() fails, jump to a label that exits through the trashcan end macro, keeping the trashcan nesting balanced.
* Replace abort with Py_FatalError.Martin v. Löwis2002-08-071-1/+1
|
* Make more functions staticNeal Norwitz2002-08-061-2/+2
|
* Make readahead functions staticNeal Norwitz2002-08-061-5/+8
|
* Fix SF bug 574207 (chained __slots__ dealloc segfault).Guido van Rossum2002-08-061-10/+52
| | | | | | | | | | | This is inspired by SF patch 581742 (by Jonathan Hogg, who also submitted the bug report, and two other suggested patches), but separates the non-GC case from the GC case to avoid testing for GC several times. Had to fix an assert() from call_finalizer() that asserted that the object wasn't untracked, because it's possible that the object isn't GC'ed!
* PyUnicode_Contains(): The memcmp() call didn't take into account theBarry Warsaw2002-08-061-1/+1
| | | | width of Py_UNICODE. Good catch, MAL.
* Committing patch #591250 which provides "str1 in str2" when str1 is aBarry Warsaw2002-08-062-26/+39
| | | | string of longer than 1 character.
* SF patch 580331 by Oren Tirosh: make file objects their own iterator.Guido van Rossum2002-08-061-31/+130
| | | | | | | | | | | | | | | | | | | | | | For a file f, iter(f) now returns f (unless f is closed), and f.next() is similar to f.readline() when EOF is not reached; however, f.next() uses a readahead buffer that messes up the file position, so mixing f.next() and f.readline() (or other methods) doesn't work right. Calling f.seek() drops the readahead buffer, but other operations don't. The real purpose of this change is to reduce the confusion between objects and their iterators. By making a file its own iterator, it's made clearer that using the iterator modifies the file object's state (in particular the current position). A nice side effect is that this speeds up "for line in f:" by not having to use the xreadlines module. The f.xreadlines() method is still supported for backwards compatibility, though it is the same as iter(f) now. (I made some cosmetic changes to Oren's code, and added a test for "file closed" to file_iternext() and file_iter().)