C Extension - return an array of longs or pointer?

Jorgen Grahn jgrahn-nntq at algonet.se
Wed Oct 12 13:35:53 EDT 2005


On 12 Oct 2005 04:46:34 -0700, Java and Swing <codecraig at gmail.com> wrote:
...
> ...my question is...in the c code, result is a pointer to an array of
> longs, how can I get the returned result to be a list or something
> similar to an array in Python?

RTFM. There are API functions to create an empty list [] and to append
objects to a list. PyList_something(), I think.

> ...I also have a function which returns a character array (denoted by a
> char *)...would it work the same as the previous question?

You might want to return this as a Python string, even if it's just random
octet data garbage. Depends on what that data really represents, but it's a
common idiom, and modules like struct and array expect their data to be
strings. Note that Python strings may contain NUL bytes.

/Jorgen

-- 
  // Jorgen Grahn <jgrahn@       Ph'nglui mglw'nafh Cthulhu
\X/                algonet.se>   R'lyeh wgah'nagl fhtagn!



More information about the Python-list mailing list