Tim Peters [Tue, 4 Feb 2003 20:56:09 +0000 (20:56 +0000)]
cPickle now generates proto 2 EXT[124] when appropriate.
Moved such EXT tests as currently exist from TempAbstractPickleTests to
AbstractPickleTests, so that test_cpickle runs them too.
Walter Dörwald [Tue, 4 Feb 2003 16:28:00 +0000 (16:28 +0000)]
filterstring() and filterunicode() in Python/bltinmodule.c
blindly assumed that tp_as_sequence->sq_item always returns
a str or unicode object. This might fail with str or unicode
subclasses.
This patch checks whether the object returned from __getitem__
is a str/unicode object and raises a TypeError if not (and
the filter function returned true).
Furthermore the result for __getitem__ can be more than one
character long, so checks for enough memory have to be done.
Jack Jansen [Tue, 4 Feb 2003 15:36:42 +0000 (15:36 +0000)]
- Handle the img and MediaFormat modules not being available (by not
providing the format info, only the raw data).
- Get rid of fsspecs.
- Make the demo program at least do something if img not available.
Fred Drake [Tue, 4 Feb 2003 15:12:06 +0000 (15:12 +0000)]
Update to better reflect the usage of struct_time instances throughout;
continuing to call these "time tuples" is misleading at best.
Closes SF bug #671731; will backport to 2.2.x.
Rename the extension registry variables to have leading underscores --
this clarifies that they are part of an internal API (albeit shared
between pickle.py, copy_reg.py and cPickle.c).
I'd like to do the same for copy_reg.dispatch_table, but worry that it
might be used by existing code. This risk doesn't exist for the
extension registry.
Tim Peters [Tue, 4 Feb 2003 00:21:07 +0000 (00:21 +0000)]
Brought some module variables into synch with pickle.py's current values.
Imported the extension-registry dicts from copy_reg.py, in preparation for
tackling EXT[124].
- Thanks to Scott David Daniels, a subtle bug in how the zlib
extension implemented flush() was fixed. Scott also rewrite the
zlib test suite using the unittest module. (SF bug #640230 and
patch #678531.)
_slotnames(): this is a fairly expensive calculation. Cache the
outcome as __slotnames__ on the class. (Like __slots__, it's not safe
to ask for this as an attribute -- you must look for it in the
specific class's __dict__. But it must be set using attribute
notation, because __dict__ is a read-only proxy.)
[Bug #676292] BaseHTTPServer incorrectly parses protocol; fix by Andrew Dalke
* Treat major, minor numbers of HTTP version as separate integers
* Fix errors if version string is "HTTP/1.2.3" or even simply "BLAH".
* send_error() checks if 'self.command' is a
HEAD. However, if there's an error parsing the first line of the
HTTP request the self.command wasn't set yet; force
self.command to be initialized to None.
Tim Peters [Mon, 3 Feb 2003 16:20:13 +0000 (16:20 +0000)]
Proper testing of proto 2 in part requires checking that the new opcodes
are actually getting generated. Add helpered method
ensure_opcode_in_pickle to do a correct job checking for that. Changed
test_long1(), test_long4(), and test_short_tuples() to use it.
_PyLong_Sign(): remove an assert that needed a variable ndigits that
wasn't used outside the assert (and hence caused a compiler warning
about an unused variable in NDEBUG mode). The assert wasn't very
useful any more.
_PyLong_NumBits(): moved the calculation of ndigits after asserting
that v != NULL.
test_float_overflow(): make shuge (added last week) a little less
huge. On older Linux systems, the C library's strtod() apparently
gives up before seeing the end of the string when it sees so many
digits that it thinks the result must be Infinity. (It is wrong, BTW
-- there could be an "e-10000" hiding behind 10,000 digits.) The
shorter shuge still tests what it's testing, without relying on
strtod() doing a super job.
Fred Drake [Mon, 3 Feb 2003 15:19:30 +0000 (15:19 +0000)]
test_support.requires(): Instead of raising TestSkipped, raise a new
exception, ResourceDenied. This is used to distinguish between tests that
are skipped for other reasons (platform support, missing data, etc.) from
those that are skipped because a "resource" has not been enabled. This
prevents those tests from being reported as unexpected skips for the
platform; those should only be considered unexpected skips if the resource
were enabled.
Skip Montanaro [Mon, 3 Feb 2003 05:13:24 +0000 (05:13 +0000)]
* Add description of PyInt_FromString.
* Correct description of PyFloat_FromString. While ignored, the pend
argument still has to be given.
* Typo in PyLong_FromString.
Skip Montanaro [Mon, 3 Feb 2003 03:56:36 +0000 (03:56 +0000)]
Add PyFloat_FromString. Left the char **pend argument out of the
description since while there, it is useless and ignored, according to Tim's
commen. (PyInt_FromString is also not described, but PyLong_FromString is.
Is the former deprecated?)
Tim Peters [Sun, 2 Feb 2003 18:29:33 +0000 (18:29 +0000)]
Massive edits. If p is a pointer to a struct, and p->f is a pointer to
a function, then
p->f(arg1, arg2, ...)
is semantically the same as
(*p->f)(arg1, arg2, ...)
Changed all instances of the latter into the former. Given how often
the code embeds this kind of expression in an if test, the unnecessary
parens and dereferening operator were a real drag on readability.
Tim Peters [Sun, 2 Feb 2003 17:26:40 +0000 (17:26 +0000)]
Beefed up the tests by putting in more "for proto in protocols:" outer
loops. Renamed DATA and BINDATA to DATA0 and DATA1. Included
disassemblies, but noted why we can't test them. Added XXX comment to
cPickle about a mysterious comment, where pickle and cPickle diverge
in how they number PUT indices.
Tim Peters [Sun, 2 Feb 2003 16:14:23 +0000 (16:14 +0000)]
dump(): Fixed a stupid bug in new code. It wasn't possible for the bug
to have an effect before protocol 3 is invented, so no test can be
written for this (yet).
Tim Peters [Sun, 2 Feb 2003 16:09:05 +0000 (16:09 +0000)]
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
the hitherto unknown (to me) noload() cPickle function, which is (a)
something we don't test at all, and (b) pickle.py doesn't have.
Tim Peters [Sun, 2 Feb 2003 07:51:32 +0000 (07:51 +0000)]
long(string, base) now takes time linear in len(string) when base is a
power of 2. Enabled the tail end of test_long() in pickletester.py
because it no longer takes forever when run from test_pickle.py.
Tim Peters [Sun, 2 Feb 2003 02:57:53 +0000 (02:57 +0000)]
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Assorted code cleanups; e.g., sizeof(char) is 1 by definition, so there's
no need to do things like multiply by sizeof(char) in hairy malloc
arguments. Fixed an undetected-overflow bug in readline_file().
longobject.c: Fixed a really stupid bug in the new _PyLong_NumBits.
pickle.py: Fixed stupid bug in save_long(): When proto is 2, it
wrote LONG1 or LONG4, but forgot to return then -- it went on to
append the proto 1 LONG opcode too.
Fixed equally stupid cancelling bugs in load_long1() and
load_long4(): they *returned* the unpickled long instead of pushing
it on the stack. The return values were ignored. Tests passed
before only because save_long() pickled the long twice.
Fixed bugs in encode_long().
Noted that decode_long() is quadratic-time despite our hopes,
because long(string, 16) is still quadratic-time in len(string).
It's hex() that's linear-time. I don't know a way to make decode_long()
linear-time in Python, short of maybe transforming the 256's-complement
bytes into marshal's funky internal format, and letting marshal decode
that. It would be more valuable to make long(string, 16) linear time.
pickletester.py: Added a global "protocols" vector so tests can try
all the protocols in a sane way. Changed test_ints() and test_unicode()
to do so. Added a new test_long(), but the tail end of it is disabled
because it "takes forever" under pickle.py (but runs very quickly under
cPickle: cPickle proto 2 for longs is linear-time).
Tim Peters [Sat, 1 Feb 2003 04:40:04 +0000 (04:40 +0000)]
New functions alloc_{time,datetime}. Got rid of all setstate-like
functions. Reworked {time,datetime}_new() to do what their corresponding
setstates used to do in their state-tuple-input paths, but directly,
without constructing an object with throwaway state first. Tightened
the "is this a state tuple input?" paths to check the presumed state
string-length too, and to raise an exception if the optional second state
element isn't a tzinfo instance (IOW, check these paths for type errors
as carefully as the normal paths).
Tim Peters [Sat, 1 Feb 2003 02:54:15 +0000 (02:54 +0000)]
There's no good reason for datetime objects to expose __getstate__()
anymore either, so don't. This also allows to get rid of obscure code
making __getnewargs__ identical to __getstate__ (hmm ... hope there
wasn't more to this than I realize!).