[geany/geany] f6e9ac: Remove use of some of our own deprecated Scintilla wrappers
Colomban Wendling
git-noreply at xxxxx
Wed May 22 02:22:53 UTC 2013
Branch: refs/heads/master
Author: Colomban Wendling <ban at herbesfolles.org>
Committer: Colomban Wendling <ban at herbesfolles.org>
Date: Wed, 22 May 2013 02:22:53 UTC
Commit: f6e9ac094a9e75ff3c2d30d8b60536f6b3e574ba
https://github.com/geany/geany/commit/f6e9ac094a9e75ff3c2d30d8b60536f6b3e574ba
Log Message:
-----------
Remove use of some of our own deprecated Scintilla wrappers
Remove most obvious calls to our very own deprecated Scintilla wrapper
functions sci_get_text(), sci_get_text_range() and
sci_get_selected_text().
Some calls are still left, but they either really benefit from these
functions or the fix would be more complex.
Modified Paths:
--------------
src/callbacks.c
src/document.c
src/symbols.c
src/tools.c
src/vte.c
Modified: src/callbacks.c
14 files changed, 4 insertions(+), 10 deletions(-)
===================================================================
@@ -738,11 +738,9 @@ G_MODULE_EXPORT void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer us
{
gchar *result = NULL;
gint cmd = SCI_LOWERCASE;
- gint text_len = sci_get_selected_text_length(sci);
gboolean rectsel = (gboolean) scintilla_send_message(sci, SCI_SELECTIONISRECTANGLE, 0, 0);
- text = g_malloc(text_len + 1);
- sci_get_selected_text(sci, text);
+ text = sci_get_selection_contents(sci);
if (utils_str_has_upper(text))
{
@@ -750,7 +748,6 @@ G_MODULE_EXPORT void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer us
cmd = SCI_LOWERCASE;
else
result = g_utf8_strdown(text, -1);
-
}
else
{
@@ -758,7 +755,6 @@ G_MODULE_EXPORT void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer us
cmd = SCI_UPPERCASE;
else
result = g_utf8_strup(text, -1);
-
}
if (result != NULL)
@@ -766,7 +762,7 @@ G_MODULE_EXPORT void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer us
sci_replace_sel(sci, result);
g_free(result);
if (keep_sel)
- sci_set_selection_start(sci, sci_get_current_position(sci) - text_len + 1);
+ sci_set_selection_start(sci, sci_get_current_position(sci) - strlen(text));
}
else
sci_send_command(sci, cmd);
@@ -911,8 +907,7 @@ static void find_usage(gboolean in_session)
if (sci_has_selection(doc->editor->sci))
{ /* take selected text if there is a selection */
- search_text = g_malloc(sci_get_selected_text_length(doc->editor->sci) + 1);
- sci_get_selected_text(doc->editor->sci, search_text);
+ search_text = sci_get_selection_contents(doc->editor->sci);
flags = SCFIND_MATCHCASE;
}
else
@@ -1710,8 +1705,7 @@ G_MODULE_EXPORT void on_context_action1_activate(GtkMenuItem *menuitem, gpointer
if (sci_has_selection(doc->editor->sci))
{ /* take selected text if there is a selection */
- word = g_malloc(sci_get_selected_text_length(doc->editor->sci) + 1);
- sci_get_selected_text(doc->editor->sci, word);
+ word = sci_get_selection_contents(doc->editor->sci);
}
else
{
Modified: src/document.c
4 files changed, 1 insertions(+), 3 deletions(-)
===================================================================
@@ -1507,13 +1507,12 @@ static gsize save_convert_to_encoding(GeanyDocument *doc, gchar **data, gsize *l
if (conv_error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
{
- gchar *context = NULL;
gint line, column;
gint context_len;
gunichar unic;
/* don't read over the doc length */
gint max_len = MIN((gint)bytes_read + 6, (gint)*len - 1);
- context = g_malloc(7); /* read 6 bytes from Sci + '\0' */
+ gchar context[7]; /* read 6 bytes from Sci + '\0' */
sci_get_text_range(doc->editor->sci, bytes_read, max_len, context);
/* take only one valid Unicode character from the context and discard the leftover */
@@ -1525,7 +1524,6 @@ static gsize save_convert_to_encoding(GeanyDocument *doc, gchar **data, gsize *l
error_text = g_strdup_printf(
_("Error message: %s\nThe error occurred at \"%s\" (line: %d, column: %d)."),
conv_error->message, context, line + 1, column);
- g_free(context);
}
else
error_text = g_strdup_printf(_("Error message: %s."), conv_error->message);
Modified: src/symbols.c
10 files changed, 2 insertions(+), 8 deletions(-)
===================================================================
@@ -2044,7 +2044,6 @@ static gboolean current_tag_changed(GeanyDocument *doc, gint cur_line, gint fold
static gchar *parse_function_at_line(ScintillaObject *sci, gint tag_line)
{
gint start, end, max_pos;
- gchar *cur_tag;
gint fn_style;
switch (sci_get_lexer(sci))
@@ -2064,9 +2063,7 @@ static gchar *parse_function_at_line(ScintillaObject *sci, gint tag_line)
if (start == end)
return NULL;
- cur_tag = g_malloc(end - start + 1);
- sci_get_text_range(sci, start, end, cur_tag);
- return cur_tag;
+ return sci_get_contents_range(sci, start, end);
}
@@ -2076,7 +2073,6 @@ static gchar *parse_cpp_function_at_line(ScintillaObject *sci, gint tag_line)
gint start, end, first_pos, max_pos;
gint tmp;
gchar c;
- gchar *cur_tag;
first_pos = end = sci_get_position_from_line(sci, tag_line);
max_pos = sci_get_position_from_line(sci, tag_line + 1);
@@ -2108,9 +2104,7 @@ static gchar *parse_cpp_function_at_line(ScintillaObject *sci, gint tag_line)
if (start != 0 && start < end) start++; /* correct for last non-matching char */
if (start == end) return NULL;
- cur_tag = g_malloc(end - start + 2);
- sci_get_text_range(sci, start, end + 1, cur_tag);
- return cur_tag;
+ return sci_get_contents_range(sci, start, end + 1);
}
Modified: src/tools.c
8 files changed, 3 insertions(+), 5 deletions(-)
===================================================================
@@ -373,7 +373,7 @@ void tools_execute_custom_command(GeanyDocument *doc, const gchar *command)
NULL, NULL, &pid, &stdin_fd, &stdout_fd, &stderr_fd, &error))
{
gchar *sel;
- gint len, remaining, wrote;
+ gint remaining, wrote;
struct cc_data *data = g_slice_alloc(sizeof *data);
data->error = FALSE;
@@ -392,12 +392,10 @@ void tools_execute_custom_command(GeanyDocument *doc, const gchar *command)
FALSE, cc_iofunc_err, data);
/* get selection */
- len = sci_get_selected_text_length(doc->editor->sci);
- sel = g_malloc0(len + 1);
- sci_get_selected_text(doc->editor->sci, sel);
+ sel = sci_get_selection_contents(doc->editor->sci);
/* write data to the command */
- remaining = len - 1;
+ remaining = strlen(sel);
do
{
wrote = write(stdin_fd, sel, remaining);
Modified: src/vte.c
3 files changed, 1 insertions(+), 2 deletions(-)
===================================================================
@@ -834,8 +834,7 @@ void vte_send_selection_to_vte(void)
if (sci_has_selection(doc->editor->sci))
{
- text = g_malloc0(sci_get_selected_text_length(doc->editor->sci) + 1);
- sci_get_selected_text(doc->editor->sci, text);
+ text = sci_get_selection_contents(doc->editor->sci);
}
else
{ /* Get the current line */
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list