Tim Peters [Thu, 10 May 2001 08:32:44 +0000 (08:32 +0000)]
SF bug #422121 Insecurities in dict comparison.
Fixed a half dozen ways in which general dict comparison could crash
Python (even cause Win98SE to reboot) in the presence of kay and/or
value comparison routines that mutate the dict during dict comparison.
Bugfix candidate.
Tim Peters [Thu, 10 May 2001 01:23:39 +0000 (01:23 +0000)]
Guido has Spoken. Restore strop.replace()'s treatment of a 0 count as
meaning infinity -- but at least warn about it in the code! I pissed
away a couple hours on this today, and don't wish the same on the next
in line.
Bugfix candidate.
Tim Peters [Thu, 10 May 2001 00:59:45 +0000 (00:59 +0000)]
The strop module and test_strop.py believe replace() with a 0 count
means "replace everything". But the string module, string.replace()
amd test_string.py believe a 0 count means "replace nothing".
"Nothing" wins, strop loses.
Bugfix candidate.
Tim Peters [Thu, 10 May 2001 00:32:57 +0000 (00:32 +0000)]
Heh. I need a break. After this: stropmodule & stringobject were more
out of synch than I realized, and I managed to break replace's "count"
argument when it was 0. All is well again. Maybe.
Bugfix candidate.
Tim Peters [Thu, 10 May 2001 00:05:33 +0000 (00:05 +0000)]
Fudge. stropmodule and stringobject both had copies of the buggy
mymemXXX stuff, and they were already out of synch. Fix the remaining
bugs in both and get them back in synch.
Bugfix release candidate.
Tim Peters [Wed, 9 May 2001 23:00:26 +0000 (23:00 +0000)]
SF bug #422088: [OSF1 alpha] string.replace().
Platform blew up on "123".replace("123", ""). Michael Hudson pinned the
blame on platform malloc(0) returning NULL.
This is a candidate for all bugfix releases.
Fred Drake [Wed, 9 May 2001 21:02:02 +0000 (21:02 +0000)]
Modify to allow file objects wherever file descriptors are needed.
This closes SF bug #231328.
Added all constants needed to use the functions defined in this module
that are not defined elsewhere (the O_* symbols are available in the
os module). No additonal modules are needed to use this now.
Fred Drake [Wed, 9 May 2001 20:14:09 +0000 (20:14 +0000)]
fdconv(): Do not second guess the error condition returned by
PyObject_AsFileDescriptor() -- it does the same thing everywhere, so
use it the same way everyone else does so that exceptions are
consistent. This means we have less code here, and we do not need to
resort to hackish ways of getting the Python-visible function name to
fdconv().
Fred Drake [Wed, 9 May 2001 19:57:37 +0000 (19:57 +0000)]
Itamar Shtull-Trauring <python@itamarst.org>:
Updates zipfile.ZipFile docs to mention the fact that you can create a
ZipFile instance from an arbitrary file-like object.
Fred Drake [Wed, 9 May 2001 19:11:33 +0000 (19:11 +0000)]
Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
this could cause invalid paths to be returned for AF_UNIX sockets on some
platforms (including FreeBSD 4.2-RELEASE), appearantly because there is
no assurance that the address will be nul-terminated when filled in by the
kernel.
PySocketSock_recvfrom(): Use PyString_AS_STRING() to get the data pointer
of a string we create ourselves; there is no need for the extra type
check from PyString_AsString().
Fred Drake [Wed, 9 May 2001 17:53:06 +0000 (17:53 +0000)]
Only import termio.h on OSF, and add a comment about why it is needed there.
This header does not exist on all Unix flavors; FreeBSD in particular does
not include it.
Fred Drake [Wed, 9 May 2001 04:03:16 +0000 (04:03 +0000)]
Job.build_html(): Be more robust in ensuring about.html exists; copying
the right HTML file to the name about.html is needed even if the
--numeric option was not given -- some other name may have been
assigned due to some non-determinism in the algorithm use to perform
name allocation. ;-(
This closes the "About..." portion of SF bug #420216.
Fred Drake [Wed, 9 May 2001 03:49:48 +0000 (03:49 +0000)]
There is no IMAP class in the imaplib module; the class is IMAP4.
There is no imap module; refer to imaplib instead, since it exists.
Move the "See Also:" section in front of the sub-sections, for
consistency with other portions of the library reference.
This closes the library reference portion of SF bug #420216.
Tim Peters [Wed, 9 May 2001 00:24:55 +0000 (00:24 +0000)]
My change to string_item() left an extra reference to each 1-character
interned string created by "string"[i]. Since they're immortal anyway,
this was hard to notice, but it was still wrong <wink>.
Tim Peters [Tue, 8 May 2001 22:33:50 +0000 (22:33 +0000)]
Intern 1-character strings as soon as they're created. As-is, they aren't
interned when created, so the cached versions generally aren't ever
interned. With the patch, the
Py_INCREF(t);
*p = t;
Py_DECREF(s);
return;
indirection block in PyString_InternInPlace() is never executed during a
full run of the test suite, but was executed very many times before. So
I'm trading more work when creating one-character strings for doing less
work later. Note that the "more work" here can happen at most 256 times
per program run, so it's trivial. The same reasoning accounts for the
patch's simplification of string_item (the new version can call
PyString_FromStringAndSize() no more than 256 times per run, so there's
no point to inlining that stuff -- if we were serious about saving time
here, we'd pre-initialize the characters vector so that no runtime testing
at all was needed!).
Tim Peters [Tue, 8 May 2001 15:19:57 +0000 (15:19 +0000)]
SF bug #422177: Results from .pyc differs from .py
Store floats and doubles to full precision in marshal.
Test that floats read from .pyc/.pyo closely match those read from .py.
Declare PyFloat_AsString() in floatobject header file.
Add new PyFloat_AsReprString() API function.
Document the functions declared in floatobject.h.
Fred Drake [Tue, 8 May 2001 05:37:52 +0000 (05:37 +0000)]
Michael Hudson <mwh21@cam.ac.uk>:
Documentation update to reflect changes to the termios module (noting
that the termios functions can take a file object as well as a file
descriptor).
This closes the documentation portion of SF patch #417081.
Tim Peters [Tue, 8 May 2001 04:38:29 +0000 (04:38 +0000)]
SF patch #421922: Implement rich comparison for dicts.
d1 == d2 and d1 != d2 now work even if the keys and values in d1 and d2
don't support comparisons other than ==, and testing dicts for equality
is faster now (especially when inequality obtains).
Jeremy Hylton [Tue, 8 May 2001 04:20:52 +0000 (04:20 +0000)]
Fix several bugs and add two features.
Assertion error message had typos in arguments to string format.
.cover files for modules in packages are now put in the right place.
The code that generate .cover files seemed to prepend a "./" to many
absolute paths, causing them to fail. The code now checks explicitly
for absolute paths and leaves them alone.
In trace/coverage code, recover from case where module has no __name__
attribute, when e.g. it is executed by PyRun_String(). In this case,
assign modulename to None and hope for the best. There isn't anywhere
to write out coverage data for this code anyway.
Also, replace several sys.stderr.writes with print >> sys.stderr.
New features:
-C/--coverdir dir: Generate .cover files in specified directory
instead of in the directory where the .py file is.
-s: Print a short summary of files coverred (# lines, % coverage,
name)
Tim Peters [Tue, 8 May 2001 03:58:01 +0000 (03:58 +0000)]
This is a test showing SF bug 422177. It won't trigger until I check in
another change (to test_import.py, which simply imports the new file). I'm
checking this piece in now, though, to make it easier to distribute a patch
for x-platform checking.
Tim Peters [Mon, 7 May 2001 20:53:51 +0000 (20:53 +0000)]
SF bug #422108 - Error in rich comparisons.
2.1.1 bugfix candidate too.
Fix a bad (albeit unlikely) return value in try_rich_to_3way_compare().
Also document do_cmp()'s return values.
(3) give better error messages
(4) removes a bunch of comments that just repeat the docstrings
(5) #includes <termio.h> before #including <sys/ioctl.h> so more
#constants are actually #defined.
(6) a couple of docstring tweaks
I have tested this minimally (i.e. it builds, and
doesn't blow up too embarassingly) on OSF1/alpha and
on one of the sf compile farm's solaris boxes, and
rather more comprehansively on my linux/x86 box.
It still needs to be tested on all the other platforms
we build termios on.
Tim Peters [Sun, 6 May 2001 01:05:02 +0000 (01:05 +0000)]
Generalize zip() to work with iterators.
NEEDS DOC CHANGES.
More AttributeErrors transmuted into TypeErrors, in test_b2.py, and,
again, this strikes me as a good thing.
This checkin completes the iterator generalization work that obviously
needed to be done. Can anyone think of others that should be changed?
Tim Peters [Sat, 5 May 2001 21:05:01 +0000 (21:05 +0000)]
Reimplement PySequence_Contains() and instance_contains(), so they work
safely together and don't duplicate logic (the common logic was factored
out into new private API function _PySequence_IterContains()).
Visible change:
some_complex_number in some_instance
no longer blows up if some_instance has __getitem__ but neither
__contains__ nor __iter__. test_iter changed to ensure that remains true.
Skeletal version; I'm checking this in now so I can keep a list of changes,
but don't plan on actually writing any text until, ooh, say, July or
thereabouts.
Tim Peters [Sat, 5 May 2001 10:06:17 +0000 (10:06 +0000)]
Make 'x in y' and 'x not in y' (PySequence_Contains) play nice w/ iterators.
NEEDS DOC CHANGES
A few more AttributeErrors turned into TypeErrors, but in test_contains
this time.
The full story for instance objects is pretty much unexplainable, because
instance_contains() tries its own flavor of iteration-based containment
testing first, and PySequence_Contains doesn't get a chance at it unless
instance_contains() blows up. A consequence is that
some_complex_number in some_instance
dies with a TypeError unless some_instance.__class__ defines __iter__ but
does not define __getitem__.
Tim Peters [Sat, 5 May 2001 05:36:48 +0000 (05:36 +0000)]
Make unicode.join() work nice with iterators. This also required a change
to string.join(), so that when the latter figures out in midstream that
it really needs unicode.join() instead, unicode.join() can actually get
all the sequence elements (i.e., there's no guarantee that the sequence
passed to string.join() can be iterated over *again* by unicode.join(),
so string.join() must not pass on the original sequence object anymore).
Tim Peters [Sat, 5 May 2001 04:24:43 +0000 (04:24 +0000)]
Mark string.join() as done. Turns out string_join() works "for free" now,
because PySequence_Fast() started working for free as soon as
PySequence_Tuple() learned how to work with iterators. For some reason
unicode.join() still doesn't work, though.
Tim Peters [Sat, 5 May 2001 03:56:37 +0000 (03:56 +0000)]
Generalize tuple() to work nicely with iterators.
NEEDS DOC CHANGES.
This one surprised me! While I expected tuple() to be a no-brainer, turns
out it's actually dripping with consequences:
1. It will *allow* the popular PySequence_Fast() to work with any iterable
object (code for that not yet checked in, but should be trivial).
2. It caused two std tests to fail. This because some places used
PyTuple_Sequence() (the C spelling of tuple()) as an indirect way to test
whether something *is* a sequence. But tuple() code only looked for the
existence of sq->item to determine that, and e.g. an instance passed
that test whether or not it supported the other operations tuple()
needed (e.g., __len__). So some things the tests *expected* to fail
with an AttributeError now fail with a TypeError instead. This looks
like an improvement to me; e.g., test_coercion used to produce 559
TypeErrors and 2 AttributeErrors, and now they're all TypeErrors. The
error details are more informative too, because the places calling this
were *looking* for TypeErrors in order to replace the generic tuple()
"not a sequence" msg with their own more specific text, and
AttributeErrors snuck by that.
Tim Peters [Thu, 3 May 2001 23:54:49 +0000 (23:54 +0000)]
Generalize map() to work with iterators.
NEEDS DOC CHANGES.
Possibly contentious: The first time s.next() yields StopIteration (for
a given map argument s) is the last time map() *tries* s.next(). That
is, if other sequence args are longer, s will never again contribute
anything but None values to the result, even if trying s.next() again
could yield another result. This is the same behavior map() used to have
wrt IndexError, so it's the only way to be wholly backward-compatible.
I'm not a fan of letting StopIteration mean "try again later" anyway.
Fred Drake [Thu, 3 May 2001 19:44:50 +0000 (19:44 +0000)]
Remove unnecessary intialization for the case of weakly-referencable objects;
the code necessary to accomplish this is simpler and faster if confined to
the object implementations, so we only do this there.
This causes no behaviorial changes beyond a (very slight) speedup.
Fred Drake [Thu, 3 May 2001 16:04:13 +0000 (16:04 +0000)]
Since Py_TPFLAGS_HAVE_WEAKREFS is set in Py_TPFLAGS_DEFAULT, it does not
need to be specified in the type structures independently. The flag
exists only for binary compatibility.
This is a "source cleanliness" issue and introduces no behavioral changes.
Fred Drake [Thu, 3 May 2001 04:58:49 +0000 (04:58 +0000)]
InteractiveInterpreter.showsyntaxerror():
When replacing the exception object, be sure we stuff the new value
in sys.last_value (which we already did for the original value).
Fred Drake [Wed, 2 May 2001 20:20:53 +0000 (20:20 +0000)]
Make the Mailbox objects support iteration -- they already had the
appropriate next() method, and this is what people really want to do with
these objects in practice.
Mchael Hudson pointed out that the code for detecting changes in
dictionary size was comparing ma_size, the hash table size, which is
always a power of two, rather than ma_used, wich changes on each
insertion or deletion. Fixed this.
Tim Peters [Tue, 1 May 2001 20:45:31 +0000 (20:45 +0000)]
Generalize list(seq) to work with iterators. This also generalizes list()
to no longer insist that len(seq) be defined.
NEEDS DOC CHANGES.
This is meant to be a model for how other functions of this ilk (max,
filter, etc) can be generalized similarly. Feel encouraged to grab your
favorite and convert it!
Note some cute consequences:
list(file) == file.readlines() == list(file.xreadlines())
list(dict) == dict.keys()
list(dict.iteritems()) = dict.items()
list(xrange(i, j, k)) == range(i, j, k)
Printing objects to a real file still wasn't done right: if the
object's type didn't define tp_print, there were still cases where the
full "print uses str() which falls back to repr()" semantics weren't
honored. This resulted in
>>> print None
<None object at 0x80bd674>
>>> print type(u'')
<type object at 0x80c0a80>
Fixed this by always using the appropriate PyObject_Repr() or
PyObject_Str() call, rather than trying to emulate what they would do.
Also simplified PyObject_Str() to always fall back on PyObject_Repr()
when tp_str is not defined (rather than making an extra check for
instances with a __str__ method). And got rid of the special case for
strings.