Commit Graph

117 Commits

Author SHA1 Message Date
Walter Dörwald 5ecd6c4db2 Fix typo in comment. 2003-06-17 20:22:24 +00:00
Guido van Rossum 4eadfa2b2e Fix from Greg Chapman from SF bug #695651: a complex subclass
constructor, when passed a single complex argument, returns the
argument unchanged.  This should be done only for the complex base
class; a complex subclass should of course cast the value to the
subclass in this case.

The fix also revealed a segfault in complex_getnewargs(): the argument
for the Py_BuildValue() format code "D" is the *address* of a
Py_complex struct, not the value.  (This corroborated by the API
documentation.)

I expect this needs to be backported to 2.2.3.
2003-03-02 13:51:47 +00:00
Guido van Rossum 5d9113d8be Implement appropriate __getnewargs__ for all immutable subclassable builtin
types.  The special handling for these can now be removed from save_newobj().
Add some testing for this.

Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.
2003-01-29 17:58:45 +00:00
Raymond Hettinger 604cd6ae79 complex() was the only numeric constructor that created a new instance
when given its own type as an argument.
2002-08-29 14:22:51 +00:00
Guido van Rossum e3a8e7ed1d Call me anal, but there was a particular phrase that was speading to
comments everywhere that bugged me: /* Foo is inlined */ instead of
/* Inline Foo */.  Somehow the "is inlined" phrase always confused me
for half a second (thinking, "No it isn't" until I added the missing
"here").  The new phrase is hopefully unambiguous.
2002-08-19 19:26:42 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Guido van Rossum 65ce6de35c Rearrange the #ifndef WITHOUT_COMPLEX so it can be picked up from
pyconfig.h.
2002-06-13 17:07:07 +00:00
Raymond Hettinger 478d47a168 Close SF bug 563740. complex() now finds __complex__() in new style classes.
Made conversion failure error messages consistent between types.
Added related unittests.
2002-06-06 15:45:38 +00:00
Guido van Rossum 69cf3c7641 Deprecate % as well. The message for deprecation of //, % and divmod
is the same in all three cases (mostly because // calls divmod :-).
2002-04-15 12:39:12 +00:00
Guido van Rossum 9ec4c78a54 SF bug #543387.
Complex numbers implement divmod() and //, neither of which makes one
lick of sense.  Unfortunately this is documented, so I'm adding a
deprecation warning now, so we can delete this silliness, oh, around
2005 or so.

Bugfix candidate (At least for 2.2.2, I think.)
2002-04-15 01:41:56 +00:00
Tim Peters 077f27141f SF bug 543840: complex(string) accepts strings with \0
complex_subtype_from_string():  this stopped parsing at the first 0
byte, as if that were the end of the input string.

Bugfix candidate.
2002-04-14 22:04:03 +00:00
Neil Schemenauer aa769ae468 PyObject_Del can now be used as a function designator. 2002-04-12 02:44:10 +00:00
Tim Peters bab22beda8 SF bug 533198: Complex power underflow raises exception.
Konrad was too kind.  Not only did it raise an exception, the specific
exception it raised made no sense.  These are old bugs in complex_pow()
and friends:

1. Raising 0 to a negative power isn't a range error, it's a domain
   error, so changed c_pow() to set errno to EDOM in that case instead
   of ERANGE.

2. Changed complex_pow() to:

A. Used the Py_ADJUST_ERANGE2 macro to try to clear errno of a spurious
   ERANGE error due to underflow in the libm pow() called by c_pow().

B. Produced different exceptions depending on the errno value:
   i) For errno==EDOM, raise ZeroDivisionError instead of ValueError.
      This is for consistency with the non-complex cases 0.0**-2 and
      0**-2 and 0L**-2.
   ii) For errno==ERANGE, raise OverflowError.

Bugfix candidate.
2002-03-22 02:48:46 +00:00
Guido van Rossum fa2e4c27d2 Declare real and imag as read-only attributes.
This fixes SF bug #514858 (Gregory Smith): complex not entirely
immutable

2.2.1 Bugfix candidate!
2002-02-08 21:26:07 +00:00
Fred Drake 526c7a0101 Ensure that complex() only accepts a string argument as the first arg,
and only if there is no second arg.
This closes SF patch #479551.
2001-12-13 19:52:22 +00:00
Barry Warsaw 01d697a067 complex_to_buf(), complex_subtype_from_c_complex(): Conversion of
sprintf() to PyOS_snprintf() for buffer overrun avoidance.

complex_print(), complex_repr(), complex_str(): Call complex_to_buf()
passing in sizeof(buf).
2001-11-28 20:50:56 +00:00
Guido van Rossum 70e3688364 complex_subtype_from_string(): move the declaration of s_buffer[] out
of the if block where it was before.  The name is only used inside
that if block, but the storage is referenced outside it via the 's'
variable.

(This patch was part of SF patch #474590 -- RISC OS support.)
2001-10-25 18:07:22 +00:00
Guido van Rossum 9475a2310d Enable GC for new-style instances. This touches lots of files, since
many types were subclassable but had a xxx_dealloc function that
called PyObject_DEL(self) directly instead of deferring to
self->ob_type->tp_free(self).  It is permissible to set tp_free in the
type object directly to _PyObject_Del, for non-GC types, or to
_PyObject_GC_Del, for GC types.  Still, PyObject_DEL was a tad faster,
so I'm fearing that our pystone rating is going down again.  I'm not
sure if doing something like

void xxx_dealloc(PyObject *self)
{
	if (PyXxxCheckExact(self))
		PyObject_DEL(self);
	else
		self->ob_type->tp_free(self);
}

is any faster than always calling the else branch, so I haven't
attempted that -- however those types whose own dealloc is fancier
(int, float, unicode) do use this pattern.
2001-10-05 20:51:39 +00:00
Guido van Rossum 2ed6bf87c9 Merge branch changes (coercion, rich comparisons) into trunk. 2001-09-27 20:30:07 +00:00
Guido van Rossum 2205642fe0 Do the same thing to complex that I did to str: the rich comparison
function returns NotImplemented when comparing objects whose
tp_richcompare slot is not itself.
2001-09-24 17:52:04 +00:00
Guido van Rossum 6f7993765a Add optional docstrings to member descriptors. For backwards
compatibility, this required all places where an array of "struct
memberlist" structures was declared that is referenced from a type's
tp_members slot to change the type of the structure to PyMemberDef;
"struct memberlist" is now only used by old code that still calls
PyMember_Get/Set.  The code in PyObject_GenericGetAttr/SetAttr now
calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef
argument.

As examples, I added actual docstrings to the attributes of a few
types: file, complex, instance method, super, and xxsubtype.spamlist.

Also converted the symtable to new style getattr.
2001-09-20 20:46:19 +00:00
Guido van Rossum 638059603c complex_coerce(): add explicit PyComplex_Check() test. Previously,
complex_coerce() would never be called with a complex argument,
because PyNumber_Coerce[Ex] doesn't bother calling the type's coercion
method if the values already have the same type.  But now, of course,
it's possible to pass an instance of a complex *subtype*, and those
must be accepted.
2001-09-19 01:13:10 +00:00
Tim Peters 2400fa4ad1 Again perhaps the end of [#460020] bug or feature: unicode() and subclasses.
Inhibited complex unary plus optimization when applied to a complex subtype.
Added PyComplex_CheckExact macro.  Some comments and minor code fiddling.
2001-09-12 19:12:49 +00:00
Martin v. Löwis 387c547fd3 Revert parts of patch #453627, documenting the resulting test failures
instead.
2001-09-06 08:16:17 +00:00
Martin v. Löwis 655c9557f6 Patch #453627: Define the following macros when compiling on a UnixWare 7.x system:
SCO_ATAN2_BUG, SCO_ACCEPT_BUG, and STRICT_SYSV_CURSES.
Work aroudn a bug in the SCO UnixWare atan2() implementation.
2001-09-05 14:45:54 +00:00
Tim Peters 9fffa3eea3 Raise OverflowError when appropriate on long->float conversion. Most of
the fiddling is simply due to that no caller of PyLong_AsDouble ever
checked for failure (so that's fixing old bugs).  PyLong_AsDouble is much
faster for big inputs now too, but that's more of a happy consequence
than a design goal.
2001-09-04 05:14:19 +00:00
Guido van Rossum 1832de4bc0 PEP 238 documented -Qwarn as warning only for classic int or long
division, and this makes sense.  Add -Qwarnall to warn for all
classic divisions, as required by the fixdiv.py tool.
2001-09-04 03:51:09 +00:00
Guido van Rossum 393661d15f Add warning mode for classic division, almost exactly as specified in
PEP 238.  Changes:

- add a new flag variable Py_DivisionWarningFlag, declared in
  pydebug.h, defined in object.c, set in main.c, and used in
  {int,long,float,complex}object.c.  When this flag is set, the
  classic division operator issues a DeprecationWarning message.

- add a new API PyRun_SimpleStringFlags() to match
  PyRun_SimpleString().  The main() function calls this so that
  commands run with -c can also benefit from -Dnew.

- While I was at it, I changed the usage message in main() somewhat:
  alphabetized the options, split it in *four* parts to fit in under
  512 bytes (not that I still believe this is necessary -- doc strings
  elsewhere are much longer), and perhaps most visibly, don't display
  the full list of options on each command line error.  Instead, the
  full list is only displayed when -h is used, and otherwise a brief
  reminder of -h is displayed.  When -h is used, write to stdout so
  that you can do `python -h | more'.

Notes:

- I don't want to use the -W option to control whether the classic
  division warning is issued or not, because the machinery to decide
  whether to display the warning or not is very expensive (it involves
  calling into the warnings.py module).  You can use -Werror to turn
  the warnings into exceptions though.

- The -Dnew option doesn't select future division for all of the
  program -- only for the __main__ module.  I don't know if I'll ever
  change this -- it would require changes to the .pyc file magic
  number to do it right, and a more global notion of compiler flags.

- You can usefully combine -Dwarn and -Dnew: this gives the __main__
  module new division, and warns about classic division everywhere
  else.
2001-08-31 17:40:15 +00:00
Martin v. Löwis 339d0f720e Patch #445762: Support --disable-unicode
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled
- check for Py_USING_UNICODE in all places that use Unicode functions
- disables unicode literals, and the builtin functions
- add the types.StringTypes list
- remove Unicode literals from most tests.
2001-08-17 18:39:25 +00:00
Martin v. Löwis e3eb1f2b23 Patch #427190: Implement and use METH_NOARGS and METH_O. 2001-08-16 13:15:00 +00:00
Guido van Rossum 4668b000a1 Implement PEP 238 in its (almost) full glory.
This introduces:

- A new operator // that means floor division (the kind of division
  where 1/2 is 0).

- The "future division" statement ("from __future__ import division)
  which changes the meaning of the / operator to implement "true
  division" (where 1/2 is 0.5).

- New overloadable operators __truediv__ and __floordiv__.

- New slots in the PyNumberMethods struct for true and floor division,
  new abstract APIs for them, new opcodes, and so on.

I emphasize that without the future division statement, the semantics
of / will remain unchanged until Python 3.0.

Not yet implemented are warnings (default off) when / is used with int
or long arguments.

This has been on display since 7/31 as SF patch #443474.

Flames to /dev/null.
2001-08-08 05:00:18 +00:00
Tim Peters 6d6c1a35e0 Merge of descr-branch back into trunk. 2001-08-02 04:15:00 +00:00
Tim Peters 0f33604e17 SF bug [ #409448 ] Complex division is braindead
http://sourceforge.net/tracker/?func=detail&aid=409448&group_id=5470&atid=105470
Now less braindead.  Also added test_complex.py, which doesn't test much, but
fails without this patch.
2001-03-18 08:21:57 +00:00
Tim Peters 7069512bd0 When 1.6 boosted the # of digits produced by repr(float), repr(complex)
apparently forgot to play along.  Make complex act like float.
2001-03-11 08:37:29 +00:00
Guido van Rossum be4cbb1668 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!
2001-01-18 01:12:39 +00:00
Fred Drake d5fadf75e4 Rationalize use of limits.h, moving the inclusion to Python.h.
Add definitions of INT_MAX and LONG_MAX to pyport.h.
Remove includes of limits.h and conditional definitions of INT_MAX
and LONG_MAX elsewhere.

This closes SourceForge patch #101659 and bug #115323.
2000-09-26 05:46:01 +00:00
Guido van Rossum 8586991099 REMOVED all CWI, CNRI and BeOpen copyright markings.
This should match the situation in the 1.6b1 tree.
2000-09-01 23:29:29 +00:00
Tim Peters 39dce29365 Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
This was a misleading bug -- the true "bug" was that hash(x) gave an error
return when x is an infinity.  Fixed that.  Added new Py_IS_INFINITY macro to
pyport.h.  Rearranged code to reduce growing duplication in hashing of float and
complex numbers, pushing Trent's earlier stab at that to a logical conclusion.
Fixed exceedingly rare bug where hashing of floats could return -1 even if there
wasn't an error (didn't waste time trying to construct a test case, it was simply
obvious from the code that it *could* happen).  Improved complex hash so that
hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.
2000-08-15 03:34:48 +00:00
Peter Schneider-Kamp 7e01890986 merge Include/my*.h into Include/pyport.h
marked my*.h as obsolete
2000-07-31 15:28:04 +00:00
Fred Drake 4288c80599 ANSI-fication of the sources. 2000-07-09 04:36:04 +00:00
Guido van Rossum ffcc3813d8 Change copyright notice - 2nd try. 2000-06-30 23:58:06 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Fred Drake 13634cf7a4 This patch addresses two main issues: (1) There exist some non-fatal
errors in some of the hash algorithms. For exmaple, in float_hash and
complex_hash a certain part of the value is not included in the hash
calculation. See Tim's, Guido's, and my discussion of this on
python-dev in May under the title "fix float_hash and complex_hash for
64-bit *nix"

(2) The hash algorithms that use pointers (e.g. func_hash, code_hash)
are universally not correct on Win64 (they assume that sizeof(long) ==
sizeof(void*))

As well, this patch significantly cleans up the hash code. It adds the
two function _Py_HashDouble and _PyHash_VoidPtr that the various
hashing routine are changed to use.

These help maintain the hash function invariant: (a==b) =>
(hash(a)==hash(b))) I have added Lib/test/test_hash.py and
Lib/test/output/test_hash to test this for some cases.
2000-06-29 19:17:04 +00:00
Guido van Rossum b18618dab7 Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives.
For documentation read the comments in mymalloc.h and objimpl.h.

(This is not exactly what Vladimir posted to the patches list; I've
made a few changes, and Vladimir sent me a fix in private email for a
problem that only occurs in debug mode.  I'm also holding back on his
change to main.c, which seems unnecessary to me.)
2000-05-03 23:44:39 +00:00
Guido van Rossum 43713e5a28 Massive patch by Skip Montanaro to add ":name" to as many
PyArg_ParseTuple() format string arguments as possible.
2000-02-29 13:59:29 +00:00
Guido van Rossum bffd683f73 The rest of the changes by Trent Mick and Dale Nagata for warning-free
compilation on NT Alpha.  Mostly added casts etc.
2000-01-20 22:32:56 +00:00
Guido van Rossum 3bbef60990 Ai! complex_nonzero() has && which should be ||, else decidedly
non-zero things like 5j and complex(1,0) are considered to be
zero/false.  Tim Peters.
1999-01-25 19:42:19 +00:00
Guido van Rossum 8530ef625a Add check to conjugate() that there are no excess arguments. 1998-05-07 16:29:10 +00:00
Guido van Rossum 967839473a Got rid of c_error in favor of errno (and EDOM/ERANGE).
Assume that errno usage is thread-safe -- most vendors do this by
making in a macro that refers to a per-thread storage area.
1997-05-20 18:21:34 +00:00
Guido van Rossum c0b618a2cc Quickly renamed the last directory. 1997-05-02 03:12:38 +00:00
Guido van Rossum 8017767420 Remove unused variable. 1997-04-09 18:22:28 +00:00
Guido van Rossum c054d70aee Get rid of .conj pseudo data attribute for complex numbers.
Add __members__ attribute.
1997-04-01 03:12:33 +00:00
Guido van Rossum 45b83915f8 New form of PyFPE_END_PROTECT macro. 1997-03-14 04:32:50 +00:00
Guido van Rossum 09e6ad0c1e Changes for Lee Busby's SIGFPE patch set.
Surround various f.p. operations with  PyFPE_{START,END}_PROTECT macros.
1997-02-14 22:54:21 +00:00
Guido van Rossum 919cf1aff1 New, better hash for floating point and complex 1997-01-11 19:26:21 +00:00
Guido van Rossum da9c2710c7 Make gcc -Wall happy 1996-12-05 21:58:58 +00:00
Guido van Rossum 24048580ca Oops... Need to clear c_error before calling c_quot(). 1996-09-12 21:02:02 +00:00
Guido van Rossum 3be12e97cd Properly(?) implemented remainder and divmod (Tim Hochberg) 1996-09-12 20:56:18 +00:00
Guido van Rossum d4ab3cde8e Raise exception instead of dropping imag part for conversion to int,
long, float.

Raise exception instead of dumping core for remainder and divmod.
1996-09-11 22:54:37 +00:00
Guido van Rossum ee09fc1c30 Don't dump core on complex % or divmod -- raise a TypeError exception. 1996-09-11 13:55:55 +00:00
Guido van Rossum 926518b683 Changes to make the file acceptable to K&R C compilers (HPUX, SunOS 4.x). 1996-08-19 19:30:45 +00:00
Guido van Rossum 9e720e390a complex -> Py_complex 1996-07-21 02:31:35 +00:00
Guido van Rossum 363078afa4 make some things static 1996-05-24 20:45:01 +00:00
Guido van Rossum 724187929a use 'j' instead of 'i' for imaginary constants 1996-01-25 16:21:31 +00:00
Jack Jansen 1e7b2aa5d6 Removed unused var 1996-01-25 16:11:19 +00:00
Guido van Rossum cf3d1087d1 Added PyComplex_AsCComplex 1996-01-12 01:21:14 +00:00
Guido van Rossum f9fca9252f complex numbers a la Konrad Hinsen 1996-01-12 00:47:05 +00:00