Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

Siyi Deng mr.siyi.deng at gmail.com
Tue May 24 13:47:50 EDT 2016


Here is a summary of what I did with numpy and the dll

I have verified that the values entering the last dll call (dl.cfunction) are identical across platforms.


 

The c function has a signature as follows: 

int cfunction(int len_data, float* data, int* ac, int num_ac, 
        int flag1, int flag2, int flag3, float* param, 
        float* out) 


and in python: 

import numpy as np 
import ctypes as ct 

dl = ct.cdll.LoadLibrary('xxx.dylib')

# data, ac, param are loaded from somewhere else.
data = np.atleast_2d(np.float32(data)) 
ac = np.atleast_2d(np.int32(a)) if a else np.zeros((2, 1), dtype=np.int32) 
param = np.atleast_2d(np.float32(param)) 
flag1 = True
flag2 = True
flag3 = True
num_ac = ac.shape[1] 
len_data = data.shape[1] 
num_inc = len_data//200
out = np.zeros((2, num_inc), dtype=np.float32) 
pt_param = param.ctypes.data_as(cf) if param else None

cf = ct.POINTER(ct.c_float) 
dl.cfunction(len_data, data.ctypes.data_as(cf), 
        ac.ctypes.data_as(ct.POINTER(ct.c_int)), 
        num_ac, flag1+0, flag2+0, flag3+0, 
        pt_param, out.ctypes.data_as(cf)) 
        
        



More information about the Python-list mailing list