Re: Regarding external binding of functions

"Diez B. Roggisch" <[email protected]> Sat, 14 Dec 2013 14:23:57 +0100
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
This should be what you are looking for, no?

http://docs.python.org/2/library/ctypes.html#callback-functions

I have to admit though that I have no idea how to deal with variadic functions in ctypes. Or in C, for that matter… It might not be possible to access variadic arguments from within python. The solution could be to provide a C helper library that uses the vararg.h-macros to build up a data-structure that is passed as list to a function - this could be implemented in Python then.

Diez


On Dec 12, 2013, at 8:01 AM, muhammad waseem sarwar <[email protected]> wrote:

> A little elaboration of my last question is that I want to assign
> hello_printf pointer to libc.printf in python before calling the API
> such that API should be able to use hello_printf.
> 
> Looking forward.
> 
> Thanks,
> Waseem
> 
> On Wed, Dec 11, 2013 at 10:44 PM, muhammad waseem sarwar
> <[email protected]> wrote:
>> Hi,
>> 
>> I am new to ctypes and I have a questions regarding external binding
>> of function using ctypes. The question is as follows,
>> 
>> Q. I have a simple library that uses function pointer of
>> hello_printf(const char *format, ...) in one of its API. While using
>> this library in C, I point the function pointer of hello_printf to
>> printf and code works seamlessly.
>> hello_printf is not the API but is used in the implementation of one
>> of the API's. The reason for this is that I want external application
>> using the library to provide implementation of printf to provide
>> flexibility and is common practice in C/C++.
>> 
>> I want to know that how I can achieve this external binding of
>> function pointer using ctypes i.e. point hello_printf() to printf in
>> python so on calling the API, it gets the right printf implementation.
>> 
>> I am not sure if I explained it well and I can post the code if there
>> is ambiguity in question.
>> 
>> Help would be highly appreciated and thanks in advance.
>> 
>> Regards,
>> Waseem
> 
> ------------------------------------------------------------------------------
> Rapidly troubleshoot problems before they affect your business. Most IT 
> organizations don't have a clear picture of how application performance 
> affects their revenue. With AppDynamics, you get 100% visibility into your 
> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> _______________________________________________
> ctypes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ctypes-users
>

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users
signature.asc (application/pgp-signature, 496 B)
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQEcBAEBCgAGBQJSrFvtAAoJEMgWrvcLlYXnEawH/2aHEeOJCoZ50+UpSDq7pUfu
EB5PwX7FY//dF8JDu01eWtXbajqkw0MzPxdyCJjkGva6Ws7lYk9zOwySq2CJDHXi
9btXAw81U52dl0OAkMI5foplMjKo1J8iPngfydPvtrlT39jHKm5qZ8pkeEVWIZe4
t8skLNhNxgzGrXbM9fz47XFFDvOdgfTCWwIEAD7hZj/SF4rMERQHcwHfePGi8RIT
bXsGpfjrUf/EUCfRDPX7F4EeuEaYNunKDN1PdzErXKD/RabwsHoAFKipa/eTeRGe
uiDMx2uN9eh+C/GkSRgxxF9tlkjO3ZHKAWb5gRTpSqZsEJhMipy6nGJN5Wm2Oy8=
=hPZF
-----END PGP SIGNATURE-----