mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Issue #9041: raised exception is misleading
An issue in ctypes.c_longdouble, ctypes.c_double, and ctypes.c_float that caused an incorrect exception to be returned in the case of overflow has been fixed.
This commit is contained in:
parent
4b6045c30f
commit
031e25b0f7
3 changed files with 19 additions and 25 deletions
|
|
@ -1002,12 +1002,8 @@ g_set(void *ptr, PyObject *value, Py_ssize_t size)
|
|||
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);
|
||||
}
|
||||
|
|
@ -1026,12 +1022,8 @@ d_set(void *ptr, PyObject *value, Py_ssize_t size)
|
|||
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);
|
||||
}
|
||||
|
|
@ -1050,12 +1042,8 @@ d_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
|
|||
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;
|
||||
|
|
@ -1082,12 +1070,8 @@ f_set(void *ptr, PyObject *value, Py_ssize_t size)
|
|||
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);
|
||||
}
|
||||
|
|
@ -1106,12 +1090,8 @@ f_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
|
|||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue