Skip to content

Commit 849c806

Browse files
authored
Use PyFloat_Pack8() on Python 3.11a7 (#499)
Python 3.11a7 adds public functions: * PyFloat_Pack4(), PyFloat_Pack8() * PyFloat_Unpack4(), PyFloat_Unpack8() https://bugs.python.org/issue46906
1 parent cb50b20 commit 849c806

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

msgpack/pack_template.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,24 @@ static inline int msgpack_pack_float(msgpack_packer* x, float d)
568568
{
569569
unsigned char buf[5];
570570
buf[0] = 0xca;
571+
572+
#if PY_VERSION_HEX >= 0x030B00A7
573+
PyFloat_Pack4(d, (char *)&buf[1], 0);
574+
#else
571575
_PyFloat_Pack4(d, &buf[1], 0);
576+
#endif
572577
msgpack_pack_append_buffer(x, buf, 5);
573578
}
574579

575580
static inline int msgpack_pack_double(msgpack_packer* x, double d)
576581
{
577582
unsigned char buf[9];
578583
buf[0] = 0xcb;
584+
#if PY_VERSION_HEX >= 0x030B00A7
585+
PyFloat_Pack8(d, (char *)&buf[1], 0);
586+
#else
579587
_PyFloat_Pack8(d, &buf[1], 0);
588+
#endif
580589
msgpack_pack_append_buffer(x, buf, 9);
581590
}
582591

msgpack/unpack_template.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,20 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize
243243
_msgpack_load32(uint32_t,n)+1,
244244
_ext_zero);
245245
case CS_FLOAT: {
246-
double f = _PyFloat_Unpack4((unsigned char*)n, 0);
246+
double f;
247+
#if PY_VERSION_HEX >= 0x030B00A7
248+
f = PyFloat_Unpack4((const char*)n, 0);
249+
#else
250+
f = _PyFloat_Unpack4((unsigned char*)n, 0);
251+
#endif
247252
push_fixed_value(_float, f); }
248253
case CS_DOUBLE: {
249-
double f = _PyFloat_Unpack8((unsigned char*)n, 0);
254+
double f;
255+
#if PY_VERSION_HEX >= 0x030B00A7
256+
f = PyFloat_Unpack8((const char*)n, 0);
257+
#else
258+
f = _PyFloat_Unpack8((unsigned char*)n, 0);
259+
#endif
250260
push_fixed_value(_double, f); }
251261
case CS_UINT_8:
252262
push_fixed_value(_uint8, *(uint8_t*)n);

0 commit comments

Comments
 (0)