[ python-Bugs-1574593 ] ctypes: Returning c_void_p from callback doesn\'t work

SourceForge.net noreply at sourceforge.net
Thu Oct 12 07:58:50 CEST 2006


Bugs item #1574593, was opened at 2006-10-10 08:18
Message generated for change (Settings changed) made by nnorwitz
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1574593&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Albert Strasheim (albertstrasheim)
>Assigned to: Thomas Heller (theller)
>Summary: ctypes: Returning c_void_p from callback doesn\'t work

Initial Comment:
C code:

extern CALLBACK_API void* foo(void*(*callback)()) {
    printf("foo calling callback\n");
    callback();
    printf("callback returned in foo\n");
}

callback.py contains:

import sys
print sys.version
from ctypes import *
def callback(*args):
    return c_void_p()
#lib = cdll['libcallback.so']
lib = cdll['callback.dll']
lib.foo.argtypes = [CFUNCTYPE(c_void_p)]
lib.foo(lib.foo.argtypes[0](callback))

With Python 2.4.3 and ctypes 1.0.0 + Thomas Heller's
patch for another issue (which doesn't seem to affect
this situation, but anyway) I get the following error:

2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit
(Intel)]
foo calling callback
Traceback (most recent call last):
  File "source/callbacks.c", line 216, in 'converting
callback result'
TypeError: cannot be converted to pointer
Exception  in None ignored
callback returned in foo

With Python 2.5 and ctypes 1.0.1 I get:

2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32
bit (Intel)]
foo calling callback
Traceback (most recent call last):
  File "\loewis\25\python\Modules\_ctypes\callbacks.c",
line 216, in
'converting callback result'
TypeError: cannot be converted to pointer
Exception  in <function callback at 0x009C3CF0> ignored
callback returned in foo

Returning a Python integer from callback() doesn't
cause an error to be raised.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1574593&group_id=5470


More information about the Python-bugs-list mailing list