Commit Graph

146 Commits

Author SHA1 Message Date
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Neal Norwitz b2da01b27c Fix icc warnings: remove unused variable 2006-01-08 01:11:25 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast().  Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.

I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc.  Predictably, there were a large set of functions that
needed to be fixed as a result of these changes.  The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].

One cast was required as a result of the changes:  A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
2005-12-10 18:50:16 +00:00
Michael W. Hudson b78a5fc004 Fix bug
[ 1346144 ] Segfaults from unaligned loads in floatobject.c

by using memcpy and not just blinding casting char* to double*.

Thanks to Rune Holm for the report.
2005-12-05 00:27:49 +00:00
Michael W. Hudson 3095ad0650 Apparently some compiler gives a warning on
float y = x;

when x is a double.  Go figure.
2005-06-30 00:02:26 +00:00
Michael W. Hudson ba283e2b7f This is my patch:
[ 1181301 ] make float packing copy bytes when they can

which hasn't been reviewed, despite numerous threats to check it in
anyway if noone reviews it.  Please read the diff on the checkin list,
at least!

The basic idea is to examine the bytes of some 'probe values' to see if
the current platform is a IEEE 754-ish platform, and if so
_PyFloat_{Pack,Unpack}{4,8} just copy bytes around.

The rest is hair for testing, and tests.
2005-05-27 15:23:20 +00:00
Brett Cannon c3647ac93e Make subclasses of int, long, complex, float, and unicode perform type
conversion using the proper magic slot (e.g., __int__()).  Also move conversion
code out of PyNumber_*() functions in the C API into the nb_* function.

Applied patch #1109424.  Thanks Walter Doewald.
2005-04-26 03:45:26 +00:00
Tim Peters e1c69b3f6f float_richcompare(): Use the new Py_IS_NAN macro to ensure that, on
platforms where that macro works, NaN compared to an int or long works
the same as NaN compared to a finite float.
2004-09-23 19:22:41 +00:00
Tim Peters 307fa78107 SF bug #513866: Float/long comparison anomaly.
When an integer is compared to a float now, the int isn't coerced to float.
This avoids spurious overflow exceptions and insane results.  This should
compute correct results, without raising spurious exceptions, in all cases
now -- although I expect that what happens when an int/long is compared to
a NaN is still a platform accident.

Note that we had potential problems here even with "short" ints, on boxes
where sizeof(long)==8.  There's #ifdef'ed code here to handle that, but
I can't test it as intended.  I tested it by changing the #ifdef to
trigger on my 32-bit box instead.

I suppose this is a bugfix candidate, but I won't backport it.  It's
long-winded (for speed) and messy (because the problem is messy).  Note
that this also depends on a previous 2.4 patch that introduced
_Py_SwappedOp[] as an extern.
2004-09-23 08:06:40 +00:00
Neal Norwitz 739a8f86d6 Fix a couple of signed/unsigned comparison warnings 2004-07-08 01:55:58 +00:00
Martin v. Löwis 737ea82a5a Patch #774665: Make Python LC_NUMERIC agnostic. 2004-06-08 18:52:54 +00:00
Michael W. Hudson 08678a1055 Remove float_compare as per
[ 899109 ] 1==float('nan')

which can now finally be closed, I think.
2004-05-26 17:36:12 +00:00
Michael W. Hudson 6bee23cdc3 Oops, didn't mean to commit the removal of float_compare! 2004-02-26 13:16:03 +00:00
Michael W. Hudson 957f9774b6 Pass a variable that actually exists to PyFPE_END_PROTECT in
float_richcompare.  Reported on c.l.py by Helmut Jarausch.
2004-02-26 12:33:09 +00:00
Michael W. Hudson d3b33b5f6f "Fix" (for certain configurations of the planets, including
recent gcc on Linux/x86)

[ 899109 ] 1==float('nan')

by implementing rich comparisons for floats.

Seems to make comparisons involving NaNs somewhat less surprising
when the underlying C compiler actually implements C99 semantics.
2004-02-19 19:35:22 +00:00
Skip Montanaro ce59c04127 Remove support for SunOS 4.
Remove BAD_EXEC_PROTOYPE (leftover from IRIX 4 demolition).
2004-01-17 14:19:44 +00:00
Jack Jansen eddc1449ba Getting rid of all the code inside #ifdef macintosh too. 2003-11-20 01:44:59 +00:00
Raymond Hettinger f466793fcc SF patch 703666: Several objects don't decref tmp on failure in subtype_new
Submitted By: Christopher A. Craig

Fillin some missing decrefs.
2003-06-28 20:04:25 +00:00
Tim Peters e87568dd9a SF bug 705231: Assertion failed, python aborts.
float_pow():  Don't let the platform pow() raise -1.0 to an integer power
anymore; at least glibc gets it wrong in some cases.  Note that
math.pow() will continue to deliver wrong (but platform-native) results
in such cases.
2003-05-24 20:18:24 +00:00
Tim Peters f1ed934278 _PyFloat_Pack4(): Removed needless call of floor(). 2003-03-21 17:10:03 +00:00
Tim Peters 9905b943f7 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
refactoring to get all the duplicates of this delicate code out of the
cPickle and struct modules.
2003-03-20 20:53:32 +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
Neal Norwitz abcb0c03ad Fix SF bug# 676155, RuntimeWarning with tp_compare
Check return value of PyLong_AsDouble(), it can return an error.
2003-01-28 19:21:24 +00:00
Tim Peters 7d791240c0 float_int(): Some systems raise an exception if a double is cast to
long but the double is too big to fit in a long.  Prevent that.  This
closes some recent bug or patch on SF, but SF is down now so I can't
say which.

Bugfix candidate.
2002-11-21 22:26:37 +00:00
Walter Dörwald f171540ab8 Change int() so that passing a string, unicode, float or long argument
that is outside the integer range no longer raises OverflowError, but
returns a long object instead.

This fixes SF bug http://www.python.org/sf/635115
2002-11-19 20:49:15 +00:00
Neil Schemenauer 2c77e90804 Improve exception message raised by PyFloat_AsDouble if the object does not
have a nb_float slot.  This matches what PyInt_AsLong does.
2002-11-18 16:06:21 +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
Jeremy Hylton 938ace69a0 staticforward bites the dust.
The staticforward define was needed to support certain broken C
compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
static keyword when it was used with a forward declaration of a static
initialized structure.  Standard C allows the forward declaration with
static, and we've decided to stop catering to broken C compilers.  (In
fact, we expect that the compilers are all fixed eight years later.)

I'm leaving staticforward and statichere defined in object.h as
static.  This is only for backwards compatibility with C extensions
that might still use it.

XXX I haven't updated the documentation.
2002-07-17 16:30:39 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Skip Montanaro 71390a9a94 clarify message when raising TypeError to indicate that float() accepts
strings or numbers
2002-05-02 13:03:22 +00:00
Tim Peters dc5a508761 SF bug 525705: [2.2] underflow raise OverflowException.
Another year in the quest to out-guess random C behavior.

Added macros Py_ADJUST_ERANGE1(X) and Py_ADJUST_ERANGE2(X, Y).  The latter
is useful for functions with complex results.  Two corrections to errno-
after-libm-call are attempted:

1. If the platform set errno to ERANGE due to underflow, clear errno.
   Some unknown subset of libm versions and link options do this.  It's
   allowed by C89, but I never figured anyone would do it.

2. If the platform did not set errno but overflow occurred, force
   errno to ERANGE.  C89 required setting errno to ERANGE, but C99
   doesn't.  Some unknown subset of libm versions and link options do
   it the C99 way now.

Bugfix candidate, but hold off until some Linux people actually try it,
with and without -lieee.  I'll send a help plea to Python-Dev.
2002-03-09 04:58:24 +00:00
Tim Peters 77d8a4fc91 float_floor_div: An expression like 3.//1j crashed the interpreter, or
delivered bizarre results.  Check float_divmod for a Py_NotImplemented
return and pass it along (instead of treating Py_NotImplemented as a
2-tuple).
CONVERT_TO_DOUBLE:  Added comments; this macro is obscure.
2001-12-11 20:31:34 +00:00
Tim Peters 63a3571e17 float_int_div(): For clarity, move this closer to the other float
division functions, and rename to float_floor_div.
2001-12-11 19:57:24 +00:00
Tim Peters 97019e4110 PyFloat_AsStringEx(): This function takes an output char* but doesn't
pass the buffer length.  Stop using it.  It should be deprecated, but too
late in the release cycle to do that now.
New static format_float() does the same thing but requires passing the
buffer length too.  Use it instead.
2001-11-28 22:43:45 +00:00
Barry Warsaw af8aef9ee2 PyFloat_FromString(): Conversion of sprintf() to PyOS_snprintf() for
buffer overrun avoidance.
2001-11-28 20:52:21 +00:00
Tim Peters 4e8ab5db38 float_divmod(): the code wasn't sick enough to stop the MS optimizer
from optimizing away mod's sign adjustment when mod == 0; so it got
the intended result only in the debug build.
2001-11-01 23:59:56 +00:00
Tim Peters d2e40d6691 SF bug #477221: abs and divmod act oddly with -0.0
Try to ensure that divmod(-0.0, 1.0) -> (-0.0, +0.0) across platforms.
It always did on Windows, and still does.  It didn't on Linux.  Alas,
there's no platform-independent way to write a test case for this.
Bugfix candidate.
2001-11-01 23:12:27 +00:00
Tim Peters faf0cd21ed float_abs() again: Guido pointed out that this could screw up in the
presence of NaNs.  So pass the issue on to the platform libm fabs();
after all, fabs() is a std C function because you can't implement it
correctly in portable C89.
2001-11-01 21:51:15 +00:00
Tim Peters d2364e8e2d SF bug #477221: abs and divmod act oddly with -0.0.
Partial fix.
float_abs():  ensure abs(-0.0) returns +0.0.
Bugfix candidate.
2001-11-01 20:09:42 +00:00
Guido van Rossum e2ae77b8b8 SF patch #474590 -- RISC OS support 2001-10-24 20:42:55 +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 1952e388ca Add additional coercion support for "self subtypes" to int, long,
float (compare the recent checkin to complex).  Added tests for these.
2001-09-19 01:25:16 +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
Tim Peters 0280cf79a7 More bug 460020: when F is a subclass of float, disable the unary plus
optimization (+F(whatever)).
2001-09-11 21:53:35 +00:00
Guido van Rossum dea6ef9bfd Replace a few places where X->ob_type was compared to &PyXXX_Type with
calls to PyXXX_CheckExact(X).
2001-09-11 16:13:52 +00:00
Tim Peters 97f4a33e12 Better error msg for 3-arg pow with a float argument. 2001-09-05 23:49:24 +00:00
Tim Peters a40c793d06 Rework the way we try to check for libm overflow, given that C99 no longer
requires that errno ever get set, and it looks like glibc is already
playing that game.  New rules:

+ Never use HUGE_VAL.  Use the new Py_HUGE_VAL instead.

+ Never believe errno.  If overflow is the only thing you're interested in,
  use the new Py_OVERFLOWED(x) macro.  If you're interested in any libm
  errors, use the new Py_SET_ERANGE_IF_OVERFLOW(x) macro, which attempts
  to set errno the way C89 said it worked.

Unfortunately, none of these are reliable, but they work on Windows and I
*expect* under glibc too.
2001-09-05 22:36:56 +00:00
Tim Peters 4c483c4d8e Make the error msgs in our pow() implementations consistent. 2001-09-05 06:24:58 +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