|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如题,使用ctypes调用so库中的接口,两个接口的参数相同,都是字符串
一个接口返回值为int,参数utf-8编码后传给so库,so库解析参数正确,接口正常调用;
另一个调用返回值为指针类型,参数utf-8编码后传给so库,so库解析参数却是乱码。
真是奇怪
附示例源码:
接口1print的信息正确,接口2print的却是乱码
so库封装源码示例:
int c_dev_unbind(char *dev_id)
{
printf("接口1的参数:%s",dev_id);
return dev_unbind(dev_id);
}
DEV_DESC_IF_S *dev_desc_get(char *dev_id)
{
printf("接口2的参数:%s",dev_id);
DEV_DESC_IF_S *dev_ifs = dev_desc_get(dev_id);
return dev_ifs;
}
python调用
def py_dev_unbind(dev_id):
dev_id = dev_id.encode() if isinstance(dev_id, str) else dev_id
method = sdk.c_dev_unbind
method.argtypes = [c_char_p,]
method.restype = c_int
res = method(dev_id)
return res
def py_dev_desc_get(dev_id):
dev_id = dev_id.encode() if isinstance(dev_id, str) else dev_id
method = sdk.c_dev_desc_get
method.argtypes = [c_char_p,]
method.restype = [POINTER(DEV_DESC_IF_S)]
res = method(dev_id)
return res
|
|