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 /Python | |
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 'Python')
-rw-r--r-- | Python/marshal.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Python/marshal.c b/Python/marshal.c index 44e4929..810244b 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -11,7 +11,6 @@ #include "Python.h" #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_code.h" // _PyCode_New() -#include "pycore_floatobject.h" // _PyFloat_Pack8() #include "pycore_hashtable.h" // _Py_hashtable_t #include "code.h" #include "marshal.h" // Py_MARSHAL_VERSION @@ -271,8 +270,8 @@ w_PyLong(const PyLongObject *ob, char flag, WFILE *p) static void w_float_bin(double v, WFILE *p) { - unsigned char buf[8]; - if (_PyFloat_Pack8(v, buf, 1) < 0) { + char buf[8]; + if (PyFloat_Pack8(v, buf, 1) < 0) { p->error = WFERR_UNMARSHALLABLE; return; } @@ -883,10 +882,10 @@ r_PyLong(RFILE *p) static double r_float_bin(RFILE *p) { - const unsigned char *buf = (const unsigned char *) r_string(8, p); + const char *buf = r_string(8, p); if (buf == NULL) return -1; - return _PyFloat_Unpack8(buf, 1); + return PyFloat_Unpack8(buf, 1); } /* Issue #33720: Disable inlining for reducing the C stack consumption |