cppyy 2.4.0及以上版本处理uint8_t数组时崩溃问题咨询
问题复现
- 在cppyy 2.3.1 + Python3.8环境下,以下代码可正常将uint8_t数组转换为bytes:
import cppyy cppyy.cppdef(''' struct T { uint8_t t[10]; }; ''') t = cppyy.gbl.T() bytes(t.t)
- 升级至cppyy 2.4.0及以上版本后,执行
bytes(t.t)会触发段错误(SIGSEGV),错误栈如下:
#8 signal handler called
#9 __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:384
#10 0x000056085fd8d582 in memcpy (__len=2147483640, __src=, __dest=0x7f0f27d56030) at /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#11 PyBuffer_ToContiguous (buf=buf entry=0x7f0f27d56030, src=src entry=0x7ffc116933b0, len=2147483640, order=order entry=67 'C') at Objects/memoryobject.c:997
#12 0x000056085fe188d9 in _PyBytes_FromBuffer (x=) at Objects/bytesobject.c:2689
#13 0x000056085fd56279 in bytes_new_impl (errors=0x0, encoding=0x0, x=0x7f0fa7dba6b0, type=0x56086000bac0 <PyBytes_Type>) at Objects/bytesobject.c:2667
#14 bytes_new (type=0x56086000bac0 <PyBytes_Type>, args=, kwargs=) at Objects/clinic/bytesobject.c.h:894
#15 0x000056085fda0bd5 in type_call (type=type entry=0x56086000bac0 <PyBytes_Type>, args=args entry=0x7f0fa7df0c70, kwds=kwds entry=0x0) at Objects/typeobject.c:1100
附加现象与尝试
- 打印
t.t[0]会得到超过255的随机值,且无法修改该值 - 已尝试通过pip/源码安装cppyy,在Python3.8和3.11环境下均能复现问题
- cppyy 2.4.0更新日志提到uint8_t枚举曾被当作单字符字符串处理
- 改用
unsigned char可正常工作,但现有代码大量使用uint8_t,无法全局替换
请求
确认此问题是否为cppyy的bug,并提供访问uint8_t缓冲区的替代方法或临时解决方案
内容的提问来源于stack exchange,提问作者fab

