texinfo-commits
[Top][All Lists]
Advanced

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

[5514] don't free references too early


From: Gavin D. Smith
Subject: [5514] don't free references too early
Date: Sat, 03 May 2014 23:12:16 +0000

Revision: 5514
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5514
Author:   gavin
Date:     2014-05-03 23:12:13 +0000 (Sat, 03 May 2014)
Log Message:
-----------
don't free references too early

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/indices.c
    trunk/info/indices.h
    trunk/info/info-utils.c
    trunk/info/info.c
    trunk/info/man.c
    trunk/info/t/infodir/dir

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-03 10:37:53 UTC (rev 5513)
+++ trunk/ChangeLog     2014-05-03 23:12:13 UTC (rev 5514)
@@ -1,5 +1,28 @@
 2014-05-03  Gavin Smith  <address@hidden>
 
+       * indices.c (info_indices_of_file_buffer, do_info_index_search)
+       (index_entry_exists, apropos_in_all_indices, info_index_apropos)
+       (info_virtual_index)
+       Call free instead of info_free_references or info_reference_free,
+       because the REFERENCE * objects in the array are still referenced
+       elsewhere.
+
+       * info-utils.c (info_concatenate_references): Don't free arguments.
+       Always return a new array, even if either of the arguments are null.
+       Callers updated.
+
+       * info/indices.c (info_apropos): Merged into info.c:main.
+       (APROPOS_NONE) Moved to indices.h.
+       * info/info.c <apropos in indices>: Call apropos_in_all_indices
+       only after infopath_init has been called.
+
+       * info/indices.c (apropos_in_all_indices): Get file buffer directly,
+       rather than loading a node first.
+
+       * info/man.c (manpage_xrefs_in_binding): Delete unused.
+
+2014-05-03  Gavin Smith  <address@hidden>
+
        * info/window.c (string_to_node): Function deleted.  Caller in
        create_internal_info_help_node updated.
 

Modified: trunk/info/indices.c
===================================================================
--- trunk/info/indices.c        2014-05-03 10:37:53 UTC (rev 5513)
+++ trunk/info/indices.c        2014-05-03 23:12:13 UTC (rev 5514)
@@ -150,7 +150,11 @@
                   add_index_to_index_nodenames (menu, node);
 
                   /* Concatenate the references found so far. */
+                  {
+                  REFERENCE **old_result = result;
                   result = info_concatenate_references (result, menu);
+                  free (old_result);
+                  }
                 }
               free (node);
             }
@@ -197,7 +201,7 @@
   if (!initial_index_filename ||
       (FILENAME_CMP (initial_index_filename, fb->filename) != 0))
     {
-      info_free_references (index_index);
+      free (index_index);
       window_message_in_echo_area (_("Finding index entries..."));
       index_index = info_indices_of_file_buffer (fb);
     }
@@ -304,7 +308,7 @@
       !fb ||
       (FILENAME_CMP (initial_index_filename, fb->filename) != 0))
     {
-      info_free_references (index_index);
+      free (index_index);
       index_index = info_indices_of_file_buffer (fb);
     }
 
@@ -549,76 +553,35 @@
   if (!dir_menu)
     return NULL;
 
-  /* For every menu item in DIR, get the associated node's file buffer and
+  /* For every menu item in DIR, get the associated file buffer and
      read the indices of that file buffer.  Gather all of the indices into
      one large one. */
   for (dir_index = 0; dir_menu[dir_index]; dir_index++)
     {
       REFERENCE **this_index, *this_item;
-      NODE *this_node;
       FILE_BUFFER *this_fb;
-      int dir_node_duplicated = 0;
 
+      /* If we already scanned this file, don't do that again.
+         In addition to being faster, this also avoids having
+         multiple identical entries in the *Apropos* menu.  */
+      for (i = 0; i < dir_index; i++)
+        if (FILENAME_CMP (this_item->filename, dir_menu[i]->filename) == 0)
+          continue;
+
       this_item = dir_menu[dir_index];
+      this_fb = info_find_file (this_item->filename);
 
-      if (!this_item->filename)
-        {
-         dir_node_duplicated = 1;
-          if (dir_node->parent)
-            this_item->filename = xstrdup (dir_node->parent);
-          else
-            this_item->filename = xstrdup (dir_node->filename);
-        }
+      if (!this_fb)
+        continue;
 
-      /* Find this node.  If we cannot find it, try using the label of the
-         entry as a file (i.e., "(LABEL)Top"). */
-      this_node = info_get_node (this_item->filename, this_item->nodename,
-                                 PARSE_NODE_VERBATIM);
+      if (this_fb && inform)
+        message_in_echo_area (_("Scanning indices of `%s'..."), 
this_item->filename);
 
-      if (!this_node && this_item->nodename &&
-          (strcmp (this_item->label, this_item->nodename) == 0))
-        this_node = info_get_node (this_item->label, "Top", PARSE_NODE_DFLT);
+      this_index = info_indices_of_file_buffer (this_fb);
 
-      if (!this_node)
-       {
-         if (dir_node_duplicated)
-           free (this_item->filename);
-         continue;
-       }
+      if (this_fb && inform)
+        unmessage_in_echo_area ();
 
-      /* Get the file buffer associated with this node. */
-      {
-        char *files_name;
-
-        files_name = this_node->parent;
-        if (!files_name)
-          files_name = this_node->filename;
-
-        this_fb = info_find_file (files_name);
-
-       /* If we already scanned this file, don't do that again.
-          In addition to being faster, this also avoids having
-          multiple identical entries in the *Apropos* menu.  */
-       for (i = 0; i < dir_index; i++)
-         if (FILENAME_CMP (this_fb->filename, dir_menu[i]->filename) == 0)
-           break;
-       if (i < dir_index)
-         {
-           if (dir_node_duplicated)
-             free (this_item->filename);
-           continue;
-         }
-
-        if (this_fb && inform)
-          message_in_echo_area (_("Scanning indices of `%s'..."), files_name);
-
-        this_index = info_indices_of_file_buffer (this_fb);
-        free (this_node);
-
-        if (this_fb && inform)
-          unmessage_in_echo_area ();
-      }
-
       if (this_index)
         {
           /* Remember the filename which contains this set of references. */
@@ -627,7 +590,11 @@
               this_index[i]->filename = xstrdup (this_fb->filename);
 
           /* Concatenate with the other indices.  */
+          {
+          REFERENCE **old_indices = all_indices;
           all_indices = info_concatenate_references (all_indices, this_index);
+          free (old_indices);
+          }
         }
       /* Try to avoid running out of memory */
       free (this_fb->contents);
@@ -648,8 +615,6 @@
               add_pointer_to_array (entry, apropos_list_index, apropos_list, 
                                     apropos_list_slots, 100);
             }
-          else
-            info_reference_free (entry);
         }
 
       free (all_indices);
@@ -658,30 +623,6 @@
   return all_indices;
 }
 
-#define APROPOS_NONE \
-   N_("No available info files have `%s' in their indices.")
-
-void
-info_apropos (char *string)
-{
-  REFERENCE **apropos_list;
-
-  apropos_list = apropos_in_all_indices (string, 0);
-
-  if (!apropos_list)
-    info_error (_(APROPOS_NONE), string);
-  else
-    {
-      register int i;
-      REFERENCE *entry;
-
-      for (i = 0; (entry = apropos_list[i]); i++)
-        fprintf (stdout, "\"(%s)%s\" -- %s\n",
-                 entry->filename, entry->nodename, entry->label);
-    }
-  info_free_references (apropos_list);
-}
-
 static char *apropos_list_nodename = "*Apropos*";
 
 DECLARE_INFO_COMMAND (info_index_apropos,
@@ -794,7 +735,7 @@
         remember_window_and_node (new, apropos_node);
         active_window = new;
       }
-      info_free_references (apropos_list);
+      free (apropos_list);
     }
   free (line);
 
@@ -883,7 +824,7 @@
       !fb ||
       (FILENAME_CMP (initial_index_filename, fb->filename) != 0))
     {
-      info_free_references (index_index);
+      free (index_index);
       window_message_in_echo_area (_("Finding index entries..."));
       index_index = info_indices_of_file_buffer (fb);
     }

Modified: trunk/info/indices.h
===================================================================
--- trunk/info/indices.h        2014-05-03 10:37:53 UTC (rev 5513)
+++ trunk/info/indices.h        2014-05-03 23:12:13 UTC (rev 5514)
@@ -26,7 +26,6 @@
 extern int show_index_match;
 
 extern REFERENCE **info_indices_of_file_buffer (FILE_BUFFER *file_buffer);
-extern void info_apropos (char *string);
 
 /* For every menu item in DIR, search the indices of that file for STRING. */
 REFERENCE **apropos_in_all_indices (char *search_string, int inform);
@@ -38,4 +37,7 @@
 extern void do_info_index_search (WINDOW *window, FILE_BUFFER *fb, int count, 
char *search_string);
 extern int index_entry_exists (FILE_BUFFER *fb, char *string);
 
+#define APROPOS_NONE \
+   N_("No available info files have `%s' in their indices.")
+
 #endif /* not INFO_INDICES_H */

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2014-05-03 10:37:53 UTC (rev 5513)
+++ trunk/info/info-utils.c     2014-05-03 23:12:13 UTC (rev 5514)
@@ -206,40 +206,45 @@
 }
 
 /* A utility function for concatenating REFERENCE **.  Returns a new
-   REFERENCE ** which is the concatenation of REF1 and REF2.  The REF1
-   and REF2 arrays are freed, but their contents are not. */
+   REFERENCE ** which is the concatenation of REF1 and REF2.  */
 REFERENCE **
 info_concatenate_references (REFERENCE **ref1, REFERENCE **ref2)
 {
   register int i, j;
   REFERENCE **result;
-  int size;
+  int size = 0;
 
-  /* With one argument passed as NULL, simply return the other arg. */
-  if (!ref1)
-    return ref2;
-  else if (!ref2)
-    return ref1;
-
   /* Get the total size of the slots that we will need. */
-  for (i = 0; ref1[i]; i++);
-  size = i;
-  for (i = 0; ref2[i]; i++);
-  size += i;
+  if (ref1)
+    {
+      for (i = 0; ref1[i]; i++);
+      size += i;
+    }
 
+  if (ref2)
+    {
+      for (i = 0; ref2[i]; i++);
+      size += i;
+    }
+
   result = xmalloc ((1 + size) * sizeof (REFERENCE *));
 
   /* Copy the contents over. */
-  for (i = 0; ref1[i]; i++)
-    result[i] = ref1[i];
 
-  j = i;
-  for (i = 0; ref2[i]; i++)
-    result[j++] = ref2[i];
+  j = 0;
+  if (ref1)
+    {
+      for (i = 0; ref1[i]; i++)
+        result[j++] = ref1[i];
+    }
 
+  if (ref2)
+    {
+      for (i = 0; ref2[i]; i++)
+        result[j++] = ref2[i];
+    }
+
   result[j] = NULL;
-  free (ref1);
-  free (ref2);
   return result;
 }
 

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2014-05-03 10:37:53 UTC (rev 5513)
+++ trunk/info/info.c   2014-05-03 23:12:13 UTC (rev 5514)
@@ -749,14 +749,6 @@
   if (user_filename)
     add_file_directory_to_path (user_filename);
 
-  /* If the user wants to search every known index for a given string,
-     do that now, and report the results. */
-  if (apropos_p)
-    {
-      info_apropos (apropos_search_string);
-      exit (EXIT_SUCCESS);
-    }
-
   argc -= optind;
   argv += optind;
   
@@ -767,6 +759,28 @@
      --directory. */
   infopath_init ();
 
+  /* If the user wants to search every known index for a given string,
+     do that now, and report the results. */
+  if (apropos_p)
+    {
+      REFERENCE **apropos_list;
+
+      apropos_list = apropos_in_all_indices (apropos_search_string, 0);
+
+      if (!apropos_list)
+        info_error (_(APROPOS_NONE), apropos_search_string);
+      else
+      {
+        register int i;
+        REFERENCE *entry;
+
+        for (i = 0; (entry = apropos_list[i]); i++)
+          fprintf (stdout, "\"(%s)%s\" -- %s\n",
+              entry->filename, entry->nodename, entry->label);
+      }
+      exit (EXIT_SUCCESS);
+    }
+
   if (all_matches_p)
     return all_files (user_filename, argc, argv);
 

Modified: trunk/info/man.c
===================================================================
--- trunk/info/man.c    2014-05-03 10:37:53 UTC (rev 5513)
+++ trunk/info/man.c    2014-05-03 23:12:13 UTC (rev 5514)
@@ -57,8 +57,6 @@
 
 static long locate_manpage_xref (NODE *node, long int start, int dir);
 static REFERENCE **xrefs_of_manpage (NODE *node);
-static REFERENCE **manpage_xrefs_in_binding (NODE *node,
-    SEARCH_BINDING *binding);
 static char *read_from_fd (int fd);
 static char *get_manpage_contents (char *pagename);
 static void create_manpage_file_buffer (void);
@@ -688,35 +686,3 @@
     }
   return position;
 }
-
-/* This one was a little tricky.  The binding buffer that is passed in has
-   a START and END value of 0 -- strlen (window-line-containing-point).
-   The BUFFER is a pointer to the start of that line. */
-REFERENCE **
-manpage_xrefs_in_binding (NODE *node, SEARCH_BINDING *binding)
-{
-  size_t i;
-  REFERENCE **all_refs = xrefs_of_manpage (node);
-  REFERENCE **brefs = NULL;
-  REFERENCE *entry;
-  size_t brefs_index = 0;
-  size_t brefs_slots = 0;
-  int start, end;
-
-  if (!all_refs)
-    return NULL;
-
-  start = binding->start + (binding->buffer - node->contents);
-  end = binding->end + (binding->buffer - node->contents);
-
-  for (i = 0; (entry = all_refs[i]); i++)
-    {
-      if ((entry->start > start) && (entry->end < end))
-        add_pointer_to_array (entry, brefs_index, brefs, brefs_slots, 10);
-      else
-        info_reference_free (entry);
-    }
-
-  free (all_refs);
-  return brefs;
-}

Modified: trunk/info/t/infodir/dir
===================================================================
(Binary files differ)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]