Cleanup xmalloc.
[bpt/emacs.git] / src / search.c
index 5608e34..a7ea363 100644 (file)
@@ -24,8 +24,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "lisp.h"
 #include "syntax.h"
 #include "category.h"
-#include "buffer.h"
 #include "character.h"
+#include "buffer.h"
 #include "charset.h"
 #include "region-cache.h"
 #include "commands.h"
@@ -101,9 +101,8 @@ static EMACS_INT boyer_moore (EMACS_INT, unsigned char *, ptrdiff_t,
 static EMACS_INT search_buffer (Lisp_Object, ptrdiff_t, ptrdiff_t,
                                 ptrdiff_t, ptrdiff_t, EMACS_INT, int,
                                 Lisp_Object, Lisp_Object, int);
-static void matcher_overflow (void) NO_RETURN;
 
-static void
+static _Noreturn void
 matcher_overflow (void)
 {
   error ("Stack overflow in regexp matcher");
@@ -1160,24 +1159,12 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
        {
          ptrdiff_t val;
 
-#ifdef REL_ALLOC
-         /* re_search_2 below is passed C pointers to buffer text.
-            If some code called by it causes memory (re)allocation,
-            buffer text could be relocated on platforms that use
-            REL_ALLOC, which invalidates those C pointers.  So we
-            inhibit relocation of buffer text for as long as
-            re_search_2 runs.  */
-         r_alloc_inhibit_buffer_relocation (1);
-#endif
          val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
                             pos_byte - BEGV_BYTE, lim_byte - pos_byte,
                             (NILP (Vinhibit_changing_match_data)
                              ? &search_regs : &search_regs_1),
                             /* Don't allow match past current point */
                             pos_byte - BEGV_BYTE);
-#ifdef REL_ALLOC
-         r_alloc_inhibit_buffer_relocation (0);
-#endif
          if (val == -2)
            {
              matcher_overflow ();
@@ -1217,19 +1204,11 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
        {
          ptrdiff_t val;
 
-#ifdef REL_ALLOC
-         /* See commentary above for the reasons for inhibiting
-            buffer text relocation here.  */
-         r_alloc_inhibit_buffer_relocation (1);
-#endif
          val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
                             pos_byte - BEGV_BYTE, lim_byte - pos_byte,
                             (NILP (Vinhibit_changing_match_data)
                              ? &search_regs : &search_regs_1),
                             lim_byte - BEGV_BYTE);
-#ifdef REL_ALLOC
-         r_alloc_inhibit_buffer_relocation (0);
-#endif
          if (val == -2)
            {
              matcher_overflow ();
@@ -1472,7 +1451,7 @@ simple_search (EMACS_INT n, unsigned char *pat,
   int forward = n > 0;
   /* Number of buffer bytes matched.  Note that this may be different
      from len_byte in a multibyte buffer.  */
-  ptrdiff_t match_byte;
+  ptrdiff_t match_byte = PTRDIFF_MIN;
 
   if (lim > pos && multibyte)
     while (n > 0)
@@ -1643,6 +1622,7 @@ simple_search (EMACS_INT n, unsigned char *pat,
  stop:
   if (n == 0)
     {
+      eassert (match_byte != PTRDIFF_MIN);
       if (forward)
        set_search_regs ((multibyte ? pos_byte : pos) - match_byte, match_byte);
       else
@@ -2084,8 +2064,8 @@ set_search_regs (ptrdiff_t beg_byte, ptrdiff_t nbytes)
      the match position.  */
   if (search_regs.num_regs == 0)
     {
-      search_regs.start = (regoff_t *) xmalloc (2 * sizeof (regoff_t));
-      search_regs.end = (regoff_t *) xmalloc (2 * sizeof (regoff_t));
+      search_regs.start = xmalloc (2 * sizeof (regoff_t));
+      search_regs.end = xmalloc (2 * sizeof (regoff_t));
       search_regs.num_regs = 2;
     }
 
@@ -2520,7 +2500,7 @@ since only regular expressions have distinguished subexpressions.  */)
       substed_alloc_size = ((STRING_BYTES_BOUND - 100) / 2 < length
                            ? STRING_BYTES_BOUND
                            : length * 2 + 100);
-      substed = (unsigned char *) xmalloc (substed_alloc_size);
+      substed = xmalloc (substed_alloc_size);
       substed_len = 0;
 
       /* Go thru NEWTEXT, producing the actual text to insert in
@@ -3060,7 +3040,7 @@ syms_of_search (void)
   for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
     {
       searchbufs[i].buf.allocated = 100;
-      searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
+      searchbufs[i].buf.buffer = xmalloc (100);
       searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
       searchbufs[i].regexp = Qnil;
       searchbufs[i].whitespace_regexp = Qnil;