[C++-sig] Can boost.python and PyQt be used together?

David Abrahams dave at boost-consulting.com
Mon Dec 9 00:04:37 CET 2002


"Paul F. Kunz" <Paul_Kunz at SLAC.Stanford.EDU> writes:

>>>>>> On Sun, 08 Dec 2002 16:37:14 -0500, David Abrahams <dave at boost-consulting.com> said:
>
>    i've moved somethings around, and now can make it fail...
>
> [pfkeb at Kunz-pbdsl1 python]$ python
> Python 2.2.2 (#1, Oct 15 2002, 07:42:56) 
> [GCC 2.95.3 20010315 (release)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from hippo import *
>>>> wc = WCFactory()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> IndexError: tuple index out of range
>>>> 
>
>    This looks like the same error that didn't get a chance to printout
> when run with PyQt.
>
> Relavent code is...
>
> WindowController * WCFactory ()
> {
>   WindowController * controller = WindowController::instance ();
>   return controller;
> }
>
>   def ( "WCFactory", WCFactory, return_internal_reference<> () );

Err, Paul: when I suggested that you use return_internal_reference<>
for your newCanvas call, I didn't mean that you should blindly
substitute it for reference_existing_object everywhere!

You probably shouldn't be using call policies until you understand
what these things do. What is unclear when you RTFM? I mean, in
particular, the 3 sections starting here:
http://www.boost.org/libs/python/doc/v2/reference.html#models_of_call_policies

It's not surprising that you're getting an exception in this case,
since the zeroth element of the argument tuple (which is going to be
the ward object in the relationship established by
return_internal_reference<>) doesn't exist.

I suppose I should add some compile-time checks to prevent users from
using return_internal_reference<> with a custodian object index that
is greater than the wrapped function's arity... though I'm not sure
that's possible without changing the CallPolicies interface.

> WindowController is a singleton, so the first call to instance() will
> create one via the default constructor, or return an existing one.
>
> WindowController::WindowController ( )
>   : m_active_window ( 0 ),
>     m_inspector ( 0 )
> {
>   s_instance = this;
> }
> WindowController * WindowController::instance ()
> {
>   if ( s_instance == 0 ) {
>     s_instance = new WindowController ();
>   }
>
>   return s_instance;
> }
>
>    Are we getting close to understanding it?

No, this pretty much has nothing to do with whatever crash you were
seeing before.

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list