[Kde-bindings] Containers passed by reference

Richard Dale rdale at foton.es
Fri Dec 12 17:25:39 UTC 2008


On Friday 12 December 2008 16:54:27 David Palacio wrote:
> On Friday 12 December 2008 07:56:42 Richard Dale wrote:
> > On Friday 12 December 2008 12:23:12 David Palacio wrote:
> > > This is similar to the QImage::bits one. In the Okular bindings a
> > > QVector is marshalled to a Ruby array but the original QVector is never
> > > updated. This is not the expected behaviour by Okular.
> > >
> > > virtual bool   loadDocument (const QString &fileName, QVector< Page * >
> > > &pagesVector)=0
> > > is the c++ signature of a method that needs to be implemented in a
> > > generator. pagesVector is a QVector& that will be updated inside this
> > > method.
> > >
> > > I have confirmed, on the C++ side, that the pagesVector has zero size.
> > >
> > > This would need a special case: create a Ruby Array outside the method
> > > and pass it as an argument. When the method finishes, update the
> > > QVector.
> >
> > That should work. In okularhandlers.cpp the QList marshaller is defined
> > like this:
> >
> > DEF_LIST_MARSHALLER( OkularPageList, QVector<Okular::Page*>, Okular::Page
> > )
> >
> > The macro is defined in qtruby/src/marshall_macros.h, and on line 80
> > there is this code to copy the C++ version of the list to the Ruby one
> > after a method has been called:
> >
> > 			m->item().s_voidp = cpplist;
> > 			m->next();
> >
> > 			if (!m->type().isConst()) {
> > 				rb_ary_clear(list);
> >
> > 				for(int i = 0; i < cpplist->size(); ++i ) {
> > 					VALUE obj = getPointerObject( (void *) cpplist->at(i) );
> > 					rb_ary_push(list, obj);
> > 				}
> > 			}
> >
> > Not that the code after the 'm->next()' call is run after the C++ method
> > has has been called.
> >
> > So I'm not sure why it isn't working in your example.
>
> It seems it is not marshalling back to QVector:
> * I run the script and capture it in Gdb
> * Set a breakpoint at kdegraphics/okular/core/document.cpp:668
> * Set a breakpoint at kdebindings/ruby/qtruby/src/marshall_macros.h:77
> ( m->item().s_voidp = cpplist; )
>
> It never breaks at the marshall_ItemList method after loadDocument is
> executed. Even if it did marshall it, I am not sure if creating a new list
> is secure:
> ItemList *cpplist = new ItemList;
I'm not sure what you mean about this not being secure? Can you provide a 
short ruby test program that reproduces the problem, so that I can look into 
what is going on?

-- Richard



More information about the Kde-bindings mailing list