[C++-sig] Pyste in boost 1.31.0 has trouble with exception specs

Stephen Tether tether at mitlns.mit.edu
Mon Mar 15 22:23:30 CET 2004


I tried running Pyste on the following files test.hh and test.pyste and 
it threw an TypeError exception.

// Begin test.hh
#include <stdexcept>

class Foo {
public:
   virtual void bar() throw(std::exception);
};
// End test.hh


# Begin test.pyste
Class("Foo", "test.hh")
# End test.pyste

The exception traceback:
Traceback (most recent call last):
   File "/evbsoft/python/v2_3_3c1/bin/pyste.py", line 8, in ?
     pyste.main()
   File 
"/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/pyste.py", 
line 405, in main
     status = Begin()
   File 
"/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/pyste.py", 
line 244, in Begin
     return GenerateCode(parser, module, out, interfaces, multiple)
   File 
"/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/pyste.py", 
line 372, in GenerateCode
     export.GenerateCode(codeunit, exported_names)
   File 
"/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/Exporter.py", 
line 50, in GenerateCode
     self.Export(codeunit, exported_names)
   File 
"/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/ClassExporter.py", 
line 92, in Export
     self.InheritMethods(exported_names)
   File 
"/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/ClassExporter.py", 
line 119, in InheritMethods
     pointers = [x.PointerDeclaration(True) for x in self.class_ if 
isinstance(x, Method)]
   File 
"/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/declarations.py", 
line 320, in PointerDeclaration
     return '(%s (%s::*)(%s) %s%s)&%s' %\
   File 
"/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/declarations.py", 
line 226, in Exceptions
     return " throw(%s)" % ', '.join (self.throws)
TypeError: sequence item 0: expected string, Type found


It looks like a list comprehension or map() call at line 226 of 
declarations.py:
     return " throw(%s)" % ', '.join ([x.name for x in self.throws])

If I make that change I get the following output:

// Boost Includes 
==============================================================
#include <boost/python.hpp>
#include <boost/cstdint.hpp>

// Includes 
====================================================================
#include <test.hh>

// Using 
=======================================================================
using namespace boost::python;

// Declarations 
================================================================
namespace  {

struct Foo_Wrapper: Foo
{
     Foo_Wrapper(PyObject* self_, const Foo& p0):
         Foo(p0), self(self_) {}

     Foo_Wrapper(PyObject* self_):
         Foo(), self(self_) {}

     void bar() throw(std::exception) {
         call_method< void >(self, "bar");
     }

     void default_bar() {
         Foo::bar();
     }

     PyObject* self;
};


}// namespace


// Module 
======================================================================
BOOST_PYTHON_MODULE(test)
{
     class_< Foo, Foo_Wrapper >("Foo", init<  >())
         .def(init< const Foo& >())
         .def("bar", &Foo::bar, &Foo_Wrapper::default_bar)
     ;

}
// End of test.cpp

- Steve Tether




More information about the Cplusplus-sig mailing list