After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 577638 - G_OPTION_ARG_CALLBACK + G_OPTION_FLAG_OPTIONAL_ARG no parse "-"value
G_OPTION_ARG_CALLBACK + G_OPTION_FLAG_OPTIONAL_ARG no parse "-"value
Status: RESOLVED NOTABUG
Product: glib
Classification: Platform
Component: general
2.20.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2009-04-01 19:05 UTC by Viviani Demetrio
Modified: 2010-08-05 06:25 UTC
See Also:
GNOME target: ---
GNOME version: 2.21/2.22



Description Viviani Demetrio 2009-04-01 19:05:40 UTC
...sorry for my english...

{
  "option"
  ...
  G_OPTION_FLAG_OPTIONAL_ARG,
  G_OPTION_ARG_CALLBACK,
  callback_function,
  ...
}

g_print("value = %s"); in callback_function...

from cmdline

--option=-3 --- value = -3
--option -3 --- value = NULL  

is a bug or i'm very dork = bischero = fava?
Comment 1 Viviani Demetrio 2009-04-01 20:28:17 UTC
...sorry for my english...
 
{
  "option"
  ...
  G_OPTION_FLAG_OPTIONAL_ARG,
  G_OPTION_ARG_CALLBACK,
  callback_function,
  ...
}
 
g_print("value = %s",value); into the callback_function...
 
from cmdline
 
--option=-3 --- value = -3
--option -3 --- value = NULL  
 
is it a bug or am i a very dork = bischero = fava?
 

Comment 2 Christian Persch 2009-04-02 22:36:38 UTC
The code explicitly uses NULL in this case:

                  if (!OPTIONAL_ARG (&group->entries[j]))       
                    {    
                      value = (*argv)[idx + 1];
                      add_pending_null (context, &((*argv)[idx + 1]), NULL);
                      *new_idx = idx + 1;
                    }
                  else
                    {
                      if ((*argv)[idx + 1][0] == '-') 
=> here:                 value = NULL;
                      else
                        {
                          value = (*argv)[idx + 1];
                          add_pending_null (context, &((*argv)[idx + 1]), NULL);
                          *new_idx = idx + 1;
                        }
                    }

but whether that's a bug or a feature remains to be seen.
Comment 3 Viviani Demetrio 2009-04-03 17:24:41 UTC
...sorry for my english...

	
I'm not sure, I think the question is not in the function "parse_short_option" but in the function "parse_long_option" (goption.c)

...
else
  {
    if ((*argv)[*idx + 1][0] == '-') 
      {
        gboolean retval;
        retval = parse_arg (context, group, &group->entries[j],
=>					      NULL, option_name, error);
        *parsed = TRUE;
        g_free (option_name);
        return retval;
      }
...

"=> NULL" == "data = NULL into the "parse_arg" function" == "value = NULL into the callback_function"

I said pure bullshit?
Comment 4 Sven Herzberg 2009-10-22 07:31:05 UTC
I don't think that this is a bug. Otherwise we'd introduce obscurity.

Imagine you have "--option" just like you described above. And you have "--triple-foo"/"-3"; how should one interpret "app --option -3" is "-3" an argument to --option or do you want to do triple-foo but with a short command option?

IMHO this is not a bug.
Comment 5 Matthias Clasen 2010-08-05 06:25:47 UTC
I agree