This is a reorganization of list_ass_slice(). It should probably be reviewed,
though I tried to be very careful. This is a slight simplification, and it
adds a new feature: a small stack-allocated "recycled" array for the cases
when we don't remove too many items.
It allows PyList_SetSlice() to never fail if:
* you are sure that the object is a list; and
* you either do not remove more than 8 items, or clear the list.
This makes a number of other places in the source code correct again -- there
are some places that delete a single item without checking for MemoryErrors
raised by PyList_SetSlice(), or that clear the whole list, and sometimes the
context doesn't allow an error to be propagated.
* Simplify and speed-up list_resize(). Relying on the newly documented
invariants allows the ob_item != NULL check to be replaced with an
assertion.
* Added assertions to list_init() which document and verify that the
tp_new slot establishes the invariants. This may preclude a future
bug if a custom tp_new slot is written.
* drop the unreasonable list invariant that ob_item should never come back
to NULL during the lifetime of the object.
* listobject.c nevertheless did not conform to the other invariants,
either; fixed.
* listobject.c now uses list_clear() as the obvious internal way to clear
a list, instead of abusing list_ass_slice() for that. It makes it easier
to enforce the invariant about ob_item == NULL.
* listsort() sets allocated to -1 during sort; any mutation will set it
to a value >= 0, so it is a safe way to detect mutation. A negative
value for allocated does not cause a problem elsewhere currently.
test_sort.py has a new test for this fix.
* listsort() leak: if items were added to the list during the sort, AND if
these items had a __del__ that puts still more stuff into the list,
then this more stuff (and the PyObject** array to hold them) were
overridden at the end of listsort() and never released.
Tim Peters [Thu, 29 Jul 2004 04:07:15 +0000 (04:07 +0000)]
Fix obscure breakage (relative to 2.3) in listsort: the test for list
mutation during list.sort() used to rely on that listobject.c always
NULL'ed ob_item when ob_size fell to 0. That's no longer true, so the
test for list mutation during a sort is no longer reliable. Changed the
test to rely instead on that listobject.c now never NULLs-out ob_item
after (if ever) ob_item gets a non-NULL value. This new assumption is
also documented now, as a required invariant in listobject.h.
The new assumption allowed some real simplification to some of the
hairier code in listsort(), so is a Good Thing on that count.
Tim Peters [Thu, 29 Jul 2004 02:28:42 +0000 (02:28 +0000)]
PyList_New(): we went to all the trouble of computing and bounds-checking
the size_t nbytes, and passed nbytes to malloc, so it was confusing to
effectively recompute the same thing from scratch in the memset call.
Fred Drake [Wed, 28 Jul 2004 14:55:10 +0000 (14:55 +0000)]
Since build_py handles package data installation, the list of outputs
can contain more than just .py files. Make sure we only report
bytecode files for the .py files.
Remove CJKCodecs implementation of UTF-7 and UTF-8 codec which
aren't intended to be part of Python distributiuon. This was
accidently imported on mass converting from standalone version of
CJKCodecs.
Tim Peters [Mon, 26 Jul 2004 00:42:41 +0000 (00:42 +0000)]
SF bugs 996748: os.environ documentation should indicate unreliability
Clarifed that os.environ is captured once; emphasized that it's better
to assign to os.environ than to call putenv() directly (the putenv()
docs said so, but the environ docs didn't).
Tim Peters [Sat, 24 Jul 2004 23:00:24 +0000 (23:00 +0000)]
SF bug 996392: math and cmath docs don't specify radians
Major rewrite of the math module docs. Slapped in "radians" where
appropriate; grouped the functions into reasonable categories; supplied
many more words to address common confusions about some of the subtler
issues.
Thomas Heller [Fri, 23 Jul 2004 19:47:32 +0000 (19:47 +0000)]
Make the distutils version number the same as the python version. It
must be literally contained here, because it is still possible to
install this distutils in older Python versions.
The script was originally used to create the initial set of
codecs (and these were (c) CNRI). While the script itself still
is (c) CNRI, the output certainly isn't anymore.
This change implements the following gettext features, as
discussed recently in python-dev:
In _locale module:
- bind_textdomain_codeset() binding
In gettext module:
- bind_textdomain_codeset() function
- lgettext(), lngettext(), ldgettext(), ldngettext(),
which return translated strings encoded in
preferred system encoding, if
bind_textdomain_codeset() was not used.
- Added equivalent functionality in translate()
function and catalog classes.
Tim Peters [Thu, 22 Jul 2004 01:46:43 +0000 (01:46 +0000)]
SF bug 994255: Py_RETURN_NONE causes too much warnings
Rewrote Py_RETURN_{NONE, TRUE, FALSE} to expand to comma expressions
rather than "do {} while(0)" thingies. The OP complained because he
likes using MS /W4 sometimes, and then all his uses of these things
generate nuisance warnings about testing a constant expression (in
the "while(0)" part). Comma expressions don't have this problem
(although it's a lucky accident that comma expressions suffice for these
macros!).
Fred Drake [Wed, 21 Jul 2004 18:53:06 +0000 (18:53 +0000)]
elaborate package data test to make sure get_outputs() gives the right
results when byte-code compilation is requested (in particular, make
sure that package data doesn't get a bogus byte-code listing
generated)
Tim Peters [Wed, 21 Jul 2004 03:36:52 +0000 (03:36 +0000)]
Thread.__delete: Discussion of internal obscurities belongs in comments
rather than in docstrings. Rewrote so that _active_limbo_lock is released
no matter what happens (it could have been left locked if _sys got None'd
out). Use "in" in preference to has_key() for dict lookup. Don't bother
looking for 'dummy_threading' in sys.modules unless KeyError is raised.
Since the heart of the method is the del, do that in only one place.
Fix bug where a KeyError was raised if -O was being used for the interpreter
and Thread.__delete() was called after a Thread instance was created. Problem
resulted from a currentThread() call in an 'assert' statement being optimized
out and dummy_thread.get_ident() always returning -1 and thus overwriting the
entry for the _MainThread() instance created in 'threading' at import time.
Neil Schemenauer [Mon, 19 Jul 2004 16:29:17 +0000 (16:29 +0000)]
Check the type of values returned by __int__, __float__, __long__,
__oct__, and __hex__. Raise TypeError if an invalid type is
returned. Note that PyNumber_Int and PyNumber_Long can still
return ints or longs. Fixes SF bug #966618.
Tim Peters [Sun, 18 Jul 2004 23:58:17 +0000 (23:58 +0000)]
Record that FCNTL.py has gone away; remove FCNTL hack in tempfile.py;
another hack remains in test___all__.py, but the problem that one
addresses is more general than *just* FCNTL, so leaving it alone.