diff options
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/clinic/floatobject.c.h | 69 | ||||
-rw-r--r-- | Objects/floatobject.c | 76 |
2 files changed, 3 insertions, 142 deletions
diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h index 2c638a2..f53018c 100644 --- a/Objects/clinic/floatobject.c.h +++ b/Objects/clinic/floatobject.c.h @@ -290,73 +290,6 @@ exit: return return_value; } -PyDoc_STRVAR(float___setformat____doc__, -"__setformat__($type, typestr, fmt, /)\n" -"--\n" -"\n" -"You probably don\'t want to use this function.\n" -"\n" -" typestr\n" -" Must be \'double\' or \'float\'.\n" -" fmt\n" -" Must be one of \'unknown\', \'IEEE, big-endian\' or \'IEEE, little-endian\',\n" -" and in addition can only be one of the latter two if it appears to\n" -" match the underlying C reality.\n" -"\n" -"It exists mainly to be used in Python\'s test suite.\n" -"\n" -"Override the automatic determination of C-level floating point type.\n" -"This affects how floats are converted to and from binary strings."); - -#define FLOAT___SETFORMAT___METHODDEF \ - {"__setformat__", (PyCFunction)(void(*)(void))float___setformat__, METH_FASTCALL|METH_CLASS, float___setformat____doc__}, - -static PyObject * -float___setformat___impl(PyTypeObject *type, const char *typestr, - const char *fmt); - -static PyObject * -float___setformat__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs) -{ - PyObject *return_value = NULL; - const char *typestr; - const char *fmt; - - if (!_PyArg_CheckPositional("__setformat__", nargs, 2, 2)) { - goto exit; - } - if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("__setformat__", "argument 1", "str", args[0]); - goto exit; - } - Py_ssize_t typestr_length; - typestr = PyUnicode_AsUTF8AndSize(args[0], &typestr_length); - if (typestr == NULL) { - goto exit; - } - if (strlen(typestr) != (size_t)typestr_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("__setformat__", "argument 2", "str", args[1]); - goto exit; - } - Py_ssize_t fmt_length; - fmt = PyUnicode_AsUTF8AndSize(args[1], &fmt_length); - if (fmt == NULL) { - goto exit; - } - if (strlen(fmt) != (size_t)fmt_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } - return_value = float___setformat___impl(type, typestr, fmt); - -exit: - return return_value; -} - PyDoc_STRVAR(float___format____doc__, "__format__($self, format_spec, /)\n" "--\n" @@ -388,4 +321,4 @@ float___format__(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=3fb0c0624cc87dff input=a9049054013a1b77]*/ +/*[clinic end generated code: output=604cb27bf751ea16 input=a9049054013a1b77]*/ diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 342e768..91ca848 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -1708,7 +1708,6 @@ typedef enum { } float_format_type; static float_format_type double_format, float_format; -static float_format_type detected_double_format, detected_float_format; /*[clinic input] @classmethod @@ -1760,78 +1759,6 @@ float___getformat___impl(PyTypeObject *type, const char *typestr) } } -/*[clinic input] -@classmethod -float.__setformat__ - - typestr: str - Must be 'double' or 'float'. - fmt: str - Must be one of 'unknown', 'IEEE, big-endian' or 'IEEE, little-endian', - and in addition can only be one of the latter two if it appears to - match the underlying C reality. - / - -You probably don't want to use this function. - -It exists mainly to be used in Python's test suite. - -Override the automatic determination of C-level floating point type. -This affects how floats are converted to and from binary strings. -[clinic start generated code]*/ - -static PyObject * -float___setformat___impl(PyTypeObject *type, const char *typestr, - const char *fmt) -/*[clinic end generated code: output=06864de1fb5f1f04 input=c0e9e04dd87f9988]*/ -{ - float_format_type f; - float_format_type detected; - float_format_type *p; - - if (strcmp(typestr, "double") == 0) { - p = &double_format; - detected = detected_double_format; - } - else if (strcmp(typestr, "float") == 0) { - p = &float_format; - detected = detected_float_format; - } - else { - PyErr_SetString(PyExc_ValueError, - "__setformat__() argument 1 must " - "be 'double' or 'float'"); - return NULL; - } - - if (strcmp(fmt, "unknown") == 0) { - f = unknown_format; - } - else if (strcmp(fmt, "IEEE, little-endian") == 0) { - f = ieee_little_endian_format; - } - else if (strcmp(fmt, "IEEE, big-endian") == 0) { - f = ieee_big_endian_format; - } - else { - PyErr_SetString(PyExc_ValueError, - "__setformat__() argument 2 must be " - "'unknown', 'IEEE, little-endian' or " - "'IEEE, big-endian'"); - return NULL; - - } - - if (f != unknown_format && f != detected) { - PyErr_Format(PyExc_ValueError, - "can only set %s format to 'unknown' or the " - "detected platform value", typestr); - return NULL; - } - - *p = f; - Py_RETURN_NONE; -} static PyObject * float_getreal(PyObject *v, void *closure) @@ -1885,7 +1812,6 @@ static PyMethodDef float_methods[] = { FLOAT_IS_INTEGER_METHODDEF FLOAT___GETNEWARGS___METHODDEF FLOAT___GETFORMAT___METHODDEF - FLOAT___SETFORMAT___METHODDEF FLOAT___FORMAT___METHODDEF {NULL, NULL} /* sentinel */ }; @@ -1989,6 +1915,8 @@ _PyFloat_InitState(PyInterpreterState *interp) return; } + float_format_type detected_double_format, detected_float_format; + /* We attempt to determine if this machine is using IEEE floating point formats by peering at the bits of some carefully chosen values. If it looks like we are on an |