简体   繁体   English

如何将原始数据复制到ctypes.Python C扩展的结构?

[英]How to copy raw data to ctypes.Structure from Python C extension?

Is it possible to get the value of pointer to raw data of ctypes.Structure instance in Python C extension? 是否可以获取指向Python C扩展中的ctypes.Structure实例的原始数据的指针的值? I would like to access and copy data from/to the instance of this class without bothering the interpreter by importing and using ctypes.memmove or ctypes.addressof . 我想通过导入和使用ctypes.memmovectypes.addressof来访问此类类的实例并从中复制数据,而不会打扰解释器。 In other words, does ctypes provide any C API which I can use directly? 换句话说, ctypes提供我可以直接使用的任何C API?

It doesn't appear that ctypes exposes a C API. ctypes似乎没有公开C API。

This is how it's done in >= 2.7: http://docs.python.org/extending/extending.html#providing-ac-api-for-an-extension-module 这是在> = 2.7中完成的操作: http : //docs.python.org/extending/extending.html#providing-ac-api-for-an-extension-module

ctypes source tagged at 2.7.1: http://svn.python.org/view/python/tags/r271/Modules/_ctypes/ 在2.7.1处标记的ctypes源: http : //svn.python.org/view/python/tags/r271/Modules/_ctypes/

I don't see anywhere in the source where an API capsule is built. 我在源代码中没有看到构建API封装的地方。 You'll have to use the ctypes Python interface via the Python C API instead. 您必须改为通过Python C API使用ctypes Python接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM