>>> import nova.cffitest
{'dummy_func1': <cdata 'struct test_struct_ *(*)(struct test_struct_ *)' 0xf71f2700>, 'dummy_func2': <function newfunc at 0x8991e2c>, 'spi_iterate_error_code': <cdata 'int(*)(struct tdlhandle_s *, structtdlhandle_s *, struct spi_error_code_ *, int(*)(struct tdlhandle_s *, struct tdlhandle_s *, struct tdlhandle_s *, int, void *), void *)' 0xf71f2730>, 'threaded_ballback_test': <cdata 'int(*)(int, int(*)(int, int))' 0xf71f27a0>}
>>>
>>> def mycallback(x,y):
... print x, y
... return 0
...
>>> x=nova.cffitest.callback('int(*)(int,int)', mycallback)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'callback'
>>> x=nova.cffitest.ffi.callback('int(*)(int,int)', mycallback)
>>> print x
<cdata 'int(*)(int, int)' calling <function mycallback at 0x8991e64>>
>>> nova.cffitest.threaded_ballback_test(1000,x)
0
>>> Beginning Wait ....
Ending Wait ....
10 10
Segmentation fault (core dumped)
[128:~]$
My code library header code
typedef int (*mycallback_func_t)(int, int);
int threaded_ballback_test(int handle, mycallback_func_t mycb);
My library C code
void *my_wait_function( void *ptr )
{
mycallback_func_t cbfunc;
int x;
cbfunc = (mycallback_func_t) ptr;
printf("Beginning Wait .... \n");
sleep(5);
printf("Ending Wait .... \n");
x=cbfunc(10, 10);
printf("Doing Callback Wait .... \n");
return NULL;
}
int threaded_ballback_test(int handle, mycallback_func_t mycb)
{
pthread_t thread;
int x;
x = pthread_create( &thread, NULL, my_wait_function, (void*) mycb);
return 0;
}
Thx,
Sarvi