Re: [C++-sig] Getting object for PyObject (reference counting)

2010-02-11 Thread Murray Cumming
On Fri, 2009-02-27 at 15:18 -0800, Alex Mohr wrote:
[snip]
>  If you have a PyObject *p and you want a bp::object, 
> construct it via:
> 
> object(handle<>(p))   // when p's a new reference

I find that I have to split the handle and object over two lines. If I
do this
  boost::python::object cppobject(boost::python::handle<>(cObject));
and then something like this:
  if(!cppobject.ptr())
doSomething()

then I get this weird compiler error on the if() line:

glom/python_embed/glom_python.cc:229: error: request for member ‘ptr’ in
‘cppobject’, which is of non-class type
‘boost::python::api::object(boost::python::handle<_object>)’

It's as if doing it on one line has changed the type. Maybe I've
discovered some weird bug with g++ 4.4

> object(handle<>(borrowed(p))) // when p's a borrowed reference

However, this works fine, when it's what I want.

-- 
[email protected]
www.murrayc.com
www.openismus.com

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Getting object for PyObject (reference counting)

2010-02-11 Thread Stefan Seefeld

On 02/11/2010 07:18 AM, Murray Cumming wrote:

On Fri, 2009-02-27 at 15:18 -0800, Alex Mohr wrote:
[snip]
   

  If you have a PyObject *p and you want a bp::object,
construct it via:

object(handle<>(p))   // when p's a new reference
 

I find that I have to split the handle and object over two lines. If I
do this
   boost::python::object cppobject(boost::python::handle<>(cObject));
and then something like this:
   if(!cppobject.ptr())
 doSomething()

then I get this weird compiler error on the if() line:

glom/python_embed/glom_python.cc:229: error: request for member ‘ptr’ in
‘cppobject’, which is of non-class type
‘boost::python::api::object(boost::python::handle<_object>)’

It's as if doing it on one line has changed the type.


It does !

In C++, if something may be interpreted as a declaration, it is a 
declaration.
And in the above case, the first line may be interpreted as a 
declaration of a function "cppobject" returning a bp::object, taking a 
handle<>.


If you split things into three statements, by first instantiating a 
(named) handle<>, then pass that to the cppobject constructor, the error 
will go away, since that line then is no longer ambiguous.


HTH,
Stefan


--

  ...ich hab' noch einen Koffer in Berlin...

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] boost::python and Date/Time values

2010-02-11 Thread Murray Cumming
On Sun, 2010-02-07 at 22:59 +0100, Murray Cumming wrote:
> Is there any easy way to get python Date, Time and DateTime values from
> boost::python::objects? In C, I'm using PyDateTime_GET_YEAR(),
> PyDateTime_GET_MONTH(), PyDateTime_GET_DAY(), etc, but it would be nice
> to use some C++ API for this.

Any ideas?


-- 
[email protected]
www.murrayc.com
www.openismus.com

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost::python and Date/Time values

2010-02-11 Thread troy d. straszheim

Murray Cumming wrote:

On Sun, 2010-02-07 at 22:59 +0100, Murray Cumming wrote:

Is there any easy way to get python Date, Time and DateTime values from
boost::python::objects? In C, I'm using PyDateTime_GET_YEAR(),
PyDateTime_GET_MONTH(), PyDateTime_GET_DAY(), etc, but it would be nice
to use some C++ API for this.


Any ideas?



Last time I had to do this it was for an app that had a custom date/time 
class on the c++ side, we rolled our own converters using the 
PyDateTime_*() methods.  Some standard converters for boost::date_time 
classes would be nice...


-t




___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] Exceptions with pybindgen and gccxmlparser

2010-02-11 Thread James Vogel
Hello --

Trying to use pybindgen.gccxmlparser, and running into an issue with exception 
handling.

I have a virtual class that declares
virtual int throw_error() throw (std::exception);
and a non-virtual class that extends the virtual class and overrides 
throw_an_error to throw an actual error. I run the module parser and generate 
foo.cpp. When I build foo.cpp, it has a build error:
"looser throw specifier for 'virtual int 
PyNon_virtual_class__PythonHelper::throw_error()' overriding 'virtual int 
non_virtual_class::throw_error() throw (std::exception)"

If I remove the function declaration from the virtual class (so that the 
implementation is not overriding an inherited method), it works correctly. 
Similarly, if I go into foo.cpp and manually add 'throw (std::exception)' to 
the relevant declarations, it works, so I suspect there's something afoot in 
the gccxml parsing that isn't picking up the throw clause in the virtual class; 
I'm just not sure if there's an annotation I might be missing, or some other 
issue.

Anyone seen this before?

James.
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Getting object for PyObject (reference counting)

2010-02-11 Thread Ralf W. Grosse-Kunstleve
>boost::python::object cppobject(boost::python::handle<>(cObject));


It should work like this:

boost::python::object cppobject((boost::python::handle<>(cObject)));

(Not that I ever understood exactly why... (or even wanted to understand))
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig