1990-10-14 12:07:46 +00:00
|
|
|
/* List object implementation */
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
#include "Python.h"
|
|
|
|
|
|
1994-08-29 12:45:32 +00:00
|
|
|
#ifdef STDC_HEADERS
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#else
|
2010-05-09 15:52:27 +00:00
|
|
|
#include <sys/types.h> /* For size_t */
|
1994-08-29 12:45:32 +00:00
|
|
|
#endif
|
1990-10-14 12:07:46 +00:00
|
|
|
|
2004-07-31 02:24:20 +00:00
|
|
|
/* Ensure ob_item has room for at least newsize elements, and set
|
|
|
|
|
* ob_size to newsize. If newsize > ob_size on entry, the content
|
|
|
|
|
* of the new slots at exit is undefined heap trash; it's the caller's
|
|
|
|
|
* responsiblity to overwrite them with sane values.
|
|
|
|
|
* The number of allocated elements may grow, shrink, or stay the same.
|
|
|
|
|
* Failure is impossible if newsize <= self.allocated on entry, although
|
|
|
|
|
* that partly relies on an assumption that the system realloc() never
|
|
|
|
|
* fails when passed a number of bytes <= the number of bytes last
|
|
|
|
|
* allocated (the C standard doesn't guarantee this, but it's hard to
|
|
|
|
|
* imagine a realloc implementation where it wouldn't be true).
|
|
|
|
|
* Note that self->ob_item may change, and even if newsize is less
|
|
|
|
|
* than ob_size on entry.
|
|
|
|
|
*/
|
1995-01-26 22:59:43 +00:00
|
|
|
static int
|
2006-02-15 17:27:45 +00:00
|
|
|
list_resize(PyListObject *self, Py_ssize_t newsize)
|
1995-01-26 22:59:43 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject **items;
|
|
|
|
|
size_t new_allocated;
|
|
|
|
|
Py_ssize_t allocated = self->allocated;
|
2001-05-26 05:28:40 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Bypass realloc() when a previous overallocation is large enough
|
|
|
|
|
to accommodate the newsize. If the newsize falls lower than half
|
|
|
|
|
the allocated size, then proceed with the realloc() to shrink the list.
|
|
|
|
|
*/
|
|
|
|
|
if (allocated >= newsize && newsize >= (allocated >> 1)) {
|
|
|
|
|
assert(self->ob_item != NULL || newsize == 0);
|
|
|
|
|
Py_SIZE(self) = newsize;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
* Optimized list appends and pops by making fewer calls the underlying system
realloc(). This is achieved by tracking the overallocation size in a new
field and using that information to skip calls to realloc() whenever
possible.
* Simplified and tightened the amount of overallocation. For larger lists,
this overallocates by 1/8th (compared to the previous scheme which ranged
between 1/4th to 1/32nd over-allocation). For smaller lists (n<6), the
maximum overallocation is one byte (formerly it could be upto eight bytes).
This saves memory in applications with large numbers of small lists.
* Eliminated the NRESIZE macro in favor of a new, static list_resize function
that encapsulates the resizing logic. Coverting this back to macro would
give a small (under 1%) speed-up. This was too small to warrant the loss
of readability, maintainability, and de-coupling.
* Some functions using NRESIZE had grown unnecessarily complex in their
efforts to bend to the macro's calling pattern. With the new list_resize
function in place, those other functions could be simplified. That is
being saved for a separate patch.
* The ob_item==NULL check could be eliminated from the new list_resize
function. This would entail finding each piece of code that sets ob_item
to NULL and adding a new line to invalidate the overallocation tracking
field. Rather than impose a new requirement on other pieces of list code,
it was preferred to leave the NULL check in place and retain the benefits
of decoupling, maintainability and information hiding (only PyList_New()
and list_sort() need to know about the new field). This approach also
reduces the odds of breaking an extension module.
(Collaborative effort by Raymond Hettinger, Hye-Shik Chang, Tim Peters,
and Armin Rigo.)
2004-02-13 11:36:39 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* This over-allocates proportional to the list size, making room
|
|
|
|
|
* for additional growth. The over-allocation is mild, but is
|
|
|
|
|
* enough to give linear-time amortized behavior over a long
|
|
|
|
|
* sequence of appends() in the presence of a poorly-performing
|
|
|
|
|
* system realloc().
|
|
|
|
|
* The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
|
|
|
|
|
*/
|
|
|
|
|
new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6);
|
2008-06-18 00:47:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* check for integer overflow */
|
|
|
|
|
if (new_allocated > PY_SIZE_MAX - newsize) {
|
|
|
|
|
PyErr_NoMemory();
|
|
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
new_allocated += newsize;
|
|
|
|
|
}
|
2008-06-18 00:47:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (newsize == 0)
|
|
|
|
|
new_allocated = 0;
|
|
|
|
|
items = self->ob_item;
|
|
|
|
|
if (new_allocated <= ((~(size_t)0) / sizeof(PyObject *)))
|
|
|
|
|
PyMem_RESIZE(items, PyObject *, new_allocated);
|
|
|
|
|
else
|
|
|
|
|
items = NULL;
|
|
|
|
|
if (items == NULL) {
|
|
|
|
|
PyErr_NoMemory();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->ob_item = items;
|
|
|
|
|
Py_SIZE(self) = newsize;
|
|
|
|
|
self->allocated = new_allocated;
|
|
|
|
|
return 0;
|
* Optimized list appends and pops by making fewer calls the underlying system
realloc(). This is achieved by tracking the overallocation size in a new
field and using that information to skip calls to realloc() whenever
possible.
* Simplified and tightened the amount of overallocation. For larger lists,
this overallocates by 1/8th (compared to the previous scheme which ranged
between 1/4th to 1/32nd over-allocation). For smaller lists (n<6), the
maximum overallocation is one byte (formerly it could be upto eight bytes).
This saves memory in applications with large numbers of small lists.
* Eliminated the NRESIZE macro in favor of a new, static list_resize function
that encapsulates the resizing logic. Coverting this back to macro would
give a small (under 1%) speed-up. This was too small to warrant the loss
of readability, maintainability, and de-coupling.
* Some functions using NRESIZE had grown unnecessarily complex in their
efforts to bend to the macro's calling pattern. With the new list_resize
function in place, those other functions could be simplified. That is
being saved for a separate patch.
* The ob_item==NULL check could be eliminated from the new list_resize
function. This would entail finding each piece of code that sets ob_item
to NULL and adding a new line to invalidate the overallocation tracking
field. Rather than impose a new requirement on other pieces of list code,
it was preferred to leave the NULL check in place and retain the benefits
of decoupling, maintainability and information hiding (only PyList_New()
and list_sort() need to know about the new field). This approach also
reduces the odds of breaking an extension module.
(Collaborative effort by Raymond Hettinger, Hye-Shik Chang, Tim Peters,
and Armin Rigo.)
2004-02-13 11:36:39 +00:00
|
|
|
}
|
1995-01-26 22:59:43 +00:00
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60618 | walter.doerwald | 2008-02-06 15:31:55 +0100 (Wed, 06 Feb 2008) | 6 lines
Remove month parameter from Calendar.yeardatescalendar(),
Calendar.yeardays2calendar() and Calendar.yeardayscalendar() as the methods
don't have such a parameter. Fixes issue #2017.
Rewrap content to 80 chars.
........
r60622 | facundo.batista | 2008-02-06 20:28:49 +0100 (Wed, 06 Feb 2008) | 4 lines
Fixes issue 1959. Converted tests to unittest.
Thanks Giampaolo Rodola.
........
r60626 | thomas.heller | 2008-02-06 21:29:17 +0100 (Wed, 06 Feb 2008) | 3 lines
Fixed refcounts and error handling.
Should not be merged to py3k branch.
........
r60630 | mark.dickinson | 2008-02-06 23:10:50 +0100 (Wed, 06 Feb 2008) | 4 lines
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
........
r60632 | mark.dickinson | 2008-02-06 23:25:16 +0100 (Wed, 06 Feb 2008) | 2 lines
Remove incorrect usage of :const: in documentation.
........
r60634 | georg.brandl | 2008-02-07 00:45:51 +0100 (Thu, 07 Feb 2008) | 2 lines
Revert accidental changes to test_queue in r60605.
........
r60636 | raymond.hettinger | 2008-02-07 01:54:20 +0100 (Thu, 07 Feb 2008) | 1 line
Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence.
........
r60637 | mark.dickinson | 2008-02-07 02:14:23 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix broken link in decimal documentation.
........
r60638 | mark.dickinson | 2008-02-07 02:42:06 +0100 (Thu, 07 Feb 2008) | 3 lines
IEEE 754 should be IEEE 854; give precise reference for
comparisons involving NaNs.
........
r60639 | raymond.hettinger | 2008-02-07 03:12:52 +0100 (Thu, 07 Feb 2008) | 1 line
Return ints instead of longs for tuple.count() and tuple.index().
........
r60640 | raymond.hettinger | 2008-02-07 04:10:33 +0100 (Thu, 07 Feb 2008) | 1 line
Merge 60627.
........
r60641 | raymond.hettinger | 2008-02-07 04:25:46 +0100 (Thu, 07 Feb 2008) | 1 line
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
........
r60642 | brett.cannon | 2008-02-07 08:47:31 +0100 (Thu, 07 Feb 2008) | 3 lines
Cast a struct to a void pointer so as to do a type-safe pointer comparison
(mistmatch found by clang).
........
r60643 | brett.cannon | 2008-02-07 09:04:07 +0100 (Thu, 07 Feb 2008) | 2 lines
Remove unnecessary curly braces around an int literal.
........
r60644 | andrew.kuchling | 2008-02-07 12:43:47 +0100 (Thu, 07 Feb 2008) | 1 line
Update URL
........
r60645 | facundo.batista | 2008-02-07 17:16:29 +0100 (Thu, 07 Feb 2008) | 4 lines
Fixes issue 2026. Tests converted to unittest. Thanks
Giampaolo Rodola.
........
r60646 | christian.heimes | 2008-02-07 18:15:30 +0100 (Thu, 07 Feb 2008) | 1 line
Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet.
........
r60648 | facundo.batista | 2008-02-07 20:06:52 +0100 (Thu, 07 Feb 2008) | 6 lines
Fixes Issue 1401. When redirected, a possible POST get converted
to GET, so it loses its payload. So, it also must lose the
headers related to the payload (if it has no content any more,
it shouldn't indicate content length and type).
........
r60649 | walter.doerwald | 2008-02-07 20:30:22 +0100 (Thu, 07 Feb 2008) | 3 lines
Clarify that the output of TextCalendar.formatmonth() and
TextCalendar.formatyear() for custom instances won't be influenced by calls
to the module global setfirstweekday() function. Fixes #2018.
........
r60651 | walter.doerwald | 2008-02-07 20:48:34 +0100 (Thu, 07 Feb 2008) | 3 lines
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
........
r60653 | walter.doerwald | 2008-02-07 20:57:32 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix typo in docstring for Calendar.itermonthdays().
........
r60655 | raymond.hettinger | 2008-02-07 21:04:37 +0100 (Thu, 07 Feb 2008) | 1 line
The float conversion recipe is simpler in Py2.6
........
r60657 | raymond.hettinger | 2008-02-07 21:10:49 +0100 (Thu, 07 Feb 2008) | 1 line
Fix typo
........
r60660 | brett.cannon | 2008-02-07 23:27:10 +0100 (Thu, 07 Feb 2008) | 3 lines
Make sure a switch statement does not have repetitive case statements.
Error found through LLVM post-2.1 svn.
........
r60661 | christian.heimes | 2008-02-08 01:11:31 +0100 (Fri, 08 Feb 2008) | 1 line
Deallocate content of the dict free list on interpreter shutdown
........
r60662 | christian.heimes | 2008-02-08 01:14:34 +0100 (Fri, 08 Feb 2008) | 1 line
Use prefix decrement
........
r60663 | amaury.forgeotdarc | 2008-02-08 01:56:02 +0100 (Fri, 08 Feb 2008) | 5 lines
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
........
r60667 | jeffrey.yasskin | 2008-02-08 07:45:40 +0100 (Fri, 08 Feb 2008) | 2 lines
Oops! 2.6's Rational.__ne__ didn't work.
........
r60671 | hyeshik.chang | 2008-02-08 18:10:20 +0100 (Fri, 08 Feb 2008) | 2 lines
Update big5hkscs codec to conform to the HKSCS:2004 revision.
........
r60673 | raymond.hettinger | 2008-02-08 23:30:04 +0100 (Fri, 08 Feb 2008) | 4 lines
Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
........
r60674 | raymond.hettinger | 2008-02-09 00:02:27 +0100 (Sat, 09 Feb 2008) | 1 line
Speed-up __iter__() mixin method.
........
r60675 | raymond.hettinger | 2008-02-09 00:34:21 +0100 (Sat, 09 Feb 2008) | 1 line
Fill-in missing Set comparisons
........
r60677 | raymond.hettinger | 2008-02-09 00:57:06 +0100 (Sat, 09 Feb 2008) | 1 line
Add advice on choosing between DictMixin and MutableMapping
........
2008-02-09 02:18:51 +00:00
|
|
|
/* Debug statistic to compare allocations with reuse through the free list */
|
|
|
|
|
#undef SHOW_ALLOC_COUNT
|
|
|
|
|
#ifdef SHOW_ALLOC_COUNT
|
|
|
|
|
static size_t count_alloc = 0;
|
|
|
|
|
static size_t count_reuse = 0;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_alloc(void)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
fprintf(stderr, "List allocations: %" PY_FORMAT_SIZE_T "d\n",
|
|
|
|
|
count_alloc);
|
|
|
|
|
fprintf(stderr, "List reuse through freelist: %" PY_FORMAT_SIZE_T
|
|
|
|
|
"d\n", count_reuse);
|
|
|
|
|
fprintf(stderr, "%.2f%% reuse rate\n\n",
|
|
|
|
|
(100.0*count_reuse/(count_alloc+count_reuse)));
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60618 | walter.doerwald | 2008-02-06 15:31:55 +0100 (Wed, 06 Feb 2008) | 6 lines
Remove month parameter from Calendar.yeardatescalendar(),
Calendar.yeardays2calendar() and Calendar.yeardayscalendar() as the methods
don't have such a parameter. Fixes issue #2017.
Rewrap content to 80 chars.
........
r60622 | facundo.batista | 2008-02-06 20:28:49 +0100 (Wed, 06 Feb 2008) | 4 lines
Fixes issue 1959. Converted tests to unittest.
Thanks Giampaolo Rodola.
........
r60626 | thomas.heller | 2008-02-06 21:29:17 +0100 (Wed, 06 Feb 2008) | 3 lines
Fixed refcounts and error handling.
Should not be merged to py3k branch.
........
r60630 | mark.dickinson | 2008-02-06 23:10:50 +0100 (Wed, 06 Feb 2008) | 4 lines
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
........
r60632 | mark.dickinson | 2008-02-06 23:25:16 +0100 (Wed, 06 Feb 2008) | 2 lines
Remove incorrect usage of :const: in documentation.
........
r60634 | georg.brandl | 2008-02-07 00:45:51 +0100 (Thu, 07 Feb 2008) | 2 lines
Revert accidental changes to test_queue in r60605.
........
r60636 | raymond.hettinger | 2008-02-07 01:54:20 +0100 (Thu, 07 Feb 2008) | 1 line
Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence.
........
r60637 | mark.dickinson | 2008-02-07 02:14:23 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix broken link in decimal documentation.
........
r60638 | mark.dickinson | 2008-02-07 02:42:06 +0100 (Thu, 07 Feb 2008) | 3 lines
IEEE 754 should be IEEE 854; give precise reference for
comparisons involving NaNs.
........
r60639 | raymond.hettinger | 2008-02-07 03:12:52 +0100 (Thu, 07 Feb 2008) | 1 line
Return ints instead of longs for tuple.count() and tuple.index().
........
r60640 | raymond.hettinger | 2008-02-07 04:10:33 +0100 (Thu, 07 Feb 2008) | 1 line
Merge 60627.
........
r60641 | raymond.hettinger | 2008-02-07 04:25:46 +0100 (Thu, 07 Feb 2008) | 1 line
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
........
r60642 | brett.cannon | 2008-02-07 08:47:31 +0100 (Thu, 07 Feb 2008) | 3 lines
Cast a struct to a void pointer so as to do a type-safe pointer comparison
(mistmatch found by clang).
........
r60643 | brett.cannon | 2008-02-07 09:04:07 +0100 (Thu, 07 Feb 2008) | 2 lines
Remove unnecessary curly braces around an int literal.
........
r60644 | andrew.kuchling | 2008-02-07 12:43:47 +0100 (Thu, 07 Feb 2008) | 1 line
Update URL
........
r60645 | facundo.batista | 2008-02-07 17:16:29 +0100 (Thu, 07 Feb 2008) | 4 lines
Fixes issue 2026. Tests converted to unittest. Thanks
Giampaolo Rodola.
........
r60646 | christian.heimes | 2008-02-07 18:15:30 +0100 (Thu, 07 Feb 2008) | 1 line
Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet.
........
r60648 | facundo.batista | 2008-02-07 20:06:52 +0100 (Thu, 07 Feb 2008) | 6 lines
Fixes Issue 1401. When redirected, a possible POST get converted
to GET, so it loses its payload. So, it also must lose the
headers related to the payload (if it has no content any more,
it shouldn't indicate content length and type).
........
r60649 | walter.doerwald | 2008-02-07 20:30:22 +0100 (Thu, 07 Feb 2008) | 3 lines
Clarify that the output of TextCalendar.formatmonth() and
TextCalendar.formatyear() for custom instances won't be influenced by calls
to the module global setfirstweekday() function. Fixes #2018.
........
r60651 | walter.doerwald | 2008-02-07 20:48:34 +0100 (Thu, 07 Feb 2008) | 3 lines
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
........
r60653 | walter.doerwald | 2008-02-07 20:57:32 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix typo in docstring for Calendar.itermonthdays().
........
r60655 | raymond.hettinger | 2008-02-07 21:04:37 +0100 (Thu, 07 Feb 2008) | 1 line
The float conversion recipe is simpler in Py2.6
........
r60657 | raymond.hettinger | 2008-02-07 21:10:49 +0100 (Thu, 07 Feb 2008) | 1 line
Fix typo
........
r60660 | brett.cannon | 2008-02-07 23:27:10 +0100 (Thu, 07 Feb 2008) | 3 lines
Make sure a switch statement does not have repetitive case statements.
Error found through LLVM post-2.1 svn.
........
r60661 | christian.heimes | 2008-02-08 01:11:31 +0100 (Fri, 08 Feb 2008) | 1 line
Deallocate content of the dict free list on interpreter shutdown
........
r60662 | christian.heimes | 2008-02-08 01:14:34 +0100 (Fri, 08 Feb 2008) | 1 line
Use prefix decrement
........
r60663 | amaury.forgeotdarc | 2008-02-08 01:56:02 +0100 (Fri, 08 Feb 2008) | 5 lines
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
........
r60667 | jeffrey.yasskin | 2008-02-08 07:45:40 +0100 (Fri, 08 Feb 2008) | 2 lines
Oops! 2.6's Rational.__ne__ didn't work.
........
r60671 | hyeshik.chang | 2008-02-08 18:10:20 +0100 (Fri, 08 Feb 2008) | 2 lines
Update big5hkscs codec to conform to the HKSCS:2004 revision.
........
r60673 | raymond.hettinger | 2008-02-08 23:30:04 +0100 (Fri, 08 Feb 2008) | 4 lines
Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
........
r60674 | raymond.hettinger | 2008-02-09 00:02:27 +0100 (Sat, 09 Feb 2008) | 1 line
Speed-up __iter__() mixin method.
........
r60675 | raymond.hettinger | 2008-02-09 00:34:21 +0100 (Sat, 09 Feb 2008) | 1 line
Fill-in missing Set comparisons
........
r60677 | raymond.hettinger | 2008-02-09 00:57:06 +0100 (Sat, 09 Feb 2008) | 1 line
Add advice on choosing between DictMixin and MutableMapping
........
2008-02-09 02:18:51 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-05-05 05:37:53 +00:00
|
|
|
/* Empty list reuse scheme to save calls to malloc and free */
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60568-60598,60600-60616 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60568 | christian.heimes | 2008-02-04 19:48:38 +0100 (Mon, 04 Feb 2008) | 1 line
Increase debugging to investige failing tests on some build bots
........
r60570 | christian.heimes | 2008-02-04 20:30:05 +0100 (Mon, 04 Feb 2008) | 1 line
Small adjustments for test compact freelist test. It's no passing on Windows as well.
........
r60573 | amaury.forgeotdarc | 2008-02-04 21:53:14 +0100 (Mon, 04 Feb 2008) | 2 lines
Correct quotes in NEWS file
........
r60575 | amaury.forgeotdarc | 2008-02-04 22:45:05 +0100 (Mon, 04 Feb 2008) | 13 lines
#1750076: Debugger did not step on every iteration of a while statement.
The mapping between bytecode offsets and source lines (lnotab) did not contain
an entry for the beginning of the loop.
Now it does, and the lnotab can be a bit larger:
in particular, several statements on the same line generate several entries.
However, this does not bother the settrace function, which will trigger only
one 'line' event.
The lnotab seems to be exactly the same as with python2.4.
........
r60584 | amaury.forgeotdarc | 2008-02-05 01:26:21 +0100 (Tue, 05 Feb 2008) | 3 lines
Change r60575 broke test_compile:
there is no need to emit co_lnotab item when both offsets are zeros.
........
r60587 | skip.montanaro | 2008-02-05 03:32:16 +0100 (Tue, 05 Feb 2008) | 1 line
sync with most recent version from python-mode sf project
........
r60588 | lars.gustaebel | 2008-02-05 12:51:40 +0100 (Tue, 05 Feb 2008) | 5 lines
Issue #2004: Use mode 0700 for temporary directories and default
permissions for missing directories.
(will backport to 2.5)
........
r60590 | georg.brandl | 2008-02-05 13:01:24 +0100 (Tue, 05 Feb 2008) | 2 lines
Convert external links to internal links. Fixes #2010.
........
r60592 | marc-andre.lemburg | 2008-02-05 15:50:40 +0100 (Tue, 05 Feb 2008) | 3 lines
Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
........
r60593 | andrew.kuchling | 2008-02-05 17:06:57 +0100 (Tue, 05 Feb 2008) | 5 lines
Update PEP URL.
(This code is duplicated between pydoc and DocXMLRPCServer; maybe it
should be refactored as a GHOP project.)
2.5.2 backport candidate.
........
r60596 | guido.van.rossum | 2008-02-05 18:32:15 +0100 (Tue, 05 Feb 2008) | 2 lines
In the experimental 'Scanner' feature, the group count was set wrong.
........
r60602 | facundo.batista | 2008-02-05 20:03:32 +0100 (Tue, 05 Feb 2008) | 3 lines
Issue 1951. Converts wave test cases to unittest.
........
r60603 | georg.brandl | 2008-02-05 20:07:10 +0100 (Tue, 05 Feb 2008) | 2 lines
Actually run the test.
........
r60604 | skip.montanaro | 2008-02-05 20:24:30 +0100 (Tue, 05 Feb 2008) | 2 lines
correct object name
........
r60605 | georg.brandl | 2008-02-05 20:58:17 +0100 (Tue, 05 Feb 2008) | 7 lines
* Use the same code to profile for test_profile and test_cprofile.
* Convert both to unittest.
* Use the same unit testing code.
* Include the expected output in both test files.
* Make it possible to regenerate the expected output by running
the file as a script with an '-r' argument.
........
r60613 | raymond.hettinger | 2008-02-06 02:49:00 +0100 (Wed, 06 Feb 2008) | 1 line
Sync-up with Py3k work.
........
r60614 | christian.heimes | 2008-02-06 13:44:34 +0100 (Wed, 06 Feb 2008) | 1 line
Limit free list of method and builtin function objects to 256 entries each.
........
r60616 | christian.heimes | 2008-02-06 14:33:44 +0100 (Wed, 06 Feb 2008) | 7 lines
Unified naming convention for free lists and their limits. All free lists
in Object/ are named ``free_list``, the counter ``numfree`` and the upper
limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block.
The chances should make it easier to adjust Python for platforms with
less memory, e.g. mobile phones.
........
2008-02-06 14:31:34 +00:00
|
|
|
#ifndef PyList_MAXFREELIST
|
|
|
|
|
#define PyList_MAXFREELIST 80
|
|
|
|
|
#endif
|
|
|
|
|
static PyListObject *free_list[PyList_MAXFREELIST];
|
|
|
|
|
static int numfree = 0;
|
2004-05-05 05:37:53 +00:00
|
|
|
|
2004-10-07 03:58:07 +00:00
|
|
|
void
|
|
|
|
|
PyList_Fini(void)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyListObject *op;
|
2004-10-07 03:58:07 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
while (numfree) {
|
|
|
|
|
op = free_list[--numfree];
|
|
|
|
|
assert(PyList_CheckExact(op));
|
|
|
|
|
PyObject_GC_Del(op);
|
|
|
|
|
}
|
2004-10-07 03:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
PyObject *
|
2006-02-15 17:27:45 +00:00
|
|
|
PyList_New(Py_ssize_t size)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyListObject *op;
|
|
|
|
|
size_t nbytes;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60618 | walter.doerwald | 2008-02-06 15:31:55 +0100 (Wed, 06 Feb 2008) | 6 lines
Remove month parameter from Calendar.yeardatescalendar(),
Calendar.yeardays2calendar() and Calendar.yeardayscalendar() as the methods
don't have such a parameter. Fixes issue #2017.
Rewrap content to 80 chars.
........
r60622 | facundo.batista | 2008-02-06 20:28:49 +0100 (Wed, 06 Feb 2008) | 4 lines
Fixes issue 1959. Converted tests to unittest.
Thanks Giampaolo Rodola.
........
r60626 | thomas.heller | 2008-02-06 21:29:17 +0100 (Wed, 06 Feb 2008) | 3 lines
Fixed refcounts and error handling.
Should not be merged to py3k branch.
........
r60630 | mark.dickinson | 2008-02-06 23:10:50 +0100 (Wed, 06 Feb 2008) | 4 lines
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
........
r60632 | mark.dickinson | 2008-02-06 23:25:16 +0100 (Wed, 06 Feb 2008) | 2 lines
Remove incorrect usage of :const: in documentation.
........
r60634 | georg.brandl | 2008-02-07 00:45:51 +0100 (Thu, 07 Feb 2008) | 2 lines
Revert accidental changes to test_queue in r60605.
........
r60636 | raymond.hettinger | 2008-02-07 01:54:20 +0100 (Thu, 07 Feb 2008) | 1 line
Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence.
........
r60637 | mark.dickinson | 2008-02-07 02:14:23 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix broken link in decimal documentation.
........
r60638 | mark.dickinson | 2008-02-07 02:42:06 +0100 (Thu, 07 Feb 2008) | 3 lines
IEEE 754 should be IEEE 854; give precise reference for
comparisons involving NaNs.
........
r60639 | raymond.hettinger | 2008-02-07 03:12:52 +0100 (Thu, 07 Feb 2008) | 1 line
Return ints instead of longs for tuple.count() and tuple.index().
........
r60640 | raymond.hettinger | 2008-02-07 04:10:33 +0100 (Thu, 07 Feb 2008) | 1 line
Merge 60627.
........
r60641 | raymond.hettinger | 2008-02-07 04:25:46 +0100 (Thu, 07 Feb 2008) | 1 line
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
........
r60642 | brett.cannon | 2008-02-07 08:47:31 +0100 (Thu, 07 Feb 2008) | 3 lines
Cast a struct to a void pointer so as to do a type-safe pointer comparison
(mistmatch found by clang).
........
r60643 | brett.cannon | 2008-02-07 09:04:07 +0100 (Thu, 07 Feb 2008) | 2 lines
Remove unnecessary curly braces around an int literal.
........
r60644 | andrew.kuchling | 2008-02-07 12:43:47 +0100 (Thu, 07 Feb 2008) | 1 line
Update URL
........
r60645 | facundo.batista | 2008-02-07 17:16:29 +0100 (Thu, 07 Feb 2008) | 4 lines
Fixes issue 2026. Tests converted to unittest. Thanks
Giampaolo Rodola.
........
r60646 | christian.heimes | 2008-02-07 18:15:30 +0100 (Thu, 07 Feb 2008) | 1 line
Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet.
........
r60648 | facundo.batista | 2008-02-07 20:06:52 +0100 (Thu, 07 Feb 2008) | 6 lines
Fixes Issue 1401. When redirected, a possible POST get converted
to GET, so it loses its payload. So, it also must lose the
headers related to the payload (if it has no content any more,
it shouldn't indicate content length and type).
........
r60649 | walter.doerwald | 2008-02-07 20:30:22 +0100 (Thu, 07 Feb 2008) | 3 lines
Clarify that the output of TextCalendar.formatmonth() and
TextCalendar.formatyear() for custom instances won't be influenced by calls
to the module global setfirstweekday() function. Fixes #2018.
........
r60651 | walter.doerwald | 2008-02-07 20:48:34 +0100 (Thu, 07 Feb 2008) | 3 lines
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
........
r60653 | walter.doerwald | 2008-02-07 20:57:32 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix typo in docstring for Calendar.itermonthdays().
........
r60655 | raymond.hettinger | 2008-02-07 21:04:37 +0100 (Thu, 07 Feb 2008) | 1 line
The float conversion recipe is simpler in Py2.6
........
r60657 | raymond.hettinger | 2008-02-07 21:10:49 +0100 (Thu, 07 Feb 2008) | 1 line
Fix typo
........
r60660 | brett.cannon | 2008-02-07 23:27:10 +0100 (Thu, 07 Feb 2008) | 3 lines
Make sure a switch statement does not have repetitive case statements.
Error found through LLVM post-2.1 svn.
........
r60661 | christian.heimes | 2008-02-08 01:11:31 +0100 (Fri, 08 Feb 2008) | 1 line
Deallocate content of the dict free list on interpreter shutdown
........
r60662 | christian.heimes | 2008-02-08 01:14:34 +0100 (Fri, 08 Feb 2008) | 1 line
Use prefix decrement
........
r60663 | amaury.forgeotdarc | 2008-02-08 01:56:02 +0100 (Fri, 08 Feb 2008) | 5 lines
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
........
r60667 | jeffrey.yasskin | 2008-02-08 07:45:40 +0100 (Fri, 08 Feb 2008) | 2 lines
Oops! 2.6's Rational.__ne__ didn't work.
........
r60671 | hyeshik.chang | 2008-02-08 18:10:20 +0100 (Fri, 08 Feb 2008) | 2 lines
Update big5hkscs codec to conform to the HKSCS:2004 revision.
........
r60673 | raymond.hettinger | 2008-02-08 23:30:04 +0100 (Fri, 08 Feb 2008) | 4 lines
Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
........
r60674 | raymond.hettinger | 2008-02-09 00:02:27 +0100 (Sat, 09 Feb 2008) | 1 line
Speed-up __iter__() mixin method.
........
r60675 | raymond.hettinger | 2008-02-09 00:34:21 +0100 (Sat, 09 Feb 2008) | 1 line
Fill-in missing Set comparisons
........
r60677 | raymond.hettinger | 2008-02-09 00:57:06 +0100 (Sat, 09 Feb 2008) | 1 line
Add advice on choosing between DictMixin and MutableMapping
........
2008-02-09 02:18:51 +00:00
|
|
|
#ifdef SHOW_ALLOC_COUNT
|
2010-05-09 15:52:27 +00:00
|
|
|
static int initialized = 0;
|
|
|
|
|
if (!initialized) {
|
|
|
|
|
Py_AtExit(show_alloc);
|
|
|
|
|
initialized = 1;
|
|
|
|
|
}
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60618 | walter.doerwald | 2008-02-06 15:31:55 +0100 (Wed, 06 Feb 2008) | 6 lines
Remove month parameter from Calendar.yeardatescalendar(),
Calendar.yeardays2calendar() and Calendar.yeardayscalendar() as the methods
don't have such a parameter. Fixes issue #2017.
Rewrap content to 80 chars.
........
r60622 | facundo.batista | 2008-02-06 20:28:49 +0100 (Wed, 06 Feb 2008) | 4 lines
Fixes issue 1959. Converted tests to unittest.
Thanks Giampaolo Rodola.
........
r60626 | thomas.heller | 2008-02-06 21:29:17 +0100 (Wed, 06 Feb 2008) | 3 lines
Fixed refcounts and error handling.
Should not be merged to py3k branch.
........
r60630 | mark.dickinson | 2008-02-06 23:10:50 +0100 (Wed, 06 Feb 2008) | 4 lines
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
........
r60632 | mark.dickinson | 2008-02-06 23:25:16 +0100 (Wed, 06 Feb 2008) | 2 lines
Remove incorrect usage of :const: in documentation.
........
r60634 | georg.brandl | 2008-02-07 00:45:51 +0100 (Thu, 07 Feb 2008) | 2 lines
Revert accidental changes to test_queue in r60605.
........
r60636 | raymond.hettinger | 2008-02-07 01:54:20 +0100 (Thu, 07 Feb 2008) | 1 line
Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence.
........
r60637 | mark.dickinson | 2008-02-07 02:14:23 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix broken link in decimal documentation.
........
r60638 | mark.dickinson | 2008-02-07 02:42:06 +0100 (Thu, 07 Feb 2008) | 3 lines
IEEE 754 should be IEEE 854; give precise reference for
comparisons involving NaNs.
........
r60639 | raymond.hettinger | 2008-02-07 03:12:52 +0100 (Thu, 07 Feb 2008) | 1 line
Return ints instead of longs for tuple.count() and tuple.index().
........
r60640 | raymond.hettinger | 2008-02-07 04:10:33 +0100 (Thu, 07 Feb 2008) | 1 line
Merge 60627.
........
r60641 | raymond.hettinger | 2008-02-07 04:25:46 +0100 (Thu, 07 Feb 2008) | 1 line
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
........
r60642 | brett.cannon | 2008-02-07 08:47:31 +0100 (Thu, 07 Feb 2008) | 3 lines
Cast a struct to a void pointer so as to do a type-safe pointer comparison
(mistmatch found by clang).
........
r60643 | brett.cannon | 2008-02-07 09:04:07 +0100 (Thu, 07 Feb 2008) | 2 lines
Remove unnecessary curly braces around an int literal.
........
r60644 | andrew.kuchling | 2008-02-07 12:43:47 +0100 (Thu, 07 Feb 2008) | 1 line
Update URL
........
r60645 | facundo.batista | 2008-02-07 17:16:29 +0100 (Thu, 07 Feb 2008) | 4 lines
Fixes issue 2026. Tests converted to unittest. Thanks
Giampaolo Rodola.
........
r60646 | christian.heimes | 2008-02-07 18:15:30 +0100 (Thu, 07 Feb 2008) | 1 line
Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet.
........
r60648 | facundo.batista | 2008-02-07 20:06:52 +0100 (Thu, 07 Feb 2008) | 6 lines
Fixes Issue 1401. When redirected, a possible POST get converted
to GET, so it loses its payload. So, it also must lose the
headers related to the payload (if it has no content any more,
it shouldn't indicate content length and type).
........
r60649 | walter.doerwald | 2008-02-07 20:30:22 +0100 (Thu, 07 Feb 2008) | 3 lines
Clarify that the output of TextCalendar.formatmonth() and
TextCalendar.formatyear() for custom instances won't be influenced by calls
to the module global setfirstweekday() function. Fixes #2018.
........
r60651 | walter.doerwald | 2008-02-07 20:48:34 +0100 (Thu, 07 Feb 2008) | 3 lines
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
........
r60653 | walter.doerwald | 2008-02-07 20:57:32 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix typo in docstring for Calendar.itermonthdays().
........
r60655 | raymond.hettinger | 2008-02-07 21:04:37 +0100 (Thu, 07 Feb 2008) | 1 line
The float conversion recipe is simpler in Py2.6
........
r60657 | raymond.hettinger | 2008-02-07 21:10:49 +0100 (Thu, 07 Feb 2008) | 1 line
Fix typo
........
r60660 | brett.cannon | 2008-02-07 23:27:10 +0100 (Thu, 07 Feb 2008) | 3 lines
Make sure a switch statement does not have repetitive case statements.
Error found through LLVM post-2.1 svn.
........
r60661 | christian.heimes | 2008-02-08 01:11:31 +0100 (Fri, 08 Feb 2008) | 1 line
Deallocate content of the dict free list on interpreter shutdown
........
r60662 | christian.heimes | 2008-02-08 01:14:34 +0100 (Fri, 08 Feb 2008) | 1 line
Use prefix decrement
........
r60663 | amaury.forgeotdarc | 2008-02-08 01:56:02 +0100 (Fri, 08 Feb 2008) | 5 lines
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
........
r60667 | jeffrey.yasskin | 2008-02-08 07:45:40 +0100 (Fri, 08 Feb 2008) | 2 lines
Oops! 2.6's Rational.__ne__ didn't work.
........
r60671 | hyeshik.chang | 2008-02-08 18:10:20 +0100 (Fri, 08 Feb 2008) | 2 lines
Update big5hkscs codec to conform to the HKSCS:2004 revision.
........
r60673 | raymond.hettinger | 2008-02-08 23:30:04 +0100 (Fri, 08 Feb 2008) | 4 lines
Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
........
r60674 | raymond.hettinger | 2008-02-09 00:02:27 +0100 (Sat, 09 Feb 2008) | 1 line
Speed-up __iter__() mixin method.
........
r60675 | raymond.hettinger | 2008-02-09 00:34:21 +0100 (Sat, 09 Feb 2008) | 1 line
Fill-in missing Set comparisons
........
r60677 | raymond.hettinger | 2008-02-09 00:57:06 +0100 (Sat, 09 Feb 2008) | 1 line
Add advice on choosing between DictMixin and MutableMapping
........
2008-02-09 02:18:51 +00:00
|
|
|
#endif
|
2004-07-29 02:28:42 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (size < 0) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/* Check for overflow without an actual overflow,
|
|
|
|
|
* which can cause compiler to optimise out */
|
|
|
|
|
if ((size_t)size > PY_SIZE_MAX / sizeof(PyObject *))
|
|
|
|
|
return PyErr_NoMemory();
|
|
|
|
|
nbytes = size * sizeof(PyObject *);
|
|
|
|
|
if (numfree) {
|
|
|
|
|
numfree--;
|
|
|
|
|
op = free_list[numfree];
|
|
|
|
|
_Py_NewReference((PyObject *)op);
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60618 | walter.doerwald | 2008-02-06 15:31:55 +0100 (Wed, 06 Feb 2008) | 6 lines
Remove month parameter from Calendar.yeardatescalendar(),
Calendar.yeardays2calendar() and Calendar.yeardayscalendar() as the methods
don't have such a parameter. Fixes issue #2017.
Rewrap content to 80 chars.
........
r60622 | facundo.batista | 2008-02-06 20:28:49 +0100 (Wed, 06 Feb 2008) | 4 lines
Fixes issue 1959. Converted tests to unittest.
Thanks Giampaolo Rodola.
........
r60626 | thomas.heller | 2008-02-06 21:29:17 +0100 (Wed, 06 Feb 2008) | 3 lines
Fixed refcounts and error handling.
Should not be merged to py3k branch.
........
r60630 | mark.dickinson | 2008-02-06 23:10:50 +0100 (Wed, 06 Feb 2008) | 4 lines
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
........
r60632 | mark.dickinson | 2008-02-06 23:25:16 +0100 (Wed, 06 Feb 2008) | 2 lines
Remove incorrect usage of :const: in documentation.
........
r60634 | georg.brandl | 2008-02-07 00:45:51 +0100 (Thu, 07 Feb 2008) | 2 lines
Revert accidental changes to test_queue in r60605.
........
r60636 | raymond.hettinger | 2008-02-07 01:54:20 +0100 (Thu, 07 Feb 2008) | 1 line
Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence.
........
r60637 | mark.dickinson | 2008-02-07 02:14:23 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix broken link in decimal documentation.
........
r60638 | mark.dickinson | 2008-02-07 02:42:06 +0100 (Thu, 07 Feb 2008) | 3 lines
IEEE 754 should be IEEE 854; give precise reference for
comparisons involving NaNs.
........
r60639 | raymond.hettinger | 2008-02-07 03:12:52 +0100 (Thu, 07 Feb 2008) | 1 line
Return ints instead of longs for tuple.count() and tuple.index().
........
r60640 | raymond.hettinger | 2008-02-07 04:10:33 +0100 (Thu, 07 Feb 2008) | 1 line
Merge 60627.
........
r60641 | raymond.hettinger | 2008-02-07 04:25:46 +0100 (Thu, 07 Feb 2008) | 1 line
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
........
r60642 | brett.cannon | 2008-02-07 08:47:31 +0100 (Thu, 07 Feb 2008) | 3 lines
Cast a struct to a void pointer so as to do a type-safe pointer comparison
(mistmatch found by clang).
........
r60643 | brett.cannon | 2008-02-07 09:04:07 +0100 (Thu, 07 Feb 2008) | 2 lines
Remove unnecessary curly braces around an int literal.
........
r60644 | andrew.kuchling | 2008-02-07 12:43:47 +0100 (Thu, 07 Feb 2008) | 1 line
Update URL
........
r60645 | facundo.batista | 2008-02-07 17:16:29 +0100 (Thu, 07 Feb 2008) | 4 lines
Fixes issue 2026. Tests converted to unittest. Thanks
Giampaolo Rodola.
........
r60646 | christian.heimes | 2008-02-07 18:15:30 +0100 (Thu, 07 Feb 2008) | 1 line
Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet.
........
r60648 | facundo.batista | 2008-02-07 20:06:52 +0100 (Thu, 07 Feb 2008) | 6 lines
Fixes Issue 1401. When redirected, a possible POST get converted
to GET, so it loses its payload. So, it also must lose the
headers related to the payload (if it has no content any more,
it shouldn't indicate content length and type).
........
r60649 | walter.doerwald | 2008-02-07 20:30:22 +0100 (Thu, 07 Feb 2008) | 3 lines
Clarify that the output of TextCalendar.formatmonth() and
TextCalendar.formatyear() for custom instances won't be influenced by calls
to the module global setfirstweekday() function. Fixes #2018.
........
r60651 | walter.doerwald | 2008-02-07 20:48:34 +0100 (Thu, 07 Feb 2008) | 3 lines
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
........
r60653 | walter.doerwald | 2008-02-07 20:57:32 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix typo in docstring for Calendar.itermonthdays().
........
r60655 | raymond.hettinger | 2008-02-07 21:04:37 +0100 (Thu, 07 Feb 2008) | 1 line
The float conversion recipe is simpler in Py2.6
........
r60657 | raymond.hettinger | 2008-02-07 21:10:49 +0100 (Thu, 07 Feb 2008) | 1 line
Fix typo
........
r60660 | brett.cannon | 2008-02-07 23:27:10 +0100 (Thu, 07 Feb 2008) | 3 lines
Make sure a switch statement does not have repetitive case statements.
Error found through LLVM post-2.1 svn.
........
r60661 | christian.heimes | 2008-02-08 01:11:31 +0100 (Fri, 08 Feb 2008) | 1 line
Deallocate content of the dict free list on interpreter shutdown
........
r60662 | christian.heimes | 2008-02-08 01:14:34 +0100 (Fri, 08 Feb 2008) | 1 line
Use prefix decrement
........
r60663 | amaury.forgeotdarc | 2008-02-08 01:56:02 +0100 (Fri, 08 Feb 2008) | 5 lines
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
........
r60667 | jeffrey.yasskin | 2008-02-08 07:45:40 +0100 (Fri, 08 Feb 2008) | 2 lines
Oops! 2.6's Rational.__ne__ didn't work.
........
r60671 | hyeshik.chang | 2008-02-08 18:10:20 +0100 (Fri, 08 Feb 2008) | 2 lines
Update big5hkscs codec to conform to the HKSCS:2004 revision.
........
r60673 | raymond.hettinger | 2008-02-08 23:30:04 +0100 (Fri, 08 Feb 2008) | 4 lines
Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
........
r60674 | raymond.hettinger | 2008-02-09 00:02:27 +0100 (Sat, 09 Feb 2008) | 1 line
Speed-up __iter__() mixin method.
........
r60675 | raymond.hettinger | 2008-02-09 00:34:21 +0100 (Sat, 09 Feb 2008) | 1 line
Fill-in missing Set comparisons
........
r60677 | raymond.hettinger | 2008-02-09 00:57:06 +0100 (Sat, 09 Feb 2008) | 1 line
Add advice on choosing between DictMixin and MutableMapping
........
2008-02-09 02:18:51 +00:00
|
|
|
#ifdef SHOW_ALLOC_COUNT
|
2010-05-09 15:52:27 +00:00
|
|
|
count_reuse++;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60618 | walter.doerwald | 2008-02-06 15:31:55 +0100 (Wed, 06 Feb 2008) | 6 lines
Remove month parameter from Calendar.yeardatescalendar(),
Calendar.yeardays2calendar() and Calendar.yeardayscalendar() as the methods
don't have such a parameter. Fixes issue #2017.
Rewrap content to 80 chars.
........
r60622 | facundo.batista | 2008-02-06 20:28:49 +0100 (Wed, 06 Feb 2008) | 4 lines
Fixes issue 1959. Converted tests to unittest.
Thanks Giampaolo Rodola.
........
r60626 | thomas.heller | 2008-02-06 21:29:17 +0100 (Wed, 06 Feb 2008) | 3 lines
Fixed refcounts and error handling.
Should not be merged to py3k branch.
........
r60630 | mark.dickinson | 2008-02-06 23:10:50 +0100 (Wed, 06 Feb 2008) | 4 lines
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
........
r60632 | mark.dickinson | 2008-02-06 23:25:16 +0100 (Wed, 06 Feb 2008) | 2 lines
Remove incorrect usage of :const: in documentation.
........
r60634 | georg.brandl | 2008-02-07 00:45:51 +0100 (Thu, 07 Feb 2008) | 2 lines
Revert accidental changes to test_queue in r60605.
........
r60636 | raymond.hettinger | 2008-02-07 01:54:20 +0100 (Thu, 07 Feb 2008) | 1 line
Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence.
........
r60637 | mark.dickinson | 2008-02-07 02:14:23 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix broken link in decimal documentation.
........
r60638 | mark.dickinson | 2008-02-07 02:42:06 +0100 (Thu, 07 Feb 2008) | 3 lines
IEEE 754 should be IEEE 854; give precise reference for
comparisons involving NaNs.
........
r60639 | raymond.hettinger | 2008-02-07 03:12:52 +0100 (Thu, 07 Feb 2008) | 1 line
Return ints instead of longs for tuple.count() and tuple.index().
........
r60640 | raymond.hettinger | 2008-02-07 04:10:33 +0100 (Thu, 07 Feb 2008) | 1 line
Merge 60627.
........
r60641 | raymond.hettinger | 2008-02-07 04:25:46 +0100 (Thu, 07 Feb 2008) | 1 line
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
........
r60642 | brett.cannon | 2008-02-07 08:47:31 +0100 (Thu, 07 Feb 2008) | 3 lines
Cast a struct to a void pointer so as to do a type-safe pointer comparison
(mistmatch found by clang).
........
r60643 | brett.cannon | 2008-02-07 09:04:07 +0100 (Thu, 07 Feb 2008) | 2 lines
Remove unnecessary curly braces around an int literal.
........
r60644 | andrew.kuchling | 2008-02-07 12:43:47 +0100 (Thu, 07 Feb 2008) | 1 line
Update URL
........
r60645 | facundo.batista | 2008-02-07 17:16:29 +0100 (Thu, 07 Feb 2008) | 4 lines
Fixes issue 2026. Tests converted to unittest. Thanks
Giampaolo Rodola.
........
r60646 | christian.heimes | 2008-02-07 18:15:30 +0100 (Thu, 07 Feb 2008) | 1 line
Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet.
........
r60648 | facundo.batista | 2008-02-07 20:06:52 +0100 (Thu, 07 Feb 2008) | 6 lines
Fixes Issue 1401. When redirected, a possible POST get converted
to GET, so it loses its payload. So, it also must lose the
headers related to the payload (if it has no content any more,
it shouldn't indicate content length and type).
........
r60649 | walter.doerwald | 2008-02-07 20:30:22 +0100 (Thu, 07 Feb 2008) | 3 lines
Clarify that the output of TextCalendar.formatmonth() and
TextCalendar.formatyear() for custom instances won't be influenced by calls
to the module global setfirstweekday() function. Fixes #2018.
........
r60651 | walter.doerwald | 2008-02-07 20:48:34 +0100 (Thu, 07 Feb 2008) | 3 lines
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
........
r60653 | walter.doerwald | 2008-02-07 20:57:32 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix typo in docstring for Calendar.itermonthdays().
........
r60655 | raymond.hettinger | 2008-02-07 21:04:37 +0100 (Thu, 07 Feb 2008) | 1 line
The float conversion recipe is simpler in Py2.6
........
r60657 | raymond.hettinger | 2008-02-07 21:10:49 +0100 (Thu, 07 Feb 2008) | 1 line
Fix typo
........
r60660 | brett.cannon | 2008-02-07 23:27:10 +0100 (Thu, 07 Feb 2008) | 3 lines
Make sure a switch statement does not have repetitive case statements.
Error found through LLVM post-2.1 svn.
........
r60661 | christian.heimes | 2008-02-08 01:11:31 +0100 (Fri, 08 Feb 2008) | 1 line
Deallocate content of the dict free list on interpreter shutdown
........
r60662 | christian.heimes | 2008-02-08 01:14:34 +0100 (Fri, 08 Feb 2008) | 1 line
Use prefix decrement
........
r60663 | amaury.forgeotdarc | 2008-02-08 01:56:02 +0100 (Fri, 08 Feb 2008) | 5 lines
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
........
r60667 | jeffrey.yasskin | 2008-02-08 07:45:40 +0100 (Fri, 08 Feb 2008) | 2 lines
Oops! 2.6's Rational.__ne__ didn't work.
........
r60671 | hyeshik.chang | 2008-02-08 18:10:20 +0100 (Fri, 08 Feb 2008) | 2 lines
Update big5hkscs codec to conform to the HKSCS:2004 revision.
........
r60673 | raymond.hettinger | 2008-02-08 23:30:04 +0100 (Fri, 08 Feb 2008) | 4 lines
Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
........
r60674 | raymond.hettinger | 2008-02-09 00:02:27 +0100 (Sat, 09 Feb 2008) | 1 line
Speed-up __iter__() mixin method.
........
r60675 | raymond.hettinger | 2008-02-09 00:34:21 +0100 (Sat, 09 Feb 2008) | 1 line
Fill-in missing Set comparisons
........
r60677 | raymond.hettinger | 2008-02-09 00:57:06 +0100 (Sat, 09 Feb 2008) | 1 line
Add advice on choosing between DictMixin and MutableMapping
........
2008-02-09 02:18:51 +00:00
|
|
|
#endif
|
2010-05-09 15:52:27 +00:00
|
|
|
} else {
|
|
|
|
|
op = PyObject_GC_New(PyListObject, &PyList_Type);
|
|
|
|
|
if (op == NULL)
|
|
|
|
|
return NULL;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60618 | walter.doerwald | 2008-02-06 15:31:55 +0100 (Wed, 06 Feb 2008) | 6 lines
Remove month parameter from Calendar.yeardatescalendar(),
Calendar.yeardays2calendar() and Calendar.yeardayscalendar() as the methods
don't have such a parameter. Fixes issue #2017.
Rewrap content to 80 chars.
........
r60622 | facundo.batista | 2008-02-06 20:28:49 +0100 (Wed, 06 Feb 2008) | 4 lines
Fixes issue 1959. Converted tests to unittest.
Thanks Giampaolo Rodola.
........
r60626 | thomas.heller | 2008-02-06 21:29:17 +0100 (Wed, 06 Feb 2008) | 3 lines
Fixed refcounts and error handling.
Should not be merged to py3k branch.
........
r60630 | mark.dickinson | 2008-02-06 23:10:50 +0100 (Wed, 06 Feb 2008) | 4 lines
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
........
r60632 | mark.dickinson | 2008-02-06 23:25:16 +0100 (Wed, 06 Feb 2008) | 2 lines
Remove incorrect usage of :const: in documentation.
........
r60634 | georg.brandl | 2008-02-07 00:45:51 +0100 (Thu, 07 Feb 2008) | 2 lines
Revert accidental changes to test_queue in r60605.
........
r60636 | raymond.hettinger | 2008-02-07 01:54:20 +0100 (Thu, 07 Feb 2008) | 1 line
Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence.
........
r60637 | mark.dickinson | 2008-02-07 02:14:23 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix broken link in decimal documentation.
........
r60638 | mark.dickinson | 2008-02-07 02:42:06 +0100 (Thu, 07 Feb 2008) | 3 lines
IEEE 754 should be IEEE 854; give precise reference for
comparisons involving NaNs.
........
r60639 | raymond.hettinger | 2008-02-07 03:12:52 +0100 (Thu, 07 Feb 2008) | 1 line
Return ints instead of longs for tuple.count() and tuple.index().
........
r60640 | raymond.hettinger | 2008-02-07 04:10:33 +0100 (Thu, 07 Feb 2008) | 1 line
Merge 60627.
........
r60641 | raymond.hettinger | 2008-02-07 04:25:46 +0100 (Thu, 07 Feb 2008) | 1 line
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
........
r60642 | brett.cannon | 2008-02-07 08:47:31 +0100 (Thu, 07 Feb 2008) | 3 lines
Cast a struct to a void pointer so as to do a type-safe pointer comparison
(mistmatch found by clang).
........
r60643 | brett.cannon | 2008-02-07 09:04:07 +0100 (Thu, 07 Feb 2008) | 2 lines
Remove unnecessary curly braces around an int literal.
........
r60644 | andrew.kuchling | 2008-02-07 12:43:47 +0100 (Thu, 07 Feb 2008) | 1 line
Update URL
........
r60645 | facundo.batista | 2008-02-07 17:16:29 +0100 (Thu, 07 Feb 2008) | 4 lines
Fixes issue 2026. Tests converted to unittest. Thanks
Giampaolo Rodola.
........
r60646 | christian.heimes | 2008-02-07 18:15:30 +0100 (Thu, 07 Feb 2008) | 1 line
Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet.
........
r60648 | facundo.batista | 2008-02-07 20:06:52 +0100 (Thu, 07 Feb 2008) | 6 lines
Fixes Issue 1401. When redirected, a possible POST get converted
to GET, so it loses its payload. So, it also must lose the
headers related to the payload (if it has no content any more,
it shouldn't indicate content length and type).
........
r60649 | walter.doerwald | 2008-02-07 20:30:22 +0100 (Thu, 07 Feb 2008) | 3 lines
Clarify that the output of TextCalendar.formatmonth() and
TextCalendar.formatyear() for custom instances won't be influenced by calls
to the module global setfirstweekday() function. Fixes #2018.
........
r60651 | walter.doerwald | 2008-02-07 20:48:34 +0100 (Thu, 07 Feb 2008) | 3 lines
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
........
r60653 | walter.doerwald | 2008-02-07 20:57:32 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix typo in docstring for Calendar.itermonthdays().
........
r60655 | raymond.hettinger | 2008-02-07 21:04:37 +0100 (Thu, 07 Feb 2008) | 1 line
The float conversion recipe is simpler in Py2.6
........
r60657 | raymond.hettinger | 2008-02-07 21:10:49 +0100 (Thu, 07 Feb 2008) | 1 line
Fix typo
........
r60660 | brett.cannon | 2008-02-07 23:27:10 +0100 (Thu, 07 Feb 2008) | 3 lines
Make sure a switch statement does not have repetitive case statements.
Error found through LLVM post-2.1 svn.
........
r60661 | christian.heimes | 2008-02-08 01:11:31 +0100 (Fri, 08 Feb 2008) | 1 line
Deallocate content of the dict free list on interpreter shutdown
........
r60662 | christian.heimes | 2008-02-08 01:14:34 +0100 (Fri, 08 Feb 2008) | 1 line
Use prefix decrement
........
r60663 | amaury.forgeotdarc | 2008-02-08 01:56:02 +0100 (Fri, 08 Feb 2008) | 5 lines
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
........
r60667 | jeffrey.yasskin | 2008-02-08 07:45:40 +0100 (Fri, 08 Feb 2008) | 2 lines
Oops! 2.6's Rational.__ne__ didn't work.
........
r60671 | hyeshik.chang | 2008-02-08 18:10:20 +0100 (Fri, 08 Feb 2008) | 2 lines
Update big5hkscs codec to conform to the HKSCS:2004 revision.
........
r60673 | raymond.hettinger | 2008-02-08 23:30:04 +0100 (Fri, 08 Feb 2008) | 4 lines
Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
........
r60674 | raymond.hettinger | 2008-02-09 00:02:27 +0100 (Sat, 09 Feb 2008) | 1 line
Speed-up __iter__() mixin method.
........
r60675 | raymond.hettinger | 2008-02-09 00:34:21 +0100 (Sat, 09 Feb 2008) | 1 line
Fill-in missing Set comparisons
........
r60677 | raymond.hettinger | 2008-02-09 00:57:06 +0100 (Sat, 09 Feb 2008) | 1 line
Add advice on choosing between DictMixin and MutableMapping
........
2008-02-09 02:18:51 +00:00
|
|
|
#ifdef SHOW_ALLOC_COUNT
|
2010-05-09 15:52:27 +00:00
|
|
|
count_alloc++;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60618 | walter.doerwald | 2008-02-06 15:31:55 +0100 (Wed, 06 Feb 2008) | 6 lines
Remove month parameter from Calendar.yeardatescalendar(),
Calendar.yeardays2calendar() and Calendar.yeardayscalendar() as the methods
don't have such a parameter. Fixes issue #2017.
Rewrap content to 80 chars.
........
r60622 | facundo.batista | 2008-02-06 20:28:49 +0100 (Wed, 06 Feb 2008) | 4 lines
Fixes issue 1959. Converted tests to unittest.
Thanks Giampaolo Rodola.
........
r60626 | thomas.heller | 2008-02-06 21:29:17 +0100 (Wed, 06 Feb 2008) | 3 lines
Fixed refcounts and error handling.
Should not be merged to py3k branch.
........
r60630 | mark.dickinson | 2008-02-06 23:10:50 +0100 (Wed, 06 Feb 2008) | 4 lines
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
........
r60632 | mark.dickinson | 2008-02-06 23:25:16 +0100 (Wed, 06 Feb 2008) | 2 lines
Remove incorrect usage of :const: in documentation.
........
r60634 | georg.brandl | 2008-02-07 00:45:51 +0100 (Thu, 07 Feb 2008) | 2 lines
Revert accidental changes to test_queue in r60605.
........
r60636 | raymond.hettinger | 2008-02-07 01:54:20 +0100 (Thu, 07 Feb 2008) | 1 line
Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence.
........
r60637 | mark.dickinson | 2008-02-07 02:14:23 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix broken link in decimal documentation.
........
r60638 | mark.dickinson | 2008-02-07 02:42:06 +0100 (Thu, 07 Feb 2008) | 3 lines
IEEE 754 should be IEEE 854; give precise reference for
comparisons involving NaNs.
........
r60639 | raymond.hettinger | 2008-02-07 03:12:52 +0100 (Thu, 07 Feb 2008) | 1 line
Return ints instead of longs for tuple.count() and tuple.index().
........
r60640 | raymond.hettinger | 2008-02-07 04:10:33 +0100 (Thu, 07 Feb 2008) | 1 line
Merge 60627.
........
r60641 | raymond.hettinger | 2008-02-07 04:25:46 +0100 (Thu, 07 Feb 2008) | 1 line
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
........
r60642 | brett.cannon | 2008-02-07 08:47:31 +0100 (Thu, 07 Feb 2008) | 3 lines
Cast a struct to a void pointer so as to do a type-safe pointer comparison
(mistmatch found by clang).
........
r60643 | brett.cannon | 2008-02-07 09:04:07 +0100 (Thu, 07 Feb 2008) | 2 lines
Remove unnecessary curly braces around an int literal.
........
r60644 | andrew.kuchling | 2008-02-07 12:43:47 +0100 (Thu, 07 Feb 2008) | 1 line
Update URL
........
r60645 | facundo.batista | 2008-02-07 17:16:29 +0100 (Thu, 07 Feb 2008) | 4 lines
Fixes issue 2026. Tests converted to unittest. Thanks
Giampaolo Rodola.
........
r60646 | christian.heimes | 2008-02-07 18:15:30 +0100 (Thu, 07 Feb 2008) | 1 line
Added some statistics code to dict and list object code. I wanted to test how a larger freelist affects the reusage of freed objects. Contrary to my gut feelings 80 objects is more than fine for small apps. I haven't profiled a large app yet.
........
r60648 | facundo.batista | 2008-02-07 20:06:52 +0100 (Thu, 07 Feb 2008) | 6 lines
Fixes Issue 1401. When redirected, a possible POST get converted
to GET, so it loses its payload. So, it also must lose the
headers related to the payload (if it has no content any more,
it shouldn't indicate content length and type).
........
r60649 | walter.doerwald | 2008-02-07 20:30:22 +0100 (Thu, 07 Feb 2008) | 3 lines
Clarify that the output of TextCalendar.formatmonth() and
TextCalendar.formatyear() for custom instances won't be influenced by calls
to the module global setfirstweekday() function. Fixes #2018.
........
r60651 | walter.doerwald | 2008-02-07 20:48:34 +0100 (Thu, 07 Feb 2008) | 3 lines
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
........
r60653 | walter.doerwald | 2008-02-07 20:57:32 +0100 (Thu, 07 Feb 2008) | 2 lines
Fix typo in docstring for Calendar.itermonthdays().
........
r60655 | raymond.hettinger | 2008-02-07 21:04:37 +0100 (Thu, 07 Feb 2008) | 1 line
The float conversion recipe is simpler in Py2.6
........
r60657 | raymond.hettinger | 2008-02-07 21:10:49 +0100 (Thu, 07 Feb 2008) | 1 line
Fix typo
........
r60660 | brett.cannon | 2008-02-07 23:27:10 +0100 (Thu, 07 Feb 2008) | 3 lines
Make sure a switch statement does not have repetitive case statements.
Error found through LLVM post-2.1 svn.
........
r60661 | christian.heimes | 2008-02-08 01:11:31 +0100 (Fri, 08 Feb 2008) | 1 line
Deallocate content of the dict free list on interpreter shutdown
........
r60662 | christian.heimes | 2008-02-08 01:14:34 +0100 (Fri, 08 Feb 2008) | 1 line
Use prefix decrement
........
r60663 | amaury.forgeotdarc | 2008-02-08 01:56:02 +0100 (Fri, 08 Feb 2008) | 5 lines
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
........
r60667 | jeffrey.yasskin | 2008-02-08 07:45:40 +0100 (Fri, 08 Feb 2008) | 2 lines
Oops! 2.6's Rational.__ne__ didn't work.
........
r60671 | hyeshik.chang | 2008-02-08 18:10:20 +0100 (Fri, 08 Feb 2008) | 2 lines
Update big5hkscs codec to conform to the HKSCS:2004 revision.
........
r60673 | raymond.hettinger | 2008-02-08 23:30:04 +0100 (Fri, 08 Feb 2008) | 4 lines
Remove unnecessary modulo division.
The preceding test guarantees that 0 <= i < len.
........
r60674 | raymond.hettinger | 2008-02-09 00:02:27 +0100 (Sat, 09 Feb 2008) | 1 line
Speed-up __iter__() mixin method.
........
r60675 | raymond.hettinger | 2008-02-09 00:34:21 +0100 (Sat, 09 Feb 2008) | 1 line
Fill-in missing Set comparisons
........
r60677 | raymond.hettinger | 2008-02-09 00:57:06 +0100 (Sat, 09 Feb 2008) | 1 line
Add advice on choosing between DictMixin and MutableMapping
........
2008-02-09 02:18:51 +00:00
|
|
|
#endif
|
2010-05-09 15:52:27 +00:00
|
|
|
}
|
|
|
|
|
if (size <= 0)
|
|
|
|
|
op->ob_item = NULL;
|
|
|
|
|
else {
|
|
|
|
|
op->ob_item = (PyObject **) PyMem_MALLOC(nbytes);
|
|
|
|
|
if (op->ob_item == NULL) {
|
|
|
|
|
Py_DECREF(op);
|
|
|
|
|
return PyErr_NoMemory();
|
|
|
|
|
}
|
|
|
|
|
memset(op->ob_item, 0, nbytes);
|
|
|
|
|
}
|
|
|
|
|
Py_SIZE(op) = size;
|
|
|
|
|
op->allocated = size;
|
|
|
|
|
_PyObject_GC_TRACK(op);
|
|
|
|
|
return (PyObject *) op;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
2006-02-15 17:27:45 +00:00
|
|
|
Py_ssize_t
|
2000-07-09 15:16:51 +00:00
|
|
|
PyList_Size(PyObject *op)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyList_Check(op)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return Py_SIZE(op);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
2004-05-05 06:28:16 +00:00
|
|
|
static PyObject *indexerr = NULL;
|
1996-08-09 20:51:27 +00:00
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
PyObject *
|
2006-02-15 17:27:45 +00:00
|
|
|
PyList_GetItem(PyObject *op, Py_ssize_t i)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyList_Check(op)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (i < 0 || i >= Py_SIZE(op)) {
|
|
|
|
|
if (indexerr == NULL) {
|
|
|
|
|
indexerr = PyUnicode_FromString(
|
|
|
|
|
"list index out of range");
|
|
|
|
|
if (indexerr == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
PyErr_SetObject(PyExc_IndexError, indexerr);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return ((PyListObject *)op) -> ob_item[i];
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2006-02-15 17:27:45 +00:00
|
|
|
PyList_SetItem(register PyObject *op, register Py_ssize_t i,
|
2000-07-09 15:16:51 +00:00
|
|
|
register PyObject *newitem)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
register PyObject *olditem;
|
|
|
|
|
register PyObject **p;
|
|
|
|
|
if (!PyList_Check(op)) {
|
|
|
|
|
Py_XDECREF(newitem);
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (i < 0 || i >= Py_SIZE(op)) {
|
|
|
|
|
Py_XDECREF(newitem);
|
|
|
|
|
PyErr_SetString(PyExc_IndexError,
|
|
|
|
|
"list assignment index out of range");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
p = ((PyListObject *)op) -> ob_item + i;
|
|
|
|
|
olditem = *p;
|
|
|
|
|
*p = newitem;
|
|
|
|
|
Py_XDECREF(olditem);
|
|
|
|
|
return 0;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2006-02-15 17:27:45 +00:00
|
|
|
ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i, n = Py_SIZE(self);
|
|
|
|
|
PyObject **items;
|
|
|
|
|
if (v == NULL) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (n == PY_SSIZE_T_MAX) {
|
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
|
"cannot add more objects to list");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2004-07-29 02:29:26 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (list_resize(self, n+1) == -1)
|
|
|
|
|
return -1;
|
* Optimized list appends and pops by making fewer calls the underlying system
realloc(). This is achieved by tracking the overallocation size in a new
field and using that information to skip calls to realloc() whenever
possible.
* Simplified and tightened the amount of overallocation. For larger lists,
this overallocates by 1/8th (compared to the previous scheme which ranged
between 1/4th to 1/32nd over-allocation). For smaller lists (n<6), the
maximum overallocation is one byte (formerly it could be upto eight bytes).
This saves memory in applications with large numbers of small lists.
* Eliminated the NRESIZE macro in favor of a new, static list_resize function
that encapsulates the resizing logic. Coverting this back to macro would
give a small (under 1%) speed-up. This was too small to warrant the loss
of readability, maintainability, and de-coupling.
* Some functions using NRESIZE had grown unnecessarily complex in their
efforts to bend to the macro's calling pattern. With the new list_resize
function in place, those other functions could be simplified. That is
being saved for a separate patch.
* The ob_item==NULL check could be eliminated from the new list_resize
function. This would entail finding each piece of code that sets ob_item
to NULL and adding a new line to invalidate the overallocation tracking
field. Rather than impose a new requirement on other pieces of list code,
it was preferred to leave the NULL check in place and retain the benefits
of decoupling, maintainability and information hiding (only PyList_New()
and list_sort() need to know about the new field). This approach also
reduces the odds of breaking an extension module.
(Collaborative effort by Raymond Hettinger, Hye-Shik Chang, Tim Peters,
and Armin Rigo.)
2004-02-13 11:36:39 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (where < 0) {
|
|
|
|
|
where += n;
|
|
|
|
|
if (where < 0)
|
|
|
|
|
where = 0;
|
|
|
|
|
}
|
|
|
|
|
if (where > n)
|
|
|
|
|
where = n;
|
|
|
|
|
items = self->ob_item;
|
|
|
|
|
for (i = n; --i >= where; )
|
|
|
|
|
items[i+1] = items[i];
|
|
|
|
|
Py_INCREF(v);
|
|
|
|
|
items[where] = v;
|
|
|
|
|
return 0;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2006-02-15 17:27:45 +00:00
|
|
|
PyList_Insert(PyObject *op, Py_ssize_t where, PyObject *newitem)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyList_Check(op)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return ins1((PyListObject *)op, where, newitem);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
2004-04-12 13:05:09 +00:00
|
|
|
static int
|
|
|
|
|
app1(PyListObject *self, PyObject *v)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t n = PyList_GET_SIZE(self);
|
2004-04-12 13:05:09 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert (v != NULL);
|
|
|
|
|
if (n == PY_SSIZE_T_MAX) {
|
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
|
"cannot add more objects to list");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2004-04-12 13:05:09 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (list_resize(self, n+1) == -1)
|
|
|
|
|
return -1;
|
2004-04-12 13:05:09 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_INCREF(v);
|
|
|
|
|
PyList_SET_ITEM(self, n, v);
|
|
|
|
|
return 0;
|
2004-04-12 13:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
int
|
2000-07-09 15:16:51 +00:00
|
|
|
PyList_Append(PyObject *op, PyObject *newitem)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (PyList_Check(op) && (newitem != NULL))
|
|
|
|
|
return app1((PyListObject *)op, newitem);
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return -1;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
|
|
static void
|
2000-07-09 15:16:51 +00:00
|
|
|
list_dealloc(PyListObject *op)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i;
|
|
|
|
|
PyObject_GC_UnTrack(op);
|
|
|
|
|
Py_TRASHCAN_SAFE_BEGIN(op)
|
|
|
|
|
if (op->ob_item != NULL) {
|
|
|
|
|
/* Do it backwards, for Christian Tismer.
|
|
|
|
|
There's a simple test case where somehow this reduces
|
|
|
|
|
thrashing when a *very* large list is created and
|
|
|
|
|
immediately deleted. */
|
|
|
|
|
i = Py_SIZE(op);
|
|
|
|
|
while (--i >= 0) {
|
|
|
|
|
Py_XDECREF(op->ob_item[i]);
|
|
|
|
|
}
|
|
|
|
|
PyMem_FREE(op->ob_item);
|
|
|
|
|
}
|
|
|
|
|
if (numfree < PyList_MAXFREELIST && PyList_CheckExact(op))
|
|
|
|
|
free_list[numfree++] = op;
|
|
|
|
|
else
|
|
|
|
|
Py_TYPE(op)->tp_free((PyObject *)op);
|
|
|
|
|
Py_TRASHCAN_SAFE_END(op)
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2000-07-09 15:16:51 +00:00
|
|
|
list_repr(PyListObject *v)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i;
|
|
|
|
|
PyObject *s, *temp;
|
|
|
|
|
PyObject *pieces = NULL, *result = NULL;
|
1998-04-10 22:47:27 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
i = Py_ReprEnter((PyObject*)v);
|
|
|
|
|
if (i != 0) {
|
|
|
|
|
return i > 0 ? PyUnicode_FromString("[...]") : NULL;
|
|
|
|
|
}
|
2001-06-16 05:11:17 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (Py_SIZE(v) == 0) {
|
|
|
|
|
result = PyUnicode_FromString("[]");
|
|
|
|
|
goto Done;
|
|
|
|
|
}
|
2001-06-16 05:11:17 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
pieces = PyList_New(0);
|
|
|
|
|
if (pieces == NULL)
|
|
|
|
|
goto Done;
|
2001-06-16 05:11:17 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Do repr() on each element. Note that this may mutate the list,
|
|
|
|
|
so must refetch the list size on each iteration. */
|
|
|
|
|
for (i = 0; i < Py_SIZE(v); ++i) {
|
|
|
|
|
int status;
|
|
|
|
|
if (Py_EnterRecursiveCall(" while getting the repr of a list"))
|
|
|
|
|
goto Done;
|
|
|
|
|
s = PyObject_Repr(v->ob_item[i]);
|
|
|
|
|
Py_LeaveRecursiveCall();
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
goto Done;
|
|
|
|
|
status = PyList_Append(pieces, s);
|
|
|
|
|
Py_DECREF(s); /* append created a new ref */
|
|
|
|
|
if (status < 0)
|
|
|
|
|
goto Done;
|
|
|
|
|
}
|
2001-06-16 05:11:17 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Add "[]" decorations to the first and last items. */
|
|
|
|
|
assert(PyList_GET_SIZE(pieces) > 0);
|
|
|
|
|
s = PyUnicode_FromString("[");
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
goto Done;
|
|
|
|
|
temp = PyList_GET_ITEM(pieces, 0);
|
|
|
|
|
PyUnicode_AppendAndDel(&s, temp);
|
|
|
|
|
PyList_SET_ITEM(pieces, 0, s);
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
goto Done;
|
2001-06-16 05:11:17 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
s = PyUnicode_FromString("]");
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
goto Done;
|
|
|
|
|
temp = PyList_GET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1);
|
|
|
|
|
PyUnicode_AppendAndDel(&temp, s);
|
|
|
|
|
PyList_SET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1, temp);
|
|
|
|
|
if (temp == NULL)
|
|
|
|
|
goto Done;
|
2001-06-16 05:11:17 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Paste them all together with ", " between. */
|
|
|
|
|
s = PyUnicode_FromString(", ");
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
goto Done;
|
|
|
|
|
result = PyUnicode_Join(s, pieces);
|
|
|
|
|
Py_DECREF(s);
|
2001-06-16 05:11:17 +00:00
|
|
|
|
|
|
|
|
Done:
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_XDECREF(pieces);
|
|
|
|
|
Py_ReprLeave((PyObject *)v);
|
|
|
|
|
return result;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
2006-02-15 17:27:45 +00:00
|
|
|
static Py_ssize_t
|
2000-07-09 15:16:51 +00:00
|
|
|
list_length(PyListObject *a)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
return Py_SIZE(a);
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
2000-04-27 21:41:03 +00:00
|
|
|
static int
|
2000-07-09 15:16:51 +00:00
|
|
|
list_contains(PyListObject *a, PyObject *el)
|
2000-04-27 21:41:03 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i;
|
|
|
|
|
int cmp;
|
2000-04-27 21:41:03 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
|
|
|
|
|
cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i),
|
|
|
|
|
Py_EQ);
|
|
|
|
|
return cmp;
|
2000-04-27 21:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2006-02-15 17:27:45 +00:00
|
|
|
list_item(PyListObject *a, Py_ssize_t i)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (i < 0 || i >= Py_SIZE(a)) {
|
|
|
|
|
if (indexerr == NULL) {
|
|
|
|
|
indexerr = PyUnicode_FromString(
|
|
|
|
|
"list index out of range");
|
|
|
|
|
if (indexerr == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
PyErr_SetObject(PyExc_IndexError, indexerr);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
Py_INCREF(a->ob_item[i]);
|
|
|
|
|
return a->ob_item[i];
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2006-02-15 17:27:45 +00:00
|
|
|
list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyListObject *np;
|
|
|
|
|
PyObject **src, **dest;
|
|
|
|
|
Py_ssize_t i, len;
|
|
|
|
|
if (ilow < 0)
|
|
|
|
|
ilow = 0;
|
|
|
|
|
else if (ilow > Py_SIZE(a))
|
|
|
|
|
ilow = Py_SIZE(a);
|
|
|
|
|
if (ihigh < ilow)
|
|
|
|
|
ihigh = ilow;
|
|
|
|
|
else if (ihigh > Py_SIZE(a))
|
|
|
|
|
ihigh = Py_SIZE(a);
|
|
|
|
|
len = ihigh - ilow;
|
|
|
|
|
np = (PyListObject *) PyList_New(len);
|
|
|
|
|
if (np == NULL)
|
|
|
|
|
return NULL;
|
2004-03-08 05:56:15 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
src = a->ob_item + ilow;
|
|
|
|
|
dest = np->ob_item;
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
PyObject *v = src[i];
|
|
|
|
|
Py_INCREF(v);
|
|
|
|
|
dest[i] = v;
|
|
|
|
|
}
|
|
|
|
|
return (PyObject *)np;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
PyObject *
|
2006-02-15 17:27:45 +00:00
|
|
|
PyList_GetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
|
1993-06-17 12:35:49 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyList_Check(a)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return list_slice((PyListObject *)a, ilow, ihigh);
|
1993-06-17 12:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2000-07-09 15:16:51 +00:00
|
|
|
list_concat(PyListObject *a, PyObject *bb)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t size;
|
|
|
|
|
Py_ssize_t i;
|
|
|
|
|
PyObject **src, **dest;
|
|
|
|
|
PyListObject *np;
|
|
|
|
|
if (!PyList_Check(bb)) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"can only concatenate list (not \"%.200s\") to list",
|
|
|
|
|
bb->ob_type->tp_name);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
1997-05-02 03:12:38 +00:00
|
|
|
#define b ((PyListObject *)bb)
|
2010-05-09 15:52:27 +00:00
|
|
|
size = Py_SIZE(a) + Py_SIZE(b);
|
|
|
|
|
if (size < 0)
|
|
|
|
|
return PyErr_NoMemory();
|
|
|
|
|
np = (PyListObject *) PyList_New(size);
|
|
|
|
|
if (np == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
src = a->ob_item;
|
|
|
|
|
dest = np->ob_item;
|
|
|
|
|
for (i = 0; i < Py_SIZE(a); i++) {
|
|
|
|
|
PyObject *v = src[i];
|
|
|
|
|
Py_INCREF(v);
|
|
|
|
|
dest[i] = v;
|
|
|
|
|
}
|
|
|
|
|
src = b->ob_item;
|
|
|
|
|
dest = np->ob_item + Py_SIZE(a);
|
|
|
|
|
for (i = 0; i < Py_SIZE(b); i++) {
|
|
|
|
|
PyObject *v = src[i];
|
|
|
|
|
Py_INCREF(v);
|
|
|
|
|
dest[i] = v;
|
|
|
|
|
}
|
|
|
|
|
return (PyObject *)np;
|
1990-10-14 12:07:46 +00:00
|
|
|
#undef b
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2006-02-15 17:27:45 +00:00
|
|
|
list_repeat(PyListObject *a, Py_ssize_t n)
|
1991-03-06 13:07:53 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i, j;
|
|
|
|
|
Py_ssize_t size;
|
|
|
|
|
PyListObject *np;
|
|
|
|
|
PyObject **p, **items;
|
|
|
|
|
PyObject *elem;
|
|
|
|
|
if (n < 0)
|
|
|
|
|
n = 0;
|
|
|
|
|
size = Py_SIZE(a) * n;
|
|
|
|
|
if (n && size/n != Py_SIZE(a))
|
|
|
|
|
return PyErr_NoMemory();
|
|
|
|
|
if (size == 0)
|
|
|
|
|
return PyList_New(0);
|
|
|
|
|
np = (PyListObject *) PyList_New(size);
|
|
|
|
|
if (np == NULL)
|
|
|
|
|
return NULL;
|
2003-05-21 05:58:46 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
items = np->ob_item;
|
|
|
|
|
if (Py_SIZE(a) == 1) {
|
|
|
|
|
elem = a->ob_item[0];
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
items[i] = elem;
|
|
|
|
|
Py_INCREF(elem);
|
|
|
|
|
}
|
|
|
|
|
return (PyObject *) np;
|
|
|
|
|
}
|
|
|
|
|
p = np->ob_item;
|
|
|
|
|
items = a->ob_item;
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
for (j = 0; j < Py_SIZE(a); j++) {
|
|
|
|
|
*p = items[j];
|
|
|
|
|
Py_INCREF(*p);
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (PyObject *) np;
|
1991-03-06 13:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-29 12:40:23 +00:00
|
|
|
static int
|
|
|
|
|
list_clear(PyListObject *a)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i;
|
|
|
|
|
PyObject **item = a->ob_item;
|
|
|
|
|
if (item != NULL) {
|
|
|
|
|
/* Because XDECREF can recursively invoke operations on
|
|
|
|
|
this list, we make it empty first. */
|
|
|
|
|
i = Py_SIZE(a);
|
|
|
|
|
Py_SIZE(a) = 0;
|
|
|
|
|
a->ob_item = NULL;
|
|
|
|
|
a->allocated = 0;
|
|
|
|
|
while (--i >= 0) {
|
|
|
|
|
Py_XDECREF(item[i]);
|
|
|
|
|
}
|
|
|
|
|
PyMem_FREE(item);
|
|
|
|
|
}
|
|
|
|
|
/* Never fails; the return value can be ignored.
|
|
|
|
|
Note that there is no guarantee that the list is actually empty
|
|
|
|
|
at this point, because XDECREF may have populated it again! */
|
|
|
|
|
return 0;
|
2004-07-29 12:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-31 21:53:19 +00:00
|
|
|
/* a[ilow:ihigh] = v if v != NULL.
|
|
|
|
|
* del a[ilow:ihigh] if v == NULL.
|
|
|
|
|
*
|
|
|
|
|
* Special speed gimmick: when v is NULL and ihigh - ilow <= 8, it's
|
|
|
|
|
* guaranteed the call cannot fail.
|
|
|
|
|
*/
|
1990-10-14 12:07:46 +00:00
|
|
|
static int
|
2006-02-15 17:27:45 +00:00
|
|
|
list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Because [X]DECREF can recursively invoke list operations on
|
|
|
|
|
this list, we must postpone all [X]DECREF activity until
|
|
|
|
|
after the list is back in its canonical shape. Therefore
|
|
|
|
|
we must allocate an additional array, 'recycle', into which
|
|
|
|
|
we temporarily copy the items that are deleted from the
|
|
|
|
|
list. :-( */
|
|
|
|
|
PyObject *recycle_on_stack[8];
|
|
|
|
|
PyObject **recycle = recycle_on_stack; /* will allocate more if needed */
|
|
|
|
|
PyObject **item;
|
|
|
|
|
PyObject **vitem = NULL;
|
|
|
|
|
PyObject *v_as_SF = NULL; /* PySequence_Fast(v) */
|
|
|
|
|
Py_ssize_t n; /* # of elements in replacement list */
|
|
|
|
|
Py_ssize_t norig; /* # of elements in list getting replaced */
|
|
|
|
|
Py_ssize_t d; /* Change in size */
|
|
|
|
|
Py_ssize_t k;
|
|
|
|
|
size_t s;
|
|
|
|
|
int result = -1; /* guilty until proved innocent */
|
1997-05-02 03:12:38 +00:00
|
|
|
#define b ((PyListObject *)v)
|
2010-05-09 15:52:27 +00:00
|
|
|
if (v == NULL)
|
|
|
|
|
n = 0;
|
|
|
|
|
else {
|
|
|
|
|
if (a == b) {
|
|
|
|
|
/* Special case "a[i:j] = a" -- copy b first */
|
|
|
|
|
v = list_slice(b, 0, Py_SIZE(b));
|
|
|
|
|
if (v == NULL)
|
|
|
|
|
return result;
|
|
|
|
|
result = list_ass_slice(a, ilow, ihigh, v);
|
|
|
|
|
Py_DECREF(v);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
v_as_SF = PySequence_Fast(v, "can only assign an iterable");
|
|
|
|
|
if(v_as_SF == NULL)
|
|
|
|
|
goto Error;
|
|
|
|
|
n = PySequence_Fast_GET_SIZE(v_as_SF);
|
|
|
|
|
vitem = PySequence_Fast_ITEMS(v_as_SF);
|
|
|
|
|
}
|
|
|
|
|
if (ilow < 0)
|
|
|
|
|
ilow = 0;
|
|
|
|
|
else if (ilow > Py_SIZE(a))
|
|
|
|
|
ilow = Py_SIZE(a);
|
2004-07-31 02:24:20 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (ihigh < ilow)
|
|
|
|
|
ihigh = ilow;
|
|
|
|
|
else if (ihigh > Py_SIZE(a))
|
|
|
|
|
ihigh = Py_SIZE(a);
|
2004-07-29 12:40:23 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
norig = ihigh - ilow;
|
|
|
|
|
assert(norig >= 0);
|
|
|
|
|
d = n - norig;
|
|
|
|
|
if (Py_SIZE(a) + d == 0) {
|
|
|
|
|
Py_XDECREF(v_as_SF);
|
|
|
|
|
return list_clear(a);
|
|
|
|
|
}
|
|
|
|
|
item = a->ob_item;
|
|
|
|
|
/* recycle the items that we are about to remove */
|
|
|
|
|
s = norig * sizeof(PyObject *);
|
|
|
|
|
if (s > sizeof(recycle_on_stack)) {
|
|
|
|
|
recycle = (PyObject **)PyMem_MALLOC(s);
|
|
|
|
|
if (recycle == NULL) {
|
|
|
|
|
PyErr_NoMemory();
|
|
|
|
|
goto Error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
memcpy(recycle, &item[ilow], s);
|
2004-07-31 02:24:20 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (d < 0) { /* Delete -d items */
|
|
|
|
|
memmove(&item[ihigh+d], &item[ihigh],
|
|
|
|
|
(Py_SIZE(a) - ihigh)*sizeof(PyObject *));
|
|
|
|
|
list_resize(a, Py_SIZE(a) + d);
|
|
|
|
|
item = a->ob_item;
|
|
|
|
|
}
|
|
|
|
|
else if (d > 0) { /* Insert d items */
|
|
|
|
|
k = Py_SIZE(a);
|
|
|
|
|
if (list_resize(a, k+d) < 0)
|
|
|
|
|
goto Error;
|
|
|
|
|
item = a->ob_item;
|
|
|
|
|
memmove(&item[ihigh+d], &item[ihigh],
|
|
|
|
|
(k - ihigh)*sizeof(PyObject *));
|
|
|
|
|
}
|
|
|
|
|
for (k = 0; k < n; k++, ilow++) {
|
|
|
|
|
PyObject *w = vitem[k];
|
|
|
|
|
Py_XINCREF(w);
|
|
|
|
|
item[ilow] = w;
|
|
|
|
|
}
|
|
|
|
|
for (k = norig - 1; k >= 0; --k)
|
|
|
|
|
Py_XDECREF(recycle[k]);
|
|
|
|
|
result = 0;
|
2004-07-31 02:24:20 +00:00
|
|
|
Error:
|
2010-05-09 15:52:27 +00:00
|
|
|
if (recycle != recycle_on_stack)
|
|
|
|
|
PyMem_FREE(recycle);
|
|
|
|
|
Py_XDECREF(v_as_SF);
|
|
|
|
|
return result;
|
1990-10-14 12:07:46 +00:00
|
|
|
#undef b
|
|
|
|
|
}
|
|
|
|
|
|
1993-06-17 12:35:49 +00:00
|
|
|
int
|
2006-02-15 17:27:45 +00:00
|
|
|
PyList_SetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
|
1993-06-17 12:35:49 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyList_Check(a)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return list_ass_slice((PyListObject *)a, ilow, ihigh, v);
|
1993-06-17 12:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
2000-08-24 20:08:19 +00:00
|
|
|
static PyObject *
|
2006-02-15 17:27:45 +00:00
|
|
|
list_inplace_repeat(PyListObject *self, Py_ssize_t n)
|
2000-08-24 20:08:19 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject **items;
|
|
|
|
|
Py_ssize_t size, i, j, p;
|
2000-08-24 20:08:19 +00:00
|
|
|
|
|
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
size = PyList_GET_SIZE(self);
|
|
|
|
|
if (size == 0 || n == 1) {
|
|
|
|
|
Py_INCREF(self);
|
|
|
|
|
return (PyObject *)self;
|
|
|
|
|
}
|
2000-08-24 20:08:19 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (n < 1) {
|
|
|
|
|
(void)list_clear(self);
|
|
|
|
|
Py_INCREF(self);
|
|
|
|
|
return (PyObject *)self;
|
|
|
|
|
}
|
2000-08-24 20:08:19 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (size > PY_SSIZE_T_MAX / n) {
|
|
|
|
|
return PyErr_NoMemory();
|
|
|
|
|
}
|
Merged revisions 60284-60349 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60286 | christian.heimes | 2008-01-25 15:54:23 +0100 (Fri, 25 Jan 2008) | 1 line
setup.py doesn't pick up changes to a header file
........
r60287 | christian.heimes | 2008-01-25 16:52:11 +0100 (Fri, 25 Jan 2008) | 2 lines
Added the Python core headers Include/*.h and pyconfig.h as dependencies for the extensions in Modules/
It forces a rebuild of all extensions when a header files has been modified
........
r60291 | raymond.hettinger | 2008-01-25 20:24:46 +0100 (Fri, 25 Jan 2008) | 4 lines
Changes 54857 and 54840 broke code and were reverted in Py2.5 just before
it was released, but that reversion never made it to the Py2.6 head.
........
r60296 | guido.van.rossum | 2008-01-25 20:50:26 +0100 (Fri, 25 Jan 2008) | 2 lines
Rewrite the list_inline_repeat overflow check slightly differently.
........
r60301 | thomas.wouters | 2008-01-25 22:09:34 +0100 (Fri, 25 Jan 2008) | 4 lines
Use the right (portable) definition of the max of a Py_ssize_t.
........
r60303 | thomas.wouters | 2008-01-26 02:47:05 +0100 (Sat, 26 Jan 2008) | 5 lines
Make 'testall' work again when building in a separate directory.
test_distutils still fails when doing that.
........
r60305 | neal.norwitz | 2008-01-26 06:54:48 +0100 (Sat, 26 Jan 2008) | 3 lines
Prevent this test from failing if there are transient network problems
by retrying the host for up to 3 times.
........
r60306 | neal.norwitz | 2008-01-26 08:26:12 +0100 (Sat, 26 Jan 2008) | 12 lines
Use a condition variable (threading.Event) rather than sleeps and checking a
global to determine when the server is ready to be used. This slows the test
down, but should make it correct. There was a race condition before where the
server could have assigned a port, yet it wasn't ready to serve requests. If
the client sent a request before the server was completely ready, it would get
an exception. There was machinery to try to handle this condition. All of
that should be unnecessary and removed if this change works. A NOTE was
added as a comment about what needs to be fixed.
The buildbots will tell us if there are more errors or
if this test is now stable.
........
r60307 | neal.norwitz | 2008-01-26 08:38:03 +0100 (Sat, 26 Jan 2008) | 3 lines
Fix exception in tearDown on ppc buildbot. If there's no directory,
that shouldn't cause the test to fail. Just like it setUp.
........
r60308 | raymond.hettinger | 2008-01-26 09:19:06 +0100 (Sat, 26 Jan 2008) | 3 lines
Make PySet_Add() work with frozensets. Works like PyTuple_SetItem() to build-up values in a brand new frozenset.
........
r60309 | neal.norwitz | 2008-01-26 09:26:00 +0100 (Sat, 26 Jan 2008) | 1 line
The OS X buildbot had errors with the unavailable exceptions disabled. Restore it.
........
r60310 | raymond.hettinger | 2008-01-26 09:37:28 +0100 (Sat, 26 Jan 2008) | 4 lines
Let marshal build-up sets and frozensets one element at a time.
Saves the unnecessary creation of a tuple as intermediate container.
........
r60311 | raymond.hettinger | 2008-01-26 09:41:13 +0100 (Sat, 26 Jan 2008) | 1 line
Update test code for change to PySet_Add().
........
r60312 | raymond.hettinger | 2008-01-26 10:31:11 +0100 (Sat, 26 Jan 2008) | 1 line
Revert PySet_Add() changes.
........
r60314 | georg.brandl | 2008-01-26 10:43:35 +0100 (Sat, 26 Jan 2008) | 2 lines
#1934: fix os.path.isabs docs.
........
r60316 | georg.brandl | 2008-01-26 12:00:18 +0100 (Sat, 26 Jan 2008) | 2 lines
Add missing things in re docstring.
........
r60317 | georg.brandl | 2008-01-26 12:02:22 +0100 (Sat, 26 Jan 2008) | 2 lines
Slashes allowed on Windows.
........
r60319 | georg.brandl | 2008-01-26 14:41:21 +0100 (Sat, 26 Jan 2008) | 2 lines
Fix markup again.
........
r60320 | andrew.kuchling | 2008-01-26 14:50:51 +0100 (Sat, 26 Jan 2008) | 1 line
Add some items
........
r60321 | georg.brandl | 2008-01-26 15:02:38 +0100 (Sat, 26 Jan 2008) | 2 lines
Clarify "b" mode under Unix.
........
r60322 | georg.brandl | 2008-01-26 15:03:47 +0100 (Sat, 26 Jan 2008) | 3 lines
#1940: make it possible to use curses.filter() before curses.initscr()
as the documentation says.
........
r60324 | georg.brandl | 2008-01-26 15:14:20 +0100 (Sat, 26 Jan 2008) | 3 lines
#1473257: add generator.gi_code attribute that refers to
the original code object backing the generator. Patch by Collin Winter.
........
r60325 | georg.brandl | 2008-01-26 15:19:22 +0100 (Sat, 26 Jan 2008) | 2 lines
Move C API entries to the corresponding section.
........
r60326 | christian.heimes | 2008-01-26 17:43:35 +0100 (Sat, 26 Jan 2008) | 1 line
Unit test fix from Giampaolo Rodola, #1938
........
r60327 | gregory.p.smith | 2008-01-26 19:51:05 +0100 (Sat, 26 Jan 2008) | 2 lines
Update docs for new callpack params added in r60188
........
r60329 | neal.norwitz | 2008-01-26 21:24:36 +0100 (Sat, 26 Jan 2008) | 3 lines
Cleanup the code a bit. test_rfind is failing on PPC and PPC64 buildbots,
this might fix the problem.
........
r60330 | neal.norwitz | 2008-01-26 22:02:45 +0100 (Sat, 26 Jan 2008) | 1 line
Always try to remove the test file even if close raises an exception
........
r60331 | neal.norwitz | 2008-01-26 22:21:59 +0100 (Sat, 26 Jan 2008) | 3 lines
Reduce the race condition by signalling when the server is ready
and not trying to connect before.
........
r60334 | neal.norwitz | 2008-01-27 00:13:46 +0100 (Sun, 27 Jan 2008) | 5 lines
On some systems (e.g., Ubuntu on hppa) the flush()
doesn't cause the exception, but the close() does.
Will backport.
........
r60335 | neal.norwitz | 2008-01-27 00:14:17 +0100 (Sun, 27 Jan 2008) | 2 lines
Consistently use tempfile.tempdir for the db_home directory.
........
r60338 | neal.norwitz | 2008-01-27 02:44:05 +0100 (Sun, 27 Jan 2008) | 4 lines
Eliminate the sleeps that assume the server will start in .5 seconds.
This should make the test less flaky. It also speeds up the test
by about 75% on my box (20+ seconds -> ~4 seconds).
........
r60342 | neal.norwitz | 2008-01-27 06:02:34 +0100 (Sun, 27 Jan 2008) | 6 lines
Try to prevent this test from being flaky. We might need a sleep in here
which isn't as bad as it sounds. The close() *should* raise an exception,
so if it didn't we should give more time to sync and really raise it.
Will backport.
........
r60344 | jeffrey.yasskin | 2008-01-27 06:40:35 +0100 (Sun, 27 Jan 2008) | 3 lines
Make rational.gcd() public and allow Rational to take decimal strings, per
Raymond's advice.
........
r60345 | neal.norwitz | 2008-01-27 08:36:03 +0100 (Sun, 27 Jan 2008) | 3 lines
Mostly reformat. Also set an error and return NULL if neither MS_WINDOWS
nor UNIX is defined. This may have caused problems on cygwin.
........
r60346 | neal.norwitz | 2008-01-27 08:37:38 +0100 (Sun, 27 Jan 2008) | 3 lines
Use int for the sign rather than a char. char can be signed or unsigned.
It's system dependent. This might fix the problem with test_rfind failing.
........
r60347 | neal.norwitz | 2008-01-27 08:41:33 +0100 (Sun, 27 Jan 2008) | 1 line
Add stdarg include for va_list to get this to compile on cygwin
........
r60348 | raymond.hettinger | 2008-01-27 11:13:57 +0100 (Sun, 27 Jan 2008) | 1 line
Docstring nit
........
r60349 | raymond.hettinger | 2008-01-27 11:47:55 +0100 (Sun, 27 Jan 2008) | 1 line
Removed an unnecessary and confusing paragraph from the namedtuple docs.
........
2008-01-27 15:18:18 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (list_resize(self, size*n) == -1)
|
|
|
|
|
return NULL;
|
* Optimized list appends and pops by making fewer calls the underlying system
realloc(). This is achieved by tracking the overallocation size in a new
field and using that information to skip calls to realloc() whenever
possible.
* Simplified and tightened the amount of overallocation. For larger lists,
this overallocates by 1/8th (compared to the previous scheme which ranged
between 1/4th to 1/32nd over-allocation). For smaller lists (n<6), the
maximum overallocation is one byte (formerly it could be upto eight bytes).
This saves memory in applications with large numbers of small lists.
* Eliminated the NRESIZE macro in favor of a new, static list_resize function
that encapsulates the resizing logic. Coverting this back to macro would
give a small (under 1%) speed-up. This was too small to warrant the loss
of readability, maintainability, and de-coupling.
* Some functions using NRESIZE had grown unnecessarily complex in their
efforts to bend to the macro's calling pattern. With the new list_resize
function in place, those other functions could be simplified. That is
being saved for a separate patch.
* The ob_item==NULL check could be eliminated from the new list_resize
function. This would entail finding each piece of code that sets ob_item
to NULL and adding a new line to invalidate the overallocation tracking
field. Rather than impose a new requirement on other pieces of list code,
it was preferred to leave the NULL check in place and retain the benefits
of decoupling, maintainability and information hiding (only PyList_New()
and list_sort() need to know about the new field). This approach also
reduces the odds of breaking an extension module.
(Collaborative effort by Raymond Hettinger, Hye-Shik Chang, Tim Peters,
and Armin Rigo.)
2004-02-13 11:36:39 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
p = size;
|
|
|
|
|
items = self->ob_item;
|
|
|
|
|
for (i = 1; i < n; i++) { /* Start counting at 1, not 0 */
|
|
|
|
|
for (j = 0; j < size; j++) {
|
|
|
|
|
PyObject *o = items[j];
|
|
|
|
|
Py_INCREF(o);
|
|
|
|
|
items[p++] = o;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Py_INCREF(self);
|
|
|
|
|
return (PyObject *)self;
|
2000-08-24 20:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
1991-04-03 19:05:18 +00:00
|
|
|
static int
|
2006-02-15 17:27:45 +00:00
|
|
|
list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v)
|
1991-04-03 19:05:18 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject *old_value;
|
|
|
|
|
if (i < 0 || i >= Py_SIZE(a)) {
|
|
|
|
|
PyErr_SetString(PyExc_IndexError,
|
|
|
|
|
"list assignment index out of range");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (v == NULL)
|
|
|
|
|
return list_ass_slice(a, i, i+1, v);
|
|
|
|
|
Py_INCREF(v);
|
|
|
|
|
old_value = a->ob_item[i];
|
|
|
|
|
a->ob_item[i] = v;
|
|
|
|
|
Py_DECREF(old_value);
|
|
|
|
|
return 0;
|
1991-04-03 19:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2000-07-09 15:16:51 +00:00
|
|
|
listinsert(PyListObject *self, PyObject *args)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i;
|
|
|
|
|
PyObject *v;
|
|
|
|
|
if (!PyArg_ParseTuple(args, "nO:insert", &i, &v))
|
|
|
|
|
return NULL;
|
|
|
|
|
if (ins1(self, i, v) == 0)
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
return NULL;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2001-08-16 13:15:00 +00:00
|
|
|
listappend(PyListObject *self, PyObject *v)
|
1990-10-14 12:07:46 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (app1(self, v) == 0)
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
return NULL;
|
1990-10-14 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
2000-08-24 20:08:19 +00:00
|
|
|
static PyObject *
|
2001-08-16 13:15:00 +00:00
|
|
|
listextend(PyListObject *self, PyObject *b)
|
2000-08-24 20:08:19 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject *it; /* iter(v) */
|
|
|
|
|
Py_ssize_t m; /* size of self */
|
|
|
|
|
Py_ssize_t n; /* guess for size of b */
|
|
|
|
|
Py_ssize_t mn; /* m + n */
|
|
|
|
|
Py_ssize_t i;
|
|
|
|
|
PyObject *(*iternext)(PyObject *);
|
2000-08-24 20:08:19 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Special cases:
|
|
|
|
|
1) lists and tuples which can use PySequence_Fast ops
|
|
|
|
|
2) extending self to self requires making a copy first
|
|
|
|
|
*/
|
|
|
|
|
if (PyList_CheckExact(b) || PyTuple_CheckExact(b) || (PyObject *)self == b) {
|
|
|
|
|
PyObject **src, **dest;
|
|
|
|
|
b = PySequence_Fast(b, "argument must be iterable");
|
|
|
|
|
if (!b)
|
|
|
|
|
return NULL;
|
|
|
|
|
n = PySequence_Fast_GET_SIZE(b);
|
|
|
|
|
if (n == 0) {
|
|
|
|
|
/* short circuit when b is empty */
|
|
|
|
|
Py_DECREF(b);
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
m = Py_SIZE(self);
|
|
|
|
|
if (list_resize(self, m + n) == -1) {
|
|
|
|
|
Py_DECREF(b);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
/* note that we may still have self == b here for the
|
|
|
|
|
* situation a.extend(a), but the following code works
|
|
|
|
|
* in that case too. Just make sure to resize self
|
|
|
|
|
* before calling PySequence_Fast_ITEMS.
|
|
|
|
|
*/
|
|
|
|
|
/* populate the end of self with b's items */
|
|
|
|
|
src = PySequence_Fast_ITEMS(b);
|
|
|
|
|
dest = self->ob_item + m;
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
PyObject *o = src[i];
|
|
|
|
|
Py_INCREF(o);
|
|
|
|
|
dest[i] = o;
|
|
|
|
|
}
|
|
|
|
|
Py_DECREF(b);
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
2004-02-15 03:57:00 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
it = PyObject_GetIter(b);
|
|
|
|
|
if (it == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
iternext = *it->ob_type->tp_iternext;
|
2000-08-24 20:08:19 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Guess a result list size. */
|
|
|
|
|
n = _PyObject_LengthHint(b, 8);
|
|
|
|
|
if (n == -1) {
|
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
m = Py_SIZE(self);
|
|
|
|
|
mn = m + n;
|
|
|
|
|
if (mn >= m) {
|
|
|
|
|
/* Make room. */
|
|
|
|
|
if (list_resize(self, mn) == -1)
|
|
|
|
|
goto error;
|
|
|
|
|
/* Make the list sane again. */
|
|
|
|
|
Py_SIZE(self) = m;
|
|
|
|
|
}
|
|
|
|
|
/* Else m + n overflowed; on the chance that n lied, and there really
|
|
|
|
|
* is enough room, ignore it. If n was telling the truth, we'll
|
|
|
|
|
* eventually run out of memory during the loop.
|
|
|
|
|
*/
|
2000-08-24 20:08:19 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Run iterator to exhaustion. */
|
|
|
|
|
for (;;) {
|
|
|
|
|
PyObject *item = iternext(it);
|
|
|
|
|
if (item == NULL) {
|
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
|
if (PyErr_ExceptionMatches(PyExc_StopIteration))
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (Py_SIZE(self) < self->allocated) {
|
|
|
|
|
/* steals ref */
|
|
|
|
|
PyList_SET_ITEM(self, Py_SIZE(self), item);
|
|
|
|
|
++Py_SIZE(self);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int status = app1(self, item);
|
|
|
|
|
Py_DECREF(item); /* append creates a new ref */
|
|
|
|
|
if (status < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-02-15 03:57:00 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Cut back result list if initial guess was too large. */
|
|
|
|
|
if (Py_SIZE(self) < self->allocated)
|
|
|
|
|
list_resize(self, Py_SIZE(self)); /* shrinking can't fail */
|
2004-09-26 19:24:20 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_DECREF(it);
|
|
|
|
|
Py_RETURN_NONE;
|
2004-02-15 03:57:00 +00:00
|
|
|
|
|
|
|
|
error:
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_DECREF(it);
|
|
|
|
|
return NULL;
|
2000-08-24 20:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-11 09:13:12 +00:00
|
|
|
PyObject *
|
|
|
|
|
_PyList_Extend(PyListObject *self, PyObject *b)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
return listextend(self, b);
|
2004-03-11 09:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-11 07:34:19 +00:00
|
|
|
static PyObject *
|
|
|
|
|
list_inplace_concat(PyListObject *self, PyObject *other)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject *result;
|
2004-03-11 07:34:19 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
result = listextend(self, other);
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
return result;
|
|
|
|
|
Py_DECREF(result);
|
|
|
|
|
Py_INCREF(self);
|
|
|
|
|
return (PyObject *)self;
|
2004-03-11 07:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
1998-06-30 15:36:32 +00:00
|
|
|
static PyObject *
|
2000-07-09 15:16:51 +00:00
|
|
|
listpop(PyListObject *self, PyObject *args)
|
1998-06-30 15:36:32 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i = -1;
|
|
|
|
|
PyObject *v;
|
|
|
|
|
int status;
|
2004-02-17 11:36:16 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyArg_ParseTuple(args, "|n:pop", &i))
|
|
|
|
|
return NULL;
|
Four months of trunk changes (including a few releases...)
Merged revisions 51434-53004 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r51434 | neal.norwitz | 2006-08-21 20:20:10 +0200 (Mon, 21 Aug 2006) | 1 line
Fix a couple of ssize-t issues reported by Alexander Belopolsky on python-dev
........
r51439 | neal.norwitz | 2006-08-21 21:47:08 +0200 (Mon, 21 Aug 2006) | 6 lines
Patch #1542451: disallow continue anywhere under a finally
I'm undecided if this should be backported to 2.5 or 2.5.1.
Armin suggested to wait (I'm of the same opinion). Thomas W thinks
it's fine to go in 2.5.
........
r51443 | neal.norwitz | 2006-08-21 22:16:24 +0200 (Mon, 21 Aug 2006) | 4 lines
Handle a few more error conditions.
Klocwork 301 and 302. Will backport.
........
r51450 | neal.norwitz | 2006-08-22 00:21:19 +0200 (Tue, 22 Aug 2006) | 5 lines
Patch #1541585: fix buffer overrun when performing repr() on
a unicode string in a build with wide unicode (UCS-4) support.
This code could be improved, so add an XXX comment.
........
r51456 | neal.norwitz | 2006-08-22 01:44:48 +0200 (Tue, 22 Aug 2006) | 1 line
Try to get the windows bots working again with the new peephole.c
........
r51461 | anthony.baxter | 2006-08-22 09:36:59 +0200 (Tue, 22 Aug 2006) | 1 line
patch for documentation for recent uuid changes (from ping)
........
r51473 | neal.norwitz | 2006-08-22 15:56:56 +0200 (Tue, 22 Aug 2006) | 1 line
Alexander Belopolsky pointed out that pos is a size_t
........
r51489 | jeremy.hylton | 2006-08-22 22:46:00 +0200 (Tue, 22 Aug 2006) | 2 lines
Expose column offset information in parse trees.
........
r51497 | andrew.kuchling | 2006-08-23 01:13:43 +0200 (Wed, 23 Aug 2006) | 1 line
Move functional howto into trunk
........
r51515 | jeremy.hylton | 2006-08-23 20:37:43 +0200 (Wed, 23 Aug 2006) | 2 lines
Baby steps towards better tests for tokenize
........
r51525 | alex.martelli | 2006-08-23 22:42:02 +0200 (Wed, 23 Aug 2006) | 6 lines
x**2 should about equal x*x (including for a float x such that the result is
inf) but didn't; added a test to test_float to verify that, and ignored the
ERANGE value for errno in the pow operation to make the new test pass (with
help from Marilyn Davis at the Google Python Sprint -- thanks!).
........
r51526 | jeremy.hylton | 2006-08-23 23:14:03 +0200 (Wed, 23 Aug 2006) | 20 lines
Bug fixes large and small for tokenize.
Small: Always generate a NL or NEWLINE token following
a COMMENT token. The old code did not generate an NL token if
the comment was on a line by itself.
Large: The output of untokenize() will now match the
input exactly if it is passed the full token sequence. The
old, crufty output is still generated if a limited input
sequence is provided, where limited means that it does not
include position information for tokens.
Remaining bug: There is no CONTINUATION token (\) so there is no way
for untokenize() to handle such code.
Also, expanded the number of doctests in hopes of eventually removing
the old-style tests that compare against a golden file.
Bug fix candidate for Python 2.5.1. (Sigh.)
........
r51527 | jeremy.hylton | 2006-08-23 23:26:46 +0200 (Wed, 23 Aug 2006) | 5 lines
Replace dead code with an assert.
Now that COMMENT tokens are reliably followed by NL or NEWLINE,
there is never a need to add extra newlines in untokenize.
........
r51530 | alex.martelli | 2006-08-24 00:17:59 +0200 (Thu, 24 Aug 2006) | 7 lines
Reverting the patch that tried to fix the issue whereby x**2 raises
OverflowError while x*x succeeds and produces infinity; apparently
these inconsistencies cannot be fixed across ``all'' platforms and
there's a widespread feeling that therefore ``every'' platform
should keep suffering forevermore. Ah well.
........
r51565 | thomas.wouters | 2006-08-24 20:40:20 +0200 (Thu, 24 Aug 2006) | 6 lines
Fix SF bug #1545837: array.array borks on deepcopy.
array.__deepcopy__() needs to take an argument, even if it doesn't actually
use it. Will backport to 2.5 and 2.4 (if applicable.)
........
r51580 | martin.v.loewis | 2006-08-25 02:03:34 +0200 (Fri, 25 Aug 2006) | 3 lines
Patch #1545507: Exclude ctypes package in Win64 MSI file.
Will backport to 2.5.
........
r51589 | neal.norwitz | 2006-08-25 03:52:49 +0200 (Fri, 25 Aug 2006) | 1 line
importing types is not necessary if we use isinstance
........
r51604 | thomas.heller | 2006-08-25 09:27:33 +0200 (Fri, 25 Aug 2006) | 3 lines
Port _ctypes.pyd to win64 on AMD64.
........
r51605 | thomas.heller | 2006-08-25 09:34:51 +0200 (Fri, 25 Aug 2006) | 3 lines
Add missing file for _ctypes.pyd port to win64 on AMD64.
........
r51606 | thomas.heller | 2006-08-25 11:26:33 +0200 (Fri, 25 Aug 2006) | 6 lines
Build _ctypes.pyd for win AMD64 into the MSVC project file.
Since MSVC doesn't know about .asm files, a helper batch file is needed
to find ml64.exe in predefined locations. The helper script hardcodes
the path to the MS Platform SDK.
........
r51608 | armin.rigo | 2006-08-25 14:44:28 +0200 (Fri, 25 Aug 2006) | 4 lines
The regular expression engine in '_sre' can segfault when interpreting
bogus bytecode. It is unclear whether this is a real bug or a "won't
fix" case like bogus_code_obj.py.
........
r51617 | tim.peters | 2006-08-26 00:05:39 +0200 (Sat, 26 Aug 2006) | 2 lines
Whitespace normalization.
........
r51618 | tim.peters | 2006-08-26 00:06:44 +0200 (Sat, 26 Aug 2006) | 2 lines
Add missing svn:eol-style property to text files.
........
r51619 | tim.peters | 2006-08-26 00:26:21 +0200 (Sat, 26 Aug 2006) | 3 lines
A new test here relied on preserving invisible trailing
whitespace in expected output. Stop that.
........
r51624 | jack.diederich | 2006-08-26 20:42:06 +0200 (Sat, 26 Aug 2006) | 4 lines
- Move functions common to all path modules into genericpath.py and have the
OS speicifc path modules import them.
- Have os2emxpath import common functions fron ntpath instead of using copies
........
r51642 | neal.norwitz | 2006-08-29 07:40:58 +0200 (Tue, 29 Aug 2006) | 1 line
Fix a couple of typos.
........
r51647 | marc-andre.lemburg | 2006-08-29 12:34:12 +0200 (Tue, 29 Aug 2006) | 5 lines
Fix a buglet in the error reporting (SF bug report #1546372).
This should probably go into Python 2.5 or 2.5.1 as well.
........
r51663 | armin.rigo | 2006-08-31 10:51:06 +0200 (Thu, 31 Aug 2006) | 3 lines
Doc fix: hashlib objects don't always return a digest of 16 bytes.
Backport candidate for 2.5.
........
r51664 | nick.coghlan | 2006-08-31 14:00:43 +0200 (Thu, 31 Aug 2006) | 1 line
Fix the wrongheaded implementation of context management in the decimal module and add unit tests. (python-dev discussion is ongoing regarding what we do about Python 2.5)
........
r51665 | nick.coghlan | 2006-08-31 14:51:25 +0200 (Thu, 31 Aug 2006) | 1 line
Remove the old decimal context management tests from test_contextlib (guess who didn't run the test suite before committing...)
........
r51669 | brett.cannon | 2006-08-31 20:54:26 +0200 (Thu, 31 Aug 2006) | 4 lines
Make sure memory is properly cleaned up in file_init.
Backport candidate.
........
r51671 | brett.cannon | 2006-08-31 23:47:52 +0200 (Thu, 31 Aug 2006) | 2 lines
Fix comment about indentation level in C files.
........
r51674 | brett.cannon | 2006-09-01 00:42:37 +0200 (Fri, 01 Sep 2006) | 3 lines
Have pre-existing C files use 8 spaces indents (to match old PEP 7 style), but
have all new files use 4 spaces (to match current PEP 7 style).
........
r51676 | fred.drake | 2006-09-01 05:57:19 +0200 (Fri, 01 Sep 2006) | 3 lines
- SF patch #1550263: Enhance and correct unittest docs
- various minor cleanups for improved consistency
........
r51677 | georg.brandl | 2006-09-02 00:30:52 +0200 (Sat, 02 Sep 2006) | 2 lines
evalfile() should be execfile().
........
r51681 | neal.norwitz | 2006-09-02 04:43:17 +0200 (Sat, 02 Sep 2006) | 1 line
SF #1547931, fix typo (missing and). Will backport to 2.5
........
r51683 | neal.norwitz | 2006-09-02 04:50:35 +0200 (Sat, 02 Sep 2006) | 1 line
Bug #1548092: fix curses.tparm seg fault on invalid input. Needs backport to 2.5.1 and earlier.
........
r51684 | neal.norwitz | 2006-09-02 04:58:13 +0200 (Sat, 02 Sep 2006) | 4 lines
Bug #1550714: fix SystemError from itertools.tee on negative value for n.
Needs backport to 2.5.1 and earlier.
........
r51685 | nick.coghlan | 2006-09-02 05:54:17 +0200 (Sat, 02 Sep 2006) | 1 line
Make decimal.ContextManager a private implementation detail of decimal.localcontext()
........
r51686 | nick.coghlan | 2006-09-02 06:04:18 +0200 (Sat, 02 Sep 2006) | 1 line
Further corrections to the decimal module context management documentation
........
r51688 | raymond.hettinger | 2006-09-02 19:07:23 +0200 (Sat, 02 Sep 2006) | 1 line
Fix documentation nits for decimal context managers.
........
r51690 | neal.norwitz | 2006-09-02 20:51:34 +0200 (Sat, 02 Sep 2006) | 1 line
Add missing word in comment
........
r51691 | neal.norwitz | 2006-09-02 21:40:19 +0200 (Sat, 02 Sep 2006) | 7 lines
Hmm, this test has failed at least twice recently on the OpenBSD and
Debian sparc buildbots. Since this goes through a lot of tests
and hits the disk a lot it could be slow (especially if NFS is involved).
I'm not sure if that's the problem, but printing periodic msgs shouldn't hurt.
The code was stolen from test_compiler.
........
r51693 | nick.coghlan | 2006-09-03 03:02:00 +0200 (Sun, 03 Sep 2006) | 1 line
Fix final documentation nits before backporting decimal module fixes to 2.5
........
r51694 | nick.coghlan | 2006-09-03 03:06:07 +0200 (Sun, 03 Sep 2006) | 1 line
Typo fix for decimal docs
........
r51697 | nick.coghlan | 2006-09-03 03:20:46 +0200 (Sun, 03 Sep 2006) | 1 line
NEWS entry on trunk for decimal module changes
........
r51704 | raymond.hettinger | 2006-09-04 17:32:48 +0200 (Mon, 04 Sep 2006) | 1 line
Fix endcase for str.rpartition()
........
r51716 | tim.peters | 2006-09-05 04:18:09 +0200 (Tue, 05 Sep 2006) | 12 lines
"Conceptual" merge of rev 51711 from the 2.5 branch.
i_divmod(): As discussed on Python-Dev, changed the overflow
checking to live happily with recent gcc optimizations that
assume signed integer arithmetic never overflows.
This differs from the corresponding change on the 2.5 and 2.4
branches, using a less obscure approach, but one that /may/
tickle platform idiocies in their definitions of LONG_MIN.
The 2.4 + 2.5 change avoided introducing a dependence on
LONG_MIN, at the cost of substantially goofier code.
........
r51717 | tim.peters | 2006-09-05 04:21:19 +0200 (Tue, 05 Sep 2006) | 2 lines
Whitespace normalization.
........
r51719 | tim.peters | 2006-09-05 04:22:17 +0200 (Tue, 05 Sep 2006) | 2 lines
Add missing svn:eol-style property to text files.
........
r51720 | neal.norwitz | 2006-09-05 04:24:03 +0200 (Tue, 05 Sep 2006) | 2 lines
Fix SF bug #1546288, crash in dict_equal.
........
r51721 | neal.norwitz | 2006-09-05 04:25:41 +0200 (Tue, 05 Sep 2006) | 1 line
Fix SF #1552093, eval docstring typo (3 ps in mapping)
........
r51724 | neal.norwitz | 2006-09-05 04:35:08 +0200 (Tue, 05 Sep 2006) | 1 line
This was found by Guido AFAIK on p3yk (sic) branch.
........
r51725 | neal.norwitz | 2006-09-05 04:36:20 +0200 (Tue, 05 Sep 2006) | 1 line
Add a NEWS entry for str.rpartition() change
........
r51728 | neal.norwitz | 2006-09-05 04:57:01 +0200 (Tue, 05 Sep 2006) | 1 line
Patch #1540470, for OpenBSD 4.0. Backport candidate for 2.[34].
........
r51729 | neal.norwitz | 2006-09-05 05:53:08 +0200 (Tue, 05 Sep 2006) | 12 lines
Bug #1520864 (again): unpacking singleton tuples in list comprehensions and
generator expressions (x for x, in ... ) works again.
Sigh, I only fixed for loops the first time, not list comps and genexprs too.
I couldn't find any more unpacking cases where there is a similar bug lurking.
This code should be refactored to eliminate the duplication. I'm sure
the listcomp/genexpr code can be refactored. I'm not sure if the for loop
can re-use any of the same code though.
Will backport to 2.5 (the only place it matters).
........
r51731 | neal.norwitz | 2006-09-05 05:58:26 +0200 (Tue, 05 Sep 2006) | 1 line
Add a comment about some refactoring. (There's probably more that should be done.) I will reformat this file in the next checkin due to the inconsistent tabs/spaces.
........
r51732 | neal.norwitz | 2006-09-05 06:00:12 +0200 (Tue, 05 Sep 2006) | 1 line
M-x untabify
........
r51737 | hyeshik.chang | 2006-09-05 14:07:09 +0200 (Tue, 05 Sep 2006) | 7 lines
Fix a few bugs on cjkcodecs found by Oren Tirosh:
- gbk and gb18030 codec now handle U+30FB KATAKANA MIDDLE DOT correctly.
- iso2022_jp_2 codec now encodes into G0 for KS X 1001, GB2312
codepoints to conform the standard.
- iso2022_jp_3 and iso2022_jp_2004 codec can encode JIS X 2013:2
codepoints now.
........
r51738 | hyeshik.chang | 2006-09-05 14:14:57 +0200 (Tue, 05 Sep 2006) | 2 lines
Fix a typo: 2013 -> 0213
........
r51740 | georg.brandl | 2006-09-05 14:44:58 +0200 (Tue, 05 Sep 2006) | 3 lines
Bug #1552618: change docs of dict.has_key() to reflect recommendation
to use "in".
........
r51742 | andrew.kuchling | 2006-09-05 15:02:40 +0200 (Tue, 05 Sep 2006) | 1 line
Rearrange example a bit, and show rpartition() when separator is not found
........
r51744 | andrew.kuchling | 2006-09-05 15:15:41 +0200 (Tue, 05 Sep 2006) | 1 line
[Bug #1525469] SimpleXMLRPCServer still uses the sys.exc_{value,type} module-level globals instead of calling sys.exc_info(). Reported by Russell Warren
........
r51745 | andrew.kuchling | 2006-09-05 15:19:18 +0200 (Tue, 05 Sep 2006) | 3 lines
[Bug #1526834] Fix crash in pdb when you do 'b f(';
the function name was placed into a regex pattern and the unbalanced paren
caused re.compile() to report an error
........
r51751 | kristjan.jonsson | 2006-09-05 19:58:12 +0200 (Tue, 05 Sep 2006) | 6 lines
Update the PCBuild8 solution.
Facilitate cross-compilation by having binaries in separate Win32 and x64 directories.
Rationalized configs by making proper use of platforms/configurations.
Remove pythoncore_pgo project.
Add new PGIRelease and PGORelease configurations to perform Profile Guided Optimisation.
Removed I64 support, but this can be easily added by copying the x64 platform settings.
........
r51758 | gustavo.niemeyer | 2006-09-06 03:58:52 +0200 (Wed, 06 Sep 2006) | 3 lines
Fixing #1531862: Do not close standard file descriptors in the
subprocess module.
........
r51760 | neal.norwitz | 2006-09-06 05:58:34 +0200 (Wed, 06 Sep 2006) | 1 line
Revert 51758 because it broke all the buildbots
........
r51762 | georg.brandl | 2006-09-06 08:03:59 +0200 (Wed, 06 Sep 2006) | 3 lines
Bug #1551427: fix a wrong NULL pointer check in the win32 version
of os.urandom().
........
r51765 | georg.brandl | 2006-09-06 08:09:31 +0200 (Wed, 06 Sep 2006) | 3 lines
Bug #1550983: emit better error messages for erroneous relative
imports (if not in package and if beyond toplevel package).
........
r51767 | neal.norwitz | 2006-09-06 08:28:06 +0200 (Wed, 06 Sep 2006) | 1 line
with and as are now keywords. There are some generated files I can't recreate.
........
r51770 | georg.brandl | 2006-09-06 08:50:05 +0200 (Wed, 06 Sep 2006) | 5 lines
Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack.
Also make sure that every exception class has __module__ set to
'exceptions'.
........
r51785 | georg.brandl | 2006-09-06 22:05:58 +0200 (Wed, 06 Sep 2006) | 2 lines
Fix missing import of the types module in logging.config.
........
r51789 | marc-andre.lemburg | 2006-09-06 22:40:22 +0200 (Wed, 06 Sep 2006) | 3 lines
Add news item for bug fix of SF bug report #1546372.
........
r51797 | gustavo.niemeyer | 2006-09-07 02:48:33 +0200 (Thu, 07 Sep 2006) | 3 lines
Fixed subprocess bug #1531862 again, after removing tests
offending buildbot
........
r51798 | raymond.hettinger | 2006-09-07 04:42:48 +0200 (Thu, 07 Sep 2006) | 1 line
Fix refcounts and add error checks.
........
r51803 | nick.coghlan | 2006-09-07 12:50:34 +0200 (Thu, 07 Sep 2006) | 1 line
Fix the speed regression in inspect.py by adding another cache to speed up getmodule(). Patch #1553314
........
r51805 | ronald.oussoren | 2006-09-07 14:03:10 +0200 (Thu, 07 Sep 2006) | 2 lines
Fix a glaring error and update some version numbers.
........
r51814 | andrew.kuchling | 2006-09-07 15:56:23 +0200 (Thu, 07 Sep 2006) | 1 line
Typo fix
........
r51815 | andrew.kuchling | 2006-09-07 15:59:38 +0200 (Thu, 07 Sep 2006) | 8 lines
[Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select()
if an input hook has been defined. Patch by Richard Boulton.
This select() code is only executed with readline 2.1, or if
READLINE_CALLBACKS is defined.
Backport candidate for 2.5, 2.4, probably earlier versions too.
........
r51816 | armin.rigo | 2006-09-07 17:06:00 +0200 (Thu, 07 Sep 2006) | 2 lines
Add a warning notice on top of the generated grammar.txt.
........
r51819 | thomas.heller | 2006-09-07 20:56:28 +0200 (Thu, 07 Sep 2006) | 5 lines
Anonymous structure fields that have a bit-width specified did not work,
and they gave a strange error message from PyArg_ParseTuple:
function takes exactly 2 arguments (3 given).
With tests.
........
r51820 | thomas.heller | 2006-09-07 21:09:54 +0200 (Thu, 07 Sep 2006) | 4 lines
The cast function did not accept c_char_p or c_wchar_p instances
as first argument, and failed with a 'bad argument to internal function'
error message.
........
r51827 | nick.coghlan | 2006-09-08 12:04:38 +0200 (Fri, 08 Sep 2006) | 1 line
Add missing NEWS entry for rev 51803
........
r51828 | andrew.kuchling | 2006-09-08 15:25:23 +0200 (Fri, 08 Sep 2006) | 1 line
Add missing word
........
r51829 | andrew.kuchling | 2006-09-08 15:35:49 +0200 (Fri, 08 Sep 2006) | 1 line
Explain SQLite a bit more clearly
........
r51830 | andrew.kuchling | 2006-09-08 15:36:36 +0200 (Fri, 08 Sep 2006) | 1 line
Explain SQLite a bit more clearly
........
r51832 | andrew.kuchling | 2006-09-08 16:02:45 +0200 (Fri, 08 Sep 2006) | 1 line
Use native SQLite types
........
r51833 | andrew.kuchling | 2006-09-08 16:03:01 +0200 (Fri, 08 Sep 2006) | 1 line
Use native SQLite types
........
r51835 | andrew.kuchling | 2006-09-08 16:05:10 +0200 (Fri, 08 Sep 2006) | 1 line
Fix typo in example
........
r51837 | brett.cannon | 2006-09-09 09:11:46 +0200 (Sat, 09 Sep 2006) | 6 lines
Remove the __unicode__ method from exceptions. Allows unicode() to be called
on exception classes. Would require introducing a tp_unicode slot to make it
work otherwise.
Fixes bug #1551432 and will be backported.
........
r51854 | neal.norwitz | 2006-09-11 06:24:09 +0200 (Mon, 11 Sep 2006) | 8 lines
Forward port of 51850 from release25-maint branch.
As mentioned on python-dev, reverting patch #1504333 because it introduced
an infinite loop in rev 47154.
This patch also adds a test to prevent the regression.
........
r51855 | neal.norwitz | 2006-09-11 06:28:16 +0200 (Mon, 11 Sep 2006) | 5 lines
Properly handle a NULL returned from PyArena_New().
(Also fix some whitespace)
Klocwork #364.
........
r51856 | neal.norwitz | 2006-09-11 06:32:57 +0200 (Mon, 11 Sep 2006) | 1 line
Add a "crasher" taken from the sgml bug report referenced in the comment
........
r51858 | georg.brandl | 2006-09-11 11:38:35 +0200 (Mon, 11 Sep 2006) | 12 lines
Forward-port of rev. 51857:
Building with HP's cc on HP-UX turned up a couple of problems.
_PyGILState_NoteThreadState was declared as static inconsistently.
Make it static as it's not necessary outside of this module.
Some tests failed because errno was reset to 0. (I think the tests
that failed were at least: test_fcntl and test_mailbox).
Ensure that errno doesn't change after a call to Py_END_ALLOW_THREADS.
This only affected debug builds.
........
r51865 | martin.v.loewis | 2006-09-12 21:49:20 +0200 (Tue, 12 Sep 2006) | 2 lines
Forward-port 51862: Add sgml_input.html.
........
r51866 | andrew.kuchling | 2006-09-12 22:50:23 +0200 (Tue, 12 Sep 2006) | 1 line
Markup typo fix
........
r51867 | andrew.kuchling | 2006-09-12 23:09:02 +0200 (Tue, 12 Sep 2006) | 1 line
Some editing, markup fixes
........
r51868 | andrew.kuchling | 2006-09-12 23:21:51 +0200 (Tue, 12 Sep 2006) | 1 line
More wordsmithing
........
r51877 | andrew.kuchling | 2006-09-14 13:22:18 +0200 (Thu, 14 Sep 2006) | 1 line
Make --help mention that -v can be supplied multiple times
........
r51878 | andrew.kuchling | 2006-09-14 13:28:50 +0200 (Thu, 14 Sep 2006) | 1 line
Rewrite help message to remove some of the parentheticals. (There were a lot of them.)
........
r51883 | ka-ping.yee | 2006-09-15 02:34:19 +0200 (Fri, 15 Sep 2006) | 2 lines
Fix grammar errors and improve clarity.
........
r51885 | georg.brandl | 2006-09-15 07:22:24 +0200 (Fri, 15 Sep 2006) | 3 lines
Correct elementtree module index entry.
........
r51889 | fred.drake | 2006-09-15 17:18:04 +0200 (Fri, 15 Sep 2006) | 4 lines
- fix module name in links in formatted documentation
- minor markup cleanup
(forward-ported from release25-maint revision 51888)
........
r51891 | fred.drake | 2006-09-15 18:11:27 +0200 (Fri, 15 Sep 2006) | 3 lines
revise explanation of returns_unicode to reflect bool values
and to include the default value
(merged from release25-maint revision 51890)
........
r51897 | martin.v.loewis | 2006-09-16 19:36:37 +0200 (Sat, 16 Sep 2006) | 2 lines
Patch #1557515: Add RLIMIT_SBSIZE.
........
r51903 | ronald.oussoren | 2006-09-17 20:42:53 +0200 (Sun, 17 Sep 2006) | 2 lines
Port of revision 51902 in release25-maint to the trunk
........
r51904 | ronald.oussoren | 2006-09-17 21:23:27 +0200 (Sun, 17 Sep 2006) | 3 lines
Tweak Mac/Makefile in to ensure that pythonw gets rebuild when the major version
of python changes (2.5 -> 2.6). Bug #1552935.
........
r51913 | guido.van.rossum | 2006-09-18 23:36:16 +0200 (Mon, 18 Sep 2006) | 2 lines
Make this thing executable.
........
r51920 | gregory.p.smith | 2006-09-19 19:35:04 +0200 (Tue, 19 Sep 2006) | 5 lines
Fixes a bug with bsddb.DB.stat where the flags and txn keyword
arguments are transposed. (reported by Louis Zechtzer)
..already committed to release24-maint
..needs committing to release25-maint
........
r51926 | brett.cannon | 2006-09-20 20:34:28 +0200 (Wed, 20 Sep 2006) | 3 lines
Accidentally didn't commit Misc/NEWS entry on when __unicode__() was removed
from exceptions.
........
r51927 | brett.cannon | 2006-09-20 20:43:13 +0200 (Wed, 20 Sep 2006) | 6 lines
Allow exceptions to be directly sliced again
(e.g., ``BaseException(1,2,3)[0:2]``).
Discovered in Python 2.5.0 by Thomas Heller and reported to python-dev. This
should be backported to 2.5 .
........
r51928 | brett.cannon | 2006-09-20 21:28:35 +0200 (Wed, 20 Sep 2006) | 2 lines
Make python.vim output more deterministic.
........
r51949 | walter.doerwald | 2006-09-21 17:09:55 +0200 (Thu, 21 Sep 2006) | 2 lines
Fix typo.
........
r51950 | jack.diederich | 2006-09-21 19:50:26 +0200 (Thu, 21 Sep 2006) | 5 lines
* regression bug, count_next was coercing a Py_ssize_t to an unsigned Py_size_t
which breaks negative counts
* added test for negative numbers
will backport to 2.5.1
........
r51953 | jack.diederich | 2006-09-21 22:34:49 +0200 (Thu, 21 Sep 2006) | 1 line
added itertools.count(-n) fix
........
r51971 | neal.norwitz | 2006-09-22 10:16:26 +0200 (Fri, 22 Sep 2006) | 10 lines
Fix %zd string formatting on Mac OS X so it prints negative numbers.
In addition to testing positive numbers, verify negative numbers work in configure.
In order to avoid compiler warnings on OS X 10.4, also change the order of the check
for the format character to use (PY_FORMAT_SIZE_T) in the sprintf format
for Py_ssize_t. This patch changes PY_FORMAT_SIZE_T from "" to "l" if it wasn't
defined at configure time. Need to verify the buildbot results.
Backport candidate (if everyone thinks this patch can't be improved).
........
r51972 | neal.norwitz | 2006-09-22 10:18:10 +0200 (Fri, 22 Sep 2006) | 7 lines
Bug #1557232: fix seg fault with def f((((x)))) and def f(((x),)).
These tests should be improved. Hopefully this fixes variations when
flipping back and forth between fpdef and fplist.
Backport candidate.
........
r51975 | neal.norwitz | 2006-09-22 10:47:23 +0200 (Fri, 22 Sep 2006) | 4 lines
Mostly revert this file to the same version as before. Only force setting
of PY_FORMAT_SIZE_T to "l" for Mac OSX. I don't know a better define
to use. This should get rid of the warnings on other platforms and Mac too.
........
r51986 | fred.drake | 2006-09-23 02:26:31 +0200 (Sat, 23 Sep 2006) | 1 line
add boilerplate "What's New" document so the docs will build
........
r51987 | neal.norwitz | 2006-09-23 06:11:38 +0200 (Sat, 23 Sep 2006) | 1 line
Remove extra semi-colons reported by Johnny Lee on python-dev. Backport if anyone cares.
........
r51989 | neal.norwitz | 2006-09-23 20:11:58 +0200 (Sat, 23 Sep 2006) | 1 line
SF Bug #1563963, add missing word and cleanup first sentance
........
r51990 | brett.cannon | 2006-09-23 21:53:20 +0200 (Sat, 23 Sep 2006) | 3 lines
Make output on test_strptime() be more verbose in face of failure. This is in
hopes that more information will help debug the failing test on HPPA Ubuntu.
........
r51991 | georg.brandl | 2006-09-24 12:36:01 +0200 (Sun, 24 Sep 2006) | 2 lines
Fix webbrowser.BackgroundBrowser on Windows.
........
r51993 | georg.brandl | 2006-09-24 14:35:36 +0200 (Sun, 24 Sep 2006) | 4 lines
Fix a bug in the parser's future statement handling that led to "with"
not being recognized as a keyword after, e.g., this statement:
from __future__ import division, with_statement
........
r51995 | georg.brandl | 2006-09-24 14:50:24 +0200 (Sun, 24 Sep 2006) | 4 lines
Fix a bug in traceback.format_exception_only() that led to an error
being raised when print_exc() was called without an exception set.
In version 2.4, this printed "None", restored that behavior.
........
r52000 | armin.rigo | 2006-09-25 17:16:26 +0200 (Mon, 25 Sep 2006) | 2 lines
Another crasher.
........
r52011 | brett.cannon | 2006-09-27 01:38:24 +0200 (Wed, 27 Sep 2006) | 2 lines
Make the error message for when the time data and format do not match clearer.
........
r52014 | andrew.kuchling | 2006-09-27 18:37:30 +0200 (Wed, 27 Sep 2006) | 1 line
Add news item for rev. 51815
........
r52018 | andrew.kuchling | 2006-09-27 21:23:05 +0200 (Wed, 27 Sep 2006) | 1 line
Make examples do error checking on Py_InitModule
........
r52032 | brett.cannon | 2006-09-29 00:10:14 +0200 (Fri, 29 Sep 2006) | 2 lines
Very minor grammatical fix in a comment.
........
r52048 | george.yoshida | 2006-09-30 07:14:02 +0200 (Sat, 30 Sep 2006) | 4 lines
SF bug #1567976 : fix typo
Will backport to 2.5.
........
r52051 | gregory.p.smith | 2006-09-30 08:08:20 +0200 (Sat, 30 Sep 2006) | 2 lines
wording change
........
r52053 | georg.brandl | 2006-09-30 09:24:48 +0200 (Sat, 30 Sep 2006) | 2 lines
Bug #1567375: a minor logical glitch in example description.
........
r52056 | georg.brandl | 2006-09-30 09:31:57 +0200 (Sat, 30 Sep 2006) | 3 lines
Bug #1565661: in webbrowser, split() the command for the default
GNOME browser in case it is a command with args.
........
r52058 | georg.brandl | 2006-09-30 10:43:30 +0200 (Sat, 30 Sep 2006) | 4 lines
Patch #1567691: super() and new.instancemethod() now don't accept
keyword arguments any more (previously they accepted them, but didn't
use them).
........
r52061 | georg.brandl | 2006-09-30 11:03:42 +0200 (Sat, 30 Sep 2006) | 3 lines
Bug #1566800: make sure that EnvironmentError can be called with any
number of arguments, as was the case in Python 2.4.
........
r52063 | georg.brandl | 2006-09-30 11:06:45 +0200 (Sat, 30 Sep 2006) | 2 lines
Bug #1566663: remove obsolete example from datetime docs.
........
r52065 | georg.brandl | 2006-09-30 11:13:21 +0200 (Sat, 30 Sep 2006) | 3 lines
Bug #1566602: correct failure of posixpath unittest when $HOME ends
with a slash.
........
r52068 | georg.brandl | 2006-09-30 12:58:01 +0200 (Sat, 30 Sep 2006) | 3 lines
Bug #1457823: cgi.(Sv)FormContentDict's constructor now takes
keep_blank_values and strict_parsing keyword arguments.
........
r52069 | georg.brandl | 2006-09-30 13:06:47 +0200 (Sat, 30 Sep 2006) | 3 lines
Bug #1560617: in pyclbr, return full module name not only for classes,
but also for functions.
........
r52072 | georg.brandl | 2006-09-30 13:17:34 +0200 (Sat, 30 Sep 2006) | 3 lines
Bug #1556784: allow format strings longer than 127 characters in
datetime's strftime function.
........
r52075 | georg.brandl | 2006-09-30 13:22:28 +0200 (Sat, 30 Sep 2006) | 3 lines
Bug #1446043: correctly raise a LookupError if an encoding name given
to encodings.search_function() contains a dot.
........
r52078 | georg.brandl | 2006-09-30 14:02:57 +0200 (Sat, 30 Sep 2006) | 3 lines
Bug #1546052: clarify that PyString_FromString(AndSize) copies the
string pointed to by its parameter.
........
r52080 | georg.brandl | 2006-09-30 14:16:03 +0200 (Sat, 30 Sep 2006) | 3 lines
Convert test_import to unittest.
........
r52083 | kurt.kaiser | 2006-10-01 23:16:45 +0200 (Sun, 01 Oct 2006) | 5 lines
Some syntax errors were being caught by tokenize during the tabnanny
check, resulting in obscure error messages. Do the syntax check
first. Bug 1562716, 1562719
........
r52084 | kurt.kaiser | 2006-10-01 23:54:37 +0200 (Sun, 01 Oct 2006) | 3 lines
Add comment explaining that error msgs may be due to user code when
running w/o subprocess.
........
r52086 | martin.v.loewis | 2006-10-02 16:55:51 +0200 (Mon, 02 Oct 2006) | 3 lines
Fix test for uintptr_t. Fixes #1568842.
Will backport.
........
r52089 | martin.v.loewis | 2006-10-02 17:20:37 +0200 (Mon, 02 Oct 2006) | 3 lines
Guard uintptr_t test with HAVE_STDINT_H, test for
stdint.h. Will backport.
........
r52100 | vinay.sajip | 2006-10-03 20:02:37 +0200 (Tue, 03 Oct 2006) | 1 line
Documentation omitted the additional parameter to LogRecord.__init__ which was added in 2.5. (See SF #1569622).
........
r52101 | vinay.sajip | 2006-10-03 20:20:26 +0200 (Tue, 03 Oct 2006) | 1 line
Documentation clarified to mention optional parameters.
........
r52102 | vinay.sajip | 2006-10-03 20:21:56 +0200 (Tue, 03 Oct 2006) | 1 line
Modified LogRecord.__init__ to make the func parameter optional. (See SF #1569622).
........
r52121 | brett.cannon | 2006-10-03 23:58:55 +0200 (Tue, 03 Oct 2006) | 2 lines
Fix minor typo in a comment.
........
r52123 | brett.cannon | 2006-10-04 01:23:14 +0200 (Wed, 04 Oct 2006) | 2 lines
Convert test_imp over to unittest.
........
r52128 | barry.warsaw | 2006-10-04 04:06:36 +0200 (Wed, 04 Oct 2006) | 3 lines
decode_rfc2231(): As Christian Robottom Reis points out, it makes no sense to
test for parts > 3 when we use .split(..., 2).
........
r52129 | jeremy.hylton | 2006-10-04 04:24:52 +0200 (Wed, 04 Oct 2006) | 9 lines
Fix for SF bug 1569998: break permitted inside try.
The compiler was checking that there was something on the fblock
stack, but not that there was a loop on the stack. Fixed that and
added a test for the specific syntax error.
Bug fix candidate.
........
r52130 | martin.v.loewis | 2006-10-04 07:47:34 +0200 (Wed, 04 Oct 2006) | 4 lines
Fix integer negation and absolute value to not rely
on undefined behaviour of the C compiler anymore.
Will backport to 2.5 and 2.4.
........
r52135 | martin.v.loewis | 2006-10-04 11:21:20 +0200 (Wed, 04 Oct 2006) | 1 line
Forward port r52134: Add uuids for 2.4.4.
........
r52137 | armin.rigo | 2006-10-04 12:23:57 +0200 (Wed, 04 Oct 2006) | 3 lines
Compilation problem caused by conflicting typedefs for uint32_t
(unsigned long vs. unsigned int).
........
r52139 | armin.rigo | 2006-10-04 14:17:45 +0200 (Wed, 04 Oct 2006) | 23 lines
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...
........
r52147 | andrew.kuchling | 2006-10-04 15:42:43 +0200 (Wed, 04 Oct 2006) | 6 lines
Cause a PyObject_Malloc() failure to trigger a MemoryError, and then
add 'if (PyErr_Occurred())' checks to various places so that NULL is
returned properly.
2.4 backport candidate.
........
r52148 | martin.v.loewis | 2006-10-04 17:25:28 +0200 (Wed, 04 Oct 2006) | 1 line
Add MSVC8 project files to create wininst-8.exe.
........
r52196 | brett.cannon | 2006-10-06 00:02:31 +0200 (Fri, 06 Oct 2006) | 7 lines
Clarify what "re-initialization" means for init_builtin() and init_dynamic().
Also remove warning about re-initialization as possibly raising an execption as
both call _PyImport_FindExtension() which pulls any module that was already
imported from the Python process' extension cache and just copies the __dict__
into the module stored in sys.modules.
........
r52200 | fred.drake | 2006-10-06 02:03:45 +0200 (Fri, 06 Oct 2006) | 3 lines
- update links
- remove Sleepycat name now that they have been bought
........
r52204 | andrew.kuchling | 2006-10-06 12:41:01 +0200 (Fri, 06 Oct 2006) | 1 line
Case fix
........
r52208 | georg.brandl | 2006-10-06 14:46:08 +0200 (Fri, 06 Oct 2006) | 3 lines
Fix name.
........
r52211 | andrew.kuchling | 2006-10-06 15:18:26 +0200 (Fri, 06 Oct 2006) | 1 line
[Bug #1545341] Allow 'classifier' parameter to be a tuple as well as a list. Will backport.
........
r52212 | armin.rigo | 2006-10-06 18:33:22 +0200 (Fri, 06 Oct 2006) | 4 lines
A very minor bug fix: this code looks like it is designed to accept
any hue value and do the modulo itself, except it doesn't quite do
it in all cases. At least, the "cannot get here" comment was wrong.
........
r52213 | andrew.kuchling | 2006-10-06 20:51:55 +0200 (Fri, 06 Oct 2006) | 1 line
Comment grammar
........
r52218 | skip.montanaro | 2006-10-07 13:05:02 +0200 (Sat, 07 Oct 2006) | 6 lines
Note that the excel_tab class is registered as the "excel-tab" dialect.
Fixes 1572471. Make a similar change for the excel class and clean up
references to the Dialects and Formatting Parameters section in a few
places.
........
r52221 | georg.brandl | 2006-10-08 09:11:54 +0200 (Sun, 08 Oct 2006) | 3 lines
Add missing NEWS entry for rev. 52129.
........
r52223 | hyeshik.chang | 2006-10-08 15:48:34 +0200 (Sun, 08 Oct 2006) | 3 lines
Bug #1572832: fix a bug in ISO-2022 codecs which may cause segfault
when encoding non-BMP unicode characters. (Submitted by Ray Chason)
........
r52227 | ronald.oussoren | 2006-10-08 19:37:58 +0200 (Sun, 08 Oct 2006) | 4 lines
Add version number to the link to the python documentation in
/Developer/Documentation/Python, better for users that install multiple versions
of python.
........
r52229 | ronald.oussoren | 2006-10-08 19:40:02 +0200 (Sun, 08 Oct 2006) | 2 lines
Fix for bug #1570284
........
r52233 | ronald.oussoren | 2006-10-08 19:49:52 +0200 (Sun, 08 Oct 2006) | 6 lines
MacOSX: distutils changes the values of BASECFLAGS and LDFLAGS when using a
universal build of python on OSX 10.3 to ensure that those flags can be used
to compile code (the universal build uses compiler flags that aren't supported
on 10.3). This patches gives the same treatment to CFLAGS, PY_CFLAGS and
BLDSHARED.
........
r52236 | ronald.oussoren | 2006-10-08 19:51:46 +0200 (Sun, 08 Oct 2006) | 5 lines
MacOSX: The universal build requires that users have the MacOSX10.4u SDK
installed to build extensions. This patch makes distutils emit a warning when
the compiler should use an SDK but that SDK is not installed, hopefully reducing
some confusion.
........
r52238 | ronald.oussoren | 2006-10-08 20:18:26 +0200 (Sun, 08 Oct 2006) | 3 lines
MacOSX: add more logic to recognize the correct startup file to patch to the
shell profile patching post-install script.
........
r52242 | andrew.kuchling | 2006-10-09 19:10:12 +0200 (Mon, 09 Oct 2006) | 1 line
Add news item for rev. 52211 change
........
r52245 | andrew.kuchling | 2006-10-09 20:05:19 +0200 (Mon, 09 Oct 2006) | 1 line
Fix wording in comment
........
r52251 | georg.brandl | 2006-10-09 21:03:06 +0200 (Mon, 09 Oct 2006) | 2 lines
Patch #1572724: fix typo ('=' instead of '==') in _msi.c.
........
r52255 | barry.warsaw | 2006-10-09 21:43:24 +0200 (Mon, 09 Oct 2006) | 2 lines
List gc.get_count() in the module docstring.
........
r52257 | martin.v.loewis | 2006-10-09 22:44:25 +0200 (Mon, 09 Oct 2006) | 1 line
Bug #1565150: Fix subsecond processing for os.utime on Windows.
........
r52268 | ronald.oussoren | 2006-10-10 09:55:06 +0200 (Tue, 10 Oct 2006) | 2 lines
MacOSX: fix permission problem in the generated installer
........
r52293 | georg.brandl | 2006-10-12 09:38:04 +0200 (Thu, 12 Oct 2006) | 2 lines
Bug #1575746: fix typo in property() docs.
........
r52295 | georg.brandl | 2006-10-12 09:57:21 +0200 (Thu, 12 Oct 2006) | 3 lines
Bug #813342: Start the IDLE subprocess with -Qnew if the parent
is started with that option.
........
r52297 | georg.brandl | 2006-10-12 10:22:53 +0200 (Thu, 12 Oct 2006) | 2 lines
Bug #1565919: document set types in the Language Reference.
........
r52299 | georg.brandl | 2006-10-12 11:20:33 +0200 (Thu, 12 Oct 2006) | 3 lines
Bug #1550524: better heuristics to find correct class definition
in inspect.findsource().
........
r52301 | georg.brandl | 2006-10-12 11:47:12 +0200 (Thu, 12 Oct 2006) | 4 lines
Bug #1548891: The cStringIO.StringIO() constructor now encodes unicode
arguments with the system default encoding just like the write()
method does, instead of converting it to a raw buffer.
........
r52303 | georg.brandl | 2006-10-12 13:14:40 +0200 (Thu, 12 Oct 2006) | 2 lines
Bug #1546628: add a note about urlparse.urljoin() and absolute paths.
........
r52305 | georg.brandl | 2006-10-12 13:27:59 +0200 (Thu, 12 Oct 2006) | 3 lines
Bug #1545497: when given an explicit base, int() did ignore NULs
embedded in the string to convert.
........
r52307 | georg.brandl | 2006-10-12 13:41:11 +0200 (Thu, 12 Oct 2006) | 3 lines
Add a note to fpectl docs that it's not built by default
(bug #1556261).
........
r52309 | georg.brandl | 2006-10-12 13:46:57 +0200 (Thu, 12 Oct 2006) | 3 lines
Bug #1560114: the Mac filesystem does have accurate information
about the case of filenames.
........
r52311 | georg.brandl | 2006-10-12 13:59:27 +0200 (Thu, 12 Oct 2006) | 2 lines
Small grammar fix, thanks Sjoerd.
........
r52313 | georg.brandl | 2006-10-12 14:03:07 +0200 (Thu, 12 Oct 2006) | 2 lines
Fix tarfile depending on buggy int('1\0', base) behavior.
........
r52315 | georg.brandl | 2006-10-12 14:33:07 +0200 (Thu, 12 Oct 2006) | 2 lines
Bug #1283491: follow docstring convention wrt. keyword-able args in sum().
........
r52316 | georg.brandl | 2006-10-12 15:08:16 +0200 (Thu, 12 Oct 2006) | 3 lines
Bug #1560179: speed up posixpath.(dir|base)name
........
r52327 | brett.cannon | 2006-10-14 08:36:45 +0200 (Sat, 14 Oct 2006) | 3 lines
Clean up the language of a sentence relating to the connect() function and
user-defined datatypes.
........
r52332 | neal.norwitz | 2006-10-14 23:33:38 +0200 (Sat, 14 Oct 2006) | 3 lines
Update the peephole optimizer to remove more dead code (jumps after returns)
and inline jumps to returns.
........
r52333 | martin.v.loewis | 2006-10-15 09:54:40 +0200 (Sun, 15 Oct 2006) | 4 lines
Patch #1576954: Update VC6 build directory; remove redundant
files in VC7. Will backport to 2.5.
........
r52335 | martin.v.loewis | 2006-10-15 10:43:33 +0200 (Sun, 15 Oct 2006) | 1 line
Patch #1576166: Support os.utime for directories on Windows NT+.
........
r52336 | martin.v.loewis | 2006-10-15 10:51:22 +0200 (Sun, 15 Oct 2006) | 2 lines
Patch #1577551: Add ctypes and ET build support for VC6.
Will backport to 2.5.
........
r52338 | martin.v.loewis | 2006-10-15 11:35:51 +0200 (Sun, 15 Oct 2006) | 1 line
Loosen the test for equal time stamps.
........
r52339 | martin.v.loewis | 2006-10-15 11:43:39 +0200 (Sun, 15 Oct 2006) | 2 lines
Bug #1567666: Emulate GetFileAttributesExA for Win95.
Will backport to 2.5.
........
r52341 | martin.v.loewis | 2006-10-15 13:02:07 +0200 (Sun, 15 Oct 2006) | 2 lines
Round to int, because some systems support sub-second time stamps in stat, but not in utime.
Also be consistent with modifying only mtime, not atime.
........
r52342 | martin.v.loewis | 2006-10-15 13:57:40 +0200 (Sun, 15 Oct 2006) | 2 lines
Set the eol-style for project files to "CRLF".
........
r52343 | martin.v.loewis | 2006-10-15 13:59:56 +0200 (Sun, 15 Oct 2006) | 3 lines
Drop binary property on dsp files, set eol-style
to CRLF instead.
........
r52344 | martin.v.loewis | 2006-10-15 14:01:43 +0200 (Sun, 15 Oct 2006) | 2 lines
Remove binary property, set eol-style to CRLF instead.
........
r52346 | martin.v.loewis | 2006-10-15 16:30:38 +0200 (Sun, 15 Oct 2006) | 2 lines
Mention the bdist_msi module. Will backport to 2.5.
........
r52354 | brett.cannon | 2006-10-16 05:09:52 +0200 (Mon, 16 Oct 2006) | 3 lines
Fix turtle so that you can launch the demo2 function on its own instead of only
when the module is launched as a script.
........
r52356 | martin.v.loewis | 2006-10-17 17:18:06 +0200 (Tue, 17 Oct 2006) | 2 lines
Patch #1457736: Update VC6 to use current PCbuild settings.
Will backport to 2.5.
........
r52360 | martin.v.loewis | 2006-10-17 20:09:55 +0200 (Tue, 17 Oct 2006) | 2 lines
Remove obsolete file. Will backport.
........
r52363 | martin.v.loewis | 2006-10-17 20:59:23 +0200 (Tue, 17 Oct 2006) | 4 lines
Forward-port r52358:
- Bug #1578513: Cross compilation was broken by a change to configure.
Repair so that it's back to how it was in 2.4.3.
........
r52365 | thomas.heller | 2006-10-17 21:30:48 +0200 (Tue, 17 Oct 2006) | 6 lines
ctypes callback functions only support 'fundamental' result types.
Check this and raise an error when something else is used - before
this change ctypes would hang or crash when such a callback was
called. This is a partial fix for #1574584.
Will backport to release25-maint.
........
r52377 | tim.peters | 2006-10-18 07:06:06 +0200 (Wed, 18 Oct 2006) | 2 lines
newIobject(): repaired incorrect cast to quiet MSVC warning.
........
r52378 | tim.peters | 2006-10-18 07:09:12 +0200 (Wed, 18 Oct 2006) | 2 lines
Whitespace normalization.
........
r52379 | tim.peters | 2006-10-18 07:10:28 +0200 (Wed, 18 Oct 2006) | 2 lines
Add missing svn:eol-style to text files.
........
r52387 | martin.v.loewis | 2006-10-19 12:58:46 +0200 (Thu, 19 Oct 2006) | 3 lines
Add check for the PyArg_ParseTuple format, and declare
it if it is supported.
........
r52388 | martin.v.loewis | 2006-10-19 13:00:37 +0200 (Thu, 19 Oct 2006) | 3 lines
Fix various minor errors in passing arguments to
PyArg_ParseTuple.
........
r52389 | martin.v.loewis | 2006-10-19 18:01:37 +0200 (Thu, 19 Oct 2006) | 2 lines
Restore CFLAGS after checking for __attribute__
........
r52390 | andrew.kuchling | 2006-10-19 23:55:55 +0200 (Thu, 19 Oct 2006) | 1 line
[Bug #1576348] Fix typo in example
........
r52414 | walter.doerwald | 2006-10-22 10:59:41 +0200 (Sun, 22 Oct 2006) | 2 lines
Port test___future__ to unittest.
........
r52415 | ronald.oussoren | 2006-10-22 12:45:18 +0200 (Sun, 22 Oct 2006) | 3 lines
Patch #1580674: with this patch os.readlink uses the filesystem encoding to
decode unicode objects and returns an unicode object when the argument is one.
........
r52416 | martin.v.loewis | 2006-10-22 12:46:18 +0200 (Sun, 22 Oct 2006) | 3 lines
Patch #1580872: Remove duplicate declaration of PyCallable_Check.
Will backport to 2.5.
........
r52418 | martin.v.loewis | 2006-10-22 12:55:15 +0200 (Sun, 22 Oct 2006) | 4 lines
- Patch #1560695: Add .note.GNU-stack to ctypes' sysv.S so that
ctypes isn't considered as requiring executable stacks.
Will backport to 2.5.
........
r52420 | martin.v.loewis | 2006-10-22 15:45:13 +0200 (Sun, 22 Oct 2006) | 3 lines
Remove passwd.adjunct.byname from list of maps
for test_nis. Will backport to 2.5.
........
r52431 | georg.brandl | 2006-10-24 18:54:16 +0200 (Tue, 24 Oct 2006) | 2 lines
Patch [ 1583506 ] tarfile.py: 100-char filenames are truncated
........
r52446 | andrew.kuchling | 2006-10-26 21:10:46 +0200 (Thu, 26 Oct 2006) | 1 line
[Bug #1579796] Wrong syntax for PyDateTime_IMPORT in documentation. Reported by David Faure.
........
r52449 | andrew.kuchling | 2006-10-26 21:16:46 +0200 (Thu, 26 Oct 2006) | 1 line
Typo fix
........
r52452 | martin.v.loewis | 2006-10-27 08:16:31 +0200 (Fri, 27 Oct 2006) | 3 lines
Patch #1549049: Rewrite type conversion in structmember.
Fixes #1545696 and #1566140. Will backport to 2.5.
........
r52454 | martin.v.loewis | 2006-10-27 08:42:27 +0200 (Fri, 27 Oct 2006) | 2 lines
Check for values.h. Will backport.
........
r52456 | martin.v.loewis | 2006-10-27 09:06:52 +0200 (Fri, 27 Oct 2006) | 2 lines
Get DBL_MAX from float.h not values.h. Will backport.
........
r52458 | martin.v.loewis | 2006-10-27 09:13:28 +0200 (Fri, 27 Oct 2006) | 2 lines
Patch #1567274: Support SMTP over TLS.
........
r52459 | andrew.kuchling | 2006-10-27 13:33:29 +0200 (Fri, 27 Oct 2006) | 1 line
Set svn:keywords property
........
r52460 | andrew.kuchling | 2006-10-27 13:36:41 +0200 (Fri, 27 Oct 2006) | 1 line
Add item
........
r52461 | andrew.kuchling | 2006-10-27 13:37:01 +0200 (Fri, 27 Oct 2006) | 1 line
Some wording changes and markup fixes
........
r52462 | andrew.kuchling | 2006-10-27 14:18:38 +0200 (Fri, 27 Oct 2006) | 1 line
[Bug #1585690] Note that line_num was added in Python 2.5
........
r52464 | andrew.kuchling | 2006-10-27 14:50:38 +0200 (Fri, 27 Oct 2006) | 1 line
[Bug #1583946] Reword description of server and issuer
........
r52466 | andrew.kuchling | 2006-10-27 15:06:25 +0200 (Fri, 27 Oct 2006) | 1 line
[Bug #1562583] Mention the set_reuse_addr() method
........
r52469 | andrew.kuchling | 2006-10-27 15:22:46 +0200 (Fri, 27 Oct 2006) | 4 lines
[Bug #1542016] Report PCALL_POP value. This makes the return value of sys.callstats() match its docstring.
Backport candidate. Though it's an API change, this is a pretty obscure
portion of the API.
........
r52473 | andrew.kuchling | 2006-10-27 16:53:41 +0200 (Fri, 27 Oct 2006) | 1 line
Point users to the subprocess module in the docs for os.system, os.spawn*, os.popen2, and the popen2 and commands modules
........
r52476 | andrew.kuchling | 2006-10-27 18:39:10 +0200 (Fri, 27 Oct 2006) | 1 line
[Bug #1576241] Let functools.wraps work with built-in functions
........
r52478 | andrew.kuchling | 2006-10-27 18:55:34 +0200 (Fri, 27 Oct 2006) | 1 line
[Bug #1575506] The _singlefileMailbox class was using the wrong file object in its flush() method, causing an error
........
r52480 | andrew.kuchling | 2006-10-27 19:06:16 +0200 (Fri, 27 Oct 2006) | 1 line
Clarify docstring
........
r52481 | andrew.kuchling | 2006-10-27 19:11:23 +0200 (Fri, 27 Oct 2006) | 5 lines
[Patch #1574068 by Scott Dial] urllib and urllib2 were using
base64.encodestring() for encoding authentication data.
encodestring() can include newlines for very long input, which
produced broken HTTP headers.
........
r52483 | andrew.kuchling | 2006-10-27 20:13:46 +0200 (Fri, 27 Oct 2006) | 1 line
Check db_setup_debug for a few print statements; change sqlite_setup_debug to False
........
r52484 | andrew.kuchling | 2006-10-27 20:15:02 +0200 (Fri, 27 Oct 2006) | 1 line
[Patch #1503717] Tiny patch from Chris AtLee to stop a lengthy line from being printed
........
r52485 | thomas.heller | 2006-10-27 20:31:36 +0200 (Fri, 27 Oct 2006) | 5 lines
WindowsError.str should display the windows error code,
not the posix error code; with test.
Fixes #1576174.
Will backport to release25-maint.
........
r52487 | thomas.heller | 2006-10-27 21:05:53 +0200 (Fri, 27 Oct 2006) | 4 lines
Modulefinder now handles absolute and relative imports, including
tests.
Will backport to release25-maint.
........
r52488 | georg.brandl | 2006-10-27 22:39:43 +0200 (Fri, 27 Oct 2006) | 2 lines
Patch #1552024: add decorator support to unparse.py demo script.
........
r52492 | walter.doerwald | 2006-10-28 12:47:12 +0200 (Sat, 28 Oct 2006) | 2 lines
Port test_bufio to unittest.
........
r52493 | georg.brandl | 2006-10-28 15:10:17 +0200 (Sat, 28 Oct 2006) | 6 lines
Convert test_global, test_scope and test_grammar to unittest.
I tried to enclose all tests which must be run at the toplevel
(instead of inside a method) in exec statements.
........
r52494 | georg.brandl | 2006-10-28 15:11:41 +0200 (Sat, 28 Oct 2006) | 3 lines
Update outstanding bugs test file.
........
r52495 | georg.brandl | 2006-10-28 15:51:49 +0200 (Sat, 28 Oct 2006) | 3 lines
Convert test_math to unittest.
........
r52496 | georg.brandl | 2006-10-28 15:56:58 +0200 (Sat, 28 Oct 2006) | 3 lines
Convert test_opcodes to unittest.
........
r52497 | georg.brandl | 2006-10-28 18:04:04 +0200 (Sat, 28 Oct 2006) | 2 lines
Fix nth() itertool recipe.
........
r52500 | georg.brandl | 2006-10-28 22:25:09 +0200 (Sat, 28 Oct 2006) | 2 lines
make test_grammar pass with python -O
........
r52501 | neal.norwitz | 2006-10-28 23:15:30 +0200 (Sat, 28 Oct 2006) | 6 lines
Add some asserts. In sysmodule, I think these were to try to silence
some warnings from Klokwork. They verify the assumptions of the format
of svn version output.
The assert in the thread module helped debug a problem on HP-UX.
........
r52502 | neal.norwitz | 2006-10-28 23:16:54 +0200 (Sat, 28 Oct 2006) | 5 lines
Fix warnings with HP's C compiler. It doesn't recognize that infinite
loops are, um, infinite. These conditions should not be able to happen.
Will backport.
........
r52503 | neal.norwitz | 2006-10-28 23:17:51 +0200 (Sat, 28 Oct 2006) | 5 lines
Fix crash in test on HP-UX. Apparently, it's not possible to delete a lock if
it's held (even by the current thread).
Will backport.
........
r52504 | neal.norwitz | 2006-10-28 23:19:07 +0200 (Sat, 28 Oct 2006) | 6 lines
Fix bug #1565514, SystemError not raised on too many nested blocks.
It seems like this should be a different error than SystemError, but
I don't have any great ideas and SystemError was raised in 2.4 and earlier.
Will backport.
........
r52505 | neal.norwitz | 2006-10-28 23:20:12 +0200 (Sat, 28 Oct 2006) | 4 lines
Prevent crash if alloc of garbage fails. Found by Typo.pl.
Will backport.
........
r52506 | neal.norwitz | 2006-10-28 23:21:00 +0200 (Sat, 28 Oct 2006) | 4 lines
Don't inline Py_ADDRESS_IN_RANGE with gcc 4+ either.
Will backport.
........
r52513 | neal.norwitz | 2006-10-28 23:56:49 +0200 (Sat, 28 Oct 2006) | 2 lines
Fix test_modulefinder so it doesn't fail when run after test_distutils.
........
r52514 | neal.norwitz | 2006-10-29 00:12:26 +0200 (Sun, 29 Oct 2006) | 4 lines
From SF 1557890, fix problem of using wrong type in example.
Will backport.
........
r52517 | georg.brandl | 2006-10-29 09:39:22 +0100 (Sun, 29 Oct 2006) | 4 lines
Fix codecs.EncodedFile which did not use file_encoding in 2.5.0, and
fix all codecs file wrappers to work correctly with the "with"
statement (bug #1586513).
........
r52519 | georg.brandl | 2006-10-29 09:47:08 +0100 (Sun, 29 Oct 2006) | 3 lines
Clean up a leftover from old listcomp generation code.
........
r52520 | georg.brandl | 2006-10-29 09:53:06 +0100 (Sun, 29 Oct 2006) | 4 lines
Bug #1586448: the compiler module now emits the same bytecode for
list comprehensions as the builtin compiler, using the LIST_APPEND
opcode.
........
r52521 | georg.brandl | 2006-10-29 10:01:01 +0100 (Sun, 29 Oct 2006) | 3 lines
Remove trailing comma.
........
r52522 | georg.brandl | 2006-10-29 10:05:04 +0100 (Sun, 29 Oct 2006) | 3 lines
Bug #1357915: allow all sequence types for shell arguments in
subprocess.
........
r52524 | georg.brandl | 2006-10-29 10:16:12 +0100 (Sun, 29 Oct 2006) | 3 lines
Patch #1583880: fix tarfile's problems with long names and posix/
GNU modes.
........
r52526 | georg.brandl | 2006-10-29 10:18:00 +0100 (Sun, 29 Oct 2006) | 3 lines
Test assert if __debug__ is true.
........
r52527 | georg.brandl | 2006-10-29 10:32:16 +0100 (Sun, 29 Oct 2006) | 2 lines
Fix the new EncodedFile test to work with big endian platforms.
........
r52529 | georg.brandl | 2006-10-29 15:39:09 +0100 (Sun, 29 Oct 2006) | 2 lines
Bug #1586613: fix zlib and bz2 codecs' incremental en/decoders.
........
r52532 | georg.brandl | 2006-10-29 19:01:08 +0100 (Sun, 29 Oct 2006) | 2 lines
Bug #1586773: extend hashlib docstring.
........
r52534 | neal.norwitz | 2006-10-29 19:30:10 +0100 (Sun, 29 Oct 2006) | 4 lines
Update comments, remove commented out code.
Move assembler structure next to assembler code to make it easier to
move it to a separate file.
........
r52535 | georg.brandl | 2006-10-29 19:31:42 +0100 (Sun, 29 Oct 2006) | 3 lines
Bug #1576657: when setting a KeyError for a tuple key, make sure that
the tuple isn't used as the "exception arguments tuple".
........
r52537 | georg.brandl | 2006-10-29 20:13:40 +0100 (Sun, 29 Oct 2006) | 3 lines
Convert test_mmap to unittest.
........
r52538 | georg.brandl | 2006-10-29 20:20:45 +0100 (Sun, 29 Oct 2006) | 3 lines
Convert test_poll to unittest.
........
r52539 | georg.brandl | 2006-10-29 20:24:43 +0100 (Sun, 29 Oct 2006) | 3 lines
Convert test_nis to unittest.
........
r52540 | georg.brandl | 2006-10-29 20:35:03 +0100 (Sun, 29 Oct 2006) | 3 lines
Convert test_types to unittest.
........
r52541 | georg.brandl | 2006-10-29 20:51:16 +0100 (Sun, 29 Oct 2006) | 3 lines
Convert test_cookie to unittest.
........
r52542 | georg.brandl | 2006-10-29 21:09:12 +0100 (Sun, 29 Oct 2006) | 3 lines
Convert test_cgi to unittest.
........
r52543 | georg.brandl | 2006-10-29 21:24:01 +0100 (Sun, 29 Oct 2006) | 3 lines
Completely convert test_httplib to unittest.
........
r52544 | georg.brandl | 2006-10-29 21:28:26 +0100 (Sun, 29 Oct 2006) | 2 lines
Convert test_MimeWriter to unittest.
........
r52545 | georg.brandl | 2006-10-29 21:31:17 +0100 (Sun, 29 Oct 2006) | 3 lines
Convert test_openpty to unittest.
........
r52546 | georg.brandl | 2006-10-29 21:35:12 +0100 (Sun, 29 Oct 2006) | 3 lines
Remove leftover test output file.
........
r52547 | georg.brandl | 2006-10-29 22:54:18 +0100 (Sun, 29 Oct 2006) | 3 lines
Move the check for openpty to the beginning.
........
r52548 | walter.doerwald | 2006-10-29 23:06:28 +0100 (Sun, 29 Oct 2006) | 2 lines
Add tests for basic argument errors.
........
r52549 | walter.doerwald | 2006-10-30 00:02:27 +0100 (Mon, 30 Oct 2006) | 3 lines
Add tests for incremental codecs with an errors
argument.
........
r52550 | neal.norwitz | 2006-10-30 00:39:03 +0100 (Mon, 30 Oct 2006) | 1 line
Fix refleak
........
r52552 | neal.norwitz | 2006-10-30 00:58:36 +0100 (Mon, 30 Oct 2006) | 1 line
I'm assuming this is correct, it fixes the tests so they pass again
........
r52555 | vinay.sajip | 2006-10-31 18:32:37 +0100 (Tue, 31 Oct 2006) | 1 line
Change to improve speed of _fixupChildren
........
r52556 | vinay.sajip | 2006-10-31 18:34:31 +0100 (Tue, 31 Oct 2006) | 1 line
Added relativeCreated to Formatter doc (has been in the system for a long time - was unaccountably left out of the docs and not noticed until now).
........
r52588 | thomas.heller | 2006-11-02 20:48:24 +0100 (Thu, 02 Nov 2006) | 5 lines
Replace the XXX marker in the 'Arrays and pointers' reference manual
section with a link to the tutorial sections.
Will backport to release25-maint.
........
r52592 | thomas.heller | 2006-11-02 21:22:29 +0100 (Thu, 02 Nov 2006) | 6 lines
Fix a code example by adding a missing import.
Fixes #1557890.
Will backport to release25-maint.
........
r52598 | tim.peters | 2006-11-03 03:32:46 +0100 (Fri, 03 Nov 2006) | 2 lines
Whitespace normalization.
........
r52619 | martin.v.loewis | 2006-11-04 19:14:06 +0100 (Sat, 04 Nov 2006) | 4 lines
- Patch #1060577: Extract list of RPM files from spec file in
bdist_rpm
Will backport to 2.5.
........
r52621 | neal.norwitz | 2006-11-04 20:25:22 +0100 (Sat, 04 Nov 2006) | 4 lines
Bug #1588287: fix invalid assertion for `1,2` in debug builds.
Will backport
........
r52630 | andrew.kuchling | 2006-11-05 22:04:37 +0100 (Sun, 05 Nov 2006) | 1 line
Update link
........
r52631 | skip.montanaro | 2006-11-06 15:34:52 +0100 (Mon, 06 Nov 2006) | 1 line
note that user can control directory location even if default dir is used
........
r52644 | ronald.oussoren | 2006-11-07 16:53:38 +0100 (Tue, 07 Nov 2006) | 2 lines
Fix a number of typos in strings and comments (sf#1589070)
........
r52647 | ronald.oussoren | 2006-11-07 17:00:34 +0100 (Tue, 07 Nov 2006) | 2 lines
Whitespace changes to make the source more compliant with PEP8 (SF#1589070)
........
r52651 | thomas.heller | 2006-11-07 19:01:18 +0100 (Tue, 07 Nov 2006) | 3 lines
Fix markup.
Will backport to release25-maint.
........
r52653 | thomas.heller | 2006-11-07 19:20:47 +0100 (Tue, 07 Nov 2006) | 3 lines
Fix grammatical error as well.
Will backport to release25-maint.
........
r52657 | andrew.kuchling | 2006-11-07 21:39:16 +0100 (Tue, 07 Nov 2006) | 1 line
Add missing word
........
r52662 | martin.v.loewis | 2006-11-08 07:46:37 +0100 (Wed, 08 Nov 2006) | 4 lines
Correctly forward exception in instance_contains().
Fixes #1591996. Patch contributed by Neal Norwitz.
Will backport.
........
r52664 | martin.v.loewis | 2006-11-08 07:48:36 +0100 (Wed, 08 Nov 2006) | 2 lines
News entry for 52662.
........
r52665 | martin.v.loewis | 2006-11-08 08:35:55 +0100 (Wed, 08 Nov 2006) | 2 lines
Patch #1351744: Add askyesnocancel helper for tkMessageBox.
........
r52666 | georg.brandl | 2006-11-08 08:45:59 +0100 (Wed, 08 Nov 2006) | 2 lines
Patch #1592072: fix docs for return value of PyErr_CheckSignals.
........
r52668 | georg.brandl | 2006-11-08 11:04:29 +0100 (Wed, 08 Nov 2006) | 3 lines
Bug #1592533: rename variable in heapq doc example, to avoid shadowing
"sorted".
........
r52671 | andrew.kuchling | 2006-11-08 14:35:34 +0100 (Wed, 08 Nov 2006) | 1 line
Add section on the functional module
........
r52672 | andrew.kuchling | 2006-11-08 15:14:30 +0100 (Wed, 08 Nov 2006) | 1 line
Add section on operator module; make a few edits
........
r52673 | andrew.kuchling | 2006-11-08 15:24:03 +0100 (Wed, 08 Nov 2006) | 1 line
Add table of contents; this required fixing a few headings. Some more smalle edits.
........
r52674 | andrew.kuchling | 2006-11-08 15:30:14 +0100 (Wed, 08 Nov 2006) | 1 line
More edits
........
r52686 | martin.v.loewis | 2006-11-09 12:06:03 +0100 (Thu, 09 Nov 2006) | 3 lines
Patch #838546: Make terminal become controlling in pty.fork().
Will backport to 2.5.
........
r52688 | martin.v.loewis | 2006-11-09 12:27:32 +0100 (Thu, 09 Nov 2006) | 2 lines
Patch #1592250: Add elidge argument to Tkinter.Text.search.
........
r52690 | andrew.kuchling | 2006-11-09 14:27:07 +0100 (Thu, 09 Nov 2006) | 7 lines
[Bug #1569790] mailbox.Maildir.get_folder() loses factory information
Both the Maildir and MH classes had this bug; the patch fixes both classes
and adds a test.
Will backport to 25-maint.
........
r52692 | andrew.kuchling | 2006-11-09 14:51:14 +0100 (Thu, 09 Nov 2006) | 1 line
[Patch #1514544 by David Watson] use fsync() to ensure data is really on disk
........
r52695 | walter.doerwald | 2006-11-09 17:23:26 +0100 (Thu, 09 Nov 2006) | 2 lines
Replace C++ comment with C comment (fixes SF bug #1593525).
........
r52712 | andrew.kuchling | 2006-11-09 22:16:46 +0100 (Thu, 09 Nov 2006) | 11 lines
[Patch #1514543] mailbox (Maildir): avoid losing messages on name clash
Two changes:
Where possible, use link()/remove() to move files into a directory; this
makes it easier to avoid overwriting an existing file.
Use _create_carefully() to create files in tmp/, which uses O_EXCL.
Backport candidate.
........
r52716 | phillip.eby | 2006-11-10 01:33:36 +0100 (Fri, 10 Nov 2006) | 4 lines
Fix SF#1566719: not creating site-packages (or other target directory) when
installing .egg-info for a project that contains no modules or packages,
while using --root (as in bdist_rpm).
........
r52719 | andrew.kuchling | 2006-11-10 14:14:01 +0100 (Fri, 10 Nov 2006) | 1 line
Reword entry
........
r52725 | andrew.kuchling | 2006-11-10 15:39:01 +0100 (Fri, 10 Nov 2006) | 1 line
[Feature request #1542920] Link to wsgi.org
........
r52731 | georg.brandl | 2006-11-11 19:29:11 +0100 (Sat, 11 Nov 2006) | 2 lines
Bug #1594742: wrong word in stringobject doc.
........
r52733 | georg.brandl | 2006-11-11 19:32:47 +0100 (Sat, 11 Nov 2006) | 2 lines
Bug #1594758: wording improvement for dict.update() docs.
........
r52736 | martin.v.loewis | 2006-11-12 11:32:47 +0100 (Sun, 12 Nov 2006) | 3 lines
Patch #1065257: Support passing open files as body in
HTTPConnection.request().
........
r52737 | martin.v.loewis | 2006-11-12 11:41:39 +0100 (Sun, 12 Nov 2006) | 2 lines
Patch #1355023: support whence argument for GzipFile.seek.
........
r52738 | martin.v.loewis | 2006-11-12 19:24:26 +0100 (Sun, 12 Nov 2006) | 2 lines
Bug #1067760: Deprecate passing floats to file.seek.
........
r52739 | martin.v.loewis | 2006-11-12 19:48:13 +0100 (Sun, 12 Nov 2006) | 3 lines
Patch #1359217: Ignore 2xx response before 150 response.
Will backport to 2.5.
........
r52741 | martin.v.loewis | 2006-11-12 19:56:03 +0100 (Sun, 12 Nov 2006) | 4 lines
Patch #1360200: Use unmangled_version RPM spec field to deal with
file name mangling.
Will backport to 2.5.
........
r52753 | walter.doerwald | 2006-11-15 17:23:46 +0100 (Wed, 15 Nov 2006) | 2 lines
Fix typo.
........
r52754 | georg.brandl | 2006-11-15 18:42:03 +0100 (Wed, 15 Nov 2006) | 2 lines
Bug #1594809: add a note to README regarding PYTHONPATH and make install.
........
r52762 | georg.brandl | 2006-11-16 16:05:14 +0100 (Thu, 16 Nov 2006) | 2 lines
Bug #1597576: mention that the new base64 api has been introduced in py2.4.
........
r52764 | georg.brandl | 2006-11-16 17:50:59 +0100 (Thu, 16 Nov 2006) | 3 lines
Bug #1597824: return the registered function from atexit.register()
to facilitate usage as a decorator.
........
r52765 | georg.brandl | 2006-11-16 18:08:45 +0100 (Thu, 16 Nov 2006) | 4 lines
Bug #1588217: don't parse "= " as a soft line break in binascii's
a2b_qp() function, instead leave it in the string as quopri.decode()
does.
........
r52776 | andrew.kuchling | 2006-11-17 14:30:25 +0100 (Fri, 17 Nov 2006) | 17 lines
Remove file-locking in MH.pack() method.
This change looks massive but it's mostly a re-indenting after
removing some try...finally blocks.
Also adds a test case that does a pack() while the mailbox is locked; this
test would have turned up bugs in the original code on some platforms.
In both nmh and GNU Mailutils' implementation of MH-format mailboxes,
no locking is done of individual message files when renaming them.
The original mailbox.py code did do locking, which meant that message
files had to be opened. This code was buggy on certain platforms
(found through reading the code); there were code paths that closed
the file object and then called _unlock_file() on it.
Will backport to 25-maint once I see how the buildbots react to this patch.
........
r52780 | martin.v.loewis | 2006-11-18 19:00:23 +0100 (Sat, 18 Nov 2006) | 5 lines
Patch #1538878: Don't make tkSimpleDialog dialogs transient if
the parent window is withdrawn. This mirrors what dialog.tcl
does.
Will backport to 2.5.
........
r52782 | martin.v.loewis | 2006-11-18 19:05:35 +0100 (Sat, 18 Nov 2006) | 4 lines
Patch #1594554: Always close a tkSimpleDialog on ok(), even
if an exception occurs.
Will backport to 2.5.
........
r52784 | martin.v.loewis | 2006-11-18 19:42:11 +0100 (Sat, 18 Nov 2006) | 3 lines
Patch #1472877: Fix Tix subwidget name resolution.
Will backport to 2.5.
........
r52786 | andrew.kuchling | 2006-11-18 23:17:33 +0100 (Sat, 18 Nov 2006) | 1 line
Expand checking in test_sha
........
r52787 | georg.brandl | 2006-11-19 09:48:30 +0100 (Sun, 19 Nov 2006) | 3 lines
Patch [ 1586791 ] better error msgs for some TypeErrors
........
r52788 | martin.v.loewis | 2006-11-19 11:41:41 +0100 (Sun, 19 Nov 2006) | 4 lines
Make cStringIO.truncate raise IOError for negative
arguments (even for -1). Fixes the last bit of
#1359365.
........
r52789 | andrew.kuchling | 2006-11-19 19:40:01 +0100 (Sun, 19 Nov 2006) | 1 line
Add a test case of data w/ bytes > 127
........
r52790 | martin.v.loewis | 2006-11-19 19:51:54 +0100 (Sun, 19 Nov 2006) | 3 lines
Patch #1070046: Marshal new-style objects like InstanceType
in xmlrpclib.
........
r52792 | neal.norwitz | 2006-11-19 22:26:53 +0100 (Sun, 19 Nov 2006) | 4 lines
Speed up function calls into the math module by using METH_O.
There should be no functional changes. However, the error msgs are
slightly different. Also verified that the module dict is not NULL on init.
........
r52794 | george.yoshida | 2006-11-20 03:24:48 +0100 (Mon, 20 Nov 2006) | 2 lines
markup fix
........
r52795 | georg.brandl | 2006-11-20 08:12:58 +0100 (Mon, 20 Nov 2006) | 3 lines
Further markup fix.
........
r52800 | andrew.kuchling | 2006-11-20 14:39:37 +0100 (Mon, 20 Nov 2006) | 2 lines
Jython compatibility fix: if uu.decode() opened its output file, be sure to
close it.
........
r52811 | neal.norwitz | 2006-11-21 06:26:22 +0100 (Tue, 21 Nov 2006) | 9 lines
Bug #1599782: Fix segfault on bsddb.db.DB().type().
The problem is that _DB_get_type() can't be called without the GIL
because it calls a bunch of PyErr_* APIs when an error occurs.
There were no other cases in this file that it was called without the GIL.
Removing the BEGIN/END THREAD around _DB_get_type() made everything work.
Will backport.
........
r52814 | neal.norwitz | 2006-11-21 06:51:51 +0100 (Tue, 21 Nov 2006) | 1 line
Oops, convert tabs to spaces
........
r52815 | neal.norwitz | 2006-11-21 07:23:44 +0100 (Tue, 21 Nov 2006) | 1 line
Fix SF #1599879, socket.gethostname should ref getfqdn directly.
........
r52817 | martin.v.loewis | 2006-11-21 19:20:25 +0100 (Tue, 21 Nov 2006) | 4 lines
Conditionalize definition of _CRT_SECURE_NO_DEPRECATE
and _CRT_NONSTDC_NO_DEPRECATE.
Will backport.
........
r52821 | martin.v.loewis | 2006-11-22 09:50:02 +0100 (Wed, 22 Nov 2006) | 4 lines
Patch #1362975: Rework CodeContext indentation algorithm to
avoid hard-coding pixel widths. Also make the text's scrollbar
a child of the text frame, not the top widget.
........
r52826 | walter.doerwald | 2006-11-23 06:03:56 +0100 (Thu, 23 Nov 2006) | 3 lines
Change decode() so that it works with a buffer (i.e. unicode(..., 'utf-8-sig'))
SF bug #1601501.
........
r52833 | georg.brandl | 2006-11-23 10:55:07 +0100 (Thu, 23 Nov 2006) | 2 lines
Bug #1601630: little improvement to getopt docs
........
r52835 | michael.hudson | 2006-11-23 14:54:04 +0100 (Thu, 23 Nov 2006) | 3 lines
a test for an error condition not covered by existing tests
(noticed this when writing the equivalent code for pypy)
........
r52839 | raymond.hettinger | 2006-11-23 22:06:03 +0100 (Thu, 23 Nov 2006) | 1 line
Fix and/add typo
........
r52840 | raymond.hettinger | 2006-11-23 22:35:19 +0100 (Thu, 23 Nov 2006) | 1 line
... and the number of the counting shall be three.
........
r52841 | thomas.heller | 2006-11-24 19:45:39 +0100 (Fri, 24 Nov 2006) | 1 line
Fix bug #1598620: A ctypes structure cannot contain itself.
........
r52843 | martin.v.loewis | 2006-11-25 16:39:19 +0100 (Sat, 25 Nov 2006) | 3 lines
Disable _XOPEN_SOURCE on NetBSD 1.x.
Will backport to 2.5
........
r52845 | georg.brandl | 2006-11-26 20:27:47 +0100 (Sun, 26 Nov 2006) | 2 lines
Bug #1603321: make pstats.Stats accept Unicode file paths.
........
r52850 | georg.brandl | 2006-11-27 19:46:21 +0100 (Mon, 27 Nov 2006) | 2 lines
Bug #1603789: grammatical error in Tkinter docs.
........
r52855 | thomas.heller | 2006-11-28 21:21:54 +0100 (Tue, 28 Nov 2006) | 7 lines
Fix #1563807: _ctypes built on AIX fails with ld ffi error.
The contents of ffi_darwin.c must be compiled unless __APPLE__ is
defined and __ppc__ is not.
Will backport.
........
r52862 | armin.rigo | 2006-11-29 22:59:22 +0100 (Wed, 29 Nov 2006) | 3 lines
Forgot a case where the locals can now be a general mapping
instead of just a dictionary. (backporting...)
........
r52872 | guido.van.rossum | 2006-11-30 20:23:13 +0100 (Thu, 30 Nov 2006) | 2 lines
Update version.
........
r52890 | walter.doerwald | 2006-12-01 17:59:47 +0100 (Fri, 01 Dec 2006) | 3 lines
Move xdrlib tests from the module into a separate test script,
port the tests to unittest and add a few new tests.
........
r52900 | raymond.hettinger | 2006-12-02 03:00:39 +0100 (Sat, 02 Dec 2006) | 1 line
Add name to credits (for untokenize).
........
r52905 | martin.v.loewis | 2006-12-03 10:54:46 +0100 (Sun, 03 Dec 2006) | 2 lines
Move IDLE news into NEWS.txt.
........
r52906 | martin.v.loewis | 2006-12-03 12:23:45 +0100 (Sun, 03 Dec 2006) | 4 lines
Patch #1544279: Improve thread-safety of the socket module by moving
the sock_addr_t storage out of the socket object.
Will backport to 2.5.
........
r52908 | martin.v.loewis | 2006-12-03 13:01:53 +0100 (Sun, 03 Dec 2006) | 3 lines
Patch #1371075: Make ConfigParser accept optional dict type
for ordering, sorting, etc.
........
r52910 | matthias.klose | 2006-12-03 18:16:41 +0100 (Sun, 03 Dec 2006) | 2 lines
- Fix build failure on kfreebsd and on the hurd.
........
r52915 | george.yoshida | 2006-12-04 12:41:54 +0100 (Mon, 04 Dec 2006) | 2 lines
fix a versionchanged tag
........
r52917 | george.yoshida | 2006-12-05 06:39:50 +0100 (Tue, 05 Dec 2006) | 3 lines
Fix pickle doc typo
Patch #1608758
........
r52938 | georg.brandl | 2006-12-06 23:21:18 +0100 (Wed, 06 Dec 2006) | 2 lines
Patch #1610437: fix a tarfile bug with long filename headers.
........
r52945 | brett.cannon | 2006-12-07 00:38:48 +0100 (Thu, 07 Dec 2006) | 3 lines
Fix a bad assumption that all objects assigned to '__loader__' on a module
will have a '_files' attribute.
........
r52951 | georg.brandl | 2006-12-07 10:30:06 +0100 (Thu, 07 Dec 2006) | 3 lines
RFE #1592899: mention string.maketrans() in docs for str.translate,
remove reference to the old regex module in the former's doc.
........
r52962 | raymond.hettinger | 2006-12-08 04:17:18 +0100 (Fri, 08 Dec 2006) | 1 line
Eliminate two redundant calls to PyObject_Hash().
........
r52963 | raymond.hettinger | 2006-12-08 05:24:33 +0100 (Fri, 08 Dec 2006) | 3 lines
Port Armin's fix for a dict resize vulnerability (svn revision 46589, sf bug 1456209).
........
r52964 | raymond.hettinger | 2006-12-08 05:57:50 +0100 (Fri, 08 Dec 2006) | 4 lines
Port Georg's dictobject.c fix keys that were tuples got unpacked on the way to setting a KeyError (svn revision 52535, sf bug
1576657).
........
r52966 | raymond.hettinger | 2006-12-08 18:35:25 +0100 (Fri, 08 Dec 2006) | 2 lines
Add test for SF bug 1576657
........
r52970 | georg.brandl | 2006-12-08 21:46:11 +0100 (Fri, 08 Dec 2006) | 3 lines
#1577756: svnversion doesn't react to LANG=C, use LC_ALL=C to force
English output.
........
r52972 | georg.brandl | 2006-12-09 10:08:29 +0100 (Sat, 09 Dec 2006) | 3 lines
Patch #1608267: fix a race condition in os.makedirs() is the directory
to be created is already there.
........
r52975 | matthias.klose | 2006-12-09 13:15:27 +0100 (Sat, 09 Dec 2006) | 2 lines
- Fix the build of the library reference in info format.
........
r52994 | neal.norwitz | 2006-12-11 02:01:06 +0100 (Mon, 11 Dec 2006) | 1 line
Fix a typo
........
r52996 | georg.brandl | 2006-12-11 08:56:33 +0100 (Mon, 11 Dec 2006) | 2 lines
Move errno imports back to individual functions.
........
r52998 | vinay.sajip | 2006-12-11 15:07:16 +0100 (Mon, 11 Dec 2006) | 1 line
Patch by Jeremy Katz (SF #1609407)
........
r53000 | vinay.sajip | 2006-12-11 15:26:23 +0100 (Mon, 11 Dec 2006) | 1 line
Patch by "cuppatea" (SF #1503765)
........
2006-12-13 04:49:30 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (Py_SIZE(self) == 0) {
|
|
|
|
|
/* Special-case most common failure cause */
|
|
|
|
|
PyErr_SetString(PyExc_IndexError, "pop from empty list");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (i < 0)
|
|
|
|
|
i += Py_SIZE(self);
|
|
|
|
|
if (i < 0 || i >= Py_SIZE(self)) {
|
|
|
|
|
PyErr_SetString(PyExc_IndexError, "pop index out of range");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v = self->ob_item[i];
|
|
|
|
|
if (i == Py_SIZE(self) - 1) {
|
|
|
|
|
status = list_resize(self, Py_SIZE(self) - 1);
|
|
|
|
|
assert(status >= 0);
|
|
|
|
|
return v; /* and v now owns the reference the list had */
|
|
|
|
|
}
|
|
|
|
|
Py_INCREF(v);
|
|
|
|
|
status = list_ass_slice(self, i, i+1, (PyObject *)NULL);
|
|
|
|
|
assert(status >= 0);
|
|
|
|
|
/* Use status, so that in a release build compilers don't
|
|
|
|
|
* complain about the unused name.
|
|
|
|
|
*/
|
|
|
|
|
(void) status;
|
2004-08-08 21:21:18 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
return v;
|
1998-06-30 15:36:32 +00:00
|
|
|
}
|
|
|
|
|
|
2002-07-19 02:33:08 +00:00
|
|
|
/* Reverse a slice of a list in place, from lo up to (exclusive) hi. */
|
|
|
|
|
static void
|
|
|
|
|
reverse_slice(PyObject **lo, PyObject **hi)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(lo && hi);
|
2002-07-19 02:33:08 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
--hi;
|
|
|
|
|
while (lo < hi) {
|
|
|
|
|
PyObject *t = *lo;
|
|
|
|
|
*lo = *hi;
|
|
|
|
|
*hi = t;
|
|
|
|
|
++lo;
|
|
|
|
|
--hi;
|
|
|
|
|
}
|
2002-07-19 02:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
/* Lots of code for an adaptive, stable, natural mergesort. There are many
|
|
|
|
|
* pieces to this algorithm; read listsort.txt for overviews and details.
|
|
|
|
|
*/
|
1996-12-10 23:55:39 +00:00
|
|
|
|
2008-01-30 20:15:17 +00:00
|
|
|
/* Comparison function: PyObject_RichCompareBool with Py_LT.
|
2002-08-01 02:13:36 +00:00
|
|
|
* Returns -1 on error, 1 if x < y, 0 if x >= y.
|
|
|
|
|
*/
|
1996-12-10 23:55:39 +00:00
|
|
|
|
2008-01-30 20:15:17 +00:00
|
|
|
#define ISLT(X, Y) (PyObject_RichCompareBool(X, Y, Py_LT))
|
2002-08-04 17:47:26 +00:00
|
|
|
|
|
|
|
|
/* Compare X to Y via "<". Goto "fail" if the comparison raises an
|
2002-07-19 03:30:57 +00:00
|
|
|
error. Else "k" is set to true iff X<Y, and an "if (k)" block is
|
|
|
|
|
started. It makes more sense in context <wink>. X and Y are PyObject*s.
|
|
|
|
|
*/
|
2008-01-30 20:15:17 +00:00
|
|
|
#define IFLT(X, Y) if ((k = ISLT(X, Y)) < 0) goto fail; \
|
2010-05-09 15:52:27 +00:00
|
|
|
if (k)
|
1998-06-16 15:18:28 +00:00
|
|
|
|
|
|
|
|
/* binarysort is the best method for sorting small arrays: it does
|
|
|
|
|
few compares, but can do data movement quadratic in the number of
|
|
|
|
|
elements.
|
1998-06-17 14:15:44 +00:00
|
|
|
[lo, hi) is a contiguous slice of a list, and is sorted via
|
2002-07-19 03:30:57 +00:00
|
|
|
binary insertion. This sort is stable.
|
1998-06-16 15:18:28 +00:00
|
|
|
On entry, must have lo <= start <= hi, and that [lo, start) is already
|
|
|
|
|
sorted (pass start == lo if you don't know!).
|
2002-07-19 03:30:57 +00:00
|
|
|
If islt() complains return -1, else 0.
|
1998-06-16 15:18:28 +00:00
|
|
|
Even in case of error, the output slice will be some permutation of
|
|
|
|
|
the input (nothing is lost or duplicated).
|
|
|
|
|
*/
|
1996-12-10 23:55:39 +00:00
|
|
|
static int
|
2008-01-30 20:15:17 +00:00
|
|
|
binarysort(PyObject **lo, PyObject **hi, PyObject **start)
|
1996-12-10 23:55:39 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
register Py_ssize_t k;
|
|
|
|
|
register PyObject **l, **p, **r;
|
|
|
|
|
register PyObject *pivot;
|
1997-12-10 15:14:24 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(lo <= start && start <= hi);
|
|
|
|
|
/* assert [lo, start) is sorted */
|
|
|
|
|
if (lo == start)
|
|
|
|
|
++start;
|
|
|
|
|
for (; start < hi; ++start) {
|
|
|
|
|
/* set l to where *start belongs */
|
|
|
|
|
l = lo;
|
|
|
|
|
r = start;
|
|
|
|
|
pivot = *r;
|
|
|
|
|
/* Invariants:
|
|
|
|
|
* pivot >= all in [lo, l).
|
|
|
|
|
* pivot < all in [r, start).
|
|
|
|
|
* The second is vacuously true at the start.
|
|
|
|
|
*/
|
|
|
|
|
assert(l < r);
|
|
|
|
|
do {
|
|
|
|
|
p = l + ((r - l) >> 1);
|
|
|
|
|
IFLT(pivot, *p)
|
|
|
|
|
r = p;
|
|
|
|
|
else
|
|
|
|
|
l = p+1;
|
|
|
|
|
} while (l < r);
|
|
|
|
|
assert(l == r);
|
|
|
|
|
/* The invariants still hold, so pivot >= all in [lo, l) and
|
|
|
|
|
pivot < all in [l, start), so pivot belongs at l. Note
|
|
|
|
|
that if there are elements equal to pivot, l points to the
|
|
|
|
|
first slot after them -- that's why this sort is stable.
|
|
|
|
|
Slide over to make room.
|
|
|
|
|
Caution: using memmove is much slower under MSVC 5;
|
|
|
|
|
we're not usually moving many slots. */
|
|
|
|
|
for (p = start; p > l; --p)
|
|
|
|
|
*p = *(p-1);
|
|
|
|
|
*l = pivot;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
1998-05-29 17:56:32 +00:00
|
|
|
|
|
|
|
|
fail:
|
2010-05-09 15:52:27 +00:00
|
|
|
return -1;
|
1998-06-16 15:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
/*
|
|
|
|
|
Return the length of the run beginning at lo, in the slice [lo, hi). lo < hi
|
|
|
|
|
is required on entry. "A run" is the longest ascending sequence, with
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
lo[0] <= lo[1] <= lo[2] <= ...
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
or the longest descending sequence, with
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
lo[0] > lo[1] > lo[2] > ...
|
2002-07-19 02:35:45 +00:00
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
Boolean *descending is set to 0 in the former case, or to 1 in the latter.
|
|
|
|
|
For its intended use in a stable mergesort, the strictness of the defn of
|
|
|
|
|
"descending" is needed so that the caller can safely reverse a descending
|
|
|
|
|
sequence without violating stability (strict > ensures there are no equal
|
|
|
|
|
elements to get out of order).
|
|
|
|
|
|
|
|
|
|
Returns -1 in case of error.
|
1998-06-16 15:18:28 +00:00
|
|
|
*/
|
2006-02-15 17:27:45 +00:00
|
|
|
static Py_ssize_t
|
2008-01-30 20:15:17 +00:00
|
|
|
count_run(PyObject **lo, PyObject **hi, int *descending)
|
1998-06-16 15:18:28 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t k;
|
|
|
|
|
Py_ssize_t n;
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(lo < hi);
|
|
|
|
|
*descending = 0;
|
|
|
|
|
++lo;
|
|
|
|
|
if (lo == hi)
|
|
|
|
|
return 1;
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
n = 2;
|
|
|
|
|
IFLT(*lo, *(lo-1)) {
|
|
|
|
|
*descending = 1;
|
|
|
|
|
for (lo = lo+1; lo < hi; ++lo, ++n) {
|
|
|
|
|
IFLT(*lo, *(lo-1))
|
|
|
|
|
;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (lo = lo+1; lo < hi; ++lo, ++n) {
|
|
|
|
|
IFLT(*lo, *(lo-1))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
return n;
|
2002-08-01 02:13:36 +00:00
|
|
|
fail:
|
2010-05-09 15:52:27 +00:00
|
|
|
return -1;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
/*
|
|
|
|
|
Locate the proper position of key in a sorted vector; if the vector contains
|
|
|
|
|
an element equal to key, return the position immediately to the left of
|
|
|
|
|
the leftmost equal element. [gallop_right() does the same except returns
|
|
|
|
|
the position to the right of the rightmost equal element (if any).]
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
"a" is a sorted vector with n elements, starting at a[0]. n must be > 0.
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
"hint" is an index at which to begin the search, 0 <= hint < n. The closer
|
|
|
|
|
hint is to the final result, the faster this runs.
|
|
|
|
|
|
|
|
|
|
The return value is the int k in 0..n such that
|
|
|
|
|
|
|
|
|
|
a[k-1] < key <= a[k]
|
|
|
|
|
|
|
|
|
|
pretending that *(a-1) is minus infinity and a[n] is plus infinity. IOW,
|
|
|
|
|
key belongs at index k; or, IOW, the first k elements of a should precede
|
|
|
|
|
key, and the last n-k should follow key.
|
|
|
|
|
|
|
|
|
|
Returns -1 on error. See listsort.txt for info on the method.
|
|
|
|
|
*/
|
2006-02-15 17:27:45 +00:00
|
|
|
static Py_ssize_t
|
2008-01-30 20:15:17 +00:00
|
|
|
gallop_left(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint)
|
2002-08-01 02:13:36 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t ofs;
|
|
|
|
|
Py_ssize_t lastofs;
|
|
|
|
|
Py_ssize_t k;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(key && a && n > 0 && hint >= 0 && hint < n);
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
a += hint;
|
|
|
|
|
lastofs = 0;
|
|
|
|
|
ofs = 1;
|
|
|
|
|
IFLT(*a, key) {
|
|
|
|
|
/* a[hint] < key -- gallop right, until
|
|
|
|
|
* a[hint + lastofs] < key <= a[hint + ofs]
|
|
|
|
|
*/
|
|
|
|
|
const Py_ssize_t maxofs = n - hint; /* &a[n-1] is highest */
|
|
|
|
|
while (ofs < maxofs) {
|
|
|
|
|
IFLT(a[ofs], key) {
|
|
|
|
|
lastofs = ofs;
|
|
|
|
|
ofs = (ofs << 1) + 1;
|
|
|
|
|
if (ofs <= 0) /* int overflow */
|
|
|
|
|
ofs = maxofs;
|
|
|
|
|
}
|
|
|
|
|
else /* key <= a[hint + ofs] */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ofs > maxofs)
|
|
|
|
|
ofs = maxofs;
|
|
|
|
|
/* Translate back to offsets relative to &a[0]. */
|
|
|
|
|
lastofs += hint;
|
|
|
|
|
ofs += hint;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* key <= a[hint] -- gallop left, until
|
|
|
|
|
* a[hint - ofs] < key <= a[hint - lastofs]
|
|
|
|
|
*/
|
|
|
|
|
const Py_ssize_t maxofs = hint + 1; /* &a[0] is lowest */
|
|
|
|
|
while (ofs < maxofs) {
|
|
|
|
|
IFLT(*(a-ofs), key)
|
|
|
|
|
break;
|
|
|
|
|
/* key <= a[hint - ofs] */
|
|
|
|
|
lastofs = ofs;
|
|
|
|
|
ofs = (ofs << 1) + 1;
|
|
|
|
|
if (ofs <= 0) /* int overflow */
|
|
|
|
|
ofs = maxofs;
|
|
|
|
|
}
|
|
|
|
|
if (ofs > maxofs)
|
|
|
|
|
ofs = maxofs;
|
|
|
|
|
/* Translate back to positive offsets relative to &a[0]. */
|
|
|
|
|
k = lastofs;
|
|
|
|
|
lastofs = hint - ofs;
|
|
|
|
|
ofs = hint - k;
|
|
|
|
|
}
|
|
|
|
|
a -= hint;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(-1 <= lastofs && lastofs < ofs && ofs <= n);
|
|
|
|
|
/* Now a[lastofs] < key <= a[ofs], so key belongs somewhere to the
|
|
|
|
|
* right of lastofs but no farther right than ofs. Do a binary
|
|
|
|
|
* search, with invariant a[lastofs-1] < key <= a[ofs].
|
|
|
|
|
*/
|
|
|
|
|
++lastofs;
|
|
|
|
|
while (lastofs < ofs) {
|
|
|
|
|
Py_ssize_t m = lastofs + ((ofs - lastofs) >> 1);
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
IFLT(a[m], key)
|
|
|
|
|
lastofs = m+1; /* a[m] < key */
|
|
|
|
|
else
|
|
|
|
|
ofs = m; /* key <= a[m] */
|
|
|
|
|
}
|
|
|
|
|
assert(lastofs == ofs); /* so a[ofs-1] < key <= a[ofs] */
|
|
|
|
|
return ofs;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
|
|
|
|
fail:
|
2010-05-09 15:52:27 +00:00
|
|
|
return -1;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Exactly like gallop_left(), except that if key already exists in a[0:n],
|
|
|
|
|
finds the position immediately to the right of the rightmost equal value.
|
|
|
|
|
|
|
|
|
|
The return value is the int k in 0..n such that
|
|
|
|
|
|
|
|
|
|
a[k-1] <= key < a[k]
|
|
|
|
|
|
|
|
|
|
or -1 if error.
|
|
|
|
|
|
|
|
|
|
The code duplication is massive, but this is enough different given that
|
|
|
|
|
we're sticking to "<" comparisons that it's much harder to follow if
|
|
|
|
|
written as one routine with yet another "left or right?" flag.
|
|
|
|
|
*/
|
2006-02-15 17:27:45 +00:00
|
|
|
static Py_ssize_t
|
2008-01-30 20:15:17 +00:00
|
|
|
gallop_right(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint)
|
2002-08-01 02:13:36 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t ofs;
|
|
|
|
|
Py_ssize_t lastofs;
|
|
|
|
|
Py_ssize_t k;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(key && a && n > 0 && hint >= 0 && hint < n);
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
a += hint;
|
|
|
|
|
lastofs = 0;
|
|
|
|
|
ofs = 1;
|
|
|
|
|
IFLT(key, *a) {
|
|
|
|
|
/* key < a[hint] -- gallop left, until
|
|
|
|
|
* a[hint - ofs] <= key < a[hint - lastofs]
|
|
|
|
|
*/
|
|
|
|
|
const Py_ssize_t maxofs = hint + 1; /* &a[0] is lowest */
|
|
|
|
|
while (ofs < maxofs) {
|
|
|
|
|
IFLT(key, *(a-ofs)) {
|
|
|
|
|
lastofs = ofs;
|
|
|
|
|
ofs = (ofs << 1) + 1;
|
|
|
|
|
if (ofs <= 0) /* int overflow */
|
|
|
|
|
ofs = maxofs;
|
|
|
|
|
}
|
|
|
|
|
else /* a[hint - ofs] <= key */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ofs > maxofs)
|
|
|
|
|
ofs = maxofs;
|
|
|
|
|
/* Translate back to positive offsets relative to &a[0]. */
|
|
|
|
|
k = lastofs;
|
|
|
|
|
lastofs = hint - ofs;
|
|
|
|
|
ofs = hint - k;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* a[hint] <= key -- gallop right, until
|
|
|
|
|
* a[hint + lastofs] <= key < a[hint + ofs]
|
|
|
|
|
*/
|
|
|
|
|
const Py_ssize_t maxofs = n - hint; /* &a[n-1] is highest */
|
|
|
|
|
while (ofs < maxofs) {
|
|
|
|
|
IFLT(key, a[ofs])
|
|
|
|
|
break;
|
|
|
|
|
/* a[hint + ofs] <= key */
|
|
|
|
|
lastofs = ofs;
|
|
|
|
|
ofs = (ofs << 1) + 1;
|
|
|
|
|
if (ofs <= 0) /* int overflow */
|
|
|
|
|
ofs = maxofs;
|
|
|
|
|
}
|
|
|
|
|
if (ofs > maxofs)
|
|
|
|
|
ofs = maxofs;
|
|
|
|
|
/* Translate back to offsets relative to &a[0]. */
|
|
|
|
|
lastofs += hint;
|
|
|
|
|
ofs += hint;
|
|
|
|
|
}
|
|
|
|
|
a -= hint;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(-1 <= lastofs && lastofs < ofs && ofs <= n);
|
|
|
|
|
/* Now a[lastofs] <= key < a[ofs], so key belongs somewhere to the
|
|
|
|
|
* right of lastofs but no farther right than ofs. Do a binary
|
|
|
|
|
* search, with invariant a[lastofs-1] <= key < a[ofs].
|
|
|
|
|
*/
|
|
|
|
|
++lastofs;
|
|
|
|
|
while (lastofs < ofs) {
|
|
|
|
|
Py_ssize_t m = lastofs + ((ofs - lastofs) >> 1);
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
IFLT(key, a[m])
|
|
|
|
|
ofs = m; /* key < a[m] */
|
|
|
|
|
else
|
|
|
|
|
lastofs = m+1; /* a[m] <= key */
|
|
|
|
|
}
|
|
|
|
|
assert(lastofs == ofs); /* so a[ofs-1] <= key < a[ofs] */
|
|
|
|
|
return ofs;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
|
|
|
|
fail:
|
2010-05-09 15:52:27 +00:00
|
|
|
return -1;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The maximum number of entries in a MergeState's pending-runs stack.
|
|
|
|
|
* This is enough to sort arrays of size up to about
|
|
|
|
|
* 32 * phi ** MAX_MERGE_PENDING
|
|
|
|
|
* where phi ~= 1.618. 85 is ridiculouslylarge enough, good for an array
|
|
|
|
|
* with 2**64 elements.
|
|
|
|
|
*/
|
|
|
|
|
#define MAX_MERGE_PENDING 85
|
|
|
|
|
|
2002-08-10 05:21:15 +00:00
|
|
|
/* When we get into galloping mode, we stay there until both runs win less
|
|
|
|
|
* often than MIN_GALLOP consecutive times. See listsort.txt for more info.
|
2002-08-01 02:13:36 +00:00
|
|
|
*/
|
2002-08-10 05:21:15 +00:00
|
|
|
#define MIN_GALLOP 7
|
2002-08-01 02:13:36 +00:00
|
|
|
|
|
|
|
|
/* Avoid malloc for small temp arrays. */
|
|
|
|
|
#define MERGESTATE_TEMP_SIZE 256
|
|
|
|
|
|
|
|
|
|
/* One MergeState exists on the stack per invocation of mergesort. It's just
|
|
|
|
|
* a convenient way to pass state around among the helper functions.
|
|
|
|
|
*/
|
2002-08-10 05:21:15 +00:00
|
|
|
struct s_slice {
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject **base;
|
|
|
|
|
Py_ssize_t len;
|
2002-08-10 05:21:15 +00:00
|
|
|
};
|
|
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
typedef struct s_MergeState {
|
2010-05-09 15:52:27 +00:00
|
|
|
/* This controls when we get *into* galloping mode. It's initialized
|
|
|
|
|
* to MIN_GALLOP. merge_lo and merge_hi tend to nudge it higher for
|
|
|
|
|
* random data, and lower for highly structured data.
|
|
|
|
|
*/
|
|
|
|
|
Py_ssize_t min_gallop;
|
2002-08-10 05:21:15 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* 'a' is temp storage to help with merges. It contains room for
|
|
|
|
|
* alloced entries.
|
|
|
|
|
*/
|
|
|
|
|
PyObject **a; /* may point to temparray below */
|
|
|
|
|
Py_ssize_t alloced;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* A stack of n pending runs yet to be merged. Run #i starts at
|
|
|
|
|
* address base[i] and extends for len[i] elements. It's always
|
|
|
|
|
* true (so long as the indices are in bounds) that
|
|
|
|
|
*
|
|
|
|
|
* pending[i].base + pending[i].len == pending[i+1].base
|
|
|
|
|
*
|
|
|
|
|
* so we could cut the storage for this, but it's a minor amount,
|
|
|
|
|
* and keeping all the info explicit simplifies the code.
|
|
|
|
|
*/
|
|
|
|
|
int n;
|
|
|
|
|
struct s_slice pending[MAX_MERGE_PENDING];
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* 'a' points to this when possible, rather than muck with malloc. */
|
|
|
|
|
PyObject *temparray[MERGESTATE_TEMP_SIZE];
|
2002-08-01 02:13:36 +00:00
|
|
|
} MergeState;
|
|
|
|
|
|
|
|
|
|
/* Conceptually a MergeState's constructor. */
|
|
|
|
|
static void
|
2008-01-30 20:15:17 +00:00
|
|
|
merge_init(MergeState *ms)
|
2002-08-01 02:13:36 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(ms != NULL);
|
|
|
|
|
ms->a = ms->temparray;
|
|
|
|
|
ms->alloced = MERGESTATE_TEMP_SIZE;
|
|
|
|
|
ms->n = 0;
|
|
|
|
|
ms->min_gallop = MIN_GALLOP;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free all the temp memory owned by the MergeState. This must be called
|
|
|
|
|
* when you're done with a MergeState, and may be called before then if
|
|
|
|
|
* you want to free the temp memory early.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
merge_freemem(MergeState *ms)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(ms != NULL);
|
|
|
|
|
if (ms->a != ms->temparray)
|
|
|
|
|
PyMem_Free(ms->a);
|
|
|
|
|
ms->a = ms->temparray;
|
|
|
|
|
ms->alloced = MERGESTATE_TEMP_SIZE;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ensure enough temp memory for 'need' array slots is available.
|
|
|
|
|
* Returns 0 on success and -1 if the memory can't be gotten.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2006-02-15 17:27:45 +00:00
|
|
|
merge_getmem(MergeState *ms, Py_ssize_t need)
|
2002-08-01 02:13:36 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(ms != NULL);
|
|
|
|
|
if (need <= ms->alloced)
|
|
|
|
|
return 0;
|
|
|
|
|
/* Don't realloc! That can cost cycles to copy the old data, but
|
|
|
|
|
* we don't care what's in the block.
|
|
|
|
|
*/
|
|
|
|
|
merge_freemem(ms);
|
|
|
|
|
if ((size_t)need > PY_SSIZE_T_MAX / sizeof(PyObject*)) {
|
|
|
|
|
PyErr_NoMemory();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
ms->a = (PyObject **)PyMem_Malloc(need * sizeof(PyObject*));
|
|
|
|
|
if (ms->a) {
|
|
|
|
|
ms->alloced = need;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
PyErr_NoMemory();
|
|
|
|
|
merge_freemem(ms); /* reset to sane state */
|
|
|
|
|
return -1;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
2010-05-09 15:52:27 +00:00
|
|
|
#define MERGE_GETMEM(MS, NEED) ((NEED) <= (MS)->alloced ? 0 : \
|
|
|
|
|
merge_getmem(MS, NEED))
|
2002-08-01 02:13:36 +00:00
|
|
|
|
|
|
|
|
/* Merge the na elements starting at pa with the nb elements starting at pb
|
|
|
|
|
* in a stable way, in-place. na and nb must be > 0, and pa + na == pb.
|
|
|
|
|
* Must also have that *pb < *pa, that pa[na-1] belongs at the end of the
|
|
|
|
|
* merge, and should have na <= nb. See listsort.txt for more info.
|
|
|
|
|
* Return 0 if successful, -1 if error.
|
|
|
|
|
*/
|
2006-02-15 17:27:45 +00:00
|
|
|
static Py_ssize_t
|
|
|
|
|
merge_lo(MergeState *ms, PyObject **pa, Py_ssize_t na,
|
|
|
|
|
PyObject **pb, Py_ssize_t nb)
|
2002-08-01 02:13:36 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t k;
|
|
|
|
|
PyObject **dest;
|
|
|
|
|
int result = -1; /* guilty until proved innocent */
|
|
|
|
|
Py_ssize_t min_gallop;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(ms && pa && pb && na > 0 && nb > 0 && pa + na == pb);
|
|
|
|
|
if (MERGE_GETMEM(ms, na) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
memcpy(ms->a, pa, na * sizeof(PyObject*));
|
|
|
|
|
dest = pa;
|
|
|
|
|
pa = ms->a;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
*dest++ = *pb++;
|
|
|
|
|
--nb;
|
|
|
|
|
if (nb == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
if (na == 1)
|
|
|
|
|
goto CopyB;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
min_gallop = ms->min_gallop;
|
|
|
|
|
for (;;) {
|
|
|
|
|
Py_ssize_t acount = 0; /* # of times A won in a row */
|
|
|
|
|
Py_ssize_t bcount = 0; /* # of times B won in a row */
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Do the straightforward thing until (if ever) one run
|
|
|
|
|
* appears to win consistently.
|
|
|
|
|
*/
|
|
|
|
|
for (;;) {
|
|
|
|
|
assert(na > 1 && nb > 0);
|
|
|
|
|
k = ISLT(*pb, *pa);
|
|
|
|
|
if (k) {
|
|
|
|
|
if (k < 0)
|
|
|
|
|
goto Fail;
|
|
|
|
|
*dest++ = *pb++;
|
|
|
|
|
++bcount;
|
|
|
|
|
acount = 0;
|
|
|
|
|
--nb;
|
|
|
|
|
if (nb == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
if (bcount >= min_gallop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*dest++ = *pa++;
|
|
|
|
|
++acount;
|
|
|
|
|
bcount = 0;
|
|
|
|
|
--na;
|
|
|
|
|
if (na == 1)
|
|
|
|
|
goto CopyB;
|
|
|
|
|
if (acount >= min_gallop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* One run is winning so consistently that galloping may
|
|
|
|
|
* be a huge win. So try that, and continue galloping until
|
|
|
|
|
* (if ever) neither run appears to be winning consistently
|
|
|
|
|
* anymore.
|
|
|
|
|
*/
|
|
|
|
|
++min_gallop;
|
|
|
|
|
do {
|
|
|
|
|
assert(na > 1 && nb > 0);
|
|
|
|
|
min_gallop -= min_gallop > 1;
|
|
|
|
|
ms->min_gallop = min_gallop;
|
|
|
|
|
k = gallop_right(*pb, pa, na, 0);
|
|
|
|
|
acount = k;
|
|
|
|
|
if (k) {
|
|
|
|
|
if (k < 0)
|
|
|
|
|
goto Fail;
|
|
|
|
|
memcpy(dest, pa, k * sizeof(PyObject *));
|
|
|
|
|
dest += k;
|
|
|
|
|
pa += k;
|
|
|
|
|
na -= k;
|
|
|
|
|
if (na == 1)
|
|
|
|
|
goto CopyB;
|
|
|
|
|
/* na==0 is impossible now if the comparison
|
|
|
|
|
* function is consistent, but we can't assume
|
|
|
|
|
* that it is.
|
|
|
|
|
*/
|
|
|
|
|
if (na == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
}
|
|
|
|
|
*dest++ = *pb++;
|
|
|
|
|
--nb;
|
|
|
|
|
if (nb == 0)
|
|
|
|
|
goto Succeed;
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
k = gallop_left(*pa, pb, nb, 0);
|
|
|
|
|
bcount = k;
|
|
|
|
|
if (k) {
|
|
|
|
|
if (k < 0)
|
|
|
|
|
goto Fail;
|
|
|
|
|
memmove(dest, pb, k * sizeof(PyObject *));
|
|
|
|
|
dest += k;
|
|
|
|
|
pb += k;
|
|
|
|
|
nb -= k;
|
|
|
|
|
if (nb == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
}
|
|
|
|
|
*dest++ = *pa++;
|
|
|
|
|
--na;
|
|
|
|
|
if (na == 1)
|
|
|
|
|
goto CopyB;
|
|
|
|
|
} while (acount >= MIN_GALLOP || bcount >= MIN_GALLOP);
|
|
|
|
|
++min_gallop; /* penalize it for leaving galloping mode */
|
|
|
|
|
ms->min_gallop = min_gallop;
|
|
|
|
|
}
|
2002-08-01 02:13:36 +00:00
|
|
|
Succeed:
|
2010-05-09 15:52:27 +00:00
|
|
|
result = 0;
|
2002-08-01 02:13:36 +00:00
|
|
|
Fail:
|
2010-05-09 15:52:27 +00:00
|
|
|
if (na)
|
|
|
|
|
memcpy(dest, pa, na * sizeof(PyObject*));
|
|
|
|
|
return result;
|
2002-08-01 02:13:36 +00:00
|
|
|
CopyB:
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(na == 1 && nb > 0);
|
|
|
|
|
/* The last element of pa belongs at the end of the merge. */
|
|
|
|
|
memmove(dest, pb, nb * sizeof(PyObject *));
|
|
|
|
|
dest[nb] = *pa;
|
|
|
|
|
return 0;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
/* Merge the na elements starting at pa with the nb elements starting at pb
|
|
|
|
|
* in a stable way, in-place. na and nb must be > 0, and pa + na == pb.
|
|
|
|
|
* Must also have that *pb < *pa, that pa[na-1] belongs at the end of the
|
|
|
|
|
* merge, and should have na >= nb. See listsort.txt for more info.
|
|
|
|
|
* Return 0 if successful, -1 if error.
|
|
|
|
|
*/
|
2006-02-15 17:27:45 +00:00
|
|
|
static Py_ssize_t
|
|
|
|
|
merge_hi(MergeState *ms, PyObject **pa, Py_ssize_t na, PyObject **pb, Py_ssize_t nb)
|
2002-08-01 02:13:36 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t k;
|
|
|
|
|
PyObject **dest;
|
|
|
|
|
int result = -1; /* guilty until proved innocent */
|
|
|
|
|
PyObject **basea;
|
|
|
|
|
PyObject **baseb;
|
|
|
|
|
Py_ssize_t min_gallop;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(ms && pa && pb && na > 0 && nb > 0 && pa + na == pb);
|
|
|
|
|
if (MERGE_GETMEM(ms, nb) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
dest = pb + nb - 1;
|
|
|
|
|
memcpy(ms->a, pb, nb * sizeof(PyObject*));
|
|
|
|
|
basea = pa;
|
|
|
|
|
baseb = ms->a;
|
|
|
|
|
pb = ms->a + nb - 1;
|
|
|
|
|
pa += na - 1;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
*dest-- = *pa--;
|
|
|
|
|
--na;
|
|
|
|
|
if (na == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
if (nb == 1)
|
|
|
|
|
goto CopyA;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
min_gallop = ms->min_gallop;
|
|
|
|
|
for (;;) {
|
|
|
|
|
Py_ssize_t acount = 0; /* # of times A won in a row */
|
|
|
|
|
Py_ssize_t bcount = 0; /* # of times B won in a row */
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Do the straightforward thing until (if ever) one run
|
|
|
|
|
* appears to win consistently.
|
|
|
|
|
*/
|
|
|
|
|
for (;;) {
|
|
|
|
|
assert(na > 0 && nb > 1);
|
|
|
|
|
k = ISLT(*pb, *pa);
|
|
|
|
|
if (k) {
|
|
|
|
|
if (k < 0)
|
|
|
|
|
goto Fail;
|
|
|
|
|
*dest-- = *pa--;
|
|
|
|
|
++acount;
|
|
|
|
|
bcount = 0;
|
|
|
|
|
--na;
|
|
|
|
|
if (na == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
if (acount >= min_gallop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*dest-- = *pb--;
|
|
|
|
|
++bcount;
|
|
|
|
|
acount = 0;
|
|
|
|
|
--nb;
|
|
|
|
|
if (nb == 1)
|
|
|
|
|
goto CopyA;
|
|
|
|
|
if (bcount >= min_gallop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* One run is winning so consistently that galloping may
|
|
|
|
|
* be a huge win. So try that, and continue galloping until
|
|
|
|
|
* (if ever) neither run appears to be winning consistently
|
|
|
|
|
* anymore.
|
|
|
|
|
*/
|
|
|
|
|
++min_gallop;
|
|
|
|
|
do {
|
|
|
|
|
assert(na > 0 && nb > 1);
|
|
|
|
|
min_gallop -= min_gallop > 1;
|
|
|
|
|
ms->min_gallop = min_gallop;
|
|
|
|
|
k = gallop_right(*pb, basea, na, na-1);
|
|
|
|
|
if (k < 0)
|
|
|
|
|
goto Fail;
|
|
|
|
|
k = na - k;
|
|
|
|
|
acount = k;
|
|
|
|
|
if (k) {
|
|
|
|
|
dest -= k;
|
|
|
|
|
pa -= k;
|
|
|
|
|
memmove(dest+1, pa+1, k * sizeof(PyObject *));
|
|
|
|
|
na -= k;
|
|
|
|
|
if (na == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
}
|
|
|
|
|
*dest-- = *pb--;
|
|
|
|
|
--nb;
|
|
|
|
|
if (nb == 1)
|
|
|
|
|
goto CopyA;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
k = gallop_left(*pa, baseb, nb, nb-1);
|
|
|
|
|
if (k < 0)
|
|
|
|
|
goto Fail;
|
|
|
|
|
k = nb - k;
|
|
|
|
|
bcount = k;
|
|
|
|
|
if (k) {
|
|
|
|
|
dest -= k;
|
|
|
|
|
pb -= k;
|
|
|
|
|
memcpy(dest+1, pb+1, k * sizeof(PyObject *));
|
|
|
|
|
nb -= k;
|
|
|
|
|
if (nb == 1)
|
|
|
|
|
goto CopyA;
|
|
|
|
|
/* nb==0 is impossible now if the comparison
|
|
|
|
|
* function is consistent, but we can't assume
|
|
|
|
|
* that it is.
|
|
|
|
|
*/
|
|
|
|
|
if (nb == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
}
|
|
|
|
|
*dest-- = *pa--;
|
|
|
|
|
--na;
|
|
|
|
|
if (na == 0)
|
|
|
|
|
goto Succeed;
|
|
|
|
|
} while (acount >= MIN_GALLOP || bcount >= MIN_GALLOP);
|
|
|
|
|
++min_gallop; /* penalize it for leaving galloping mode */
|
|
|
|
|
ms->min_gallop = min_gallop;
|
|
|
|
|
}
|
2002-08-01 02:13:36 +00:00
|
|
|
Succeed:
|
2010-05-09 15:52:27 +00:00
|
|
|
result = 0;
|
2002-08-01 02:13:36 +00:00
|
|
|
Fail:
|
2010-05-09 15:52:27 +00:00
|
|
|
if (nb)
|
|
|
|
|
memcpy(dest-(nb-1), baseb, nb * sizeof(PyObject*));
|
|
|
|
|
return result;
|
2002-08-01 02:13:36 +00:00
|
|
|
CopyA:
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(nb == 1 && na > 0);
|
|
|
|
|
/* The first element of pb belongs at the front of the merge. */
|
|
|
|
|
dest -= na;
|
|
|
|
|
pa -= na;
|
|
|
|
|
memmove(dest+1, pa+1, na * sizeof(PyObject *));
|
|
|
|
|
*dest = *pb;
|
|
|
|
|
return 0;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Merge the two runs at stack indices i and i+1.
|
|
|
|
|
* Returns 0 on success, -1 on error.
|
|
|
|
|
*/
|
2006-02-15 17:27:45 +00:00
|
|
|
static Py_ssize_t
|
|
|
|
|
merge_at(MergeState *ms, Py_ssize_t i)
|
2002-08-01 02:13:36 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject **pa, **pb;
|
|
|
|
|
Py_ssize_t na, nb;
|
|
|
|
|
Py_ssize_t k;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(ms != NULL);
|
|
|
|
|
assert(ms->n >= 2);
|
|
|
|
|
assert(i >= 0);
|
|
|
|
|
assert(i == ms->n - 2 || i == ms->n - 3);
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
pa = ms->pending[i].base;
|
|
|
|
|
na = ms->pending[i].len;
|
|
|
|
|
pb = ms->pending[i+1].base;
|
|
|
|
|
nb = ms->pending[i+1].len;
|
|
|
|
|
assert(na > 0 && nb > 0);
|
|
|
|
|
assert(pa + na == pb);
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Record the length of the combined runs; if i is the 3rd-last
|
|
|
|
|
* run now, also slide over the last run (which isn't involved
|
|
|
|
|
* in this merge). The current run i+1 goes away in any case.
|
|
|
|
|
*/
|
|
|
|
|
ms->pending[i].len = na + nb;
|
|
|
|
|
if (i == ms->n - 3)
|
|
|
|
|
ms->pending[i+1] = ms->pending[i+2];
|
|
|
|
|
--ms->n;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Where does b start in a? Elements in a before that can be
|
|
|
|
|
* ignored (already in place).
|
|
|
|
|
*/
|
|
|
|
|
k = gallop_right(*pb, pa, na, 0);
|
|
|
|
|
if (k < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
pa += k;
|
|
|
|
|
na -= k;
|
|
|
|
|
if (na == 0)
|
|
|
|
|
return 0;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Where does a end in b? Elements in b after that can be
|
|
|
|
|
* ignored (already in place).
|
|
|
|
|
*/
|
|
|
|
|
nb = gallop_left(pa[na-1], pb, nb, nb-1);
|
|
|
|
|
if (nb <= 0)
|
|
|
|
|
return nb;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Merge what remains of the runs, using a temp array with
|
|
|
|
|
* min(na, nb) elements.
|
|
|
|
|
*/
|
|
|
|
|
if (na <= nb)
|
|
|
|
|
return merge_lo(ms, pa, na, pb, nb);
|
|
|
|
|
else
|
|
|
|
|
return merge_hi(ms, pa, na, pb, nb);
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Examine the stack of runs waiting to be merged, merging adjacent runs
|
|
|
|
|
* until the stack invariants are re-established:
|
|
|
|
|
*
|
|
|
|
|
* 1. len[-3] > len[-2] + len[-1]
|
|
|
|
|
* 2. len[-2] > len[-1]
|
|
|
|
|
*
|
|
|
|
|
* See listsort.txt for more info.
|
|
|
|
|
*
|
|
|
|
|
* Returns 0 on success, -1 on error.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
merge_collapse(MergeState *ms)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
struct s_slice *p = ms->pending;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(ms);
|
|
|
|
|
while (ms->n > 1) {
|
|
|
|
|
Py_ssize_t n = ms->n - 2;
|
|
|
|
|
if (n > 0 && p[n-1].len <= p[n].len + p[n+1].len) {
|
|
|
|
|
if (p[n-1].len < p[n+1].len)
|
|
|
|
|
--n;
|
|
|
|
|
if (merge_at(ms, n) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else if (p[n].len <= p[n+1].len) {
|
|
|
|
|
if (merge_at(ms, n) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Regardless of invariants, merge all runs on the stack until only one
|
|
|
|
|
* remains. This is used at the end of the mergesort.
|
|
|
|
|
*
|
|
|
|
|
* Returns 0 on success, -1 on error.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
merge_force_collapse(MergeState *ms)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
struct s_slice *p = ms->pending;
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(ms);
|
|
|
|
|
while (ms->n > 1) {
|
|
|
|
|
Py_ssize_t n = ms->n - 2;
|
|
|
|
|
if (n > 0 && p[n-1].len < p[n+1].len)
|
|
|
|
|
--n;
|
|
|
|
|
if (merge_at(ms, n) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2002-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Compute a good value for the minimum run length; natural runs shorter
|
|
|
|
|
* than this are boosted artificially via binary insertion.
|
|
|
|
|
*
|
|
|
|
|
* If n < 64, return n (it's too small to bother with fancy stuff).
|
|
|
|
|
* Else if n is an exact power of 2, return 32.
|
|
|
|
|
* Else return an int k, 32 <= k <= 64, such that n/k is close to, but
|
|
|
|
|
* strictly less than, an exact power of 2.
|
|
|
|
|
*
|
|
|
|
|
* See listsort.txt for more info.
|
|
|
|
|
*/
|
2006-02-15 17:27:45 +00:00
|
|
|
static Py_ssize_t
|
|
|
|
|
merge_compute_minrun(Py_ssize_t n)
|
2002-08-01 02:13:36 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t r = 0; /* becomes 1 if any 1 bits are shifted off */
|
2002-08-01 02:13:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(n >= 0);
|
|
|
|
|
while (n >= 64) {
|
|
|
|
|
r |= n & 1;
|
|
|
|
|
n >>= 1;
|
|
|
|
|
}
|
|
|
|
|
return n + r;
|
1998-06-16 15:18:28 +00:00
|
|
|
}
|
1998-05-29 17:56:32 +00:00
|
|
|
|
2003-10-16 03:41:09 +00:00
|
|
|
/* Special wrapper to support stable sorting using the decorate-sort-undecorate
|
2004-09-10 12:59:54 +00:00
|
|
|
pattern. Holds a key which is used for comparisons and the original record
|
2004-07-29 02:29:26 +00:00
|
|
|
which is returned during the undecorate phase. By exposing only the key
|
|
|
|
|
during comparisons, the underlying sort stability characteristics are left
|
2008-01-30 20:15:17 +00:00
|
|
|
unchanged. Also, the comparison function will only see the key instead of
|
|
|
|
|
a full record. */
|
2003-10-16 03:41:09 +00:00
|
|
|
|
|
|
|
|
typedef struct {
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject_HEAD
|
|
|
|
|
PyObject *key;
|
|
|
|
|
PyObject *value;
|
2003-10-16 03:41:09 +00:00
|
|
|
} sortwrapperobject;
|
|
|
|
|
|
|
|
|
|
PyDoc_STRVAR(sortwrapper_doc, "Object wrapper with a custom sort key.");
|
2006-04-21 10:40:58 +00:00
|
|
|
static PyObject *
|
|
|
|
|
sortwrapper_richcompare(sortwrapperobject *, sortwrapperobject *, int);
|
|
|
|
|
static void
|
|
|
|
|
sortwrapper_dealloc(sortwrapperobject *);
|
2003-10-16 03:41:09 +00:00
|
|
|
|
2007-11-29 22:35:39 +00:00
|
|
|
PyTypeObject PySortWrapper_Type = {
|
2010-05-09 15:52:27 +00:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
|
"sortwrapper", /* tp_name */
|
|
|
|
|
sizeof(sortwrapperobject), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
/* methods */
|
|
|
|
|
(destructor)sortwrapper_dealloc, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
0, /* tp_getattr */
|
|
|
|
|
0, /* tp_setattr */
|
|
|
|
|
0, /* tp_reserved */
|
|
|
|
|
0, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_hash */
|
|
|
|
|
0, /* tp_call */
|
|
|
|
|
0, /* tp_str */
|
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
|
0, /* tp_setattro */
|
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
|
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|
|
|
|
sortwrapper_doc, /* tp_doc */
|
|
|
|
|
0, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
(richcmpfunc)sortwrapper_richcompare, /* tp_richcompare */
|
2003-10-16 03:41:09 +00:00
|
|
|
};
|
|
|
|
|
|
2006-04-21 10:40:58 +00:00
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
sortwrapper_richcompare(sortwrapperobject *a, sortwrapperobject *b, int op)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyObject_TypeCheck(b, &PySortWrapper_Type)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"expected a sortwrapperobject");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return PyObject_RichCompare(a->key, b->key, op);
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sortwrapper_dealloc(sortwrapperobject *so)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_XDECREF(so->key);
|
|
|
|
|
Py_XDECREF(so->value);
|
|
|
|
|
PyObject_Del(so);
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
2003-10-16 03:41:09 +00:00
|
|
|
/* Returns a new reference to a sortwrapper.
|
|
|
|
|
Consumes the references to the two underlying objects. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
build_sortwrapper(PyObject *key, PyObject *value)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
sortwrapperobject *so;
|
2004-07-29 02:29:26 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
so = PyObject_New(sortwrapperobject, &PySortWrapper_Type);
|
|
|
|
|
if (so == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
so->key = key;
|
|
|
|
|
so->value = value;
|
|
|
|
|
return (PyObject *)so;
|
2003-10-16 03:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns a new reference to the value underlying the wrapper. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
sortwrapper_getvalue(PyObject *so)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject *value;
|
2003-10-16 03:41:09 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyObject_TypeCheck(so, &PySortWrapper_Type)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"expected a sortwrapperobject");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
value = ((sortwrapperobject *)so)->value;
|
|
|
|
|
Py_INCREF(value);
|
|
|
|
|
return value;
|
2003-10-16 03:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-01 02:13:36 +00:00
|
|
|
/* An adaptive, stable, natural mergesort. See listsort.txt.
|
|
|
|
|
* Returns Py_None on success, NULL on error. Even in case of error, the
|
|
|
|
|
* list will be some permutation of its input state (nothing is lost or
|
|
|
|
|
* duplicated).
|
|
|
|
|
*/
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2003-10-16 03:41:09 +00:00
|
|
|
listsort(PyListObject *self, PyObject *args, PyObject *kwds)
|
1996-12-10 23:55:39 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
MergeState ms;
|
|
|
|
|
PyObject **lo, **hi;
|
|
|
|
|
Py_ssize_t nremaining;
|
|
|
|
|
Py_ssize_t minrun;
|
|
|
|
|
Py_ssize_t saved_ob_size, saved_allocated;
|
|
|
|
|
PyObject **saved_ob_item;
|
|
|
|
|
PyObject **final_ob_item;
|
|
|
|
|
PyObject *result = NULL; /* guilty until proved innocent */
|
|
|
|
|
int reverse = 0;
|
|
|
|
|
PyObject *keyfunc = NULL;
|
|
|
|
|
Py_ssize_t i;
|
|
|
|
|
PyObject *key, *value, *kvpair;
|
|
|
|
|
static char *kwlist[] = {"key", "reverse", 0};
|
1998-06-16 15:18:28 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(self != NULL);
|
|
|
|
|
assert (PyList_Check(self));
|
|
|
|
|
if (args != NULL) {
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:sort",
|
|
|
|
|
kwlist, &keyfunc, &reverse))
|
|
|
|
|
return NULL;
|
|
|
|
|
if (Py_SIZE(args) > 0) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"must use keyword argument for key function");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (keyfunc == Py_None)
|
|
|
|
|
keyfunc = NULL;
|
2003-10-16 03:41:09 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* The list is temporarily made empty, so that mutations performed
|
|
|
|
|
* by comparison functions can't affect the slice of memory we're
|
|
|
|
|
* sorting (allowing mutations during sorting is a core-dump
|
|
|
|
|
* factory, since ob_item may change).
|
|
|
|
|
*/
|
|
|
|
|
saved_ob_size = Py_SIZE(self);
|
|
|
|
|
saved_ob_item = self->ob_item;
|
|
|
|
|
saved_allocated = self->allocated;
|
|
|
|
|
Py_SIZE(self) = 0;
|
|
|
|
|
self->ob_item = NULL;
|
|
|
|
|
self->allocated = -1; /* any operation will reset it to >= 0 */
|
2002-07-19 07:05:44 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (keyfunc != NULL) {
|
|
|
|
|
for (i=0 ; i < saved_ob_size ; i++) {
|
|
|
|
|
value = saved_ob_item[i];
|
|
|
|
|
key = PyObject_CallFunctionObjArgs(keyfunc, value,
|
|
|
|
|
NULL);
|
|
|
|
|
if (key == NULL) {
|
|
|
|
|
for (i=i-1 ; i>=0 ; i--) {
|
|
|
|
|
kvpair = saved_ob_item[i];
|
|
|
|
|
value = sortwrapper_getvalue(kvpair);
|
|
|
|
|
saved_ob_item[i] = value;
|
|
|
|
|
Py_DECREF(kvpair);
|
|
|
|
|
}
|
|
|
|
|
goto dsu_fail;
|
|
|
|
|
}
|
|
|
|
|
kvpair = build_sortwrapper(key, value);
|
|
|
|
|
if (kvpair == NULL)
|
|
|
|
|
goto dsu_fail;
|
|
|
|
|
saved_ob_item[i] = kvpair;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-04 11:25:46 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Reverse sort stability achieved by initially reversing the list,
|
|
|
|
|
applying a stable forward sort, then reversing the final result. */
|
|
|
|
|
if (reverse && saved_ob_size > 1)
|
|
|
|
|
reverse_slice(saved_ob_item, saved_ob_item + saved_ob_size);
|
2003-12-04 11:25:46 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
merge_init(&ms);
|
2003-12-04 11:25:46 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
nremaining = saved_ob_size;
|
|
|
|
|
if (nremaining < 2)
|
|
|
|
|
goto succeed;
|
2002-07-19 07:05:44 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* March over the array once, left to right, finding natural runs,
|
|
|
|
|
* and extending short natural runs to minrun elements.
|
|
|
|
|
*/
|
|
|
|
|
lo = saved_ob_item;
|
|
|
|
|
hi = lo + nremaining;
|
|
|
|
|
minrun = merge_compute_minrun(nremaining);
|
|
|
|
|
do {
|
|
|
|
|
int descending;
|
|
|
|
|
Py_ssize_t n;
|
2002-07-19 07:05:44 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Identify next run. */
|
|
|
|
|
n = count_run(lo, hi, &descending);
|
|
|
|
|
if (n < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
if (descending)
|
|
|
|
|
reverse_slice(lo, lo + n);
|
|
|
|
|
/* If short, extend to min(minrun, nremaining). */
|
|
|
|
|
if (n < minrun) {
|
|
|
|
|
const Py_ssize_t force = nremaining <= minrun ?
|
|
|
|
|
nremaining : minrun;
|
|
|
|
|
if (binarysort(lo, lo + force, lo + n) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
n = force;
|
|
|
|
|
}
|
|
|
|
|
/* Push run onto pending-runs stack, and maybe merge. */
|
|
|
|
|
assert(ms.n < MAX_MERGE_PENDING);
|
|
|
|
|
ms.pending[ms.n].base = lo;
|
|
|
|
|
ms.pending[ms.n].len = n;
|
|
|
|
|
++ms.n;
|
|
|
|
|
if (merge_collapse(&ms) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
/* Advance to find next run. */
|
|
|
|
|
lo += n;
|
|
|
|
|
nremaining -= n;
|
|
|
|
|
} while (nremaining);
|
|
|
|
|
assert(lo == hi);
|
2002-07-19 07:05:44 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (merge_force_collapse(&ms) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
assert(ms.n == 1);
|
|
|
|
|
assert(ms.pending[0].base == saved_ob_item);
|
|
|
|
|
assert(ms.pending[0].len == saved_ob_size);
|
2002-08-01 02:13:36 +00:00
|
|
|
|
|
|
|
|
succeed:
|
2010-05-09 15:52:27 +00:00
|
|
|
result = Py_None;
|
2002-07-19 07:05:44 +00:00
|
|
|
fail:
|
2010-05-09 15:52:27 +00:00
|
|
|
if (keyfunc != NULL) {
|
|
|
|
|
for (i=0 ; i < saved_ob_size ; i++) {
|
|
|
|
|
kvpair = saved_ob_item[i];
|
|
|
|
|
value = sortwrapper_getvalue(kvpair);
|
|
|
|
|
saved_ob_item[i] = value;
|
|
|
|
|
Py_DECREF(kvpair);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-04 11:25:46 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (self->allocated != -1 && result != NULL) {
|
|
|
|
|
/* The user mucked with the list during the sort,
|
|
|
|
|
* and we don't already have another error to report.
|
|
|
|
|
*/
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, "list modified during sort");
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
2003-12-04 11:25:46 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (reverse && saved_ob_size > 1)
|
|
|
|
|
reverse_slice(saved_ob_item, saved_ob_item + saved_ob_size);
|
2003-12-04 11:25:46 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
merge_freemem(&ms);
|
2003-12-04 11:25:46 +00:00
|
|
|
|
|
|
|
|
dsu_fail:
|
2010-05-09 15:52:27 +00:00
|
|
|
final_ob_item = self->ob_item;
|
|
|
|
|
i = Py_SIZE(self);
|
|
|
|
|
Py_SIZE(self) = saved_ob_size;
|
|
|
|
|
self->ob_item = saved_ob_item;
|
|
|
|
|
self->allocated = saved_allocated;
|
|
|
|
|
if (final_ob_item != NULL) {
|
|
|
|
|
/* we cannot use list_clear() for this because it does not
|
|
|
|
|
guarantee that the list is really empty when it returns */
|
|
|
|
|
while (--i >= 0) {
|
|
|
|
|
Py_XDECREF(final_ob_item[i]);
|
|
|
|
|
}
|
|
|
|
|
PyMem_FREE(final_ob_item);
|
|
|
|
|
}
|
|
|
|
|
Py_XINCREF(result);
|
|
|
|
|
return result;
|
1996-12-10 23:55:39 +00:00
|
|
|
}
|
2002-07-19 07:05:44 +00:00
|
|
|
#undef IFLT
|
2002-08-04 17:47:26 +00:00
|
|
|
#undef ISLT
|
2002-07-19 07:05:44 +00:00
|
|
|
|
1998-06-16 15:18:28 +00:00
|
|
|
int
|
2000-07-09 15:16:51 +00:00
|
|
|
PyList_Sort(PyObject *v)
|
1998-06-16 15:18:28 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (v == NULL || !PyList_Check(v)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
v = listsort((PyListObject *)v, (PyObject *)NULL, (PyObject *)NULL);
|
|
|
|
|
if (v == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
Py_DECREF(v);
|
|
|
|
|
return 0;
|
1998-06-16 15:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
2001-02-12 22:06:02 +00:00
|
|
|
static PyObject *
|
2001-08-16 13:15:00 +00:00
|
|
|
listreverse(PyListObject *self)
|
2001-02-12 22:06:02 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (Py_SIZE(self) > 1)
|
|
|
|
|
reverse_slice(self->ob_item, self->ob_item + Py_SIZE(self));
|
|
|
|
|
Py_RETURN_NONE;
|
1991-03-06 13:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
1995-01-17 16:34:45 +00:00
|
|
|
int
|
2000-07-09 15:16:51 +00:00
|
|
|
PyList_Reverse(PyObject *v)
|
1995-01-17 16:34:45 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyListObject *self = (PyListObject *)v;
|
2002-08-08 01:06:39 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (v == NULL || !PyList_Check(v)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (Py_SIZE(self) > 1)
|
|
|
|
|
reverse_slice(self->ob_item, self->ob_item + Py_SIZE(self));
|
|
|
|
|
return 0;
|
1995-01-17 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
PyObject *
|
2000-07-09 15:16:51 +00:00
|
|
|
PyList_AsTuple(PyObject *v)
|
1994-08-29 12:45:32 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject *w;
|
|
|
|
|
PyObject **p, **q;
|
|
|
|
|
Py_ssize_t n;
|
|
|
|
|
if (v == NULL || !PyList_Check(v)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
n = Py_SIZE(v);
|
|
|
|
|
w = PyTuple_New(n);
|
|
|
|
|
if (w == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
p = ((PyTupleObject *)w)->ob_item;
|
|
|
|
|
q = ((PyListObject *)v)->ob_item;
|
|
|
|
|
while (--n >= 0) {
|
|
|
|
|
Py_INCREF(*q);
|
|
|
|
|
*p = *q;
|
|
|
|
|
p++;
|
|
|
|
|
q++;
|
|
|
|
|
}
|
|
|
|
|
return w;
|
1994-08-29 12:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2003-06-17 05:05:49 +00:00
|
|
|
listindex(PyListObject *self, PyObject *args)
|
1991-03-06 13:07:53 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i, start=0, stop=Py_SIZE(self);
|
|
|
|
|
PyObject *v, *format_tuple, *err_string;
|
|
|
|
|
static PyObject *err_format = NULL;
|
2000-02-24 15:23:03 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
|
|
|
|
|
_PyEval_SliceIndex, &start,
|
|
|
|
|
_PyEval_SliceIndex, &stop))
|
|
|
|
|
return NULL;
|
|
|
|
|
if (start < 0) {
|
|
|
|
|
start += Py_SIZE(self);
|
|
|
|
|
if (start < 0)
|
|
|
|
|
start = 0;
|
|
|
|
|
}
|
|
|
|
|
if (stop < 0) {
|
|
|
|
|
stop += Py_SIZE(self);
|
|
|
|
|
if (stop < 0)
|
|
|
|
|
stop = 0;
|
|
|
|
|
}
|
|
|
|
|
for (i = start; i < stop && i < Py_SIZE(self); i++) {
|
|
|
|
|
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
|
|
|
|
|
if (cmp > 0)
|
|
|
|
|
return PyLong_FromSsize_t(i);
|
|
|
|
|
else if (cmp < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (err_format == NULL) {
|
|
|
|
|
err_format = PyUnicode_FromString("%r is not in list");
|
|
|
|
|
if (err_format == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
format_tuple = PyTuple_Pack(1, v);
|
|
|
|
|
if (format_tuple == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
err_string = PyUnicode_Format(err_format, format_tuple);
|
|
|
|
|
Py_DECREF(format_tuple);
|
|
|
|
|
if (err_string == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
PyErr_SetObject(PyExc_ValueError, err_string);
|
|
|
|
|
Py_DECREF(err_string);
|
|
|
|
|
return NULL;
|
1991-03-06 13:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2001-08-16 13:15:00 +00:00
|
|
|
listcount(PyListObject *self, PyObject *v)
|
1991-10-20 20:20:40 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t count = 0;
|
|
|
|
|
Py_ssize_t i;
|
2000-02-24 15:23:03 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
for (i = 0; i < Py_SIZE(self); i++) {
|
|
|
|
|
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
|
|
|
|
|
if (cmp > 0)
|
|
|
|
|
count++;
|
|
|
|
|
else if (cmp < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return PyLong_FromSsize_t(count);
|
1991-10-20 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyObject *
|
2001-08-16 13:15:00 +00:00
|
|
|
listremove(PyListObject *self, PyObject *v)
|
1991-03-06 13:07:53 +00:00
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i;
|
2000-02-24 15:23:03 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
for (i = 0; i < Py_SIZE(self); i++) {
|
|
|
|
|
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
|
|
|
|
|
if (cmp > 0) {
|
|
|
|
|
if (list_ass_slice(self, i, i+1,
|
|
|
|
|
(PyObject *)NULL) == 0)
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
else if (cmp < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list");
|
|
|
|
|
return NULL;
|
1991-03-06 13:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:18:11 +00:00
|
|
|
static int
|
|
|
|
|
list_traverse(PyListObject *o, visitproc visit, void *arg)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t i;
|
2000-06-23 14:18:11 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
for (i = Py_SIZE(o); --i >= 0; )
|
|
|
|
|
Py_VISIT(o->ob_item[i]);
|
|
|
|
|
return 0;
|
2000-06-23 14:18:11 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-17 22:11:59 +00:00
|
|
|
static PyObject *
|
|
|
|
|
list_richcompare(PyObject *v, PyObject *w, int op)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyListObject *vl, *wl;
|
|
|
|
|
Py_ssize_t i;
|
2001-01-17 22:11:59 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyList_Check(v) || !PyList_Check(w)) {
|
|
|
|
|
Py_INCREF(Py_NotImplemented);
|
|
|
|
|
return Py_NotImplemented;
|
|
|
|
|
}
|
2001-01-17 22:11:59 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
vl = (PyListObject *)v;
|
|
|
|
|
wl = (PyListObject *)w;
|
2001-01-17 22:11:59 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (Py_SIZE(vl) != Py_SIZE(wl) && (op == Py_EQ || op == Py_NE)) {
|
|
|
|
|
/* Shortcut: if the lengths differ, the lists differ */
|
|
|
|
|
PyObject *res;
|
|
|
|
|
if (op == Py_EQ)
|
|
|
|
|
res = Py_False;
|
|
|
|
|
else
|
|
|
|
|
res = Py_True;
|
|
|
|
|
Py_INCREF(res);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2001-01-17 22:11:59 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Search for the first index where items are different */
|
|
|
|
|
for (i = 0; i < Py_SIZE(vl) && i < Py_SIZE(wl); i++) {
|
|
|
|
|
int k = PyObject_RichCompareBool(vl->ob_item[i],
|
|
|
|
|
wl->ob_item[i], Py_EQ);
|
|
|
|
|
if (k < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
if (!k)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-01-17 22:11:59 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (i >= Py_SIZE(vl) || i >= Py_SIZE(wl)) {
|
|
|
|
|
/* No more items to compare -- compare sizes */
|
|
|
|
|
Py_ssize_t vs = Py_SIZE(vl);
|
|
|
|
|
Py_ssize_t ws = Py_SIZE(wl);
|
|
|
|
|
int cmp;
|
|
|
|
|
PyObject *res;
|
|
|
|
|
switch (op) {
|
|
|
|
|
case Py_LT: cmp = vs < ws; break;
|
|
|
|
|
case Py_LE: cmp = vs <= ws; break;
|
|
|
|
|
case Py_EQ: cmp = vs == ws; break;
|
|
|
|
|
case Py_NE: cmp = vs != ws; break;
|
|
|
|
|
case Py_GT: cmp = vs > ws; break;
|
|
|
|
|
case Py_GE: cmp = vs >= ws; break;
|
|
|
|
|
default: return NULL; /* cannot happen */
|
|
|
|
|
}
|
|
|
|
|
if (cmp)
|
|
|
|
|
res = Py_True;
|
|
|
|
|
else
|
|
|
|
|
res = Py_False;
|
|
|
|
|
Py_INCREF(res);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2001-01-17 22:11:59 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* We have an item that differs -- shortcuts for EQ/NE */
|
|
|
|
|
if (op == Py_EQ) {
|
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
|
return Py_False;
|
|
|
|
|
}
|
|
|
|
|
if (op == Py_NE) {
|
|
|
|
|
Py_INCREF(Py_True);
|
|
|
|
|
return Py_True;
|
|
|
|
|
}
|
2001-01-17 22:11:59 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Compare the final item again using the proper operator */
|
|
|
|
|
return PyObject_RichCompare(vl->ob_item[i], wl->ob_item[i], op);
|
2001-01-17 22:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
2001-08-02 04:15:00 +00:00
|
|
|
static int
|
|
|
|
|
list_init(PyListObject *self, PyObject *args, PyObject *kw)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject *arg = NULL;
|
|
|
|
|
static char *kwlist[] = {"sequence", 0};
|
2001-08-02 04:15:00 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:list", kwlist, &arg))
|
|
|
|
|
return -1;
|
2004-07-29 23:31:29 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Verify list invariants established by PyType_GenericAlloc() */
|
|
|
|
|
assert(0 <= Py_SIZE(self));
|
|
|
|
|
assert(Py_SIZE(self) <= self->allocated || self->allocated == -1);
|
|
|
|
|
assert(self->ob_item != NULL ||
|
|
|
|
|
self->allocated == 0 || self->allocated == -1);
|
2004-07-29 23:31:29 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Empty previous contents */
|
|
|
|
|
if (self->ob_item != NULL) {
|
|
|
|
|
(void)list_clear(self);
|
|
|
|
|
}
|
|
|
|
|
if (arg != NULL) {
|
|
|
|
|
PyObject *rv = listextend(self, arg);
|
|
|
|
|
if (rv == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
Py_DECREF(rv);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2001-08-02 04:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-04 14:18:43 +00:00
|
|
|
static PyObject *
|
|
|
|
|
list_sizeof(PyListObject *self)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t res;
|
2008-06-04 14:18:43 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
res = sizeof(PyListObject) + self->allocated * sizeof(void*);
|
|
|
|
|
return PyLong_FromSsize_t(res);
|
2008-06-04 14:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-07 15:38:09 +00:00
|
|
|
static PyObject *list_iter(PyObject *seq);
|
|
|
|
|
static PyObject *list_reversed(PyListObject* seq, PyObject* unused);
|
|
|
|
|
|
2003-12-13 11:26:12 +00:00
|
|
|
PyDoc_STRVAR(getitem_doc,
|
|
|
|
|
"x.__getitem__(y) <==> x[y]");
|
2003-11-07 15:38:09 +00:00
|
|
|
PyDoc_STRVAR(reversed_doc,
|
|
|
|
|
"L.__reversed__() -- return a reverse iterator over the list");
|
2008-06-04 14:18:43 +00:00
|
|
|
PyDoc_STRVAR(sizeof_doc,
|
|
|
|
|
"L.__sizeof__() -- size of L in memory, in bytes");
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(append_doc,
|
|
|
|
|
"L.append(object) -- append object to end");
|
|
|
|
|
PyDoc_STRVAR(extend_doc,
|
2002-12-29 05:49:09 +00:00
|
|
|
"L.extend(iterable) -- extend list by appending elements from the iterable");
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(insert_doc,
|
|
|
|
|
"L.insert(index, object) -- insert object before index");
|
|
|
|
|
PyDoc_STRVAR(pop_doc,
|
2008-10-11 00:49:57 +00:00
|
|
|
"L.pop([index]) -> item -- remove and return item at index (default last).\n"
|
|
|
|
|
"Raises IndexError if list is empty or index is out of range.");
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(remove_doc,
|
2008-10-11 00:49:57 +00:00
|
|
|
"L.remove(value) -- remove first occurrence of value.\n"
|
|
|
|
|
"Raises ValueError if the value is not present.");
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(index_doc,
|
2008-10-11 00:49:57 +00:00
|
|
|
"L.index(value, [start, [stop]]) -> integer -- return first index of value.\n"
|
|
|
|
|
"Raises ValueError if the value is not present.");
|
2002-06-13 20:33:02 +00:00
|
|
|
PyDoc_STRVAR(count_doc,
|
|
|
|
|
"L.count(value) -> integer -- return number of occurrences of value");
|
|
|
|
|
PyDoc_STRVAR(reverse_doc,
|
|
|
|
|
"L.reverse() -- reverse *IN PLACE*");
|
|
|
|
|
PyDoc_STRVAR(sort_doc,
|
2008-09-30 02:08:36 +00:00
|
|
|
"L.sort(key=None, reverse=False) -- stable sort *IN PLACE*");
|
1998-06-30 15:36:32 +00:00
|
|
|
|
2003-12-13 11:26:12 +00:00
|
|
|
static PyObject *list_subscript(PyListObject*, PyObject*);
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PyMethodDef list_methods[] = {
|
2010-05-09 15:52:27 +00:00
|
|
|
{"__getitem__", (PyCFunction)list_subscript, METH_O|METH_COEXIST, getitem_doc},
|
|
|
|
|
{"__reversed__",(PyCFunction)list_reversed, METH_NOARGS, reversed_doc},
|
|
|
|
|
{"__sizeof__", (PyCFunction)list_sizeof, METH_NOARGS, sizeof_doc},
|
|
|
|
|
{"append", (PyCFunction)listappend, METH_O, append_doc},
|
|
|
|
|
{"insert", (PyCFunction)listinsert, METH_VARARGS, insert_doc},
|
|
|
|
|
{"extend", (PyCFunction)listextend, METH_O, extend_doc},
|
|
|
|
|
{"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc},
|
|
|
|
|
{"remove", (PyCFunction)listremove, METH_O, remove_doc},
|
|
|
|
|
{"index", (PyCFunction)listindex, METH_VARARGS, index_doc},
|
|
|
|
|
{"count", (PyCFunction)listcount, METH_O, count_doc},
|
|
|
|
|
{"reverse", (PyCFunction)listreverse, METH_NOARGS, reverse_doc},
|
|
|
|
|
{"sort", (PyCFunction)listsort, METH_VARARGS | METH_KEYWORDS, sort_doc},
|
|
|
|
|
{NULL, NULL} /* sentinel */
|
1990-10-14 12:07:46 +00:00
|
|
|
};
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
static PySequenceMethods list_as_sequence = {
|
2010-05-09 15:52:27 +00:00
|
|
|
(lenfunc)list_length, /* sq_length */
|
|
|
|
|
(binaryfunc)list_concat, /* sq_concat */
|
|
|
|
|
(ssizeargfunc)list_repeat, /* sq_repeat */
|
|
|
|
|
(ssizeargfunc)list_item, /* sq_item */
|
|
|
|
|
0, /* sq_slice */
|
|
|
|
|
(ssizeobjargproc)list_ass_item, /* sq_ass_item */
|
|
|
|
|
0, /* sq_ass_slice */
|
|
|
|
|
(objobjproc)list_contains, /* sq_contains */
|
|
|
|
|
(binaryfunc)list_inplace_concat, /* sq_inplace_concat */
|
|
|
|
|
(ssizeargfunc)list_inplace_repeat, /* sq_inplace_repeat */
|
1990-10-14 12:07:46 +00:00
|
|
|
};
|
|
|
|
|
|
2002-06-14 02:04:18 +00:00
|
|
|
PyDoc_STRVAR(list_doc,
|
2010-03-01 04:08:34 +00:00
|
|
|
"list() -> new empty list\n"
|
|
|
|
|
"list(iterable) -> new list initialized from iterable's items");
|
2001-08-02 04:15:00 +00:00
|
|
|
|
2002-07-13 03:51:17 +00:00
|
|
|
static PyObject *
|
2002-06-11 10:55:12 +00:00
|
|
|
list_subscript(PyListObject* self, PyObject* item)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (PyIndex_Check(item)) {
|
|
|
|
|
Py_ssize_t i;
|
|
|
|
|
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
|
|
|
|
|
if (i == -1 && PyErr_Occurred())
|
|
|
|
|
return NULL;
|
|
|
|
|
if (i < 0)
|
|
|
|
|
i += PyList_GET_SIZE(self);
|
|
|
|
|
return list_item(self, i);
|
|
|
|
|
}
|
|
|
|
|
else if (PySlice_Check(item)) {
|
|
|
|
|
Py_ssize_t start, stop, step, slicelength, cur, i;
|
|
|
|
|
PyObject* result;
|
|
|
|
|
PyObject* it;
|
|
|
|
|
PyObject **src, **dest;
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self),
|
|
|
|
|
&start, &stop, &step, &slicelength) < 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (slicelength <= 0) {
|
|
|
|
|
return PyList_New(0);
|
|
|
|
|
}
|
|
|
|
|
else if (step == 1) {
|
|
|
|
|
return list_slice(self, start, stop);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result = PyList_New(slicelength);
|
|
|
|
|
if (!result) return NULL;
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
src = self->ob_item;
|
|
|
|
|
dest = ((PyListObject *)result)->ob_item;
|
|
|
|
|
for (cur = start, i = 0; i < slicelength;
|
|
|
|
|
cur += step, i++) {
|
|
|
|
|
it = src[cur];
|
|
|
|
|
Py_INCREF(it);
|
|
|
|
|
dest[i] = it;
|
|
|
|
|
}
|
2002-07-19 02:35:45 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"list indices must be integers, not %.200s",
|
|
|
|
|
item->ob_type->tp_name);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2002-06-11 10:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
2002-07-19 02:35:45 +00:00
|
|
|
static int
|
2002-06-11 10:55:12 +00:00
|
|
|
list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
if (PyIndex_Check(item)) {
|
|
|
|
|
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
|
|
|
|
|
if (i == -1 && PyErr_Occurred())
|
|
|
|
|
return -1;
|
|
|
|
|
if (i < 0)
|
|
|
|
|
i += PyList_GET_SIZE(self);
|
|
|
|
|
return list_ass_item(self, i, value);
|
|
|
|
|
}
|
|
|
|
|
else if (PySlice_Check(item)) {
|
|
|
|
|
Py_ssize_t start, stop, step, slicelength;
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self),
|
|
|
|
|
&start, &stop, &step, &slicelength) < 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (step == 1)
|
|
|
|
|
return list_ass_slice(self, start, stop, value);
|
2002-06-19 15:44:15 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* Make sure s[5:2] = [..] inserts at the right place:
|
|
|
|
|
before 5, not before 2. */
|
|
|
|
|
if ((step < 0 && start < stop) ||
|
|
|
|
|
(step > 0 && start > stop))
|
|
|
|
|
stop = start;
|
Merge the trunk changes in. Breaks socket.ssl for now.
Merged revisions 57392-57619 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57395 | georg.brandl | 2007-08-24 19:23:23 +0200 (Fri, 24 Aug 2007) | 2 lines
Bug #1011: fix rfc822.Message.getheader docs.
........
r57397 | georg.brandl | 2007-08-24 19:38:49 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1006: port test_winreg to unittest.
........
r57398 | georg.brandl | 2007-08-24 19:46:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Fix #1012: wrong URL to :mod:`site` in install/index.rst.
........
r57399 | georg.brandl | 2007-08-24 20:07:52 +0200 (Fri, 24 Aug 2007) | 2 lines
Patch #1008: port test_signal to unittest.
........
r57400 | georg.brandl | 2007-08-24 20:22:54 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_frozen to unittest.
........
r57401 | georg.brandl | 2007-08-24 20:27:43 +0200 (Fri, 24 Aug 2007) | 2 lines
Document new utility functions in test_support.
........
r57402 | georg.brandl | 2007-08-24 20:30:06 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove test_rgbimg output file, there is no test_rgbimg.py.
........
r57403 | georg.brandl | 2007-08-24 20:35:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Remove output file for test_ossaudiodev, also properly close the dsp object.
........
r57404 | georg.brandl | 2007-08-24 20:46:27 +0200 (Fri, 24 Aug 2007) | 2 lines
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
........
r57406 | collin.winter | 2007-08-24 21:13:58 +0200 (Fri, 24 Aug 2007) | 1 line
Convert test_pkg to use unittest.
........
r57408 | georg.brandl | 2007-08-24 21:22:34 +0200 (Fri, 24 Aug 2007) | 2 lines
Catch the correct errors.
........
r57409 | georg.brandl | 2007-08-24 21:33:53 +0200 (Fri, 24 Aug 2007) | 2 lines
Port test_class to unittest. Patch #1671298.
........
r57415 | collin.winter | 2007-08-24 23:09:42 +0200 (Fri, 24 Aug 2007) | 1 line
Make test_structmembers pass when run with regrtests's -R flag.
........
r57455 | nick.coghlan | 2007-08-25 06:32:07 +0200 (Sat, 25 Aug 2007) | 1 line
Revert misguided attempt at fixing incompatibility between -m and -i switches (better fix coming soon)
........
r57456 | nick.coghlan | 2007-08-25 06:35:54 +0200 (Sat, 25 Aug 2007) | 1 line
Revert compile.c changes that shouldn't have been included in previous checkin
........
r57461 | nick.coghlan | 2007-08-25 12:50:41 +0200 (Sat, 25 Aug 2007) | 1 line
Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
........
r57464 | guido.van.rossum | 2007-08-25 17:08:43 +0200 (Sat, 25 Aug 2007) | 4 lines
Server-side SSL and certificate validation, by Bill Janssen.
While cleaning up Bill's C style, I may have cleaned up some code
he didn't touch as well (in _ssl.c).
........
r57465 | neal.norwitz | 2007-08-25 18:41:36 +0200 (Sat, 25 Aug 2007) | 3 lines
Try to get this to build with Visual Studio by moving all the variable
declarations to the beginning of a scope.
........
r57466 | neal.norwitz | 2007-08-25 18:54:38 +0200 (Sat, 25 Aug 2007) | 1 line
Fix test so it is skipped properly if there is no SSL support.
........
r57467 | neal.norwitz | 2007-08-25 18:58:09 +0200 (Sat, 25 Aug 2007) | 2 lines
Fix a few more variables to try to get this to compile with Visual Studio.
........
r57473 | neal.norwitz | 2007-08-25 19:25:17 +0200 (Sat, 25 Aug 2007) | 1 line
Try to get this test to pass for systems that do not have SO_REUSEPORT
........
r57482 | gregory.p.smith | 2007-08-26 02:26:00 +0200 (Sun, 26 Aug 2007) | 7 lines
keep setup.py from listing unneeded hash modules (_md5, _sha*) as
missing when they were not built because _hashlib with openssl provided
their functionality instead.
don't build bsddb185 if bsddb was built.
........
r57483 | neal.norwitz | 2007-08-26 03:08:16 +0200 (Sun, 26 Aug 2007) | 1 line
Fix typo in docstring (missing c in reacquire)
........
r57484 | neal.norwitz | 2007-08-26 03:42:03 +0200 (Sun, 26 Aug 2007) | 2 lines
Spell check (also americanify behaviour, it's almost 3 times as common)
........
r57503 | neal.norwitz | 2007-08-26 08:29:57 +0200 (Sun, 26 Aug 2007) | 4 lines
Reap children before the test starts so hopefully SocketServer
won't find any old children left around which causes an exception
in collect_children() and the test to fail.
........
r57510 | neal.norwitz | 2007-08-26 20:50:39 +0200 (Sun, 26 Aug 2007) | 1 line
Fail gracefully if the cert files cannot be created
........
r57513 | guido.van.rossum | 2007-08-26 21:35:09 +0200 (Sun, 26 Aug 2007) | 4 lines
Bill Janssen wrote:
Here's a patch which makes test_ssl a better player in the buildbots
environment. I deep-ended on "try-except-else" clauses.
........
r57518 | neal.norwitz | 2007-08-26 23:40:16 +0200 (Sun, 26 Aug 2007) | 1 line
Get the test passing by commenting out some writes (should they be removed?)
........
r57522 | neal.norwitz | 2007-08-27 00:16:23 +0200 (Mon, 27 Aug 2007) | 3 lines
Catch IOError for when the device file doesn't exist or the user doesn't have
permission to write to the device.
........
r57524 | neal.norwitz | 2007-08-27 00:20:03 +0200 (Mon, 27 Aug 2007) | 5 lines
Another patch from Bill Janssen that:
1) Fixes the bug that two class names are initial-lower-case.
2) Replaces the poll waiting for the server to become ready with
a threading.Event signal.
........
r57536 | neal.norwitz | 2007-08-27 02:58:33 +0200 (Mon, 27 Aug 2007) | 1 line
Stop using string.join (from the module) to ease upgrade to py3k
........
r57537 | neal.norwitz | 2007-08-27 03:03:18 +0200 (Mon, 27 Aug 2007) | 1 line
Make a utility function for handling (printing) an error
........
r57538 | neal.norwitz | 2007-08-27 03:15:33 +0200 (Mon, 27 Aug 2007) | 4 lines
If we can't create a certificate, print a warning, but don't fail the test.
Modified patch from what Bill Janssen sent on python-3000.
........
r57539 | facundo.batista | 2007-08-27 03:15:34 +0200 (Mon, 27 Aug 2007) | 7 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised in the test server thread, since SimpleXMLRPCServer
does not gracefully handle them. Changed number of requests handled
by tests server thread to one (was 2) because no tests require more
than one request. [GSoC - Alan McIntyre]
........
r57561 | guido.van.rossum | 2007-08-27 19:19:42 +0200 (Mon, 27 Aug 2007) | 8 lines
> Regardless, building a fixed test certificate and checking it in sounds like
> the better option. Then the openssl command in the test code can be turned
> into a comment describing how the test data was pregenerated.
Here's a patch that does that.
Bill
........
r57568 | guido.van.rossum | 2007-08-27 20:42:23 +0200 (Mon, 27 Aug 2007) | 26 lines
> Some of the code sets the error string in this directly before
> returning NULL, and other pieces of the code call PySSL_SetError,
> which creates the error string. I think some of the places which set
> the string directly probably shouldn't; instead, they should call
> PySSL_SetError to cons up the error name directly from the err code.
> However, PySSL_SetError only works after the construction of an ssl
> object, which means it can't be used there... I'll take a longer look
> at it and see if there's a reasonable fix.
Here's a patch which addresses this. It also fixes the indentation in
PySSL_SetError, bringing it into line with PEP 7, fixes a compile warning
about one of the OpenSSL macros, and makes the namespace a bit more
consistent. I've tested it on FC 7 and OS X 10.4.
% ./python ./Lib/test/regrtest.py -R :1: -u all test_ssl
test_ssl
beginning 6 repetitions
123456
......
1 test OK.
[29244 refs]
%
[GvR: slightly edited to enforce 79-char line length, even if it required
violating the style guide.]
........
r57570 | guido.van.rossum | 2007-08-27 21:11:11 +0200 (Mon, 27 Aug 2007) | 2 lines
Patch 10124 by Bill Janssen, docs for the new ssl code.
........
r57574 | guido.van.rossum | 2007-08-27 22:51:00 +0200 (Mon, 27 Aug 2007) | 3 lines
Patch # 1739906 by Christian Heimes -- add reduce to functools (importing
it from __builtin__).
........
r57575 | guido.van.rossum | 2007-08-27 22:52:10 +0200 (Mon, 27 Aug 2007) | 2 lines
News about functools.reduce.
........
r57611 | georg.brandl | 2007-08-28 10:29:08 +0200 (Tue, 28 Aug 2007) | 2 lines
Document rev. 57574.
........
r57612 | sean.reifschneider | 2007-08-28 11:07:54 +0200 (Tue, 28 Aug 2007) | 2 lines
Adding basic imputil documentation.
........
r57614 | georg.brandl | 2007-08-28 12:48:18 +0200 (Tue, 28 Aug 2007) | 2 lines
Fix some glitches.
........
r57616 | lars.gustaebel | 2007-08-28 14:31:09 +0200 (Tue, 28 Aug 2007) | 5 lines
TarFile.__init__() no longer fails if no name argument is passed and
the fileobj argument has no usable name attribute (e.g. StringIO).
(will backport to 2.5)
........
r57619 | thomas.wouters | 2007-08-28 17:28:19 +0200 (Tue, 28 Aug 2007) | 22 lines
Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
is done for simple slices, in the tuple, string and unicode case.
- Specialcase step-1 extended slices to optimize the common case for all
involved types.
- For lists, allow extended slice assignment of differing lengths as long
as the step is 1. (Previously, 'l[:2:1] = []' failed even though
'l[:2] = []' and 'l[:2:None] = []' do not.)
- Implement extended slicing for buffer, array, structseq, mmap and
UserString.UserString.
- Implement slice-object support (but not non-step-1 slice assignment) for
UserString.MutableString.
- Add tests for all new functionality.
........
2007-08-28 21:37:11 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (value == NULL) {
|
|
|
|
|
/* delete slice */
|
|
|
|
|
PyObject **garbage;
|
|
|
|
|
size_t cur;
|
|
|
|
|
Py_ssize_t i;
|
2002-07-19 02:35:45 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (slicelength <= 0)
|
|
|
|
|
return 0;
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (step < 0) {
|
|
|
|
|
stop = start + 1;
|
|
|
|
|
start = stop + step*(slicelength - 1) - 1;
|
|
|
|
|
step = -step;
|
|
|
|
|
}
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert((size_t)slicelength <=
|
|
|
|
|
PY_SIZE_MAX / sizeof(PyObject*));
|
2008-06-18 00:47:36 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
garbage = (PyObject**)
|
|
|
|
|
PyMem_MALLOC(slicelength*sizeof(PyObject*));
|
|
|
|
|
if (!garbage) {
|
|
|
|
|
PyErr_NoMemory();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2002-07-19 02:35:45 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* drawing pictures might help understand these for
|
|
|
|
|
loops. Basically, we memmove the parts of the
|
|
|
|
|
list that are *not* part of the slice: step-1
|
|
|
|
|
items for each item that is part of the slice,
|
|
|
|
|
and then tail end of the list that was not
|
|
|
|
|
covered by the slice */
|
|
|
|
|
for (cur = start, i = 0;
|
|
|
|
|
cur < (size_t)stop;
|
|
|
|
|
cur += step, i++) {
|
|
|
|
|
Py_ssize_t lim = step - 1;
|
2002-07-29 14:35:04 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
garbage[i] = PyList_GET_ITEM(self, cur);
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (cur + step >= (size_t)Py_SIZE(self)) {
|
|
|
|
|
lim = Py_SIZE(self) - cur - 1;
|
|
|
|
|
}
|
2002-07-29 14:35:04 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
memmove(self->ob_item + cur - i,
|
|
|
|
|
self->ob_item + cur + 1,
|
|
|
|
|
lim * sizeof(PyObject *));
|
|
|
|
|
}
|
|
|
|
|
cur = start + slicelength*step;
|
|
|
|
|
if (cur < (size_t)Py_SIZE(self)) {
|
|
|
|
|
memmove(self->ob_item + cur - slicelength,
|
|
|
|
|
self->ob_item + cur,
|
|
|
|
|
(Py_SIZE(self) - cur) *
|
|
|
|
|
sizeof(PyObject *));
|
|
|
|
|
}
|
2004-03-09 13:05:22 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_SIZE(self) -= slicelength;
|
|
|
|
|
list_resize(self, Py_SIZE(self));
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
for (i = 0; i < slicelength; i++) {
|
|
|
|
|
Py_DECREF(garbage[i]);
|
|
|
|
|
}
|
|
|
|
|
PyMem_FREE(garbage);
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* assign slice */
|
|
|
|
|
PyObject *ins, *seq;
|
|
|
|
|
PyObject **garbage, **seqitems, **selfitems;
|
|
|
|
|
Py_ssize_t cur, i;
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
/* protect against a[::-1] = a */
|
|
|
|
|
if (self == (PyListObject*)value) {
|
|
|
|
|
seq = list_slice((PyListObject*)value, 0,
|
|
|
|
|
PyList_GET_SIZE(value));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
seq = PySequence_Fast(value,
|
|
|
|
|
"must assign iterable "
|
|
|
|
|
"to extended slice");
|
|
|
|
|
}
|
|
|
|
|
if (!seq)
|
|
|
|
|
return -1;
|
2002-12-05 21:32:32 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
|
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
|
"attempt to assign sequence of "
|
|
|
|
|
"size %zd to extended slice of "
|
|
|
|
|
"size %zd",
|
|
|
|
|
PySequence_Fast_GET_SIZE(seq),
|
|
|
|
|
slicelength);
|
|
|
|
|
Py_DECREF(seq);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2002-12-05 21:32:32 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!slicelength) {
|
|
|
|
|
Py_DECREF(seq);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
garbage = (PyObject**)
|
|
|
|
|
PyMem_MALLOC(slicelength*sizeof(PyObject*));
|
|
|
|
|
if (!garbage) {
|
|
|
|
|
Py_DECREF(seq);
|
|
|
|
|
PyErr_NoMemory();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2002-07-19 02:35:45 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
selfitems = self->ob_item;
|
|
|
|
|
seqitems = PySequence_Fast_ITEMS(seq);
|
|
|
|
|
for (cur = start, i = 0; i < slicelength;
|
|
|
|
|
cur += step, i++) {
|
|
|
|
|
garbage[i] = selfitems[cur];
|
|
|
|
|
ins = seqitems[i];
|
|
|
|
|
Py_INCREF(ins);
|
|
|
|
|
selfitems[cur] = ins;
|
|
|
|
|
}
|
2002-06-11 10:55:12 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
for (i = 0; i < slicelength; i++) {
|
|
|
|
|
Py_DECREF(garbage[i]);
|
|
|
|
|
}
|
2002-07-19 02:35:45 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
PyMem_FREE(garbage);
|
|
|
|
|
Py_DECREF(seq);
|
2002-07-19 02:35:45 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"list indices must be integers, not %.200s",
|
|
|
|
|
item->ob_type->tp_name);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2002-06-11 10:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyMappingMethods list_as_mapping = {
|
2010-05-09 15:52:27 +00:00
|
|
|
(lenfunc)list_length,
|
|
|
|
|
(binaryfunc)list_subscript,
|
|
|
|
|
(objobjargproc)list_ass_subscript
|
2002-06-11 10:55:12 +00:00
|
|
|
};
|
|
|
|
|
|
1997-05-02 03:12:38 +00:00
|
|
|
PyTypeObject PyList_Type = {
|
2010-05-09 15:52:27 +00:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
|
"list",
|
|
|
|
|
sizeof(PyListObject),
|
|
|
|
|
0,
|
|
|
|
|
(destructor)list_dealloc, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
0, /* tp_getattr */
|
|
|
|
|
0, /* tp_setattr */
|
|
|
|
|
0, /* tp_reserved */
|
|
|
|
|
(reprfunc)list_repr, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
&list_as_sequence, /* tp_as_sequence */
|
|
|
|
|
&list_as_mapping, /* tp_as_mapping */
|
|
|
|
|
(hashfunc)PyObject_HashNotImplemented, /* tp_hash */
|
|
|
|
|
0, /* tp_call */
|
|
|
|
|
0, /* tp_str */
|
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
|
0, /* tp_setattro */
|
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
|
|
|
|
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_LIST_SUBCLASS, /* tp_flags */
|
|
|
|
|
list_doc, /* tp_doc */
|
|
|
|
|
(traverseproc)list_traverse, /* tp_traverse */
|
|
|
|
|
(inquiry)list_clear, /* tp_clear */
|
|
|
|
|
list_richcompare, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
list_iter, /* tp_iter */
|
|
|
|
|
0, /* tp_iternext */
|
|
|
|
|
list_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
|
|
|
|
0, /* tp_getset */
|
|
|
|
|
0, /* tp_base */
|
|
|
|
|
0, /* tp_dict */
|
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
|
(initproc)list_init, /* tp_init */
|
|
|
|
|
PyType_GenericAlloc, /* tp_alloc */
|
|
|
|
|
PyType_GenericNew, /* tp_new */
|
|
|
|
|
PyObject_GC_Del, /* tp_free */
|
1990-10-14 12:07:46 +00:00
|
|
|
};
|
1998-06-16 15:18:28 +00:00
|
|
|
|
|
|
|
|
|
2002-05-31 21:40:38 +00:00
|
|
|
/*********************** List Iterator **************************/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject_HEAD
|
|
|
|
|
long it_index;
|
|
|
|
|
PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
|
2002-05-31 21:40:38 +00:00
|
|
|
} listiterobject;
|
|
|
|
|
|
2006-04-21 10:40:58 +00:00
|
|
|
static PyObject *list_iter(PyObject *);
|
|
|
|
|
static void listiter_dealloc(listiterobject *);
|
|
|
|
|
static int listiter_traverse(listiterobject *, visitproc, void *);
|
|
|
|
|
static PyObject *listiter_next(listiterobject *);
|
|
|
|
|
static PyObject *listiter_len(listiterobject *);
|
2004-03-18 22:43:10 +00:00
|
|
|
|
2006-02-11 21:32:43 +00:00
|
|
|
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
|
2005-09-24 21:23:05 +00:00
|
|
|
|
|
|
|
|
static PyMethodDef listiter_methods[] = {
|
2010-05-09 15:52:27 +00:00
|
|
|
{"__length_hint__", (PyCFunction)listiter_len, METH_NOARGS, length_hint_doc},
|
|
|
|
|
{NULL, NULL} /* sentinel */
|
2004-03-18 22:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
2002-05-31 21:40:38 +00:00
|
|
|
PyTypeObject PyListIter_Type = {
|
2010-05-09 15:52:27 +00:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
|
"list_iterator", /* tp_name */
|
|
|
|
|
sizeof(listiterobject), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
/* methods */
|
|
|
|
|
(destructor)listiter_dealloc, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
0, /* tp_getattr */
|
|
|
|
|
0, /* tp_setattr */
|
|
|
|
|
0, /* tp_reserved */
|
|
|
|
|
0, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_hash */
|
|
|
|
|
0, /* tp_call */
|
|
|
|
|
0, /* tp_str */
|
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
|
0, /* tp_setattro */
|
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
|
|
|
|
0, /* tp_doc */
|
|
|
|
|
(traverseproc)listiter_traverse, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
0, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
PyObject_SelfIter, /* tp_iter */
|
|
|
|
|
(iternextfunc)listiter_next, /* tp_iternext */
|
|
|
|
|
listiter_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
2002-05-31 21:40:38 +00:00
|
|
|
};
|
2003-11-07 15:38:09 +00:00
|
|
|
|
2006-04-21 10:40:58 +00:00
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
list_iter(PyObject *seq)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
listiterobject *it;
|
2006-04-21 10:40:58 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (!PyList_Check(seq)) {
|
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
it = PyObject_GC_New(listiterobject, &PyListIter_Type);
|
|
|
|
|
if (it == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
it->it_index = 0;
|
|
|
|
|
Py_INCREF(seq);
|
|
|
|
|
it->it_seq = (PyListObject *)seq;
|
|
|
|
|
_PyObject_GC_TRACK(it);
|
|
|
|
|
return (PyObject *)it;
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
listiter_dealloc(listiterobject *it)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
_PyObject_GC_UNTRACK(it);
|
|
|
|
|
Py_XDECREF(it->it_seq);
|
|
|
|
|
PyObject_GC_Del(it);
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
listiter_traverse(listiterobject *it, visitproc visit, void *arg)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_VISIT(it->it_seq);
|
|
|
|
|
return 0;
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
listiter_next(listiterobject *it)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyListObject *seq;
|
|
|
|
|
PyObject *item;
|
2006-04-21 10:40:58 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
assert(it != NULL);
|
|
|
|
|
seq = it->it_seq;
|
|
|
|
|
if (seq == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
assert(PyList_Check(seq));
|
2006-04-21 10:40:58 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (it->it_index < PyList_GET_SIZE(seq)) {
|
|
|
|
|
item = PyList_GET_ITEM(seq, it->it_index);
|
|
|
|
|
++it->it_index;
|
|
|
|
|
Py_INCREF(item);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
2006-04-21 10:40:58 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_DECREF(seq);
|
|
|
|
|
it->it_seq = NULL;
|
|
|
|
|
return NULL;
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
listiter_len(listiterobject *it)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t len;
|
|
|
|
|
if (it->it_seq) {
|
|
|
|
|
len = PyList_GET_SIZE(it->it_seq) - it->it_index;
|
|
|
|
|
if (len >= 0)
|
|
|
|
|
return PyLong_FromSsize_t(len);
|
|
|
|
|
}
|
|
|
|
|
return PyLong_FromLong(0);
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
2003-11-07 15:38:09 +00:00
|
|
|
/*********************** List Reverse Iterator **************************/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject_HEAD
|
|
|
|
|
Py_ssize_t it_index;
|
|
|
|
|
PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
|
2003-11-07 15:38:09 +00:00
|
|
|
} listreviterobject;
|
|
|
|
|
|
2006-04-21 10:40:58 +00:00
|
|
|
static PyObject *list_reversed(PyListObject *, PyObject *);
|
|
|
|
|
static void listreviter_dealloc(listreviterobject *);
|
|
|
|
|
static int listreviter_traverse(listreviterobject *, visitproc, void *);
|
|
|
|
|
static PyObject *listreviter_next(listreviterobject *);
|
2008-12-02 21:33:45 +00:00
|
|
|
static PyObject *listreviter_len(listreviterobject *);
|
2004-03-10 10:10:42 +00:00
|
|
|
|
2008-12-02 21:33:45 +00:00
|
|
|
static PyMethodDef listreviter_methods[] = {
|
2010-05-09 15:52:27 +00:00
|
|
|
{"__length_hint__", (PyCFunction)listreviter_len, METH_NOARGS, length_hint_doc},
|
|
|
|
|
{NULL, NULL} /* sentinel */
|
2004-03-10 10:10:42 +00:00
|
|
|
};
|
|
|
|
|
|
2003-11-07 15:38:09 +00:00
|
|
|
PyTypeObject PyListRevIter_Type = {
|
2010-05-09 15:52:27 +00:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
|
"list_reverseiterator", /* tp_name */
|
|
|
|
|
sizeof(listreviterobject), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
/* methods */
|
|
|
|
|
(destructor)listreviter_dealloc, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
0, /* tp_getattr */
|
|
|
|
|
0, /* tp_setattr */
|
|
|
|
|
0, /* tp_reserved */
|
|
|
|
|
0, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_hash */
|
|
|
|
|
0, /* tp_call */
|
|
|
|
|
0, /* tp_str */
|
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
|
0, /* tp_setattro */
|
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
|
|
|
|
0, /* tp_doc */
|
|
|
|
|
(traverseproc)listreviter_traverse, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
0, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
PyObject_SelfIter, /* tp_iter */
|
|
|
|
|
(iternextfunc)listreviter_next, /* tp_iternext */
|
|
|
|
|
listreviter_methods, /* tp_methods */
|
|
|
|
|
0,
|
2003-11-07 15:38:09 +00:00
|
|
|
};
|
2006-04-21 10:40:58 +00:00
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
list_reversed(PyListObject *seq, PyObject *unused)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
listreviterobject *it;
|
2006-04-21 10:40:58 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
it = PyObject_GC_New(listreviterobject, &PyListRevIter_Type);
|
|
|
|
|
if (it == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
assert(PyList_Check(seq));
|
|
|
|
|
it->it_index = PyList_GET_SIZE(seq) - 1;
|
|
|
|
|
Py_INCREF(seq);
|
|
|
|
|
it->it_seq = seq;
|
|
|
|
|
PyObject_GC_Track(it);
|
|
|
|
|
return (PyObject *)it;
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
listreviter_dealloc(listreviterobject *it)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject_GC_UnTrack(it);
|
|
|
|
|
Py_XDECREF(it->it_seq);
|
|
|
|
|
PyObject_GC_Del(it);
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
listreviter_traverse(listreviterobject *it, visitproc visit, void *arg)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_VISIT(it->it_seq);
|
|
|
|
|
return 0;
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
listreviter_next(listreviterobject *it)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
PyObject *item;
|
|
|
|
|
Py_ssize_t index = it->it_index;
|
|
|
|
|
PyListObject *seq = it->it_seq;
|
2006-04-21 10:40:58 +00:00
|
|
|
|
2010-05-09 15:52:27 +00:00
|
|
|
if (index>=0 && index < PyList_GET_SIZE(seq)) {
|
|
|
|
|
item = PyList_GET_ITEM(seq, index);
|
|
|
|
|
it->it_index--;
|
|
|
|
|
Py_INCREF(item);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
it->it_index = -1;
|
|
|
|
|
if (seq != NULL) {
|
|
|
|
|
it->it_seq = NULL;
|
|
|
|
|
Py_DECREF(seq);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 21:33:45 +00:00
|
|
|
static PyObject *
|
2006-04-21 10:40:58 +00:00
|
|
|
listreviter_len(listreviterobject *it)
|
|
|
|
|
{
|
2010-05-09 15:52:27 +00:00
|
|
|
Py_ssize_t len = it->it_index + 1;
|
|
|
|
|
if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len)
|
|
|
|
|
len = 0;
|
|
|
|
|
return PyLong_FromSsize_t(len);
|
2006-04-21 10:40:58 +00:00
|
|
|
}
|
|
|
|
|
|