[C++-sig] Re: Re: Re: Boost.Python v2: object facilities updated
Dave Hawkes
daveh at cadlink.com
Thu Jun 20 05:55:40 CEST 2002
"David Abrahams" <david.abrahams at rcn.com> wrote in message
news:0cc701c21804$c6d7c340$6601a8c0 at boostconsulting.com...
>
> From: "Dave Hawkes" <daveh at cadlink.com>
>
> > > In theory it's not, but I could really use some help with that stuff.
> Do
> > > you think you might take on the job of fleshing out the missing
pieces?
> > > It's fairly mechanical, mostly, but requires some attention. My idea
> was
> > to
> > > follow the Python/C API documentation and make files like
> > > object_protocol.hpp which mirror pages like
> > > http://www.python.org/dev/doc/devel/api/object.html. Of course, many
> > > functions are covered by the operators already defined, so we don't
> need
> > > separate functions for those. The idea is just to cover the built-in
> > > functions
(http://www.python.org/dev/doc/devel/lib/built-in-funcs.html)
> > and
> > > any 'C' API functions which aren't otherwise handled.
> > >
> >
> > I have a number of ideas for an aproach to this,
>
> Not to thwart creativity, but I hope you're not thinking of anything too
> fancy. It does seem like a fairly mechanical job to me...
>
No, nothing very elaborate, more ideas for consistancy, especially as I
don't have access to a large number of platforms.
> > but I want to try a couple
> > of things before I post here. Once I'm clear what's involved I can let
> you
> > know if I can do this, plus some timescales.
>
> Thanks, I really appreciate your contributions.
>
> > An issue I keep having with 'object' is the lack of a default
> constructor. I
> > think this may have been discussed before, but I can't remember the
> outcome.
>
> You can always search
> http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/c++-sig...
>
> > What is the reason for not creating a Py_None object with the default
> > constructor?
>
> No direct analogue in Python. But that's not neccessarily a good reason.
> Wouldn't it be better to have a None object, though?
>
> object x = None;
>
> > With all its extra functionality now it can be used for much
> > more than just capturing return values. It is occasionally useful to
> declare
> > an object and defer its actual assignment.
>
> Sure. I'll add the default constructor if there's a good reason to, but I
> don't see one yet.
There's no direct analogue in Python because there's no variable
declarations. I was just thinking that a C++ variable declaration:
object x;
is equivalent to Python
x = None
A bit of a stretch I know, but there has to be some accomadation for the
fundamental language differences.
My reasononing for requiring the default constructor is that should a user
have a number of object classes as member variables of another class, then
these must all be initialised in the constructor initialiser list which is a
little tedious. It could be that the user cannot fully assign relavent
values until later or that their compiler does not support catching
exceptions in the initialiser list.
ie we have to do:
class MyClass {
MyClass() : x1(handle<>(borrowed(Py_none))),
x2(handle<>(borrowed(Py_none))), x3(handle<>(borrowed(Py_none)))
{
try {
x1 = 4;
x2 = get_some_value();
x3 = x1 + x2;
} catch(...) {
...
}
}
object x1, x2, x3;
};
Dave Hawkes
More information about the Cplusplus-sig
mailing list