ctypes help for "array of character pointers" as an output parameter

S

stalex

I'm wrapping a C function exists in a shared library. Its prototype
looks like as follows

int getFileNames(int aSize, char **names);

The documentation says that the asSize is the number of entries to be
returned and
names is output array of character pointers of at least aSize
elements. So, I defined
a function prototype in python, follow ctypes tutorial, and try to run
it. The following
code section shows what I did.

_getNames = TheLib.getNames
_getNames.restype = c_int
_getNames.argtypes = [
c_int,
POINTER(c_char_p)
]

def getNames():
aSize = 1024
names = (c_char_p * arraySize)()
rc = _getNames(aSize, names)

After that, I make a call to getNames() in my python program and,
unfortunately, either TypeError
or Segmentation fault. Sigh...

I wonder that whether the _getNames prototype definition in my code
section is correct??
If it isn't, I guess so, how do I do a right one?
Another, whether the usage in getNames() is correct??
Appreciate for any reply or recommendation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top