ctypes question

B

Brendan Miller

I'm using python 2.5.2.

I have a ctypes function with argtypes like this:

_create_folder.argyptes = [c_void_p, c_int]

The issue I am having is that I can call it like this

_create_folder(some_pointer, "asdf")

and it won't raise a TypeError. Why would it accept a string for an
integer argument?

I didn't see this behavior documented when I read through
http://docs.python.org/library/ctypes.html, maybe I'm just missing
it... if that's the case a reference would be appreciated.

Brendan
 
M

Mark Dickinson

I'm using python 2.5.2.

I have a ctypes function with argtypes like this:

_create_folder.argyptes = [c_void_p, c_int]

Is that line a cut-and-paste? If so, try 'argtypes' instead of
'argyptes'. :)
The issue I am having is that I can call it like this

_create_folder(some_pointer, "asdf")

and it won't raise a TypeError. Why would it accept a string for an
integer argument?

I get the expected TypeError in 2.5.4 (OS X) (using printf, for lack
of anything better):

Python 2.5.4 (r254:67916, Feb 11 2010, 00:50:55)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
from ctypes import *
libc = CDLL("libc.dylib")
libc
printf = libc.printf
printf.argtypes = [c_char_p, c_int]
printf("%d\n", 53)
53
3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: wrong
type
 
B

Brendan Miller

I'm using python 2.5.2.

I have a ctypes function with argtypes like this:

_create_folder.argyptes = [c_void_p, c_int]

Is that line a cut-and-paste?  If so, try 'argtypes' instead of
'argyptes'.  :)

Woops! Well, nice to know that ctypes works as I expect.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top