Hello all > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:numpy- > [EMAIL PROTECTED] On Behalf Of Lars Friedrich > Sent: 25 July 2006 13:55 > To: numpy-discussion@lists.sourceforge.net > Subject: Re: [Numpy-discussion] ctypes, numpy-array > > > 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...
Travis added this quite recently. Somebody (probably me) still has to update the wiki to reflect these changes. > > 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 > > ??? You can read about PyDLL here: http://docs.python.org/dev/lib/ctypes-loading-shared-libraries.html I think PyDLL might turn out to be an interesting alternative to traditional extension modules. But for wrapping C code, I think writing functions that operate on pointers to ints and floats and whatnot works nicely. > > - Write your function as: > > > > int foo(int* x); > > > > Then do something like this: > > > > x = N.array([...], dtype=N.intc) > > mydll.foo.restype = None Slight typo on my part. For this example it should be: mydll.foo.restype = c_int > > 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. Cool. Enjoy! Regards, Albert ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion