[anjuta] symbol-db: bgo#604581 - Crash Scintilla when writing a comment



commit 0fd9f2d993c735ce389156a2bff0c88d3da7797c
Author: Massimo Corà <mcora src gnome org>
Date:   Thu Dec 17 22:17:07 2009 +0100

    symbol-db: bgo#604581 -  Crash Scintilla when writing a comment
    
    improvements on query interfaces. Now we keep an internal copy of GList
    to avoid race conditions problems.

 libanjuta/interfaces/libanjuta.idl           |    1 +
 plugins/symbol-db/symbol-db-engine-queries.c |   69 +++++++++++++++++++++----
 plugins/symbol-db/symbol-db-engine-queries.h |    4 +-
 plugins/symbol-db/symbol-db-iface.c          |    2 +-
 plugins/symbol-db/symbol-db-search-command.c |   39 ++++++++++----
 5 files changed, 90 insertions(+), 25 deletions(-)
---
diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index 063a3a9..0fca726 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -5461,6 +5461,7 @@ interface IAnjutaSymbolManager
 	*          or something like 'foo_fun%' (LIKE match, matching all the symbol prefixed with 
 	*          'foo_fun'). NULL _is not_ accepted
 	* @file GFile of the file, belonging to the project, which you want to scan symbols for.
+	*       Note that if the file doesn't belong to the project, it won't be scanned correctly.
 	* @results_limit: Limit results to an upper bound. -1 If you don't want to use this par.
 	* @results_offset: Skip results_offset results. -1 If you don't want to use this par.	 
 	* @err: Error propagation and reporting.	 
diff --git a/plugins/symbol-db/symbol-db-engine-queries.c b/plugins/symbol-db/symbol-db-engine-queries.c
index a175453..e1b3419 100644
--- a/plugins/symbol-db/symbol-db-engine-queries.c
+++ b/plugins/symbol-db/symbol-db-engine-queries.c
@@ -2808,7 +2808,7 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 									SymType filter_kinds,
 									gboolean include_kinds,
 									SymSearchFileScope filescope_search,
-									GList *session_projects,
+									const GList *session_projects,
 									gint results_limit, 
 									gint results_offset,
 									SymExtraInfo sym_info)
@@ -2832,11 +2832,22 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 	gboolean ret_bool;
 	GPtrArray *filter_kinds_array;
 	GError* error = NULL;
-
+	GList *session_prjs;
+	
 	g_return_val_if_fail (dbe != NULL, NULL);
 	g_return_val_if_fail (pattern != NULL, NULL);
 	priv = dbe->priv;
 
+	/* create a backup internal copy of the struct.
+	 * There shouldn't be a big performance loss 
+	 */
+	session_prjs = NULL;
+	GList *node;
+	for (node = (GList*)session_projects; node; node = node->next)
+	{
+		session_prjs = g_list_prepend (session_prjs, g_strdup (node->data));
+	}
+
 	SDB_LOCK(priv);
 	
 	sym_info = sym_info & ~SYMINFO_KIND;
@@ -2898,9 +2909,9 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 		offset_free = TRUE;
 	}
 
-	if (session_projects != NULL)
+	if (session_prjs != NULL)
 	{
-		gint list_length = g_list_length (session_projects);
+		gint list_length = g_list_length (session_prjs);
 		if (list_length < 255 && list_length > 0) 
 		{		
 			/* shift the bits. We want to put the result on the third byte */
@@ -2910,7 +2921,7 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 		else 
 		{
 			g_warning ("symbol_db_engine_find_symbol_by_name_pattern_filtered (): "
-				"session_projects has 0 length.");						   
+				"session_prjs has 0 length.");						   
 		}
 	}
 	
@@ -2936,7 +2947,7 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 			
 			/* build session projects filter string */
 			filter_projects = g_string_new ("");
-			if (session_projects != NULL)
+			if (session_prjs != NULL)
 			{
 				filter_projects = g_string_append (filter_projects,
 				"AND symbol.file_defined_id IN "
@@ -2944,7 +2955,7 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 					"project.project_id WHERE project.project_name IN ( "
 					"## /* name:'prj_filter0' type:gchararray */");
 				
-				for (i = 1; i < g_list_length (session_projects); i++)
+				for (i = 1; i < g_list_length (session_prjs); i++)
 				{				
 					g_string_append_printf (filter_projects, 
 						",## /* name:'prj_filter%d' type:gchararray */", i);
@@ -3034,7 +3045,7 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 			
 			/* build session projects filter string */
 			filter_projects = g_string_new ("");
-			if (session_projects != NULL)
+			if (session_prjs != NULL)
 			{
 				filter_projects = g_string_append (filter_projects,
 				"AND symbol.file_defined_id IN "
@@ -3042,7 +3053,7 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 					"project.project_id WHERE project.project_name IN ( "
 					"## /* name:'prj_filter0' type:gchararray */");
 				
-				for (i = 1; i < g_list_length (session_projects); i++)
+				for (i = 1; i < g_list_length (session_prjs); i++)
 				{				
 					g_string_append_printf (filter_projects, 
 						",## /* name:'prj_filter%d' type:gchararray */", i);
@@ -3082,6 +3093,12 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 	if (dyn_node == NULL)
 	{
 		SDB_UNLOCK(priv);
+		if (session_prjs)
+		{
+			g_list_foreach (session_prjs, (GFunc)g_free, NULL);
+			g_list_free (session_prjs);
+		}
+		
 		return NULL;
 	}
 	
@@ -3090,6 +3107,12 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 		if ((param = gda_set_get_holder ((GdaSet*)dyn_node->plist, "limit")) == NULL)
 		{
 			SDB_UNLOCK(priv);
+			if (session_prjs)
+			{
+				g_list_foreach (session_prjs, (GFunc)g_free, NULL);
+				g_list_free (session_prjs);
+			}
+			
 			return NULL;
 		}
 
@@ -3101,6 +3124,12 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 		if ((param = gda_set_get_holder ((GdaSet*)dyn_node->plist, "offset")) == NULL)
 		{
 			SDB_UNLOCK(priv);			
+			if (session_prjs)
+			{
+				g_list_foreach (session_prjs, (GFunc)g_free, NULL);
+				g_list_free (session_prjs);
+			}
+			
 			return NULL;
 		}
 
@@ -3124,11 +3153,11 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 	}
 
 	/* fill parameters for filter projects (packages) */
-	if (session_projects != NULL)
+	if (session_prjs != NULL)
 	{
 		gint i = 0;
 		GList *item;
-		item = session_projects;
+		item = session_prjs;
 		while (item != NULL)
 		{
 			gchar *curr_str = g_strdup_printf ("prj_filter%d", i);
@@ -3144,6 +3173,12 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 	if ((param = gda_set_get_holder ((GdaSet*)dyn_node->plist, "pattern")) == NULL)
 	{
 		SDB_UNLOCK(priv);
+		if (session_prjs)
+		{
+			g_list_foreach (session_prjs, (GFunc)g_free, NULL);
+			g_list_free (session_prjs);
+		}
+		
 		return NULL;
 	}
 
@@ -3175,11 +3210,23 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 	{
 		if (data != NULL)
 			g_object_unref (data);
+
+		if (session_prjs)
+		{
+			g_list_foreach (session_prjs, (GFunc)g_free, NULL);
+			g_list_free (session_prjs);
+		}
 		
 		SDB_UNLOCK(priv);
 		return NULL;
 	}
 
+	if (session_prjs)
+	{
+		g_list_foreach (session_prjs, (GFunc)g_free, NULL);
+		g_list_free (session_prjs);
+	}
+	
 	SDB_UNLOCK(priv);
 	return (SymbolDBEngineIterator *)symbol_db_engine_iterator_new (data, 
 												priv->sym_type_conversion_hash,
diff --git a/plugins/symbol-db/symbol-db-engine-queries.h b/plugins/symbol-db/symbol-db-engine-queries.h
index ed7ed23..b5e538b 100644
--- a/plugins/symbol-db/symbol-db-engine-queries.h
+++ b/plugins/symbol-db/symbol-db-engine-queries.h
@@ -70,7 +70,7 @@ symbol_db_engine_find_symbol_by_name_pattern (SymbolDBEngine *dbe,
  *        SYMSEARCH_FILESCOPE_IGNORE to be ignored (e.g. Will search both private and public scopes). 
  *        You cannot use bitwise OR in this parameter.
  * @param session_projects Should the search, a global search, be filtered by some packages (projects)?
- *        If yes then provide a GList, if no then pass NULL.	 
+ *        If yes then provide a GList, if no then pass NULL.
  * @param results_limit Limit results to an upper bound. -1 If you don't want to use this par.
  * @param results_offset Skip results_offset results. -1 If you don't want to use this par.
  * @param sym_info Infos about symbols you want to know.
@@ -81,7 +81,7 @@ symbol_db_engine_find_symbol_by_name_pattern_filtered (SymbolDBEngine *dbe,
 									SymType filter_kinds,
 									gboolean include_kinds,
 									SymSearchFileScope filescope_search,
-									GList *session_projects,													   
+									const GList *session_projects,													   
 									gint results_limit, 
 									gint results_offset,
 									SymExtraInfo sym_info);
diff --git a/plugins/symbol-db/symbol-db-iface.c b/plugins/symbol-db/symbol-db-iface.c
index 851b04c..d66bffd 100644
--- a/plugins/symbol-db/symbol-db-iface.c
+++ b/plugins/symbol-db/symbol-db-iface.c
@@ -288,7 +288,7 @@ do_search_prj_glb (SymbolDBEngine *dbe, IAnjutaSymbolType match_types,
            gboolean include_types, IAnjutaSymbolField info_fields,
            const gchar *pattern, IAnjutaSymbolManagerSearchFileScope filescope_search,
     	   gint results_limit, gint results_offset, 
-           GList *session_packages)
+           const GList *session_packages)
 {
 	SymbolDBEngineIterator *iterator;
 	
diff --git a/plugins/symbol-db/symbol-db-search-command.c b/plugins/symbol-db/symbol-db-search-command.c
index ec0ce3d..3758136 100644
--- a/plugins/symbol-db/symbol-db-search-command.c
+++ b/plugins/symbol-db/symbol-db-search-command.c
@@ -25,8 +25,7 @@ struct _SymbolDBSearchCommandPriv {
 	/* may be set or not. Initial value (at init time) is NULL */
 	GFile *gfile;	
 
-	/* may be set or not. Initial value (at init time) is NULL 
-	 * it shouldn't be freed. */
+	/* may be set or not. Initial value (at init time) is NULL */
 	GList *session_packages;
 
 	SymbolDBEngine *dbe;
@@ -44,8 +43,6 @@ struct _SymbolDBSearchCommandPriv {
 	 * freed 
 	 */
 	SymbolDBEngineIterator *iterator_result;
-
-	gboolean cancelled;
 };
 
 
@@ -58,8 +55,7 @@ sdb_search_command_init (SymbolDBSearchCommand *object)
 
 	object->priv->gfile = NULL;
 	object->priv->session_packages = NULL;
-	object->priv->pattern = NULL;
-	object->priv->cancelled = FALSE;
+	object->priv->pattern = NULL;	
 }
 
 static void
@@ -71,11 +67,21 @@ sdb_search_command_finalize (GObject *object)
 
 	priv = sdbsc->priv;
 	
-	if (priv->gfile) g_object_unref (priv->gfile);
+	if (priv->gfile) 
+		g_object_unref (priv->gfile);
 	priv->gfile = NULL;
 
 	g_free (priv->pattern);	
 	priv->pattern = NULL;
+
+	/* we can safely destroy the packages' list */
+	if (priv->session_packages)
+	{
+		g_list_foreach (priv->session_packages, (GFunc)g_free, NULL);
+		g_list_free (priv->session_packages);		
+	}
+	priv->session_packages = NULL;
+	
 	
 	g_free (sdbsc->priv);
 	
@@ -91,9 +97,6 @@ do_search_file (SymbolDBSearchCommand *sdbsc)
 
 	priv = sdbsc->priv;
 
-	if (priv->cancelled)
-		return NULL;
-	
 	abs_file_path = g_file_get_path (priv->gfile);
 
 	if (abs_file_path == NULL)
@@ -260,8 +263,22 @@ symbol_db_search_command_set_session_packages (SymbolDBSearchCommand* sdbsc,
 	g_return_if_fail (sdbsc != NULL);
 	
 	priv = sdbsc->priv;
+
+	/* if there's an old glist then clear it before setting the new one. */
+	if (priv->session_packages)
+	{
+		g_list_foreach (priv->session_packages, (GFunc)g_free, NULL);
+		g_list_free (priv->session_packages);		
+		priv->session_packages = NULL;
+	}	
 	
-	priv->session_packages = (GList*)session_packages;
+	/* copy the list passed as parameter */
+	GList *node;
+	for (node = (GList*)session_packages; node; node = node->next)
+	{
+		priv->session_packages = g_list_prepend (priv->session_packages, 
+		                                         g_strdup (node->data));
+	}
 }	
 
 SymbolDBEngineIterator *



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