[C++-sig] Re: Boost.Python: few thoughts and questions...

Roman Sulzhyk roman_sulzhyk at yahoo.com
Fri Jun 13 16:19:26 CEST 2003


David, Paul, thanks for following up.

David, sorry about confused terminology in the original email, I'm a
bit rusty.

Anyway, here's a more complete example of what I meant.

==== world.h ====
#include <string>
#include <iostream>
#include <sstream>
 
struct useless {};
 
class BaseWorld {
public:
   // Should be exposed but isn't!
   virtual const char *uber_greet() const { return "uber greet"; }
 
   virtual const std::string &greet() throw (useless) = NULL;
};
 
class World : public BaseWorld
{
public:
   World(const std::string &msg): msg(msg) {}
   void set(const std::string &msg) { this->msg = msg; }
   virtual const std::string &greet() throw (useless) { return msg; }
 
   // Pseudo overload
   // const char *uber_greet() { return this->BaseWorld::uber_greet();
}
 
private:
   std::string msg;
};
 
std::string test_world(void)
{
   World w("greet from derived");
 
   std::ostringstream os;
   os << w.uber_greet() << " " << w.greet();
 
   return os.str();
}
==== world.pyste =====
world = Class("World", "world.h")
Function ( "test_world", "world.h" )
 
unvirtual ( world.greet )
set_policy ( world.greet, return_value_policy(copy_const_reference) )
==== world.cpp =======
[roman at mholden ~/src/pysymphony]$ cat world.cpp
 
// Includes
====================================================================#include
<boost/python.hpp>
#include <world.h>
 
// Using
=======================================================================using
namespace boost::python;
 
// Module
======================================================================BOOST_PYTHON_MODULE(world)
{
    def("test_world", &test_world);
    class_< World >("World", init< const World & >())
        .def(init< const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
>())
        .def("set", &World::set)
        .def("greet", &World::greet, return_value_policy<
copy_const_reference >())
    ;
 
}
==========================
This example demonstrates all of the original points. 

Notice that I'm using my patched version of 1.3.0 pyste, which has
'unvirtual' - if you try the example with regular pyste it will fail on
throw(useless), removing that should work fine.

However, I do believe it's a useful feature to be able to disable
automatic wrapping of classes which have virtual functions. In any
case, the current implementation has a bug whereas 'exclude' is not
taken into account when generating wrappers - i.e. if a class has
virtual functions and you 'exclude' all of them, a blank wrapper will
still be generated.

A bigger problem is that public methods of the BaseWorld class are not
exported. As far as I can tell it should be possible to add it, all of
required info appears to be generated by gccxml.

Glad to hear extraction of exception specifications is added to GCCXML.

I'm planning to fix the problems I've mentioned since I'd like to use
this functionality, is it worthwhile submitting a patch?

Thanks!

Roman

--- David Abrahams <dave at boost-consulting.com> wrote:
> Paul Rudin <paul.rudin at ntlworld.com> writes:
> 
> > David Abrahams <dave at boost-consulting.com> writes:
> >
> >> Roman Sulzhyk <roman_sulzhyk at yahoo.com> writes:
> >> 
> >> > 3. Specifying the set_policy() for virtual functions
> >> >
> >> > It appears that the policy setting is ignored for virtual
> function
> >> > declarations.
> >> 
> >> What makes you think so?
> 
> <demonstrates, beyond a shadow of a doubt, that Pyste is ignoring
> policy settings>
> 
> OK, it looks like Pyste has a bit of a bug here!  Thanks to Roman for
> reporting it and to Paul for following up. 
> 
> -- 
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
> 
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com




More information about the Cplusplus-sig mailing list