[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/4] gui: Fix Glib-GObject-WARNING when closing the active da
From: |
Ben Pfaff |
Subject: |
Re: [PATCH 1/4] gui: Fix Glib-GObject-WARNING when closing the active dataset. |
Date: |
Sun, 08 Jul 2012 22:13:07 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
John Darrington <address@hidden> writes:
> On Sat, Jul 07, 2012 at 11:49:13PM -0700, Ben Pfaff wrote:
> The DATASET CLOSE command, when it act on the active dataset, just
> ^^^
> This verb is incorrectly conjugated.
>
> +/* Returns an identifier that is is not currently in use as a dataset
> name. */
> +char *
> +session_generate_dataset_name (struct session *s)
> +{
> + for (;;)
> + {
> + char *name = xasprintf ("DataSet%d", ++s->n_dataset_names);
> + if (!session_lookup_dataset (s, name))
> + return name;
> + free (name);
> + }
> +}
> I suppose it's unlikely, but this loop could become endless. Might it not be
> an
> idea to check that n_dataset_names is non-negative?
> Also, perhaps the comment should say that the caller should free the returned
> name.
Thanks for the comments.
I applied all of your suggestions and will soon push the
following:
--8<--------------------------cut here-------------------------->8--
From: Ben Pfaff <address@hidden>
Date: Sun, 8 Jul 2012 22:12:49 -0700
Subject: [PATCH] gui: Fix Glib-GObject-WARNING when closing the active dataset.
The DATASET CLOSE command, when it acts on the active dataset, just
removes the active dataset's name, changing it to the empty string.
(This is the documented behavior.) However, the GUI relies on
every dataset having a name, so this caused the following warning:
GLib-GObject-WARNING **: value """" of type `gchararray' is invalid
or out of range for property `id' of type `gchararray'
This commit fixes the problem by giving any unnamed dataset a name
after running syntax.
---
src/data/session.c | 23 ++++++++++++++++++++++-
src/data/session.h | 4 +++-
src/ui/gui/executor.c | 18 +++++++++++++++++-
src/ui/gui/psppire-data-window.c | 5 +----
4 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/src/data/session.c b/src/data/session.c
index 24c22b2..a308ec1 100644
--- a/src/data/session.c
+++ b/src/data/session.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,6 +35,7 @@ struct session
struct hmapx datasets;
struct dataset *active;
char *syntax_encoding; /* Default encoding for syntax files. */
+ unsigned int n_dataset_names; /* For session_generate_dataset_name(). */
};
static struct hmapx_node *session_lookup_dataset__ (const struct session *,
@@ -49,6 +50,7 @@ session_create (void)
hmapx_init (&s->datasets);
s->active = NULL;
s->syntax_encoding = xstrdup ("Auto");
+ s->n_dataset_names = 0;
return s;
}
@@ -164,6 +166,25 @@ session_get_dataset_by_seqno (const struct session *s,
unsigned int seqno)
return ds;
return NULL;
}
+
+/* Returns an identifier that is is not currently in use as a dataset name.
+ The caller must free the returned identifier, with free(). */
+char *
+session_generate_dataset_name (struct session *s)
+{
+ for (;;)
+ {
+ char *name;
+
+ s->n_dataset_names++;
+ assert(s->n_dataset_names != 0);
+
+ name = xasprintf ("DataSet%u", s->n_dataset_names);
+ if (!session_lookup_dataset (s, name))
+ return name;
+ free (name);
+ }
+}
static struct hmapx_node *
session_lookup_dataset__ (const struct session *s_, const char *name)
diff --git a/src/data/session.h b/src/data/session.h
index f45cceb..b61c394 100644
--- a/src/data/session.h
+++ b/src/data/session.h
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -44,4 +44,6 @@ void session_for_each_dataset (const struct session *,
struct dataset *session_get_dataset_by_seqno (const struct session *,
unsigned int seqno);
+char *session_generate_dataset_name (struct session *);
+
#endif /* session.h */
diff --git a/src/ui/gui/executor.c b/src/ui/gui/executor.c
index 8fb4c26..ee83c2c 100644
--- a/src/ui/gui/executor.c
+++ b/src/ui/gui/executor.c
@@ -1,5 +1,5 @@
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation
+ Copyright (C) 2007, 2009, 2010, 2011, 2012 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -36,6 +36,20 @@ create_casereader_from_data_store (void *data_store_)
return psppire_data_store_get_reader (data_store);
}
+/* Ensures that dataset DS has a name, because some parts of the GUI insist
+ upon this. */
+static void
+name_dataset_cb (struct dataset *ds, void *aux UNUSED)
+{
+ if (dataset_name (ds)[0] == '\0')
+ {
+ struct session *session = dataset_session (ds);
+ char *dataset_name = session_generate_dataset_name (session);
+ dataset_set_name (ds, dataset_name);
+ free (dataset_name);
+ }
+}
+
static void
new_pdw_cb (struct dataset *ds, void *aux UNUSED)
{
@@ -131,6 +145,8 @@ execute_syntax (PsppireDataWindow *window, struct
lex_reader *lex_reader)
break;
}
+ session_for_each_dataset (the_session, name_dataset_cb, NULL);
+
ll_for_each_safe (pdw, next_pdw, PsppireDataWindow, ll, &all_data_windows)
{
struct dataset *ds;
diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c
index 6dc422e..c22f7bb 100644
--- a/src/ui/gui/psppire-data-window.c
+++ b/src/ui/gui/psppire-data-window.c
@@ -1288,10 +1288,7 @@ psppire_data_window_new (struct dataset *ds)
if (ds == NULL)
{
- static int n_datasets;
- char *dataset_name;
-
- dataset_name = xasprintf ("DataSet%d", ++n_datasets);
+ char *dataset_name = session_generate_dataset_name (the_session);
ds = dataset_create (the_session, dataset_name);
free (dataset_name);
}
--
1.7.2.5
[PATCH 2/4] psppire-dict: Make PsppireDict not own its "struct dictionary"., Ben Pfaff, 2012/07/08
Re: [PATCH 0/4] bug fixes for master, Ben Pfaff, 2012/07/08