This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kermode
Recipients kermode
Date 2008-01-11.23:14:57
SpamBayes Score 0.010496493
Marked as misclassified No
Message-id <1200093299.88.0.890377527012.issue1800@psf.upfronthosting.co.za>
In-reply-to
Content
When a callback is created with an array argument and then is called
from Python the callback function receives an array full of garbage.

Here is an example:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> A = c_int * 1
>>> A
<class '__main__.c_long_Array_1'>
>>> Foo = CFUNCTYPE(None, A)
>>> def py_foo(a):
...     print a
...     print a[0]
...
>>> foo = Foo(py_foo)
>>> foo(A(42))
<__main__.c_long_Array_1 object at 0x00B54440>
11879448

It works correctly when the callback is declared with a pointer argument
instead:

>>> A = c_int * 1
>>> Foo = CFUNCTYPE(None, POINTER(c_int))
>>> def py_foo(p):
...     print p
...     print p[0]
...
>>> foo = Foo(py_foo)
>>> foo(A(42))
<ctypes.LP_c_long object at 0x00B54440>
42
History
Date User Action Args
2008-01-11 23:15:00kermodesetspambayes_score: 0.0104965 -> 0.010496493
recipients: + kermode
2008-01-11 23:14:59kermodesetspambayes_score: 0.0104965 -> 0.0104965
messageid: <1200093299.88.0.890377527012.issue1800@psf.upfronthosting.co.za>
2008-01-11 23:14:58kermodelinkissue1800 messages
2008-01-11 23:14:57kermodecreate