gpt4 book ai didi

python - 如何使用 Python 和 ctypes 处理指向指针的指针

转载 作者:太空宇宙 更新时间:2023-11-04 03:53:42 25 4
gpt4 key购买 nike

我正在尝试对在我正在包装的库中找到的结构进行建模,其中该结构有一个指向指针的指针,如下所示:

typedef struct item_t {
char* name;
}

typedef struct container_t {
item_t **items;
}

当使用 Python 的 ctypes 模块的 Structure 类建模时,我如何表示具有可变长度的指针数组?

最佳答案

您可以使用 POINTER并将 item_t ** 转换为 POINTER(POINTER(item_t)):

from ctypes import *

class item_t(Structure):
_fields_ = [
('name', c_char_p),
]


class container_t(Structure):
_fields_ = [
('items', POINTER(POINTER(item_t))),
]

关于python - 如何使用 Python 和 ctypes 处理指向指针的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18796737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com