Re: Glib option parser: Default arguments are overridden



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Murray Cumming wrote:
> On Wed, 2006-03-29 at 21:56 +0200, Armin Burgmeier wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hello list.
>>
>> When I tried to use the Glibmm wrapper for the glib option parser I
>> recognized that it seems to override default settings an argument was
>> assigned to before calling Glib::OptionContext::parse with zero.
> [snip]
> 
> This is very possible. The code is quite simple, so someone might be
> able to make a patch to stop that.
> 
I made a patch and attached the output of 'cvs diff optiongroup.ccg
optiongroup.hg' to this email. Hope it is somewhat useful since I do not
know too much about creating such patches/diffs.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEKw3whOtxKlDYm6cRAnDMAJ0RK3a7gQCYqvc5/+ArwDZ1/ymgVwCgoEd7
EkkNJXnoLJVnHkNcKnuhYeE=
=v+VD
-----END PGP SIGNATURE-----
Index: optiongroup.ccg
===================================================================
RCS file: /cvs/gnome/glibmm/glib/src/optiongroup.ccg,v
retrieving revision 1.17
diff -r1.17 optiongroup.ccg
24a25
> #include <glib/gmem.h> // g_malloc
163a165
>     cppEntry.default_c_arg(cpp_arg);
253a256,320
>       break;
>     }
>     default:
>     {
>       break;
>     }
>   }
> }
> 
> void OptionGroup::CppOptionEntry::default_c_arg(void* cpp_arg)
> {
>   switch(carg_type_)
>   {
>     case G_OPTION_ARG_INT:
>     {
>       *static_cast<int*>(carg_) = *static_cast<int*>(cpp_arg);
>       break;
>     }
>     case G_OPTION_ARG_NONE:
>     {
>       *static_cast<gboolean*>(carg_) = *static_cast<bool*>(cpp_arg);
>       break;
>     }
>     case G_OPTION_ARG_STRING:
>     {
>       *static_cast<const char**>(carg_) = g_strdup(
>         static_cast<std::string*>(cpp_arg)->c_str()
>       );
>       break;
>     }
>     case G_OPTION_ARG_FILENAME:
>     {
>       *static_cast<const char**>(carg_) = g_strdup(
>         static_cast<Glib::ustring*>(cpp_arg)->c_str()
>       );
>       break;
>     }
>     case G_OPTION_ARG_STRING_ARRAY:
>     {
>       std::vector<Glib::ustring>& vec =
>         *static_cast<std::vector<Glib::ustring>*>(cpp_arg);
> 
>       const char** array = static_cast<const char**>(
>         g_malloc(sizeof(char*) * (vec.size() + 1))
>       );
>       for(std::vector<Glib::ustring>::size_type i = 0; i < vec.size(); ++ i)
> 	array[i] = g_strdup(vec[i].c_str());
> 
>       array[vec.size()] = NULL;
>       *static_cast<const char***>(carg_) = array;
>       break;
>     }
>     case G_OPTION_ARG_FILENAME_ARRAY:
>     {
>       std::vector<std::string>& vec =
>         *static_cast<std::vector<std::string>*>(cpp_arg);
> 
>       const char** array = static_cast<const char**>(
>         g_malloc(sizeof(char*) * (vec.size() + 1))
>       );
>       for(std::vector<std::string>::size_type i = 0; i < vec.size(); ++ i)
> 	array[i] = g_strdup(vec[i].c_str());
> 
>       array[vec.size()] = NULL;
>       *static_cast<const char***>(carg_) = array;
Index: optiongroup.hg
===================================================================
RCS file: /cvs/gnome/glibmm/glib/src/optiongroup.hg,v
retrieving revision 1.10
diff -r1.10 optiongroup.hg
98a99
>     void default_c_arg(void* cpp_arg);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]