Skip to content

Use PyFloat_Pack2() on Python 3.11a7 #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bitstruct/c.c
Original file line number Diff line number Diff line change
@@ -403,9 +403,15 @@ static void pack_float_16(struct bitstream_writer_t *self_p,
{
uint8_t buf[2];

#if PY_VERSION_HEX >= 0x030B00A7
PyFloat_Pack2(PyFloat_AsDouble(value_p),
(char*)&buf[0],
PY_BIG_ENDIAN);
#else
_PyFloat_Pack2(PyFloat_AsDouble(value_p),
&buf[0],
PY_BIG_ENDIAN);
#endif
bitstream_writer_write_bytes(self_p, &buf[0], sizeof(buf));
}

@@ -416,7 +422,11 @@ static PyObject *unpack_float_16(struct bitstream_reader_t *self_p,
double value;

bitstream_reader_read_bytes(self_p, &buf[0], sizeof(buf));
#if PY_VERSION_HEX >= 0x030B00A7
value = PyFloat_Unpack2((const char*)&buf[0], PY_BIG_ENDIAN);
#else
value = _PyFloat_Unpack2(&buf[0], PY_BIG_ENDIAN);
#endif

return (PyFloat_FromDouble(value));
}