[dasher: 105/217] Minor cleanup, fix a few string related memory leaks and delete a few unusued function declarations.



commit a271b6753a9ab154d68ce96f1a16dd932bfd2a22
Author: lbaudoin <lbaudoin google com>
Date:   Tue Nov 3 21:21:19 2015 -0800

    Minor cleanup, fix a few string related memory leaks and delete a few unusued function declarations.

 Src/Gtk2/DasherAppSettings.cpp            |    2 +-
 Src/Gtk2/DasherControl.cpp                |   10 ++++------
 Src/Gtk2/GtkDasherControl.cpp             |    4 ++--
 Src/Gtk2/GtkDasherControl.h               |    4 ++--
 Src/Gtk2/dasher_editor.cpp                |   23 ++++++++++++++++-------
 Src/Gtk2/dasher_editor.h                  |   12 ++----------
 Src/Gtk2/dasher_editor_external.h         |    2 +-
 Src/Gtk2/dasher_editor_external_atspi.cpp |   16 ++++++++++------
 Src/Gtk2/dasher_editor_external_cspi.cpp  |    9 +++++++--
 Src/Gtk2/dasher_editor_external_xtest.cpp |    3 +--
 10 files changed, 46 insertions(+), 39 deletions(-)
---
diff --git a/Src/Gtk2/DasherAppSettings.cpp b/Src/Gtk2/DasherAppSettings.cpp
index 7cbda1d..0f34de9 100644
--- a/Src/Gtk2/DasherAppSettings.cpp
+++ b/Src/Gtk2/DasherAppSettings.cpp
@@ -393,7 +393,7 @@ const gchar *dasher_app_settings_get_string(DasherAppSettings *pSelf, int iParam
     if(pPrivate->pDasherWidget)
       return gtk_dasher_control_get_parameter_string(pPrivate->pDasherWidget, iParameter);
     else
-      return false;
+      return nullptr;
   }
   else
     return app_stringparamtable[ iParameter - FIRST_APP_SP ].value;
diff --git a/Src/Gtk2/DasherControl.cpp b/Src/Gtk2/DasherControl.cpp
index e806199..4d68013 100644
--- a/Src/Gtk2/DasherControl.cpp
+++ b/Src/Gtk2/DasherControl.cpp
@@ -148,14 +148,13 @@ void CDasherControl::ClearAllContext() {
 }
 
 std::string CDasherControl::GetAllContext() {
-  const gchar *text = gtk_dasher_control_get_all_text(m_pDasherControl);
-  return text;
+  return gtk_dasher_control_get_all_text(m_pDasherControl);
 }
 
 int CDasherControl::GetAllContextLenght()
 {
-  const gchar *text = gtk_dasher_control_get_all_text(m_pDasherControl);
-  return g_utf8_strlen(text,-1);
+  auto text = gtk_dasher_control_get_all_text(m_pDasherControl);
+  return g_utf8_strlen(text.c_str(),-1);
 }
 
 std::string CDasherControl::GetTextAroundCursor(CControlManager::EditDistance dist) {
@@ -163,8 +162,7 @@ std::string CDasherControl::GetTextAroundCursor(CControlManager::EditDistance di
 }
 
 std::string CDasherControl::GetContext(unsigned int iStart, unsigned int iLength) {
-  const gchar *text = gtk_dasher_control_get_context(m_pDasherControl, iStart, iLength);
-  return text;
+  return gtk_dasher_control_get_context(m_pDasherControl, iStart, iLength);
 }
 
 bool CDasherControl::SupportsClipboard() {
diff --git a/Src/Gtk2/GtkDasherControl.cpp b/Src/Gtk2/GtkDasherControl.cpp
index 1740736..6e1aea1 100644
--- a/Src/Gtk2/GtkDasherControl.cpp
+++ b/Src/Gtk2/GtkDasherControl.cpp
@@ -219,13 +219,13 @@ gtk_dasher_control_train(GtkDasherControl *pControl, const gchar *szFilename) {
   pPrivate->pControl->ImportTrainingText(szFilename);
 };
 
-const gchar *
+std::string
 gtk_dasher_control_get_context(GtkDasherControl *pControl, unsigned int iStart, unsigned int iLength) {
   GtkDasherControlPrivate *pPrivate = GTK_DASHER_CONTROL_GET_PRIVATE(pControl);
   return dasher_editor_get_context(pPrivate->pEditor, iStart, iLength);
 }
 
-const gchar *
+std::string
 gtk_dasher_control_get_all_text(GtkDasherControl *pControl) {
   GtkDasherControlPrivate *pPrivate = GTK_DASHER_CONTROL_GET_PRIVATE(pControl);
   return dasher_editor_get_all_text(pPrivate->pEditor);
diff --git a/Src/Gtk2/GtkDasherControl.h b/Src/Gtk2/GtkDasherControl.h
index 4b71bb3..0c7fdf5 100644
--- a/Src/Gtk2/GtkDasherControl.h
+++ b/Src/Gtk2/GtkDasherControl.h
@@ -71,8 +71,8 @@ GArray *gtk_dasher_control_get_allowed_values(GtkDasherControl * pControl, int i
 void gtk_dasher_control_train(GtkDasherControl * pControl, const gchar * szFilename);
 void gtk_dasher_control_set_editor(GtkDasherControl *pControl, DasherEditor *pEditor);
 void gtk_dasher_control_clear_all_context(GtkDasherControl *pControl);
-const gchar* gtk_dasher_control_get_all_text(GtkDasherControl *pControl);
-const gchar* gtk_dasher_control_get_context(GtkDasherControl *pControl, unsigned int iOffset, unsigned int 
iLength);
+std::string gtk_dasher_control_get_all_text(GtkDasherControl *pControl);
+std::string gtk_dasher_control_get_context(GtkDasherControl *pControl, unsigned int iOffset, unsigned int 
iLength);
 std::string gtk_dasher_control_get_text_around_cursor(GtkDasherControl *pControl, 
Dasher::CControlManager::EditDistance dist);
 //void gtk_dasher_control_invalidate_context(GtkDasherControl *pControl, bool bForceStart);
 void gtk_dasher_control_set_buffer(GtkDasherControl *pControl, int iOffset);
diff --git a/Src/Gtk2/dasher_editor.cpp b/Src/Gtk2/dasher_editor.cpp
index 1382a19..f4a3361 100644
--- a/Src/Gtk2/dasher_editor.cpp
+++ b/Src/Gtk2/dasher_editor.cpp
@@ -420,22 +420,25 @@ dasher_editor_delete(DasherEditor *pSelf, int iLength, int iOffset) {
 //   else
 //     return NULL;
 // }   
-const gchar *
-dasher_editor_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
+std::string dasher_editor_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
   DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
 
   if (isdirect(pPrivate->pAppSettings))
     return dasher_editor_external_get_context(pSelf, iOffset, iLength);
 
-  //  g_message("Buffer lenght: %d", gtk_text_buffer_get_char_count(pPrivate->pBuffer));
-
   GtkTextIter start;
   GtkTextIter end; // Refers to end of context, which is start of selection!
 
   gtk_text_buffer_get_iter_at_offset(pPrivate->pBuffer, &start, iOffset);
   gtk_text_buffer_get_iter_at_offset(pPrivate->pBuffer, &end, iOffset + iLength);
 
-  return gtk_text_buffer_get_text( pPrivate->pBuffer, &start, &end, false );
+  auto text = gtk_text_buffer_get_text( pPrivate->pBuffer, &start, &end, false );
+  if (text != nullptr) {
+    std::string context = text;
+    g_free(text);
+    return context;
+  }
+  return "";
 }
 
 std::string dasher_editor_get_text_around_cursor(DasherEditor *pSelf, Dasher::CControlManager::EditDistance 
distance) {
@@ -725,7 +728,7 @@ dasher_editor_get_filename(DasherEditor *pSelf) {
 }
 
 // TODO: We shouldn't need to know about the buffer here - make this a method of the buffer set
-const gchar *
+std::string
 dasher_editor_get_all_text(DasherEditor *pSelf) {
   DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
   if (pPrivate == NULL) {
@@ -740,7 +743,13 @@ dasher_editor_get_all_text(DasherEditor *pSelf) {
 
   pPrivate->pNewMark = gtk_text_buffer_create_mark(pPrivate->pBuffer, NULL, &oEnd, TRUE);
 
-  return gtk_text_buffer_get_text(pPrivate->pBuffer, &oStart, &oEnd, false );
+  std::string all_text;
+  auto text = gtk_text_buffer_get_text(pPrivate->pBuffer, &oStart, &oEnd, false );
+  if (text != nullptr) {
+    all_text = text;
+    g_free(text);
+  }
+  return all_text;
 }
 
 const gchar *
diff --git a/Src/Gtk2/dasher_editor.h b/Src/Gtk2/dasher_editor.h
index c63f288..444493d 100644
--- a/Src/Gtk2/dasher_editor.h
+++ b/Src/Gtk2/dasher_editor.h
@@ -40,11 +40,6 @@ struct _DasherEditor {
 struct _DasherEditorClass {
   GtkVBoxClass parent_class;
 
-  void (*output)(DasherEditor *, const gchar *, int);
-  void (*delete_text)(DasherEditor *, int, int);
-  const gchar *(*get_context)(DasherEditor *, int, int);
-  gint (*get_offset)(DasherEditor *);
-
   void (*filename_changed)(DasherEditor *pDasherEditor);
   void (*buffer_changed)(DasherEditor *pDasherEditor);
   void (*context_changed)(DasherEditor *pDasherEditor);
@@ -66,17 +61,14 @@ gboolean dasher_editor_command(DasherEditor *pSelf, const gchar *szCommand);
 GtkTextBuffer *dasher_editor_game_text_buffer(DasherEditor *);
 
 void dasher_editor_clear(DasherEditor *pSelf);
-const gchar *dasher_editor_get_all_text(DasherEditor *pSelf);
-const gchar *dasher_editor_get_new_text(DasherEditor *pSelf);
+std::string dasher_editor_get_all_text(DasherEditor *pSelf);
 
 /* Functions for editing the active buffer */
 void dasher_editor_output(DasherEditor *pSelf, const gchar *szText, int iOffset);
 void dasher_editor_delete(DasherEditor *pSelf, int iLength, int iOffset);
-void dasher_editor_start_compose(DasherEditor *pSelf);
-void dasher_editor_end_compose(DasherEditor *pSelf, bool bKeep);
 
 /* Function for reading the active buffer */
-const gchar *dasher_editor_get_context(DasherEditor *pSelf, int iOffset, int iLength);
+std::string dasher_editor_get_context(DasherEditor *pSelf, int iOffset, int iLength);
 std::string dasher_editor_get_text_around_cursor(DasherEditor *pSelf, Dasher::CControlManager::EditDistance 
dist);
 gint dasher_editor_get_offset(DasherEditor *pSelf);
 
diff --git a/Src/Gtk2/dasher_editor_external.h b/Src/Gtk2/dasher_editor_external.h
index e3180bf..fc0a9a2 100644
--- a/Src/Gtk2/dasher_editor_external.h
+++ b/Src/Gtk2/dasher_editor_external.h
@@ -7,7 +7,7 @@ void dasher_editor_external_finalize(GObject*);
 void dasher_editor_external_create_buffer(DasherEditor*); //  for dasher_editor_external_initialise, and 
calls focus bits
 void dasher_editor_external_output(DasherEditor *pSelf, const char *szText, int iOffset);
 void dasher_editor_external_delete(DasherEditor *pSelf, int iLength, int iOffset);
-const char * dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength);
+std::string dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength);
 int dasher_editor_external_get_offset(DasherEditor *pSelf);
 void dasher_editor_external_toggle_direct_mode(DasherEditor *, bool);
 void dasher_editor_external_move(DasherEditor *pSelf, bool bForwards, Dasher::CControlManager::EditDistance 
iDist);
diff --git a/Src/Gtk2/dasher_editor_external_atspi.cpp b/Src/Gtk2/dasher_editor_external_atspi.cpp
index 09d0d92..76f637a 100644
--- a/Src/Gtk2/dasher_editor_external_atspi.cpp
+++ b/Src/Gtk2/dasher_editor_external_atspi.cpp
@@ -121,7 +121,7 @@ dasher_editor_external_delete(DasherEditor *pSelf, int iLength, int iOffset) {
   atspi_generate_keyboard_event(XK_BackSpace, NULL, ATSPI_KEY_SYM, NULL);
 }
 
-const char *
+std::string
 dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
   DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
 
@@ -132,10 +132,15 @@ dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength
   DASHER_ASSERT(pPrivate->pExtPrivate != NULL);
   AtspiText *textobj = pPrivate->pExtPrivate->pAccessibleText;
 
-  if (textobj)
-    return atspi_text_get_text(textobj, iOffset, iOffset + iLength, NULL);
-  else
-    return "";
+  if (textobj != nullptr) {
+    auto text = atspi_text_get_text(textobj, iOffset, iOffset + iLength, NULL);
+    if (text != nullptr) {
+      std::string context = text;
+      g_free(text);
+      return context;
+    }
+  }
+  return "";
 }
 
 int
@@ -246,7 +251,6 @@ dasher_editor_external_handle_caret(DasherEditor *pSelf, const AtspiEvent *pEven
   if (textobj) {
     // If dasher moved the caret don't send a notification to the control.
     glong caret = atspi_text_get_caret_offset(textobj, NULL);
-    bool in_control_action = false;
     if (caret == pPrivate->pExtPrivate->current_caret_position) {
       return;
     }
diff --git a/Src/Gtk2/dasher_editor_external_cspi.cpp b/Src/Gtk2/dasher_editor_external_cspi.cpp
index 479eea6..23c6cd0 100644
--- a/Src/Gtk2/dasher_editor_external_cspi.cpp
+++ b/Src/Gtk2/dasher_editor_external_cspi.cpp
@@ -114,11 +114,16 @@ dasher_editor_external_delete(DasherEditor *pSelf, int iLength, int iOffset) {
   SPI_generateKeyboardEvent(XK_BackSpace, NULL, SPI_KEY_SYM);
 }
 
-const gchar *
+std::string
 dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
   DasherEditorPrivate *pPrivate = DASHER_EDITOR_GET_PRIVATE(pSelf);
   if(pPrivate->pExtPrivate->pAccessibleText)
-    return AccessibleText_getText(pPrivate->pExtPrivate->pAccessibleText, iOffset, iOffset + iLength);
+    auto text = AccessibleText_getText(pPrivate->pExtPrivate->pAccessibleText, iOffset, iOffset + iLength);
+    if (text != nullptr) {
+      std::string context = text;
+      SPI_freeString(text);
+      return text;
+    }
   else
     return "";
 }
diff --git a/Src/Gtk2/dasher_editor_external_xtest.cpp b/Src/Gtk2/dasher_editor_external_xtest.cpp
index 361d3b3..a53520a 100644
--- a/Src/Gtk2/dasher_editor_external_xtest.cpp
+++ b/Src/Gtk2/dasher_editor_external_xtest.cpp
@@ -138,8 +138,7 @@ dasher_editor_external_delete(DasherEditor *pSelf, int iLength, int iOffset) {
   XFlush(dpy);
 }
 
-const gchar *
-dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
+std::string dasher_editor_external_get_context(DasherEditor *pSelf, int iOffset, int iLength) {
   return "";
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]