From: Lars F. <lfr...@im...> - 2006-07-25 11:55:17
|
> What's might be happening here is that a.ctypes.data is in fact being passed > to your function via ctypes's from_param magic (check the ctypes tutorial > for details). > > In [10]: x = N.array([]) > > In [11]: x.ctypes.data > Out[11]: c_void_p(15502816) > > In [12]: x._as_parameter_ > Out[12]: 15502816 > OK, I did not know about x.ctypes.data... > So what's probably happening here is that you already have a pointer to the > array's data which you then cast to a PyArrayObject pointer. Dereferencing > myPtr->data is looking for a pointer inside the array's data, which contains > zeros. I understand. > - look at ctypes's PyDLL option if you want to pass around Python objects ??? > - Write your function as: > > int foo(int* x); > > Then do something like this: > > x = N.array([...], dtype=N.intc) > mydll.foo.restype = None > mydll.foo.argtypes = [POINTER(c_int)] > mydll.foo(x.ctypes.data) I did that, and it worked fine for me. Thank you very much! This is really great. Lars |