Guido van Rossum [Thu, 18 Jan 2001 23:33:37 +0000 (23:33 +0000)]
Rich comparisons fallout: PyObject_Hash() should check for both
tp_compare and tp_richcompare NULL before deciding to do a quickie
based on the object address. (Tim Peters discovered this.)
Guido van Rossum [Thu, 18 Jan 2001 22:07:06 +0000 (22:07 +0000)]
Changes to recursive-object comparisons, having to do with a test case
I found where rich comparison of unequal recursive objects gave
unintuituve results. In a discussion with Tim, where we discovered
that our intuition on when a<=b should be true was failing, we decided
to outlaw ordering comparisons on recursive objects. (Once we have
fixed our intuition and designed a matching algorithm that's practical
and reasonable to implement, we can allow such orderings again.)
- Refactored the recursive-object comparison framework; more is now
done in the support routines so less needs to be done in the calling
routines (even at the expense of slowing it down a bit -- this
should normally never be invoked, it's mostly just there to avoid
blowing up the interpreter).
- Changed the framework so that the comparison operator used is also
stored. (The dictionary now stores triples (v, w, op) instead of
pairs (v, w).)
- Changed the nesting limit to a more reasonable small 20; this only
slows down comparisons of very deeply nested objects (unlikely to
occur in practice), while speeding up comparisons of recursive
objects (previously, this would first waste time and space on 500
nested comparisons before it would start detecting recursion).
- Changed rich comparisons for recursive objects to raise a ValueError
exception when recursion is detected for ordering oprators (<, <=,
>, >=).
Unrelated change:
- Moved PyObject_Unicode() to just under PyObject_Str(), where it
belongs. MAL's patch must've inserted in a random spot between two
functions in the file -- between two helpers for rich comparison...
Guido van Rossum [Thu, 18 Jan 2001 21:52:26 +0000 (21:52 +0000)]
Since I'm about to check in a change to the recursion-detection code
for comparisons that outlaws requets for ordering on recursive data
structures, remove the tests for ordering recursive data structures.
Patch #103313: Fixes "make test" by adding a little file named
"platform", running the Python binary to create it, and then
using it to set PYTHONPATH.
Patch from Barry: gets rid of two unused imports,
wraps to 80chars, and adds some really hacky setting of compiler
options when CC and LDSHARED are given on the make command line.
(The Distutils should probably provide a utility function to
automatically handle a number of common environment variables)
Sizable reorganization of how header and library files are found
Check additional include directories for SSL
Don't build modules that are linked into the Python binary statically
Factored out the detection of Tkinter out into a method, since it's
the most complicated module to set up
Simplify the logic for detecting Tkinter
Make the original, makesetup-based, targets for building shared modules
available as "oldsharedmods" and "oldsharedinstall". You'll need
to get a copy of the full Setup.dist out of the CVS for them to
actually do much.
Guido van Rossum [Thu, 18 Jan 2001 14:28:08 +0000 (14:28 +0000)]
- Add note about complex numbers.
- Changed description of rich comparisons to emphasize that < and >
(etc.) are each other's reflection. Also use this word in the note
about the demise of __rcmp__.
Guido van Rossum [Thu, 18 Jan 2001 01:12:39 +0000 (01:12 +0000)]
Use rich comparisons to fulfill an old wish: complex numbers now raise
exceptions when compared using <, <=, > or >=.
NOTE: This is a tentative change: this means that cmp() involving
complex numbers will raise an exception when the numbers differ, and
that in turn means that e.g. dictionaries and certain other compounds
(e.g. UserLists) containing complex numbers can't be compared either.
So we'll have to decide whether this is acceptable. The alpha test
cycle is a good time to keep an eye on this!
Guido van Rossum [Thu, 18 Jan 2001 00:39:02 +0000 (00:39 +0000)]
Rich comparisons:
- Use PyObject_RichCompareBool() when comparing keys; this makes the
error handling cleaner.
- There were two implementations for dictionary comparison, an old one
(#ifdef'ed out) and a new one. Got rid of the old one, which was
abandoned years ago.
- In the characterize() function, part of dictionary comparison, use
PyObject_RichCompareBool() to compare keys and values instead. But
continue to use PyObject_Compare() for comparing the final
(deciding) elements.
- Align the comments in the type struct initializer.
Note: I don't implement rich comparison for dictionaries -- there
doesn't seem to be much to be gained. (The existing comparison
already decides that shorter dicts are always smaller than longer
dicts.)
Guido van Rossum [Wed, 17 Jan 2001 23:43:43 +0000 (23:43 +0000)]
Fix a leak in instance_coerce(). This was introduced by Neil's
earlier coercion changes, not by rich comparisons. When a coercion
function returns 1 (meaning it cannot do it), it should not INCREF the
arguments. When no __coerce__() method was found, instance_coerce()
originally returned 0, pretending it did it. Neil changed the return
value to 1, more accurately reflecting that it didn't do anything, but
forgot to take out the two INCREF calls.
- Get rid of list_compare(), in favor of new list_richcompare(). The
latter does some nice shortcuts, like when == or != is requested, it
first compares the lengths for trivial accept/reject. Then it goes
over the items until it finds an index where the items differe; then
it does more shortcut magic to minimize the number of additional
comparisons.
- Aligned the comments for large struct initializers.
Guido van Rossum [Wed, 17 Jan 2001 21:43:06 +0000 (21:43 +0000)]
Marc-Andre must not have run these tests -- they used verify() but
didn't import it. Also got rid of some inconsistent spaces inside
parentheses in test_gzip.py.
Guido van Rossum [Wed, 17 Jan 2001 21:27:02 +0000 (21:27 +0000)]
Deal properly (?) with comparing recursive datastructures.
- Use the compare nesting level and in-progress dictionary properly in
PyObject_RichCompare().
- Change the in-progress code to use static variables instead of
globals (both the nesting level and the key for the thread dict were
globals but have no reason to be globals; the key can even be a
function-static variable in get_inprogress_dict()).
- Rewrote try_rich_to_3way_compare() to benefit from the similarity of
the three cases, making it table-driven.
- In try_rich_to_3way_compare(), test for EQ before LT and GT. This
turns out essential when comparing recursive UserList instances;
with the old code, these would recurse into rich comparison three
times for each nesting level up to NESTING_LIMIT/2, making the total
number of calls in the order of 3**(NESTING_LIMIT/2)!
NOTE: I'm not 100% comfortable with this. It works for the standard
test suite (which compares a few trivial recursive data structures
only), but I'm not sure that the in-progress dictionary is used
properly by the rich comparison code. Jeremy suggested that maybe the
operation should be included in the dict. Currently I presume that
objects in the dict are equal unless proven otherwise, and I set the
outcome for the rich comparison accordingly: true for operators EQ,
LE, GE, and false for the other three. But Jeremy seems to think that
there may be counter-examples where this doesn't do the right thing.
Fix for bug #129173, reported by Skip Montanaro:
Check for the two possible headers for Expat, expat.h and xmlparse.h,
and only compile the pyexpat module if one of them is found.
This patch removes all uses of "assert" in the regression test suite
and replaces them with a new API verify(). As a result the regression
suite will also perform its tests in optimization mode.
Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
Tim Peters [Wed, 17 Jan 2001 18:59:46 +0000 (18:59 +0000)]
Stop creating an unbounded number of "Jack is my hero" files under Windows.
Not that Jack doesn't deserve them, but saying it so often cheapens the
sentiment.
Various clean-ups:
* Uncomment the xreadlines module
* The Tcl/Tk detection code doesn't need to worry about pre-8.0 versions
* Fix some debugging changes (not running ar, a commented-out line)
Guido van Rossum [Wed, 17 Jan 2001 15:24:28 +0000 (15:24 +0000)]
Rich comparisons. Refactored internal routine do_cmp() and added APIs
PyObject_RichCompare() and PyObject_RichCompareBool().
XXX Note: the code that checks for deeply nested rich comparisons is
bogus -- it assumes the two objects are always identical, rather than
using the same logic as PyObject_Compare(). I'll fix that later.
[Patch #102588/PEP 229]:
Check in the setup.py script, and the setup.cfg.in file, which
handle compiling and installing as many extension modules as possible
Patch #103279: sysconfig.py always looks for versions of files in
sys.prefix + 'config/Makefile'. When building Python for the first
time, these files aren't there, so the files from the build tree have
to be used instead; this file adds an entry point for specifying that
the build tree files should be used. (Perhaps 'set_python_build' should
should be preceded with an underscore?)
Guido van Rossum [Wed, 17 Jan 2001 15:08:37 +0000 (15:08 +0000)]
Fix a bizarre typo in the helper class ComparableException: the
__getattr__() method, which clearly (like the other methods) was
intended to pass the __getattr__() call on to the self.err object,
mistakenly returned getattr(self, self.err) rather than
getattr(self.err, attr). Since self.err is not a string, this always
raises a TypeError. Apparently that doesn't bother for the one
attribute for which __getattr__() is actually called ('__coerce__'),
but it broke the rich comparisons stuff that I'm trying to get into
shape, so I'm fixing this now. (I could also simply remove the
__getattr__() method, but fixing it seems more in the spirit of what
the ComparableException class is trying to do.)
via untabifying and shifting the real code left. Semantically the
same but made the intent of the commented-out-in-column-0 unused code
unclear. The exact same unused code appears to have gotten copied from
file to file over the years.
Eric S. Raymond [Wed, 17 Jan 2001 08:25:11 +0000 (08:25 +0000)]
Eric the half-a-wit, driven to berserk rage after repeatedly doing
builds during which he forgot to uncomment crucial library lines in
Setup, walks into Guido's East End nightclub with a tactical nuclear
weapon on his shoulder. Said nuclear weapon is promptly deployed
exactly where it will do the most good, right in the middle of
configure.in.
With this patch, the set of libraries autoconfigured in is extended to
include ndbm, gdbm, and crypt. This essentially eliminates any need to
tweak Setup for a normal Linux build.
Guido van Rossum [Wed, 17 Jan 2001 03:12:01 +0000 (03:12 +0000)]
Use __name__ instead of "test_regex" as the module name in the
warnings.filterwarnings() call. This suppresses the warning when the
module is imported with its full name (test.test_regex) too.
Guido van Rossum [Tue, 16 Jan 2001 20:53:31 +0000 (20:53 +0000)]
Rationalizing the fallback code for portable fseek -- this is all much
simpler if we use fgetpos and fsetpos, rather than trying to mess with
platform-specific TELL64 alternatives.
Of course, this hasn't been tested on a 64-bit platform, so I may have
to withdraw this -- but I'm hopeful, and Trent Mick supports this
patch!
Fix bugs with integer-valued variables when parsing Makefiles. Values
for done[n] can be integers as well as strings, but the code
concatenates them with strings (fixed by adding a str()) and calls
string.strip() on them (fixed by rearranging the logic)
(Presumably this wasn't noticed previously because parse_makefile()
was only called on Modules/Makefile, which contains no integer-valued
variables.)
Modified version of a patch from Jeremy Kloth, to make .get_outputs()
produce a list of unique filenames:
"While attempting to build an RPM using distutils on Python 2.0,
rpm complained about duplicate files. The following patch fixed
that problem.
Eric S. Raymond [Tue, 16 Jan 2001 15:01:26 +0000 (15:01 +0000)]
Make HAVE_TERMIOS_H and associated config.sh shell variable available
when configure detects the presence of termios.h; later we'll use this
for correct configuration of edline/readline.
Also, fix a bug in acconfig.h -- somebody forgot to add an undef to
cover the LIBNDBM configure symbol, which was preventing autoheader
from working properly.
Eric S. Raymond [Tue, 16 Jan 2001 14:18:55 +0000 (14:18 +0000)]
push_source() and pop_source() entry points for shlex instances.
These basically just make available to the user what userhook()
does to the source stack. Documentation included.
Added checks to prevent PyUnicode_Count() from dumping core
in case the parameters are out of bounds and fixes error handling
for .count(), .startswith() and .endswith() for the case of
mixed string/Unicode objects.
This patch adds Python style index semantics to PyUnicode_Count()
indices (including the special handling of negative indices).
The patch is an extended version of patch #103249 submitted
by Michael Hudson (mwh) on SF. It also includes new test cases.
Thomas Wouters [Tue, 16 Jan 2001 06:35:14 +0000 (06:35 +0000)]
Fix for SF bug #123625: some newsservers need 'authinfo' *before* 'mode
readers', others *after*. (Netscape Collabra for the first category,
INN-which-forks-nnrpd for the second.)
Add strip_dir argument to the single call to .object_filenames(), to
prevent creating files such as build/lib.whatever/Modules/foo.o
when given a source filename such as Modules/foo.c.