# probably be changed:
self.assertRaises(TypeError, c_int, c_long(42))
+ def test_float_overflow(self):
+ import sys
+ big_int = int(sys.float_info.max) * 2
+ for t in float_types + [c_longdouble]:
+ self.assertRaises(OverflowError, t, big_int)
+ if (hasattr(t, "__ctype_be__")):
+ self.assertRaises(OverflowError, t.__ctype_be__, big_int)
+ if (hasattr(t, "__ctype_le__")):
+ self.assertRaises(OverflowError, t.__ctype_le__, big_int)
+
## def test_perf(self):
## check_perf()
long double x;
x = PyFloat_AsDouble(value);
- if (x == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- " float expected instead of %s instance",
- value->ob_type->tp_name);
+ if (x == -1 && PyErr_Occurred())
return NULL;
- }
memcpy(ptr, &x, sizeof(long double));
_RET(value);
}
double x;
x = PyFloat_AsDouble(value);
- if (x == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- " float expected instead of %s instance",
- value->ob_type->tp_name);
+ if (x == -1 && PyErr_Occurred())
return NULL;
- }
memcpy(ptr, &x, sizeof(double));
_RET(value);
}
double x;
x = PyFloat_AsDouble(value);
- if (x == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- " float expected instead of %s instance",
- value->ob_type->tp_name);
+ if (x == -1 && PyErr_Occurred())
return NULL;
- }
#ifdef WORDS_BIGENDIAN
if (_PyFloat_Pack8(x, (unsigned char *)ptr, 1))
return NULL;
float x;
x = (float)PyFloat_AsDouble(value);
- if (x == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- " float expected instead of %s instance",
- value->ob_type->tp_name);
+ if (x == -1 && PyErr_Occurred())
return NULL;
- }
memcpy(ptr, &x, sizeof(x));
_RET(value);
}
float x;
x = (float)PyFloat_AsDouble(value);
- if (x == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError,
- " float expected instead of %s instance",
- value->ob_type->tp_name);
+ if (x == -1 && PyErr_Occurred())
return NULL;
- }
#ifdef WORDS_BIGENDIAN
if (_PyFloat_Pack4(x, (unsigned char *)ptr, 1))
return NULL;