Commit Graph

91 Commits

Author SHA1 Message Date
Neal Norwitz 18aa388ca0 Fix:
* crashes on memory allocation failure found with failmalloc
 * memory leaks found with valgrind
 * compiler warnings in opt mode which would lead to invalid memory reads
 * problem using wrong name in decimal module reported by pychecker

Update the valgrind suppressions file with new leaks that are small/one-time
leaks we don't care about (ie, they are too hard to fix).

TBR=barry
TESTED=./python -E -tt ./Lib/test/regrtest.py -uall (both debug and opt modes)
  in opt mode:
  valgrind -q --leak-check=yes --suppressions=Misc/valgrind-python.supp \
    ./python -E -tt ./Lib/test/regrtest.py -uall,-bsddb,-compiler \
                        -x test_logging test_ssl test_multiprocessing
  valgrind -q --leak-check=yes --suppressions=Misc/valgrind-python.supp \
    ./python -E -tt ./Lib/test/regrtest.py test_multiprocessing
  for i in `seq 1 4000` ; do
    LD_PRELOAD=~/local/lib/libfailmalloc.so FAILMALLOC_INTERVAL=$i \
        ./python -c pass
  done

At least some of these fixes should probably be backported to 2.5.
2008-08-24 05:04:52 +00:00
Nick Coghlan 53663a695e Issue 2235: __hash__ is once again inherited by default, but inheritance can be blocked explicitly so that collections.Hashable remains meaningful 2008-07-15 14:27:37 +00:00
Mark Dickinson 70c3289085 Replace occurrences of '\d' with '[0-9]' in Decimal regex, to make sure
that the behaviour of Decimal doesn't change if/when re.UNICODE becomes
assumed in Python 3.0.

Also add a check that alternative Unicode digits (e.g. u'\N{FULLWIDTH
DIGIT ONE}') are *not* accepted in a numeric string.
2008-07-02 09:37:01 +00:00
Mark Dickinson 71f3b85497 Make sure that Context traps and flags dictionaries have values 0 and 1
(as documented) rather than True and False.
2008-05-04 02:25:46 +00:00
Mark Dickinson 8aca9d032e Some very minor changes to decimal.py in Python 2.6, aimed
at reducing the size of the diff between the 2.x decimal.py
and 3.x decimal.py and thereby making future merges easier:

- replace one instnace of an old-style raise statement
- define __div__ in terms of __truediv__ instead of the
  other way around
- make wording match on an exception message
2008-05-04 02:05:06 +00:00
Mark Dickinson 1840c1abca Backport Raymond's changes in r60508 to Python 2.6.
'Context flags get set, not incremented'
2008-05-03 18:23:14 +00:00
Facundo Batista ee340e501d Fixed some test structures. Thanks Mark Dickinson. 2008-05-02 17:39:00 +00:00
Mark Dickinson 8e85ffa4b2 Issue #2482: Make sure that the coefficient of a Decimal
instance is always stored as a str instance, even
when that Decimal has been created from a unicode string.
2008-03-25 18:47:59 +00:00
Mark Dickinson 3b24ccbe7e Issue #2478: Decimal(sqrt(0)) failed when the decimal context
was not explicitly supplied.
2008-03-25 14:33:23 +00:00
Mark Dickinson f4da77765f Fix docstring typo. 2008-02-29 03:29:17 +00:00
Mark Dickinson 1ddf1d8482 Add __format__ method to Decimal, to support PEP 3101 2008-02-29 02:16:37 +00:00
Mark Dickinson 6a123cb782 Remove duplicate 'import re' in decimal.py 2008-02-24 18:12:36 +00:00
Raymond Hettinger abe3237187 Fix decimal repr which should have used single quotes like other reprs. 2008-02-14 02:41:22 +00:00
Raymond Hettinger 116f72fa5c Bring decimal a bit closer to the spec for Reals. 2008-02-12 01:18:03 +00:00
Mark Dickinson 3a94ee05f7 Typos in decimal comment and documentation 2008-02-10 15:19:58 +00:00
Mark Dickinson 2fc9263df5 Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
2008-02-06 22:10:50 +00:00
Raymond Hettinger 5a05364049 Add support for trunc(). 2008-01-24 19:05:29 +00:00
Andrew M. Kuchling c8acc882a9 Docstring typos 2008-01-16 00:32:03 +00:00
Mark Dickinson 59bc20bb27 Issue 1780: Allow leading and trailing whitespace in Decimal constructor,
when constructing from a string. Disallow trailing newlines in
Context.create_decimal.
2008-01-12 01:56:00 +00:00
Raymond Hettinger 097a190303 Have Decimal.as_tuple return a named tuple. 2008-01-11 02:24:13 +00:00
Facundo Batista 52b25795c0 Issue #1757: The hash of a Decimal instance is no longer affected
by the current context.  Thanks Mark Dickinson.
2008-01-08 12:25:20 +00:00
Facundo Batista 0f5e7bf304 Some minor cleanups. Thanks Mark Dickinson. 2007-12-19 12:53:01 +00:00
Facundo Batista e64acfad3d Removed the private _rounding_decision: it was not needed, and the code
is now simpler.  Thanks Mark Dickinson.
2007-12-17 14:18:42 +00:00
Facundo Batista 58f6f2e0c9 fma speedup by avoiding to create a Context. Thanks Mark Dickinson. 2007-12-04 16:31:53 +00:00
Facundo Batista 2ec7415db5 Faster _fix function, and some reordering for a more elegant
coding. Thanks Mark Dickinson.
2007-12-03 17:55:00 +00:00
Facundo Batista 62edb71556 Speedup and cleaning of __str__. Thanks Mark Dickinson. 2007-12-03 16:29:52 +00:00
Facundo Batista 0d157a0154 Reordering of __new__ to minimize isinstance() calls to most
used types. Thanks Mark Dickinson.
2007-11-30 17:15:25 +00:00
Facundo Batista 72bc54faed Major change in the internal structure of the Decimal
number: now it does not store the mantissa as a tuple
of numbers, but as a string.

This avoids a lot of conversions, and achieves a
speedup of 40%. The API remains intact.

Thanks Mark Dickinson.
2007-11-23 17:59:00 +00:00
Facundo Batista 9b5e23148b The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.

Test cases added for these issues. Thanks Mark Dickinson.
2007-10-19 19:25:57 +00:00
Facundo Batista be6c7ba72a Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing.  Thanks Mark Dickinson
2007-10-02 18:21:18 +00:00
Facundo Batista 1a191df14d Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.

Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).

Thanks Mark Dickinson
2007-10-02 17:01:24 +00:00
Facundo Batista 8c20244069 Issue #1772851. Optimization of __hash__ to behave better for big big
numbers.
2007-09-19 17:53:25 +00:00
Facundo Batista cce8df2f67 Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
2007-09-18 16:53:18 +00:00
Facundo Batista 6c398da0e7 The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
2007-09-17 17:30:13 +00:00
Facundo Batista bd2fe839db Put the parameter watchexp back in (changed watchexp from an int
to a bool).  Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.

Thanks Mark Dickinson.
2007-09-13 18:42:09 +00:00
Facundo Batista 353750c405 Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).

Thanks to Mark Dickinson for all his help during this process.
2007-09-13 18:13:15 +00:00
Facundo Batista 849693989a When passed a bad formed literal to Decimal, now we have a
better error message, more descriptive. (bug #1770009)
2007-08-15 15:13:09 +00:00
Neal Norwitz 0d4c06e06e Whitespace normalization. Ugh, we really need to do this more often.
You might want to review this change as it's my first time.  Be gentle. :-)
2007-04-25 06:30:05 +00:00
Facundo Batista 59c5884b4c General clean-up. Lot of margin corrections, comments, some typos.
Exceptions now are raised in the new style. And a mockup class is
now also new style. Thanks Santiago Pereson.
2007-04-10 12:58:45 +00:00
Raymond Hettinger 495df4716f Fix docstring bug 2007-02-08 01:42:35 +00:00
Neal Norwitz 681d86743c Add missing word in comment 2006-09-02 18:51:34 +00:00
Nick Coghlan ced1218dd1 Make decimal.ContextManager a private implementation detail of decimal.localcontext() 2006-09-02 03:54:17 +00:00
Nick Coghlan 8b6999b4c5 Fix the wrongheaded implementation of context management in the decimal module and add unit tests. (python-dev discussion is ongoing regarding what we do about Python 2.5) 2006-08-31 12:00:43 +00:00
Martin v. Löwis cfe3128cd5 Revert r50706 (Whitespace normalization) and
r50697: Comments and docs cleanups, and some little fixes
per recommendation from Raymond Hettinger.
2006-07-19 17:18:32 +00:00
Tim Peters 73a9eade1c Whitespace normalization. 2006-07-18 21:55:15 +00:00
Facundo Batista ac4ae4baf7 Comments and docs cleanups, and some little fixes, provided by Santiágo Peresón 2006-07-18 12:16:13 +00:00
Georg Brandl 1fb9f528bd Typo fix. 2006-05-11 19:57:09 +00:00
Nick Coghlan afd5e63e24 Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager() 2006-05-03 13:02:47 +00:00
Guido van Rossum da5b701aee Get rid of __context__, per the latest changes to PEP 343 and python-dev
discussion.
There are two places of documentation that still mention __context__:
Doc/lib/libstdtypes.tex -- I wasn't quite sure how to rewrite that without
spending a whole lot of time thinking about it; and whatsnew, which Andrew
usually likes to change himself.
2006-05-02 19:47:52 +00:00
Nick Coghlan a7e820a408 Move the PEP 343 documentation and implementation closer to the
terminology in the alpha 1 documentation.

 - "context manager" reverts to its alpha 1 definition
 - the term "context specifier" goes away entirely
 - contextlib.GeneratorContextManager is renamed GeneratorContext

There are still a number of changes relative to alpha 1:

  - the expression in the with statement is explicitly called the
    "context expression" in the language reference
  - the terms 'with statement context', 'context object' or 'with
    statement context' are used in several places instead of a bare
    'context'. The aim of this is to avoid ambiguity in relation to the
    runtime context set up when the block is executed, and the context
    objects that already exist in various application domains (such as
    decimal.Context)
  - contextlib.contextmanager is renamed to contextfactory
    This best reflects the nature of the function resulting from the
    use of that decorator
  - decimal.ContextManager is renamed to WithStatementContext
    Simple dropping the 'Manager' part wasn't possible due to the
    fact that decimal.Context already exists and means something
    different. WithStatementContext is ugly but workable.

A technically unrelated change snuck into this commit:
contextlib.closing now avoids the overhead of creating a
generator, since it's trivial to implement that particular
context manager directly.
2006-04-25 10:56:51 +00:00