Statically Typed

because Hindley-Milner rocks

Swig, Python and C++ exceptions, part 3

I patted myself on the back way too soon to be proud.  If you look back to the first post and know a little about Swig you might see why.  If you don’t, let me explain.

Swig doesn’t create a valid constructor for abstract C++ classes when it wraps them.  Thus when I was enclosing my calls in Python’s trycatch clauses the real exception I was catching was an AttributeError “constructor not defined.”  That error was thrown by the seemingly innocuous line Foo.__init__(self).  Changing the C++ code so that Foo was not an abstract class solved the problem… for that code at least.

Thing is, we need to wrap an abstract class.  All functions are pure and virtual.  Swig includes a %noabstract instruction but very little guidance as to how it interacts with directors and cross-language polymorphism.  Looks like first thing I’ll do tomorrow is make a new SO post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


This entry was posted on June 3, 2010 by in C++, Python.
%d bloggers like this: