Skip to content

Commit 169e012

Browse files
authored
Merge pull request #26 from vstinner/float_pack2
Use PyFloat_Pack2() on Python 3.11a7
2 parents cf46229 + 5f99da8 commit 169e012

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

bitstruct/c.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,15 @@ static void pack_float_16(struct bitstream_writer_t *self_p,
403403
{
404404
uint8_t buf[2];
405405

406+
#if PY_VERSION_HEX >= 0x030B00A7
407+
PyFloat_Pack2(PyFloat_AsDouble(value_p),
408+
(char*)&buf[0],
409+
PY_BIG_ENDIAN);
410+
#else
406411
_PyFloat_Pack2(PyFloat_AsDouble(value_p),
407412
&buf[0],
408413
PY_BIG_ENDIAN);
414+
#endif
409415
bitstream_writer_write_bytes(self_p, &buf[0], sizeof(buf));
410416
}
411417

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

418424
bitstream_reader_read_bytes(self_p, &buf[0], sizeof(buf));
425+
#if PY_VERSION_HEX >= 0x030B00A7
426+
value = PyFloat_Unpack2((const char*)&buf[0], PY_BIG_ENDIAN);
427+
#else
419428
value = _PyFloat_Unpack2(&buf[0], PY_BIG_ENDIAN);
429+
#endif
420430

421431
return (PyFloat_FromDouble(value));
422432
}

0 commit comments

Comments
 (0)