GNOME Bugzilla – Bug 371487
Gnome::Vfs::DirectoryHandle::list_load has wrong signature
Last modified: 2011-01-16 23:36:18 UTC
Hello The following static member-function of Gnome::Vfs::DirectoryHandle: <directory-handle.h> static void list_load(const Glib::ListHandle<Glib::ustring>& list, const Glib::ustring& text_uri, FileInfoOptions info_options) throw(exception); </directory-handle.h> seems to be useless. See this little example program: <code> #include <libgnomevfsmm.h> #include <iostream> #include <list> int main(int argc, char** argv) { Gnome::Vfs::init(); std::list<Glib::ustring> list; Glib::ListHandle<Glib::ustring> listHandle(list); Gnome::Vfs::DirectoryHandle::list_load( listHandle, "ftp://ftp.gnome.org", Gnome::Vfs::FILE_INFO_DEFAULT ); std::cout << list.size() << std::endl; // ------------------------------ GList* glist; gnome_vfs_directory_list_load( &glist, "ftp://ftp.gnome.org", static_cast<GnomeVFSFileInfoOptions>(Gnome::Vfs::FILE_INFO_DEFAULT) ); std::cout << g_list_length(glist) << std::endl; // prints: 17 GnomeVFSFileInfo* info = static_cast<GnomeVFSFileInfo*>(g_list_nth_data(glist,5)); std::cout << info->name << std::endl; return 0; } </code> <output> 0 17 conspiracy </output> The GList holds pointers GnomeVFSFileInfo structures, so Glib::ustring being ListHandle-type makes no sense. Maik Beckmann <doc-links> - Glib::ListHandle http://gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1ListHandle.html - Gnome::Vfs::DirectoryHandle http://www.gtkmm.org/gnomemm2/reference/html/classGnome_1_1Vfs_1_1DirectoryHandle.html - gnome_vfs_directory_list_load http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/gnome-vfs-20-gnome-vfs-directory-list-ops.html#gnome-vfs-directory-list-load <doc-links>
Hello Again I worked on this issue, but didn't solve it yet. I want to comment to points 1. The interface 2. Implementation 3. Is a ListHandle object mutable? ############################ ### 1. The interface Since Gnome::Vfs::FileInfo is a reference counted type <doc-link> http://www.gtkmm.org/gnomemm2/reference/html/classGnome_1_1Vfs_1_1FileInfo.html </doc-link> the Interface should IMHO look like this: <directory-handle.h> // We are inside namespace Gnome::Vfs and class-definition DirectoryHandle static void list_load( Glib::ListHandle<Glib::RefPtr<FileInfo> >& list, const Glib::ustring& text_uri, FileInfoOptions info_options ) throw(exception); </directory-handle.h> Note: The ListHandle isn't const anymore, since we want to alter the GList it wraps. (Why isn't FileInfoOptions const?) ### 2. Implementation If we alter the interface only, it would look like this <directory-handle.cc> static void DirectoryHandle::list_load( Glib::ListHandle<Glib::RefPtr<FileInfo> >& list, const Glib::ustring& text_uri, FileInfoOptions info_options ) throw(exception); { GList* temp_list = list.data(); GnomeVFSResult result = gnome_vfs_directory_list_load( &temp_list, text_uri.c_str(), static_cast<GnomeVFSFileInfoOptions>(info_options) ); handle_result(result); } </directory-handle.cc> but didn't work though. The line <code> GList* temp_list = list.data(); </code> itents to use temp_list for altering the the GList ListHandle holds. But the following line <code> gnome_vfs_directory_list_load( &temp_list, // temp_list itself will be altered text_uri.c_str(), static_cast<GnomeVFSFileInfoOptions>(info_options) ); </code> alters the variable temp_list, not the object it points to. (I notized this by using ddd for debugging) ### 3. Is a ListHandle object mutable? If you look at the ListHandle documentation <doc-link> http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1ListHandle.html </doc-link> you'll see that all member functions are const. This brings up the question: - Is a ListHandle object mutable? If not the interface has to look like this <code> static Glib::ListHandle<Glib::RefPtr<FileInfo> > list_load( const Glib::ustring& text_uri, /* const? */FileInfoOptions info_options ) throw(exception) ; </code> Regards, Maik
I'm thinking about something like this: <code> #include <libgnomevfsmm.h> #include <iostream> #include <list> Glib::ListHandle<Glib::RefPtr<Gnome::Vfs::FileInfo> > list_load( const Glib::ustring& text_uri, const Gnome::Vfs::FileInfoOptions info_options) // throw(exception) { typedef Glib::ListHandle<Glib::RefPtr<Gnome::Vfs::FileInfo> > ret_t; GList* temp_list; GnomeVFSResult result = gnome_vfs_directory_list_load( &temp_list, text_uri.c_str(), static_cast<GnomeVFSFileInfoOptions>(info_options) ); //handle_result(result); return ret_t(temp_list, Glib::OWNERSHIP_SHALLOW); // ... // ...I'm not sure about the right ownership!! } int main(int argc, char** argv) { Gnome::Vfs::init(); typedef Glib::ListHandle<Glib::RefPtr<Gnome::Vfs::FileInfo> > list_t ; list_t listHandle = list_load( "ftp://ftp.gnome.org/", Gnome::Vfs::FILE_INFO_DEFAULT ); listHandle.begin(); for (list_t::const_iterator it=listHandle.begin(); it!= listHandle.end(); ++it) { std::cout << (*it)->get_name() << std::endl; } return 0; } </code> please spend your 2 cents Maik
> Glib::ListHandle<Glib::RefPtr<Gnome::Vfs::FileInfo> > > list_load( const Glib::ustring& text_uri, const Gnome::Vfs::FileInfoOptions info_options) // throw(exception) This looks fine, though the const for info_options is meaningless (the parameter is passed by value) and should be removed. Could you submit a patch, please, now that you seem to have figured out how this should work. That's easier for me to review and test. Many thanks.
Ok! I would like to add some test cases and run them before sending a patch, so please be patient until the weekend. Maik PS: const-correcting a value arg is indeed... ;o) Thanks for the hint Murray.
Created attachment 76285 [details] [review] patch which fixes this bug I changed the function for --disable-api-exceptions too, but didn't test if it compiles, since my glibmm version uses exceptions. Since there is no testing framework at all, I omitted the test cases. Doxygen docs has been added to the both function decleations, with and without exceptions. Note: Doxygen always generates for the "--disable-api-exceptions" case for all. So work has to be done to change this. Regards, Maik
Will the patch be applied? Maik
Sorry for the delay. I will probably deprecate the existing method and add your new method, because we can't just change an existing method without breaking ABI. Or maybe there can not possibly be anybody using this method because it is useless/broken as is, so maybe it's OK to just change it. But I will do at least something with this soon. Many thanks for taking care of this.
I'm thinking of just ignoring this because giomm replaces gnome-vfsmm. Would that make life difficult for you?
Yeah, moving to giomm is the best solution, and it's not that difficult.