python 传参const char_constchar*参数只给出第一个字符(在python3上)

我在c++中创建了一个非常简单的函数,它使用aio-write。在参数中,我得到了创建文件的路径及其大小。要创建新文件,我使用int open(const char *pathname, int flags, mode_t mode)。在

然后我使用:g++ -Wall -g -Werror aio_calls.cpp -shared -o aio_calls.so -fPIC -lrt将其编译为共享对象。在

在Python2.7.5上,一切都很完美,但在Python3.4上,我只得到路径的第一个字符。有什么线索可以让它工作,这样它就可以走完这条路了吗?在

以下是功能代码:#include

#include

#include

#include

#include

#include

#include

#include

#include

#include "aio_calls.h"

#define DLLEXPORT extern "C"

using namespace std;

DLLEXPORT int awrite(const char *path, int size)

{

// create the file

cout << path << endl;

int file = open(path, O_WRONLY | O_CREAT, 0644);

if (file == -1)

return errno;

// create the buffer

char* buffer = new char[size];

// create the control block structure

aiocb cb;

memset(buffer, 'a', size);

memset(&cb, 0, sizeof(aiocb));

cb.aio_nbytes = size;

cb.aio_fildes = file;

cb.aio_offset = 0;

cb.aio_buf = buffer;

// write!

if (aio_write(&cb) == -1)

{

close(file);

return errno;

}

// wait until the request has finished

while(aio_error(&cb) == EINPROGRESS);

// return final status for aio request

int ret = aio_return(&cb);

if (ret == -1)

return errno;

// now clean up

delete[] buffer;

close(file);

return 0;

}

如你所见,我在函数的开头写了cout。以下是python 2上发生的情况:

^{pr2}$

Python3上的情况如下:Python 3.4.5 (default, May 29 2017, 15:17:55)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> from ctypes import cdll

>>> m=cdll.LoadLibrary('/home/administrator/Documents/aio_calls.so')

>>> m.awrite('aa.txt', 40)

a

0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值