>>> On quite the same topic, would a patch that fixes a lot of small
>>> problems like that in Geany's core be appreciated? It isn't hard to do
>>> but I think it would clean the code a bit.
>> Yes, but only if it's clear that const is really meant, not just to
>> silence compiler warnings.
> Of course. Casting away should only be done where the cast is completely
> wanted or at least carefully understood.
> I'll then do it unless somebody else go faster than me.
I've took a look and fixed some warnings around and other small stuff.
They are consts, a little uint vs. int when I'm sure it makes sense,
staticize a few local functions, and so on.

I've found 4 things that I haven't fixed/touched:
* build.c:174: This type of assignations aren't valid C90 (it's a C99
addition I think). Not sure it should be fixed or not since it gives a
little gain - being sure the affected element is the right one.
* document.c:473: The function document_stop_file_monitoring() has no
prototype and isn't static, but the name made me think it is perhaps
meant to be external for some reason and only misses its prototype?
* main.c:1212+: What's that malloc stuff for??? These functions aren't
even used...
* the stash_group_add_entry() and its widget_id. The thing is that when
it is a string it should be constant, but when it is a widget it
shouldn't be... perhaps it is fine as now.

There is 2 patches: one that modifies the Geany's core, and the other
that modifies that core plugins [1].

Regards,
Colomban

[1] there is a missing free() fix for the export plugin too.
Index: plugins/saveactions.c
===================================================================
--- plugins/saveactions.c	(révision 4852)
+++ plugins/saveactions.c	(copie de travail)
@@ -278,7 +278,7 @@
 };
 
 
-gboolean auto_save(gpointer data)
+static gboolean auto_save(gpointer data)
 {
 	GeanyDocument *doc;
 	GeanyDocument *cur_doc = document_get_current();
@@ -316,7 +316,7 @@
 }
 
 
-void autosave_set_timeout(void)
+static void autosave_set_timeout(void)
 {
 	if (! enable_autosave)
 		return;
Index: plugins/export.c
===================================================================
--- plugins/export.c	(révision 4852)
+++ plugins/export.c	(copie de travail)
@@ -207,7 +207,7 @@
 		gchar *file_name;
 		gchar *locale_filename;
 		gchar *locale_dirname;
-		gchar *suffix = "";
+		const gchar *suffix = "";
 
 		if (g_str_has_suffix(doc->file_name, extension))
 			suffix = "_export";
@@ -220,6 +220,7 @@
 		 * gtk_file_chooser_set_current_folder() additionally */
 		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_dirname);
 		gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), file_name);
+		g_free(locale_dirname);
 		g_free(locale_filename);
 		g_free(short_name);
 		g_free(file_name);
@@ -275,7 +276,7 @@
 
 static gchar *get_date(gint type)
 {
-	gchar *format;
+	const gchar *format;
 
 	if (type == DATE_TYPE_HTML)
 /* needs testing */
Index: plugins/filebrowser.c
===================================================================
--- plugins/filebrowser.c	(révision 4852)
+++ plugins/filebrowser.c	(copie de travail)
@@ -150,7 +150,8 @@
 static void add_item(const gchar *name)
 {
 	GtkTreeIter iter;
-	gchar *fname, *utf8_name, *utf8_fullname, *sep;
+	gchar *fname, *utf8_name, *utf8_fullname;
+	const gchar *sep;
 	gboolean dir;
 
 	if (! show_hidden_files && check_hidden(name))
Index: plugins/htmlchars.c
===================================================================
--- plugins/htmlchars.c	(révision 4852)
+++ plugins/htmlchars.c	(copie de travail)
@@ -345,7 +345,7 @@
 
 
 /* Functions to toggle the status of plugin */
-void set_status(gboolean new_status)
+static void set_status(gboolean new_status)
 {
 	if (plugin_active != new_status)
 	{
@@ -398,7 +398,7 @@
 
 /* Function takes over value of key which was pressed and returns
  * HTML/SGML entity if any */
-const gchar *get_entity(gchar *letter)
+static const gchar *get_entity(gchar *letter)
 {
 	guint i, len;
 
@@ -635,7 +635,7 @@
 }
 
 
-static void replace_special_character()
+static void replace_special_character(void)
 {
 	GeanyDocument *doc = NULL;
 	doc = document_get_current();
@@ -707,7 +707,7 @@
 }
 
 
-static void init_configuration()
+static void init_configuration(void)
 {
 	GKeyFile *config = g_key_file_new();
 
Index: src/templates.c
===================================================================
--- src/templates.c	(révision 4852)
+++ src/templates.c	(copie de travail)
@@ -495,9 +495,9 @@
 /* TODO make this function operating on a GString */
 static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, guint indent)
 {
-	gchar *frame_start;		/* to add before comment_text */
-	gchar *frame_end;		/* to add after comment_text */
-	gchar *line_prefix;		/* to add before every line in comment_text */
+	gchar *frame_start;			/* to add before comment_text */
+	gchar *frame_end;			/* to add after comment_text */
+	const gchar *line_prefix;	/* to add before every line in comment_text */
 	gchar *result;
 	gchar *tmp;
 	gchar *prefix;
@@ -666,7 +666,7 @@
 gchar *templates_get_template_changelog(GeanyDocument *doc)
 {
 	GString *result = g_string_new(templates[GEANY_TEMPLATE_CHANGELOG]);
-	gchar *file_type_name = (doc != NULL) ? doc->file_type->name : "";
+	const gchar *file_type_name = (doc != NULL) ? doc->file_type->name : "";
 
 	replace_static_values(result);
 	templates_replace_default_dates(result);
Index: src/build.c
===================================================================
--- src/build.c	(révision 4852)
+++ src/build.c	(copie de travail)
@@ -211,7 +211,7 @@
 
 
 /* for debug only, print the commands structures in priority order */
-static void printfcmds()
+static void printfcmds(void)
 {
 	GeanyFiletype	*ft = NULL;
 	GeanyDocument	*doc;
@@ -752,7 +752,8 @@
 	GeanyProject 		*project = app->project;
 	GeanyBuildCommand	*cmd = NULL;
 	gchar				*executable = NULL;
-	gchar				*working_dir = NULL, *cmd_working_dir;
+	gchar				*working_dir = NULL;
+	const gchar			*cmd_working_dir;
 	gboolean 			 autoclose = FALSE;
 	gboolean 			 result = FALSE;
 	gchar				*tmp;
@@ -1272,7 +1273,7 @@
 	}
 	else
 		build_command(doc, grp, cmd, NULL);
-};
+}
 
 
 /* group codes for menu items other than the known commands
@@ -1337,7 +1338,7 @@
 
 
 static void create_build_menu_item(GtkWidget *menu, GeanyKeyGroup *group, GtkAccelGroup *ag,
-							struct BuildMenuItemSpec *bs, gchar *lbl, gint grp, gint cmd)
+							struct BuildMenuItemSpec *bs, const gchar *lbl, gint grp, gint cmd)
 {
 	GtkWidget *item = gtk_image_menu_item_new_with_mnemonic(lbl);
 	if (bs->stock_id != NULL)
@@ -1392,14 +1393,14 @@
 			for (j = bs->build_cmd; j < build_groups_count[grp]; ++j)
 			{
 				GeanyBuildCommand *bc = get_build_cmd(NULL, grp, j, NULL);
-				gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc);
+				const gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc);
 				create_build_menu_item(menu, keygroup, accel_group, bs, lbl, grp, j);
 			}
 		}
 		else
 		{
 			GeanyBuildCommand *bc = get_build_cmd(NULL, bs->build_grp, bs->build_cmd, NULL);
-			gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc);
+			const gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc);
 			create_build_menu_item(menu, keygroup, accel_group, bs, lbl, bs->build_grp, bs->build_cmd);
 		}
 	}
@@ -1412,7 +1413,7 @@
 /* portability to various GTK versions needs checking
  * conforms to description of gtk_accel_label as child of menu item
  * NB 2.16 adds set_label but not yet set_label_mnemonic */
-static void geany_menu_item_set_label(GtkWidget *w, gchar *label)
+static void geany_menu_item_set_label(GtkWidget *w, const gchar *label)
 {
 	GtkWidget *c = gtk_bin_get_child(GTK_BIN(w));
 	gtk_label_set_text_with_mnemonic(GTK_LABEL(c), label);
@@ -1484,7 +1485,7 @@
 				for (cmd = bs->build_cmd; cmd < cmdcount; ++cmd)
 				{
 					GtkWidget *menu_item = menu_items.menu_item[grp][cmd];
-					gchar *label;
+					const gchar *label;
 					bc = get_build_cmd(doc, grp, cmd, NULL);
 					if (bc)
 						label = buildcmd_label(bc);
@@ -1771,7 +1772,7 @@
 
 
 /* Column headings, array NULL-terminated */
-static gchar *colheads[] =
+static const gchar *colheads[] =
 {
 	N_("Item"),
 	N_("Label"),
@@ -1785,11 +1786,11 @@
 #define DC_CLEAR 4
 #define DC_N_COL 5
 
-static const int entry_x_padding = 3;
-static const int entry_y_padding = 0;
+static const guint entry_x_padding = 3;
+static const guint entry_y_padding = 0;
 
 
-static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gint row,
+static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, guint row,
 				GeanyBuildSource dst, gint grp, gint cmd, gboolean dir)
 {
 	GtkWidget 	*label, *clear, *clearicon;
@@ -1797,7 +1798,7 @@
 	GeanyBuildCommand *bc;
 	gint src;
 	enum GeanyBuildCmdEntries i;
-	gint column = 0;
+	guint column = 0;
 
 	label = gtk_label_new(g_strdup_printf("%d:", cmd + 1));
 	gtk_table_attach(table, label, column, column + 1, row, row + 1, GTK_FILL,
@@ -1837,7 +1838,7 @@
 
 	for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++)
 	{
-		gchar *str = "";
+		const gchar *str = "";
 		if (bc != NULL && (str = bc->entries[i]) == NULL)
 			str = "";
 		set_build_command_entry_text(roww->entries[i], str);
@@ -1868,11 +1869,13 @@
 	GtkWidget		*label, *sep, *clearicon, *clear;
 	TableFields		*fields;
 	GtkTable		*table;
-	gchar			**ch, *txt;
-	gint			 col, row, cmdindex, cmd;
+	const gchar		**ch;
+	gchar			*txt;
+	guint			 col, row, cmdindex;
+	gint 			 cmd;
 	gint			 src;
 	gboolean		 sensitivity;
-	gint sep_padding = entry_y_padding + 3;
+	guint sep_padding = entry_y_padding + 3;
 
 	table = GTK_TABLE(gtk_table_new(build_items_count + 12, 5, FALSE));
 	fields = g_new0(TableFields, 1);
@@ -2580,7 +2583,7 @@
 
 static struct
 {
-	gchar *entries[GEANY_BC_CMDENTRIES_COUNT];
+	const gchar *entries[GEANY_BC_CMDENTRIES_COUNT];
 	GeanyBuildCommand **ptr;
 	gint index;
 } default_cmds[] = {
Index: src/build.h
===================================================================
--- src/build.h	(révision 4852)
+++ src/build.h	(copie de travail)
@@ -127,7 +127,7 @@
     GEANY_BC_LABEL,				/**< The menu item label, _ marks mnemonic */
     GEANY_BC_COMMAND,			/**< The command to run. */
     GEANY_BC_WORKING_DIR,		/**< The directory to run in */
-    GEANY_BC_CMDENTRIES_COUNT,	/**< Count of entries */
+    GEANY_BC_CMDENTRIES_COUNT	/**< Count of entries */
 } GeanyBuildCmdEntries;
 
 /** The command for a menu item. */
Index: src/sidebar.c
===================================================================
--- src/sidebar.c	(révision 4852)
+++ src/sidebar.c	(copie de travail)
@@ -184,7 +184,7 @@
 		gtk_scrolled_window_get_hadjustment(scrolled_window),
 		gtk_scrolled_window_get_vadjustment(scrolled_window));
 	label = gtk_label_new(_("No tags found"));
-	gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.01);
+	gtk_misc_set_alignment(GTK_MISC(label), 0.1f, 0.01f);
 	gtk_container_add(GTK_CONTAINER(tv.default_tag_tree), label);
 	gtk_widget_show_all(tv.default_tag_tree);
 	g_signal_connect(tv.default_tag_tree, "button-press-event",
Index: src/geanymenubuttonaction.c
===================================================================
--- src/geanymenubuttonaction.c	(révision 4852)
+++ src/geanymenubuttonaction.c	(copie de travail)
@@ -56,7 +56,7 @@
 static guint signals[LAST_SIGNAL];
 
 
-G_DEFINE_TYPE(GeanyMenubuttonAction, geany_menu_button_action, GTK_TYPE_ACTION);
+G_DEFINE_TYPE(GeanyMenubuttonAction, geany_menu_button_action, GTK_TYPE_ACTION)
 
 
 static void geany_menu_button_action_finalize(GObject *object)
Index: src/project.c
===================================================================
--- src/project.c	(révision 4852)
+++ src/project.c	(copie de travail)
@@ -89,7 +89,7 @@
 static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e);
 static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e);
 static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line);
-static void apply_editor_prefs();
+static void apply_editor_prefs(void);
 
 
 #define SHOW_ERR(args) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args)
@@ -1033,7 +1033,7 @@
 }
 
 
-static void apply_editor_prefs()
+static void apply_editor_prefs(void)
 {
 	guint i;
 
@@ -1135,7 +1135,7 @@
 
 	if (cl_options.load_session)
 	{
-		gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
+		const gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
 
 		g_key_file_set_string(config, "project", "session_file", utf8_filename);
 	}
Index: src/encodings.c
===================================================================
--- src/encodings.c	(révision 4852)
+++ src/encodings.c	(copie de travail)
@@ -523,7 +523,7 @@
 {
 	gchar *locale_charset = NULL;
 	gchar *regex_charset = NULL;
-	gchar *charset;
+	const gchar *charset;
 	gchar *utf8_content;
 	gboolean check_regex = FALSE;
 	gboolean check_locale = FALSE;
Index: src/encodings.h
===================================================================
--- src/encodings.h	(révision 4852)
+++ src/encodings.h	(copie de travail)
@@ -63,9 +63,9 @@
 	/** Internally used member for grouping */
 	GeanyEncodingGroup   group;
 	/** String representation of the encoding, e.g. "ISO-8859-3" */
-	gchar				*charset;
+	const gchar			*charset;
 	/** Translatable and descriptive name of the encoding, e.g. "South European" */
-	gchar				*name;
+	const gchar			*name;
 } GeanyEncoding;
 
 
Index: src/geanyentryaction.c
===================================================================
--- src/geanyentryaction.c	(révision 4852)
+++ src/geanyentryaction.c	(copie de travail)
@@ -52,7 +52,7 @@
 static guint signals[LAST_SIGNAL];
 
 
-G_DEFINE_TYPE(GeanyEntryAction, geany_entry_action, GTK_TYPE_ACTION);
+G_DEFINE_TYPE(GeanyEntryAction, geany_entry_action, GTK_TYPE_ACTION)
 
 
 static GtkWidget *geany_entry_action_create_tool_item(GtkAction *action)
Index: src/gb.c
===================================================================
--- src/gb.c	(révision 4852)
+++ src/gb.c	(copie de travail)
@@ -44,7 +44,7 @@
 gushort iconset;
 GtkWidget *image1, *image2, *image3, *image4, *label1, *label2, *label3, *okbutton1, *textview1;
 gchar info_texts[4][50];
-gchar *help_text;
+const gchar *help_text;
 gboolean is_running;
 static GdkPixbuf **icons;
 
Index: src/geanyobject.c
===================================================================
--- src/geanyobject.c	(révision 4852)
+++ src/geanyobject.c	(copie de travail)
@@ -53,7 +53,7 @@
 };
 
 
-G_DEFINE_TYPE(GeanyObject, geany_object, G_TYPE_OBJECT);
+G_DEFINE_TYPE(GeanyObject, geany_object, G_TYPE_OBJECT)
 
 
 
Index: src/callbacks.c
===================================================================
--- src/callbacks.c	(révision 4852)
+++ src/callbacks.c	(copie de travail)
@@ -1365,7 +1365,7 @@
 {
 	GeanyDocument *doc = document_get_current();
 	gchar *text;
-	gchar *fname;
+	const gchar *fname;
 	GeanyFiletype *ft;
 
 	g_return_if_fail(doc != NULL);
@@ -1385,7 +1385,7 @@
                                         gpointer         user_data)
 {
 	GeanyDocument *doc = document_get_current();
-	gchar *format = NULL;
+	const gchar *format = NULL;
 	gchar *time_str;
 
 	g_return_if_fail(doc != NULL);
Index: src/keyfile.c
===================================================================
--- src/keyfile.c	(révision 4852)
+++ src/keyfile.c	(copie de travail)
@@ -738,7 +738,7 @@
 	if (vte_info.load_vte)
 	{
 		struct passwd *pw = getpwuid(getuid());
-		gchar *shell = (pw != NULL) ? pw->pw_shell : "/bin/sh";
+		const gchar *shell = (pw != NULL) ? pw->pw_shell : "/bin/sh";
 
 		vc = g_new0(VteConfig, 1);
 		vte_info.dir = utils_get_setting_string(config, "VTE", "last_dir", NULL);
Index: src/editor.c
===================================================================
--- src/editor.c	(révision 4852)
+++ src/editor.c	(copie de travail)
@@ -99,7 +99,7 @@
 	AUTOC_CANCELLED,
 	AUTOC_SCOPE,
 	AUTOC_TAGS,
-	AUTOC_DOC_WORDS,
+	AUTOC_DOC_WORDS
 } autocompletion_mode = AUTOC_CANCELLED;
 
 static gchar indent[100];
@@ -1946,7 +1946,7 @@
 	gchar *linebuf, *root;
 	ScintillaObject *sci;
 	gboolean ret = FALSE;
-	gchar *wordchars;
+	const gchar *wordchars;
 	GeanyFiletype *ft;
 
 	if (! editor_prefs.auto_complete_symbols && ! force)
Index: src/symbols.c
===================================================================
--- src/symbols.c	(révision 4852)
+++ src/symbols.c	(copie de travail)
@@ -128,7 +128,7 @@
 }
 
 
-static gsize get_tag_count()
+static gsize get_tag_count(void)
 {
 	GPtrArray *tags = tm_get_workspace()->global_tags;
 	gsize count = tags ? tags->len : 0;
@@ -975,7 +975,7 @@
 
 
 /* find the last word in "foo::bar::blah", e.g. "blah" */
-const gchar *get_parent_name(const TMTag *tag, filetype_id ft_id)
+static const gchar *get_parent_name(const TMTag *tag, filetype_id ft_id)
 {
 	const gchar *scope = tag->atts.entry.scope;
 	const gchar *separator = symbols_get_context_separator(ft_id);
Index: src/socket.c
===================================================================
--- src/socket.c	(révision 4852)
+++ src/socket.c	(copie de travail)
@@ -122,7 +122,7 @@
 
 
 
-void send_open_command(gint sock, gint argc, gchar **argv)
+static void send_open_command(gint sock, gint argc, gchar **argv)
 {
 	gint i;
 	gchar *filename;
Index: src/ui_utils.c
===================================================================
--- src/ui_utils.c	(révision 4852)
+++ src/ui_utils.c	(copie de travail)
@@ -768,7 +768,7 @@
 
 void ui_document_show_hide(GeanyDocument *doc)
 {
-	gchar *widget_name;
+	const gchar *widget_name;
 	GtkWidget *item;
 	const GeanyIndentPrefs *iprefs;
 
Index: src/geanywraplabel.c
===================================================================
--- src/geanywraplabel.c	(révision 4852)
+++ src/geanywraplabel.c	(copie de travail)
@@ -57,7 +57,7 @@
 static void geany_wrap_label_size_allocate	(GtkWidget *widget, GtkAllocation *alloc);
 static void geany_wrap_label_set_wrap_width	(GtkWidget *widget, gsize width);
 
-G_DEFINE_TYPE(GeanyWrapLabel, geany_wrap_label, GTK_TYPE_LABEL);
+G_DEFINE_TYPE(GeanyWrapLabel, geany_wrap_label, GTK_TYPE_LABEL)
 
 
 static void geany_wrap_label_class_init(GeanyWrapLabelClass *klass)
_______________________________________________
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to