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 /Objects/floatobject.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 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 91ca848..736ddc9 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -2033,7 +2033,7 @@ _PyFloat_DebugMallocStats(FILE *out) /*---------------------------------------------------------------------------- - * _PyFloat_{Pack,Unpack}{2,4,8}. See floatobject.h. + * PyFloat_{Pack,Unpack}{2,4,8}. See floatobject.h. * To match the NPY_HALF_ROUND_TIES_TO_EVEN behavior in: * https://github.com/numpy/numpy/blob/master/numpy/core/src/npymath/halffloat.c * We use: @@ -2044,8 +2044,9 @@ _PyFloat_DebugMallocStats(FILE *out) */ int -_PyFloat_Pack2(double x, unsigned char *p, int le) +PyFloat_Pack2(double x, char *data, int le) { + unsigned char *p = (unsigned char *)data; unsigned char sign; int e; double f; @@ -2148,8 +2149,9 @@ _PyFloat_Pack2(double x, unsigned char *p, int le) } int -_PyFloat_Pack4(double x, unsigned char *p, int le) +PyFloat_Pack4(double x, char *data, int le) { + unsigned char *p = (unsigned char *)data; if (float_format == unknown_format) { unsigned char sign; int e; @@ -2255,8 +2257,9 @@ _PyFloat_Pack4(double x, unsigned char *p, int le) } int -_PyFloat_Pack8(double x, unsigned char *p, int le) +PyFloat_Pack8(double x, char *data, int le) { + unsigned char *p = (unsigned char *)data; if (double_format == unknown_format) { unsigned char sign; int e; @@ -2384,8 +2387,9 @@ _PyFloat_Pack8(double x, unsigned char *p, int le) } double -_PyFloat_Unpack2(const unsigned char *p, int le) +PyFloat_Unpack2(const char *data, int le) { + unsigned char *p = (unsigned char *)data; unsigned char sign; int e; unsigned int f; @@ -2446,8 +2450,9 @@ _PyFloat_Unpack2(const unsigned char *p, int le) } double -_PyFloat_Unpack4(const unsigned char *p, int le) +PyFloat_Unpack4(const char *data, int le) { + unsigned char *p = (unsigned char *)data; if (float_format == unknown_format) { unsigned char sign; int e; @@ -2524,8 +2529,9 @@ _PyFloat_Unpack4(const unsigned char *p, int le) } double -_PyFloat_Unpack8(const unsigned char *p, int le) +PyFloat_Unpack8(const char *data, int le) { + unsigned char *p = (unsigned char *)data; if (double_format == unknown_format) { unsigned char sign; int e; |