Hello,
I believe this is the offending code at the top of function
'option_parsing_results_init':
<code>
static OptionParsingResults *
option_parsing_results_init (OptionParsingResults *results, int *argc,
char **argv)
{
int i;
results = g_new0 (OptionParsingResults, 1);
results->screen_number = -1;
results->default_working_dir = NULL;
results->zoom = "1.0";
</code>
You're allocating a new 'OptionParsingResults' and storing the new
pointer in 'results' which basically overwrites the pointer that was
passed to the function.
Thus, in main:
<code>
results = &parsing_results;
g_assert (initialization_complete);
results = option_parsing_results_init (results, &argc, argv);
</code>
After the call to 'option_parsing_results_init' your pointer 'results'
points to a different place.
Regards,
Jose
Christian Kirbach wrote:
> Hi,
>
> I am hacking on gnome-terminal to switch from popt to GOption command line
> option parsing. I have a problem adressing a struct by means of a pointer
> to that struct. Consider
>
> =============================================
> typedef struct
> {
> gboolean option_fullscreen;
> /* stuff */
> }
> OptionParsingResults;
>
> OptionParsingResults parsing_results;
>
> int main (int argc, char **argv)
> {
>
> OptionParsingResults *results = &parsing_results;
> printf("%o %o\n", *results, parsing_results);
> }
> =============================================
>
> In the main function I create a pointer to the struct in the main scope.
> The printf shows that both dereference the same memory spot (equal
> numbers).
> At some point in main() the option parsing takes places. The
> parser writes its results directly into the 'struct parsing_results' like
>
> &parsing_results.option_fullscreen = foo
>
> However when trying to access the results via the pointer 'results'
> I read different values in contrast to reading the outcome using
> parsing_results,
> i.e.
>
> parsing_results.option_fullscreen != results->option_fullscreen
>
> I have no explanation for this. Can someone shed some light on this,
> please?
>
> I've attached the current state of my patch for gnome-terminal. You can
> try this patch and run e.g.
> gnome-terminal --zoom=5
>
> I've added some printf to show the difference.
>
>
> Regards
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> gnome-love mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/gnome-love
_______________________________________________
gnome-love mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnome-love