[Kde-bindings] Containers passed by reference

David Palacio dpalacio at uninorte.edu.co
Fri Dec 12 18:13:51 UTC 2008


On Friday 12 December 2008 12:25:39 Richard Dale wrote:
> 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
> _______________________________________________
> Kde-bindings mailing list
> Kde-bindings at kde.org
> https://mail.kde.org/mailman/listinfo/kde-bindings
Attached are the Okular plugin (based on the comicbook generator) and a test 
script. Run okularpart.rb and open a zip file with images.

As you can see from the program output, the plugin loads the zip file 
correctly. But, the last message:
PageView::notifyViewportChanged: viewport for page 0 has no matching item!
(from kdegraphics/okular/ui/pageview.cpp:897)
Indicates that the pagesVector was not updated since it was not a returned 
value from loadDocument (generator_comicbook.rb:22).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: okularpart.rb
Type: application/x-ruby
Size: 813 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20081212/0188bd7a/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: comicbookruby.tar.gz
Type: application/x-compressed-tar
Size: 4280 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20081212/0188bd7a/attachment.tar.gz>


More information about the Kde-bindings mailing list