[C++-sig] Re: Boost... Exception safe (can I turn it off?), and controlled object construction?
David Abrahams
dave at boost-consulting.com
Mon Mar 1 14:09:32 CET 2004
"Adrian Bentley" <adruab at hotmail.com> writes:
> Hi,
>
> I'd like to turn off the exception forwarding feature
Not sure which one you're referring to here, but...
> of boost python (trying to adapt for use in high performance where
> exceptions are not desired).
Even if you could turn off the feature, I doubt you'd notice any
measurable difference in performance because the Python interpreter is
so much slower than C++. Any performance loss due to the try/catch
block at the boundary between the two languages will almost surely be
swamped by the cost of executing code in the Python interpreter.
> What I'd really like to do is be able to handle the exception
> classically, by giving it a function to call or the like. I've read
> through some of the documentation and haven't found anything like
> this. Any pointers would be welcome.
There's nothing of that kind. Boost.Python uses the C++ standard
library, and the C++ standard library throws exceptions, so trying to
avoid them would be fruitless.
> Also, I'm trying to use the language in kind of a weird way. It's
> probably a bad idea but I'm running with it anyway :)... I'm trying
> to embed python as a scripting language for my object system thing
> (game engine framework), and I'd like to be able to extend objects
> using python (extend embed at the same time! :P).
That's pretty typical, actually.
> Example of something like what I'm trying to do:
>
> //In pyobject file class BaseObject { void *data; //where the
> variables will all go //All it's stuff in here, some which requires
> manual construction and such
> };
>
> Pythonclass : BaseObject { //add stuff here
> }
>
> //in actual program class Py_wrapper : public BaseObject { PyObject
> *pyo; //gotten from embedded python
>
> //forward variable requests to python object etc....
> };
>
> // End example
That doesn't illustrate very much, but I don't know why anyone would
use PyObject* when they could use boost::python::object.
> Ok, now that you all know I'm crazy the reason why I want to do this
> is that the base object is designed to communicate a certain way with
> things it's attached to, which probably wouldn't cooperate with the
> way python works
Maybe you should find out for sure before deciding.
> , so I need to manually construct the base object (also not sure how
> to do this in boost python).
I've no clue what you're asking about, sorry.
> Basically what I'd like is to have python override things like a class
> normally would, and track it in my object system. I'm kind of
> doubting there's a way to do that, hence then extra layer of
> indirection py_wrapper (which should work).
http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html
http://www.boost.org/libs/python/doc/tutorial/doc/deriving_a_python_class.html
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list