[C++-sig] optimizing away calls to the python runtime -- was [detecting if a function is written in python or C++]

Mathieu Lacage Mathieu.Lacage at sophia.inria.fr
Fri Jan 27 08:52:07 CET 2006


On Wed, 2006-01-18 at 15:09 -0500, François Duranleau wrote:

> template < typename Function ,
>             typename Tag >
> struct function_wrapper_callback
>      : Callback1
> {
>      static Function func ;
> 
>      void operator () ( int a )
>      {
>          func( a ) ;
>      }
> } ;
> 
> template < typename Function ,
>             typename Tag >
> Function function_wrapper< Function , Tag >::func = Function() ;

you meant function_wrapper_callback here, I assume.

> 
> template < typename Tag ,
>             typename Function >
> void
> export_function_callback( Function f ,
>                            const char* name )
> {
>      typedef function_wrapper_callback< Function , Tab > callback_type ;
> 
>      // Ensures unicity of callback_type for f
>      assert( callback_type::func == Function() ) ;
> 
>      callback_type::func = f ;
> 
>      class_< callback_type ,
>              bases< Callback1 > ,
>              boost::noncopyable >( name ) ;
> }
> 
> 
> And in the module section, taking your example of function 
> 'real_function', you could export it like this:
> 
> // declare the tag ouside of BOOST_PYTHON_MODULE(...)
> struct real_function_tag ;
> 
> export_function_callback< real_function_tag >( & real_function ,
>                                                 "real_function_callback" );

Am I right in assuming that your "tag" is here to deal with multiple
functions having the same signature ?

Mathieu
-- 




More information about the Cplusplus-sig mailing list