ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
Re: [C++-sig] extracting a c++ object from a PyObject
by David Abrahams other posts by this author
Feb 27 2003 8:08PM messages near this date
[C++-sig] extracting a c++ object from a PyObject | [C++-sig] Enhanced shared_ptr support
Francois Ostiguy <ostiguy@[...].gov>  writes:

>  This is a follow-up question to a recent thread.
>  Dave Abrahams provided the following code to extract a c++ object from a
>  PyObject
> 
>  void f(PyObject* p) {
> 
>    handle<> ph(borrowed(p));
>    MyObj* op = extract<MyObj*>(object(ph));
> 
>  }
> 
>  this works beautifully, but appenrently fails in the case where MyObj
>  is a simple function. That is
> 
> 
>  typedef void (fcntptr*)();
> 
>  void f(PyObject* p) {
> 
>    handle<> ph(borrowed(p));
>    fcntptr op = extract<fcntptr>(object(ph));
> 
>  }
> 
>  results in the following compilation error message.
> 
>  /usr/local/include/boost/type_traits/add_cv.hpp:34: `const volatile'
>  qualifiers cannot be applied to `void ()()'
> 
>  As always, any help/insight is greatly appreciated.

The compilation error occurs because Boost.Python isn't set up to
convert Python objects to function pointers.  It's not a crazy
idea to do so if, for example, you have a Python object which actually
contains a C++ function pointer in the first place, but that's not
implemented.  If you're trying to convert arbitrary Python functions
to C++ function pointers...

Can you figure out how to turn an arbitrary Python object into a C++
function pointer at runtime, using just the Python 'C' API?  If the
C++ function pointed to always does the same thing regardless of the
source Python object, you can... but that's not a very interesting
case.  If you want the C++ function to do something different based on
the Python function passed (e.g. call the Python object), where would
the code for that C++ function come from?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
Francois Ostiguy
David Abrahams

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved