Tim Peters [Tue, 31 Aug 2004 02:19:55 +0000 (02:19 +0000)]
HardwareRandom: Go back to multiplying by 2**-BPF instead of using
ldexp. Both methods are exact, and return the same results. Turns out
multiplication is a few (but just a few) percent faster on my box.
They're both significantly faster than using struct with a Q format
to convert bytes to a 64-bit long (struct.unpack() appears to lose due
to the tuple creation/teardown overhead), and calling _hexlify is
significantly faster than doing bytes.encode('hex'). So we appear to
have hit a local minimum (wrt speed) here.
Take advantage of the math library's ldexp for assembling a float by
components without division and without roundoff error for properly
sized mantissas (i.e. on systems with 53 or more mantissa bits per
float). Eliminates the previous implementation's rounding bias as
aptly demonstrated by Tim Peters.
Tim Peters [Mon, 30 Aug 2004 21:14:51 +0000 (21:14 +0000)]
Updated test-runner .bat for new location of Tcl/Tk.
Replaced outcomes from native Tcl/Tk tests. Maybe the diffs are legit,
maybe not. I noticed that the Tcl results I'm replacing here claimed
both that there were no failures, and that one file had tests with
failures, so I wasn't inclined to trust them <wink>.
Tim Peters [Mon, 30 Aug 2004 16:19:24 +0000 (16:19 +0000)]
The distinction between comparison flags and reporting flags isn't unique
to unittest, so make it official: new module constants COMPARISON_FLAGS
and REPORTING_FLAGS, which are bitmasks or'ing together the relevant
individual option flags.
set_unittest_reportflags(): Reworked to use REPORTING_FLAGS, and
simplified overly complicated flag logic.
class FakeModule: Removed this; neither documented nor used.
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
1) When a breakpoint is set via a function name:
- the breakpoint gets the lineno of the def statement
- a new funcname attribute is attached to the breakpoint
2) bdb.effective() calls new function checkfuncname() to handle:
- def statement is executed: don't break.
- a first executable line of a function with a breakpoint on the lineno of the
def statement is reached: break.
This fixes bugs 976878, 926369 and 875404. Thanks Ilya Sandler.
Tim Peters [Mon, 30 Aug 2004 02:44:38 +0000 (02:44 +0000)]
SF patch 936813: fast modular exponentiation
This checkin is adapted from part 2 (of 3) of Trevor Perrin's patch set.
BACKWARD INCOMPATIBILITY: SHIFT must now be divisible by 5. AFAIK,
nobody will care. long_pow() could be complicated to worm around that,
if necessary.
long_pow():
- BUGFIX: This leaked the base and power when the power was negative
(and so the computation delegated to float pow).
- Instead of doing right-to-left exponentiation, do left-to-right. This
is more efficient for small bases, which is the common case.
- In addition, if the exponent is large (more than FIVEARY_CUTOFF
digits), precompute [a**i % c for i in range(32)], and go left to
right 5 bits at a time.
l_divmod():
- The signature changed so that callers who don't want the quotient,
or don't want the remainder, can pass NULL in the slot they don't
want. This saves them from having to declare a vrbl for unwanted
stuff, and remembering to decref it.
long_mod(), long_div(), long_classic_div():
- Adjust to new l_divmod() signature, and simplified as a result.
Tim Peters [Sun, 29 Aug 2004 22:16:50 +0000 (22:16 +0000)]
SF patch 936813: fast modular exponentiation
This checkin is adapted from part 1 (of 3) of Trevor Perrin's patch set.
x_mul()
- sped a little by optimizing the C
- sped a lot (~2X) if it's doing a square; note that long_pow() squares
often
k_mul()
- more cache-friendly now if it's doing a square
KARATSUBA_CUTOFF
- boosted; gradeschool mult is quicker now, and it may have been too low
for many platforms anyway
KARATSUBA_SQUARE_CUTOFF
- new
- since x_mul is a lot faster at squaring now, the point at which
Karatsuba pays for squaring is much higher than for general mult
Tim Peters [Sun, 29 Aug 2004 19:33:36 +0000 (19:33 +0000)]
Reverting whitespace normalization. test_difflib fails with it -- the
test depends on invisible trailing whitespace in .py files. The author will
have to repair that.
Tim Peters [Fri, 27 Aug 2004 22:35:44 +0000 (22:35 +0000)]
PyUnicode_Join(): Bozo Alert. While this is chugging along, it may
need to convert str objects from the iterable to unicode. So, if
someone set the system default encoding to something nasty enough,
the conversion process could mutate the input iterable as a side
effect, and PySequence_Fast doesn't hide that from us if the input was
a list. IOW, can't assume the size of PySequence_Fast's result is
invariant across PyUnicode_FromObject() calls.
Tim Peters [Fri, 27 Aug 2004 21:32:02 +0000 (21:32 +0000)]
PyUnicode_Join(): Rewrote to use PySequence_Fast(). This doesn't do
much to reduce the size of the code, but greatly improves its clarity.
It's also quicker in what's probably the most common case (the argument
iterable is a list). Against it, if the iterable isn't a list or a tuple,
a temp tuple is materialized containing the entire input sequence, and
that's a bigger temp memory burden. Yawn.
Tim Peters [Fri, 27 Aug 2004 15:12:49 +0000 (15:12 +0000)]
Don't really need ellipsis doctests for the syntax errors, because
this module imports itself explicitly from test (so the "file names"
current doctest synthesizes for examples don't vary depending on how
test_generators is run).
Tim Peters [Fri, 27 Aug 2004 05:36:07 +0000 (05:36 +0000)]
test_bug1001011(): Verify that
s.join([t]) is t
for (s, t) in (str, str), (unicode, unicode), and (str, unicode).
For (unicode, str), verify that it's *not* t (the result is promoted
to unicode instead). Also verify that when t is a subclass of str or
unicode that "the right thing" happens.
Tim Peters [Fri, 27 Aug 2004 05:08:36 +0000 (05:08 +0000)]
PyUnicode_Join(): Missed a spot where I intended a cast from size_t to
int. I sure wish MS would gripe about that! Whatever, note that the
statement above it guarantees that the cast loses no info.
Edward Loper [Fri, 27 Aug 2004 02:07:46 +0000 (02:07 +0000)]
- Removed redundant call to expandtabs in DocTestParesr.
- Improvements to interactive debugging support:
- Changed the replacement pdb.set_trace to redirect stdout to the
real stdout *only* during interactive debugging; stdout from code
continues to go to the fake stdout.
- When the interactive debugger gets to the end of an example,
automatically continue.
- Use a replacement linecache.getlines that will return source lines
from doctest examples; this makes the source available to the
debugger for interactive debugging.
- In test_doctest, use a specialized _FakeOutput class instead of a
temporary file to fake stdin for the interactive interpreter.
Edward Loper [Thu, 26 Aug 2004 18:05:07 +0000 (18:05 +0000)]
- Added DocTestParser.parse(), which parses a docstring into Examples
and intervening text strings.
- Removed DocTestParser.get_program(): use script_from_examples()
instead.
- Fixed bug in DocTestParser._INDENT_RE
- Fixed bug in DocTestParser._min_indent
- Moved _want_comment() to the utility function section
Walter Dörwald [Thu, 26 Aug 2004 16:53:04 +0000 (16:53 +0000)]
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
it can be used for str and unicode. Drop the test for
"".join([s]) is s
because this is an implementation detail (and doesn't work for unicode)
Tim Peters [Thu, 26 Aug 2004 05:44:27 +0000 (05:44 +0000)]
output_difference(): In fancy-diff cases, the way this split expected &
actual output into lines created spurious empty lines at the ends of
each. Those matched, but the fancy diffs had surprising line counts (1
larger than expected), and tests kept having to slam <BLANKLINE> into the
expected output to account for this. Using the splitlines() string method
with keepends=True instead accomplishes what was intended directly.
Tim Peters [Thu, 26 Aug 2004 05:21:59 +0000 (05:21 +0000)]
_do_a_fancy_diff(): Pay no attention to the ellipses behind the curtain.
While a fancy diff can be confusing in the presence of ellipses, so far
I'm finding (2-0-0) that it's much more a major aid in narrowing down the
possibilities when an ellipsis-slinging test fails. So we no longer
refuse to do a fancy diff just because of ellipses.
Tim Peters [Thu, 26 Aug 2004 04:47:31 +0000 (04:47 +0000)]
Reorg of exception section. Now that there are fewer details needing
explanation, it's easier to push the remaining insufferably anal details
into a "fine print" section at the bottom.
Edward Loper [Thu, 26 Aug 2004 03:00:24 +0000 (03:00 +0000)]
Changed OutputChecker.output_difference to expect an Example object,
rather than an expected output string. This gives the
output_difference method access to more information, such as the
indentation of the example, which might be useful.
Brett Cannon [Thu, 26 Aug 2004 01:44:07 +0000 (01:44 +0000)]
When building with --disable-toolbox-glue under Darwin, skip building any
Mac-specific modules. Before all modules were compiled but would fail thanks
to a dependence on the code included when Python was built without the compiler
flag.
Edward Loper [Thu, 26 Aug 2004 01:41:51 +0000 (01:41 +0000)]
Renamed UNIFIED_DIFF->REPORT_UDIFF; CONTEXT_DIFF->REPORT_CDIFF; and
NDIFF_DIFF->REPORT_NDIFF. This establishes the naming convention that
all reporting options should begin with "REPORT_" (since reporting
options are a different class from output comparison options; but they
are both set in optionflags).
Edward Loper [Thu, 26 Aug 2004 01:19:50 +0000 (01:19 +0000)]
- Changed the output of report_start() and report_unexpected_exception()
to be more consistent with report_failure()
- If `want` or `got` is empty, then print "Expected nothing\n" or
"Got nothing\n" rather than "Expected:\n" or "Got:\n"
- Got rid of _tag_msg
* Add comment bars segregating this code from the rest.
* Improve readability of the re pattern with indentation and comments on
the same line.
* Replace the groupdict() and get() pair with a direct call to group()
which does the same thing.
Edward Loper [Thu, 26 Aug 2004 00:05:43 +0000 (00:05 +0000)]
Added an "exc_msg" attribute to Example (containing the expected
exception message, or None if no exception is expected); and moved
exception parsing from DocTestRunner to DocTestParser. This is
architecturally cleaner, since it moves all parsing work to
DocTestParser; and it should make it easier for code outside
DocTestRunner (notably debugging code) to properly handle expected
exceptions.