> Ok, then take care to post proper code next time. Details can be important,
> especially when asking about non-obvious problems.

Point taken - however the original context where the problem arose
consists of several massive libraries, which would be quite
impractical to post on a forum. The code I did post was proper in the
sense that it compiles and demonstrates the problem.

> Hmm, so you think that to call a C function, ctypes doesn't need to know
> what the exact signature is? That sounds a bit naive to me.

I fully agree that ctypes needs to know the type signature of the C
functions it wishes to call, my point is that this particular
information is not present in the shared library, and for that reason
we must set the input / return attributes of the ctypes functions
manually. In the Python code I do this like:

class BugTest:
   ....
   def from_param(self):
       return self.c_ptr

   def __init__(self)
       self.c_ptr =

lib_handle = ctypes.CDLL( "lib.so" )
...
func = getattr( lib_handle , "print_addr")

# Set the return type:
func.restype  = None

# Set the types of the arguments:
func.argtypes = [ BugTest ]

Now - the point is that if I omit the ctypes method from_param() and
instead set the argtype as:

func.argtypes = [ ctypes.c_void_p ]

And manually passing the internalized C - pointer to C things work as
I expect; I believe that the problem is somewhere along the
from_param() function path.

I did not make it really clear that if the original C allocation
points to memory in "32 bit region" everything works fine (as I
expected).

Thank you for your time.

Joakim

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to