linux下c 调用python,在Linux下使用python ctypes调用io\u submit
我正在尝试使用python ctypes调用io帴ubmit。
我写的代码应该可以在32位和64位Intel/AMD体系结构上工作,但这里我将重点放在64位上。在
我定义了以下内容:def PADDED64(type, name1, name2):
return [(name1, type), (name2, type)]
def PADDEDptr64(type, name1, name2):
return [(name1, type)]
def PADDEDul64(name1, name2):
return [(name1, ctypes.c_ulong)]
class IOVec(ctypes.Structure):
_fields_ = [("iov_base", ctypes.c_void_p), ("iov_len", ctypes.c_size_t)]
class IOCBDataCommon64(ctypes.Structure):
_fields_ = PADDEDptr64(ctypes.c_void_p, "buf", "__pad1") + \
PADDEDul64("nbytes", "__pad2") + \
[("offset", ctypes.c_longlong), ("__pad3", ctypes.c_longlong), ("flags", ctypes.c_uint), ("resfd", ctypes.c_uint)]
class IOCBDataVector(ctypes.Structure):
_fields_ = [("vec", ctypes.POINTER(IOVec)), ("nr", ctypes.c_int), ("offset", ctypes.c_longlong)]
class IOCBDataPoll64(ctypes.Structure):
_fields_ = PADDED64(ctypes.c_int, "events", "__pad1")
class SockAddr(ctypes.Structure):
_fields_ = [("sa_family", ctypes.c_ushort), ("sa_data", ctypes.c_char * 14)]
class IOCBDataSockAddr(ctypes.Structure):
_fields_ = [("addr", ctypes.POINTER(SockAddr)), ("len", ctypes.c_int)]
class IOCBDataUnion64(ctypes.Union):
_fields_ = [("c", IOCBDataCommon64), ("v", IOCBDataVector), ("poll", IOCBDataPoll64), ("saddr", IOCBDataSockAddr)]
class IOCB64(ctypes.Structure):
_fields_ = PADDEDptr64(ctypes.c_void_p, "data" , "__pad1") + \
PADDED64(ctypes.c_uint, "key", "__pad2") + \
[("aio_lio_opcode", ctypes.c_short), ("aio_reqprio", ctypes.c_short), ("aio_fildes", ctypes.c_int), ("u", IOCBDataUnion64)]
class Timespec(ctypes.Structure):
_fields_ = [("tv_sec", ctypes.c_long), ("tv_nsec", ctypes.c_long)]
class IOEvent64(ctypes.Structure):
_fields_ = PADDEDptr64(ctypes.c_void_p, "data", "__pad1") + \
PADDEDptr64(ctypes.POINTER(IOCB64), "obj", "__pad2") + \
PADDEDul64("res", "__pad3") + \
PADDEDul64("res2", "__pad4")
我有一个名为AIOCommands的包装类:
^{pr2}$
我已经定义了io\u submit的参数和返回值:class Executor:
def __init__(self, aioLibraryPath):
self.__aio = ctypes.CDLL(aioLibraryPath)
self.__aio.io_submit.argtypes = [self.aio_context_t, ctypes.c_long, ctypes.POINTER(ctypes.POINTER(IOCB64))]
self.__aio.io_submit.restype = ctypes.c_long
现在,该怎么办遗嘱执行人提交身体看起来像?我试过了:def io_submit(self, aioContext, aioCommands):
iocbPtr = ctypes.cast(aioCommands.getIOCBArray(), ctypes.POINTER(self.iocb_t))
return self.__aio.io_submit(aioContext, aioCommands.size(), ctypes.byref(iocbPtr))
但是每当aiocommandlest的长度大于1时,我就会得到一个分段错误。
当列表只包含1个命令时,代码按预期工作。在
这可能是我的结构定义有问题吗?我试图模仿libaio.h中的定义(假设只支持little-endian架构):#if defined(__i386__) /* little endian, 32 bits */
#define PADDED(x, y) x; unsigned y
#define PADDEDptr(x, y) x; unsigned y
#define PADDEDul(x, y) unsigned long x; unsigned y
#elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__)
#define PADDED(x, y) x, y
#define PADDEDptr(x, y) x
#define PADDEDul(x, y) unsigned long x
#elif defined(__powerpc64__) /* big endian, 64 bits */
#define PADDED(x, y) unsigned y; x
#define PADDEDptr(x,y) x
#define PADDEDul(x, y) unsigned long x
#elif defined(__PPC__) /* big endian, 32 bits */
#define PADDED(x, y) unsigned y; x
#define PADDEDptr(x, y) unsigned y; x
#define PADDEDul(x, y) unsigned y; unsigned long x
#elif defined(__s390x__) /* big endian, 64 bits */
#define PADDED(x, y) unsigned y; x
#define PADDEDptr(x,y) x
#define PADDEDul(x, y) unsigned long x
#elif defined(__s390__) /* big endian, 32 bits */
#define PADDED(x, y) unsigned y; x
#define PADDEDptr(x, y) unsigned y; x
#define PADDEDul(x, y) unsigned y; unsigned long x
#else
#error endian?
#endif
struct io_iocb_poll {
PADDED(int events, __pad1);
}; /* result code is the set of result flags or -'ve errno */
struct io_iocb_sockaddr {
struct sockaddr *addr;
int len;
}; /* result code is the length of the sockaddr, or -'ve errno */
struct io_iocb_common {
PADDEDptr(void *buf, __pad1);
PADDEDul(nbytes, __pad2);
long long offset;
long long __pad3;
unsigned flags;
unsigned resfd;
}; /* result code is the amount read or -'ve errno */
struct io_iocb_vector {
const struct iovec *vec;
int nr;
long long offset;
}; /* result code is the amount read or -'ve errno */
struct iocb {
PADDEDptr(void *data, __pad1); /* Return in the io completion event */
PADDED(unsigned key, __pad2); /* For use in identifying io requests */
short aio_lio_opcode;
short aio_reqprio;
int aio_fildes;
union {
struct io_iocb_common c;
struct io_iocb_vector v;
struct io_iocb_poll poll;
struct io_iocb_sockaddr saddr;
} u;
};
任何帮助都将不胜感激,我已经被困在这几个小时了。在
linux下c 调用python,在Linux下使用python ctypes调用io\u submit相关推荐
- Linux下 Python通过ctypes调用cAPI (一)
c_long和c_int是一种类型. cdll加载使用标准cdecl调用约定导出函数的库 windll使用stdcall调用约定调用函数 oledll也使用stdcall调用约定 在linux下通过两 ...
- python能调用身份证读卡器吗_用Python在Linux下调用新中新DKQ-A16D读卡器,读二代证数据...
1.背景 最近在研究二代证读卡器,手头上的设备是新中新DKQ-A16D,在官网(https://www.onecardok.com.cn/download)逛了一圈,发现Win下的示例,浏览器插件很多 ...
- linux下载哪个python版本-Linux下升级安装Python-3.6.2版本
本文主要介绍在Linux(CentOS)下将Python的版本升级为3.6.2的方法 众所周知,在2020年python官方将不再支持2.7版本的python,所以使用3.x版本的python是必要的 ...
- linux下载哪个python版本-Linux下切换Python版本的几种方法
本篇博文面向Linux用户,在Ubuntu下测试通过 0 为什么需要有两个版本的Python Python2和Python3不兼容是每个接触过Python的开发者都知道的事,虽说Python3是未来, ...
- linux python3.8源码安装_linux 下从源码安装 Python——小白踩坑记
实验室服务器使用的系统为 Ubuntu 16.04,自带的 python 版本为 Python 2.7.12 和 Python 3.5.2,命令行下使用$ python命令来启动 python 时默认 ...
- linux python指向python3_linux下切换python2和python3(转)
0x00 为什么需要有两个版本的Python Python2和Python3不兼容是每个接触过Python的开发者都知道的事,虽说Python3是未来,但是仍然有很多项目采用Python2开发.Lin ...
- Python在Linux地址已在使用,python在linux下的使用
1.查看python(解释器)的版本(什么版本的解释器支持哪一版版的语言标准) 一般在linux上已经预装了python,只要在Bash Shell中输入python,即可看到如下版本信息: 按Ctr ...
- linux python版本_linux下更新Python版本并修改默认版本
linux下更新Python版本并修改默认版本,有需要的朋友可以参考下. 很多情况下拿到的服务器python版本很低,需要自己动手更改默认python版本 1.从官网下载python安装包(这个版本可 ...
- Python安装(Windows下安装/Linux下安装)
1.准备工作 1.1.运行环境 课程中:Windows下的运行环境 1.2.Python是什么 (1)Python是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum于1 ...
最新文章
- pycharm goland clion 修改注释颜色
- 智能骨传导眼镜vue_穿戴设备迎新机遇,智能音频眼镜或将是下一个风口
- 这些Windows 10隐藏秘技,你知道几个?
- An end-to-end TextSpotter with Explicit Alignment and Attention
- 3-8Tensor的算术运算编程实例
- 让我们深入了解PP YOLO做出的贡献
- 【软件测试】单元测试是软件测试的最基础环节
- centos7卸载docker_新手快速入门Docker,轻松掌握Docker安装与使用
- plsql developer 无法登录Oracle
- 【scratch高阶案例教学】scratch斐波那契数列 scratch创意编程 少儿编程 小朋友们也可以完成如此神奇的数列
- CDN网站加速,为什么会打不开
- 实战无成本搭建php社工库,简单、高效、几T数据随便查,高效社工库搭建与数据库整理–深夜福利...
- WeUI实现登录页面
- Mac和Win7双系统 + 完美文件共享
- 如何自动执行Excel的多次替换--Excel批量替换工具
- 计算机应用方向的毕业设计,计算机应用(动画方向)毕业设计.pdf
- C++学习15:C++模板的参数
- leetcode572.另一棵树的子树
- Altium designer DRC规则中英文对照
- 答题APP开发解决方案