diff options
author | Victor Stinner <vstinner@python.org> | 2022-03-11 23:10:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-11 23:10:02 (GMT) |
commit | 882d8096c262a5945e0cfdd706e5db3ad2b73543 (patch) | |
tree | 5e903c7e87a13203543e3e215f30b6b708df018d /Modules/arraymodule.c | |
parent | ecfff63e06e77e22035a7f7caa26986f033f3aea (diff) | |
download | cpython-882d8096c262a5945e0cfdd706e5db3ad2b73543.zip cpython-882d8096c262a5945e0cfdd706e5db3ad2b73543.tar.gz cpython-882d8096c262a5945e0cfdd706e5db3ad2b73543.tar.bz2 |
bpo-46906: Add PyFloat_Pack8() to the C API (GH-31657)
Add new functions to pack and unpack C double (serialize and
deserialize):
* PyFloat_Pack2(), PyFloat_Pack4(), PyFloat_Pack8()
* PyFloat_Unpack2(), PyFloat_Unpack4(), PyFloat_Unpack8()
Document these functions and add unit tests.
Rename private functions and move them from the internal C API
to the public C API:
* _PyFloat_Pack2() => PyFloat_Pack2()
* _PyFloat_Pack4() => PyFloat_Pack4()
* _PyFloat_Pack8() => PyFloat_Pack8()
* _PyFloat_Unpack2() => PyFloat_Unpack2()
* _PyFloat_Unpack4() => PyFloat_Unpack4()
* _PyFloat_Unpack8() => PyFloat_Unpack8()
Replace the "unsigned char*" type with "char*" which is more common
and easy to use.
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r-- | Modules/arraymodule.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 73104ce..18991f8 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -9,7 +9,6 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_floatobject.h" // _PyFloat_Unpack4() #include "pycore_moduleobject.h" // _PyModule_GetState() #include "structmember.h" // PyMemberDef #include <stddef.h> // offsetof() @@ -2056,15 +2055,14 @@ array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype, Py_ssize_t i; int le = (mformat_code == IEEE_754_FLOAT_LE) ? 1 : 0; Py_ssize_t itemcount = Py_SIZE(items) / 4; - const unsigned char *memstr = - (unsigned char *)PyBytes_AS_STRING(items); + const char *memstr = PyBytes_AS_STRING(items); converted_items = PyList_New(itemcount); if (converted_items == NULL) return NULL; for (i = 0; i < itemcount; i++) { PyObject *pyfloat = PyFloat_FromDouble( - _PyFloat_Unpack4(&memstr[i * 4], le)); + PyFloat_Unpack4(&memstr[i * 4], le)); if (pyfloat == NULL) { Py_DECREF(converted_items); return NULL; @@ -2078,15 +2076,14 @@ array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype, Py_ssize_t i; int le = (mformat_code == IEEE_754_DOUBLE_LE) ? 1 : 0; Py_ssize_t itemcount = Py_SIZE(items) / 8; - const unsigned char *memstr = - (unsigned char *)PyBytes_AS_STRING(items); + const char *memstr = PyBytes_AS_STRING(items); converted_items = PyList_New(itemcount); if (converted_items == NULL) return NULL; for (i = 0; i < itemcount; i++) { PyObject *pyfloat = PyFloat_FromDouble( - _PyFloat_Unpack8(&memstr[i * 8], le)); + PyFloat_Unpack8(&memstr[i * 8], le)); if (pyfloat == NULL) { Py_DECREF(converted_items); return NULL; |