emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 1/4] Compilation cleanups


From: Paul Eggert
Subject: Re: [PATCH 1/4] Compilation cleanups
Date: Sat, 31 Dec 2011 12:29:56 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0

On 12/31/11 06:50, Ken Brown wrote:
>  static __ptr_t align PP ((__malloc_size_t));
>  static __ptr_t
> -align (size)
> -     __malloc_size_t size;
> +align (__malloc_size_t size)

Good idea, and there's more where that came from --
for example, that first line (with the PP) can be removed
since it was there only because of the old-style definitions.

Here's an improved version of that patch, which includes
some hopefully-obvious extra cleanups.  (And there's more
where this came from -- that code is pretty crufty....)


=== modified file 'lib-src/update-game-score.c'
--- lib-src/update-game-score.c 2011-11-17 09:09:20 +0000
+++ lib-src/update-game-score.c 2011-12-31 18:37:05 +0000
@@ -46,10 +46,7 @@
 #include <fcntl.h>
 #endif
 #include <sys/stat.h>
-
-/* Needed for SunOS4, for instance.  */
-extern char *optarg;
-extern int optind, opterr;
+#include <getopt.h>
 
 static int usage (int err) NO_RETURN;
 

=== modified file 'src/buffer.c'
--- src/buffer.c        2011-11-27 04:43:11 +0000
+++ src/buffer.c        2011-12-31 19:24:12 +0000
@@ -2004,10 +2004,6 @@
   return byte_pos;
 }
 
-#ifdef REL_ALLOC
-extern void r_alloc_reset_variable (POINTER_TYPE *, POINTER_TYPE *);
-#endif /* REL_ALLOC */
-
 DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
        1, 1, 0,
        doc: /* Swap the text between current buffer and BUFFER.  */)
@@ -4763,13 +4759,6 @@
                            Buffer-text Allocation
  ***********************************************************************/
 
-#ifdef REL_ALLOC
-extern POINTER_TYPE *r_alloc (POINTER_TYPE **, size_t);
-extern POINTER_TYPE *r_re_alloc (POINTER_TYPE **, size_t);
-extern void r_alloc_free (POINTER_TYPE **ptr);
-#endif /* REL_ALLOC */
-
-
 /* Allocate NBYTES bytes for buffer B's text buffer.  */
 
 static void

=== modified file 'src/gmalloc.c'
--- src/gmalloc.c       2011-09-09 01:06:52 +0000
+++ src/gmalloc.c       2011-12-31 20:23:17 +0000
@@ -27,10 +27,6 @@
    The author may be reached (Email) at the address address@hidden,
    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
 
-#ifndef _MALLOC_H
-
-#define _MALLOC_H      1
-
 #ifdef _MALLOC_INTERNAL
 
 #ifdef HAVE_CONFIG_H
@@ -78,17 +74,8 @@
 extern void free PP ((__ptr_t __ptr));
 
 /* Allocate SIZE bytes allocated to ALIGNMENT bytes.  */
-#if !defined (_MALLOC_INTERNAL) || defined (MSDOS) /* Avoid conflict.  */
 extern __ptr_t memalign PP ((__malloc_size_t __alignment,
                             __malloc_size_t __size));
-extern int posix_memalign PP ((__ptr_t *, __malloc_size_t,
-                              __malloc_size_t size));
-#endif
-
-/* Allocate SIZE bytes on a page boundary.  */
-#if ! (defined (_MALLOC_INTERNAL) && defined (GMALLOC_INHIBIT_VALLOC))
-extern __ptr_t valloc PP ((__malloc_size_t __size));
-#endif
 
 #ifdef USE_PTHREAD
 /* Set up mutexes and make malloc etc. thread-safe.  */
@@ -173,7 +160,7 @@
 /* Free list headers for each fragment size.  */
 extern struct list _fraghead[];
 
-/* List of blocks allocated with `memalign' (or `valloc').  */
+/* List of blocks allocated with `memalign'.  */
 struct alignlist
   {
     struct alignlist *next;
@@ -305,24 +292,10 @@
 extern void memory_warnings PP ((__ptr_t __start,
                                 void (*__warnfun) PP ((const char *))));
 
-
-/* Relocating allocator.  */
-
-/* Allocate SIZE bytes, and store the address in *HANDLEPTR.  */
-extern __ptr_t r_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size));
-
-/* Free the storage allocated in HANDLEPTR.  */
-extern void r_alloc_free PP ((__ptr_t *__handleptr));
-
-/* Adjust the block at HANDLEPTR to be SIZE bytes long.  */
-extern __ptr_t r_re_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size));
-
-
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* malloc.h  */
 /* Memory allocator `malloc'.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
                  Written May 1989 by Mike Haertel.
@@ -453,10 +426,8 @@
 
 
 /* Aligned allocation.  */
-static __ptr_t align PP ((__malloc_size_t));
 static __ptr_t
-align (size)
-     __malloc_size_t size;
+align (__malloc_size_t size)
 {
   __ptr_t result;
   unsigned long int adj;
@@ -473,9 +444,8 @@
                                                  (char *) NULL)) % BLOCKSIZE;
   if (adj != 0)
     {
-      __ptr_t new;
       adj = BLOCKSIZE - adj;
-      new = (*__morecore) (adj);
+      (*__morecore) (adj);
       result = (char *) result + adj;
     }
 
@@ -488,11 +458,8 @@
 /* Get SIZE bytes, if we can get them starting at END.
    Return the address of the space we got.
    If we cannot get space at END, fail and return 0.  */
-static __ptr_t get_contiguous_space PP ((__malloc_ptrdiff_t, __ptr_t));
 static __ptr_t
-get_contiguous_space (size, position)
-     __malloc_ptrdiff_t size;
-     __ptr_t position;
+get_contiguous_space (__malloc_ptrdiff_t size, __ptr_t position)
 {
   __ptr_t before;
   __ptr_t after;
@@ -548,21 +515,21 @@
 int _malloc_thread_enabled_p;
 
 static void
-malloc_atfork_handler_prepare ()
+malloc_atfork_handler_prepare (void)
 {
   LOCK ();
   LOCK_ALIGNED_BLOCKS ();
 }
 
 static void
-malloc_atfork_handler_parent ()
+malloc_atfork_handler_parent (void)
 {
   UNLOCK_ALIGNED_BLOCKS ();
   UNLOCK ();
 }
 
 static void
-malloc_atfork_handler_child ()
+malloc_atfork_handler_child (void)
 {
   UNLOCK_ALIGNED_BLOCKS ();
   UNLOCK ();
@@ -570,7 +537,7 @@
 
 /* Set up mutexes and make malloc etc. thread-safe.  */
 void
-malloc_enable_thread ()
+malloc_enable_thread (void)
 {
   if (_malloc_thread_enabled_p)
     return;
@@ -589,7 +556,7 @@
 #endif
 
 static void
-malloc_initialize_1 ()
+malloc_initialize_1 (void)
 {
 #ifdef GC_MCHECK
   mcheck (NULL);
@@ -630,7 +597,7 @@
    main will call malloc which calls this function.  That is before any threads
    or signal handlers has been set up, so we don't need thread protection.  */
 int
-__malloc_initialize ()
+__malloc_initialize (void)
 {
   if (__malloc_initialized)
     return 0;
@@ -644,10 +611,8 @@
 
 /* Get neatly aligned memory, initializing or
    growing the heap info table as necessary. */
-static __ptr_t morecore_nolock PP ((__malloc_size_t));
 static __ptr_t
-morecore_nolock (size)
-     __malloc_size_t size;
+morecore_nolock (__malloc_size_t size)
 {
   __ptr_t result;
   malloc_info *newinfo, *oldinfo;
@@ -760,8 +725,7 @@
 
 /* Allocate memory from the heap.  */
 __ptr_t
-_malloc_internal_nolock (size)
-     __malloc_size_t size;
+_malloc_internal_nolock (__malloc_size_t size)
 {
   __ptr_t result;
   __malloc_size_t block, blocks, lastblocks, start;
@@ -960,8 +924,7 @@
 }
 
 __ptr_t
-_malloc_internal (size)
-     __malloc_size_t size;
+_malloc_internal (__malloc_size_t size)
 {
   __ptr_t result;
 
@@ -973,8 +936,7 @@
 }
 
 __ptr_t
-malloc (size)
-     __malloc_size_t size;
+malloc (__malloc_size_t size)
 {
   __ptr_t (*hook) (__malloc_size_t);
 
@@ -998,24 +960,24 @@
 /* On some ANSI C systems, some libc functions call _malloc, _free
    and _realloc.  Make them use the GNU functions.  */
 
+extern __ptr_t _malloc (__malloc_size_t);
+extern void _free (__ptr_t);
+extern __ptr_t _realloc (__ptr_t, __malloc_size_t);
+
 __ptr_t
-_malloc (size)
-     __malloc_size_t size;
+_malloc (__malloc_size_t size)
 {
   return malloc (size);
 }
 
 void
-_free (ptr)
-     __ptr_t ptr;
+_free (__ptr_t ptr)
 {
   free (ptr);
 }
 
 __ptr_t
-_realloc (ptr, size)
-     __ptr_t ptr;
-     __malloc_size_t size;
+_realloc (__ptr_t ptr, __malloc_size_t size)
 {
   return realloc (ptr, size);
 }
@@ -1058,8 +1020,7 @@
 /* Return memory to the heap.
    Like `_free_internal' but don't lock mutex.  */
 void
-_free_internal_nolock (ptr)
-     __ptr_t ptr;
+_free_internal_nolock (__ptr_t ptr)
 {
   int type;
   __malloc_size_t block, blocks;
@@ -1076,7 +1037,7 @@
     return;
 
 #ifdef CYGWIN
-  if (ptr < _heapbase)
+  if ((char *) ptr < _heapbase)
     /* We're being asked to free something in the static heap. */
     return;
 #endif
@@ -1313,8 +1274,7 @@
 /* Return memory to the heap.
    Like `free' but don't call a __free_hook if there is one.  */
 void
-_free_internal (ptr)
-     __ptr_t ptr;
+_free_internal (__ptr_t ptr)
 {
   LOCK ();
   _free_internal_nolock (ptr);
@@ -1324,8 +1284,7 @@
 /* Return memory to the heap.  */
 
 void
-free (ptr)
-     __ptr_t ptr;
+free (__ptr_t ptr)
 {
   void (*hook) (__ptr_t) = __free_hook;
 
@@ -1340,8 +1299,7 @@
 weak_alias (free, cfree)
 #else
 void
-cfree (ptr)
-     __ptr_t ptr;
+cfree (__ptr_t ptr)
 {
   free (ptr);
 }
@@ -1381,9 +1339,7 @@
    data.  */
 #ifdef CYGWIN
 __ptr_t
-special_realloc (ptr, size)
-     __ptr_t ptr;
-     __malloc_size_t size;
+special_realloc (__ptr_t ptr, __malloc_size_t size)
 {
   __ptr_t result;
   int type;
@@ -1411,9 +1367,7 @@
    new region.  This module has incestuous knowledge of the
    internals of both free and malloc. */
 __ptr_t
-_realloc_internal_nolock (ptr, size)
-     __ptr_t ptr;
-     __malloc_size_t size;
+_realloc_internal_nolock (__ptr_t ptr, __malloc_size_t size)
 {
   __ptr_t result;
   int type;
@@ -1428,7 +1382,7 @@
     return _malloc_internal_nolock (size);
 
 #ifdef CYGWIN
-  if (ptr < _heapbase)
+  if ((char *) ptr < _heapbase)
     /* ptr points into the static heap */
     return special_realloc (ptr, size);
 #endif
@@ -1535,9 +1489,7 @@
 }
 
 __ptr_t
-_realloc_internal (ptr, size)
-     __ptr_t ptr;
-     __malloc_size_t size;
+_realloc_internal (__ptr_t ptr, __malloc_size_t size)
 {
   __ptr_t result;
 
@@ -1549,9 +1501,7 @@
 }
 
 __ptr_t
-realloc (ptr, size)
-     __ptr_t ptr;
-     __malloc_size_t size;
+realloc (__ptr_t ptr, __malloc_size_t size)
 {
   __ptr_t (*hook) (__ptr_t, __malloc_size_t);
 
@@ -1589,9 +1539,7 @@
 /* Allocate an array of NMEMB elements each SIZE bytes long.
    The entire array is initialized to zeros.  */
 __ptr_t
-calloc (nmemb, size)
-     register __malloc_size_t nmemb;
-     register __malloc_size_t size;
+calloc (register __malloc_size_t nmemb, register __malloc_size_t size)
 {
   register __ptr_t result = malloc (nmemb * size);
 
@@ -1643,8 +1591,7 @@
    and return the start of data space, or NULL on errors.
    If INCREMENT is negative, shrink data space.  */
 __ptr_t
-__default_morecore (increment)
-     __malloc_ptrdiff_t increment;
+__default_morecore (__malloc_ptrdiff_t increment)
 {
   __ptr_t result;
 #if defined (CYGWIN)
@@ -1658,6 +1605,9 @@
     return NULL;
   return result;
 }
+
+#ifdef USE_POSIX_MEMALIGN
+
 /* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
 
 This library is free software; you can redistribute it and/or
@@ -1684,9 +1634,7 @@
                                __malloc_size_t __alignment));
 
 __ptr_t
-memalign (alignment, size)
-     __malloc_size_t alignment;
-     __malloc_size_t size;
+memalign (__malloc_size_t alignment, __malloc_size_t size)
 {
   __ptr_t result;
   unsigned long int adj, lastadj;
@@ -1767,10 +1715,8 @@
 #endif
 
 int
-posix_memalign (memptr, alignment, size)
-     __ptr_t *memptr;
-     __malloc_size_t alignment;
-     __malloc_size_t size;
+posix_memalign (__ptr_t *memptr, __malloc_size_t alignment,
+               __malloc_size_t size)
 {
   __ptr_t mem;
 
@@ -1787,70 +1733,7 @@
 
   return 0;
 }
-
-/* Allocate memory on a page boundary.
-   Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc.
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public
-License along with this library; see the file COPYING.  If
-not, write to the Free Software Foundation, Inc., 51 Franklin Street,
-Fifth Floor, Boston, MA 02110-1301, USA.
-
-   The author may be reached (Email) at the address address@hidden,
-   or (US mail) as Mike Haertel c/o Free Software Foundation.  */
-
-#if defined (_MALLOC_INTERNAL) && defined (GMALLOC_INHIBIT_VALLOC)
-
-/* Emacs defines GMALLOC_INHIBIT_VALLOC to avoid this definition
-   on MSDOS, where it conflicts with a system header file.  */
-
-#define ELIDE_VALLOC
-
-#endif
-
-#ifndef        ELIDE_VALLOC
-
-#if defined (__GNU_LIBRARY__) || defined (_LIBC)
-#include <stddef.h>
-#include <sys/cdefs.h>
-#if defined (__GLIBC__) && __GLIBC__ >= 2
-/* __getpagesize is already declared in <unistd.h> with return type int */
-#else
-extern size_t __getpagesize PP ((void));
-#endif
-#else
-#include "getpagesize.h"
-#define         __getpagesize()        getpagesize ()
-#endif
-
-#ifndef        _MALLOC_INTERNAL
-#define        _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-static __malloc_size_t pagesize;
-
-__ptr_t
-valloc (size)
-     __malloc_size_t size;
-{
-  if (pagesize == 0)
-    pagesize = __getpagesize ();
-
-  return memalign (pagesize, size);
-}
-
-#endif /* Not ELIDE_VALLOC.  */
+#endif /* USE_POSIX_MEMALIGN */
 
 #ifdef GC_MCHECK
 
@@ -1933,10 +1816,8 @@
   return status;
 }
 
-static void freehook (__ptr_t);
 static void
-freehook (ptr)
-     __ptr_t ptr;
+freehook (__ptr_t ptr)
 {
   struct hdr *hdr;
 
@@ -1955,10 +1836,8 @@
   __free_hook = freehook;
 }
 
-static __ptr_t mallochook (__malloc_size_t);
 static __ptr_t
-mallochook (size)
-     __malloc_size_t size;
+mallochook (__malloc_size_t size)
 {
   struct hdr *hdr;
 
@@ -1975,11 +1854,8 @@
   return (__ptr_t) (hdr + 1);
 }
 
-static __ptr_t reallochook (__ptr_t, __malloc_size_t);
 static __ptr_t
-reallochook (ptr, size)
-     __ptr_t ptr;
-     __malloc_size_t size;
+reallochook (__ptr_t ptr, __malloc_size_t size)
 {
   struct hdr *hdr = NULL;
   __malloc_size_t osize = 0;

=== modified file 'src/lisp.h'
--- src/lisp.h  2011-12-05 00:15:15 +0000
+++ src/lisp.h  2011-12-31 19:26:02 +0000
@@ -2835,6 +2835,14 @@
 extern struct buffer * allocate_buffer (void);
 extern int valid_lisp_object_p (Lisp_Object);
 
+#ifdef REL_ALLOC
+/* Defined in ralloc.c */
+extern POINTER_TYPE *r_alloc (POINTER_TYPE **, size_t);
+extern POINTER_TYPE r_alloc_free (POINTER_TYPE **);
+extern POINTER_TYPE *r_re_alloc (POINTER_TYPE **, size_t);
+void r_alloc_reset_variable (POINTER_TYPE **old, POINTER_TYPE **new);
+#endif
+
 /* Defined in chartab.c */
 EXFUN (Fmake_char_table, 2);
 EXFUN (Fset_char_table_parent, 2);

=== modified file 'src/m/ia64.h'
--- src/m/ia64.h        2011-04-19 00:34:42 +0000
+++ src/m/ia64.h        2011-12-31 19:23:14 +0000
@@ -30,13 +30,3 @@
 #define EMACS_INT              long
 #define pI                     "l"
 #define EMACS_UINT             unsigned long
-
-#ifdef REL_ALLOC
-#ifndef _MALLOC_INTERNAL
-/* "char *" because ralloc.c defines it that way.  gmalloc.c thinks it
-   is allowed to prototype these as "void *" so we don't prototype in
-   that case.  You're right: it stinks!  */
-extern char *r_alloc (), *r_re_alloc ();
-extern void r_alloc_free ();
-#endif /* not _MALLOC_INTERNAL */
-#endif /* REL_ALLOC */

=== modified file 'src/ralloc.c'
--- src/ralloc.c        2011-11-15 00:54:19 +0000
+++ src/ralloc.c        2011-12-31 19:22:20 +0000
@@ -95,10 +95,8 @@
 /* Macros for rounding.  Note that rounding to any value is possible
    by changing the definition of PAGE.  */
 #define PAGE (getpagesize ())
-#define ALIGNED(addr) (((unsigned long int) (addr) & (page_size - 1)) == 0)
 #define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \
                       & ~(page_size - 1))
-#define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1)))
 
 #define MEM_ALIGN sizeof (double)
 #define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \
@@ -151,7 +149,6 @@
 } *heap_ptr;
 
 #define NIL_HEAP ((heap_ptr) 0)
-#define HEAP_PTR_SIZE (sizeof (struct heap))
 
 /* This is the first heap object.
    If we need additional heap objects, each one resides at the beginning of
@@ -366,15 +363,6 @@
        }
     }
 }
-
-/* Return the total size in use by relocating allocator,
-   above where malloc gets space.  */
-
-long
-r_alloc_size_in_use (void)
-{
-  return (char *) break_value - (char *) virtual_break_value;
-}
 
 /* The meat - allocating, freeing, and relocating blocs.  */
 
@@ -745,7 +733,7 @@
    __morecore hook values - in particular, __default_morecore in the
    GNU malloc package.  */
 
-POINTER
+static POINTER
 r_alloc_sbrk (long int size)
 {
   register bloc_ptr b;
@@ -1009,52 +997,6 @@
   return *ptr;
 }
 
-/* Disable relocations, after making room for at least SIZE bytes
-   of non-relocatable heap if possible.  The relocatable blocs are
-   guaranteed to hold still until thawed, even if this means that
-   malloc must return a null pointer.  */
-
-void
-r_alloc_freeze (long int size)
-{
-  if (! r_alloc_initialized)
-    r_alloc_init ();
-
-  /* If already frozen, we can't make any more room, so don't try.  */
-  if (r_alloc_freeze_level > 0)
-    size = 0;
-  /* If we can't get the amount requested, half is better than nothing.  */
-  while (size > 0 && r_alloc_sbrk (size) == 0)
-    size /= 2;
-  ++r_alloc_freeze_level;
-  if (size > 0)
-    r_alloc_sbrk (-size);
-}
-
-void
-r_alloc_thaw (void)
-{
-
-  if (! r_alloc_initialized)
-    r_alloc_init ();
-
-  if (--r_alloc_freeze_level < 0)
-    abort ();
-
-  /* This frees all unused blocs.  It is not too inefficient, as the resize
-     and memcpy is done only once.  Afterwards, all unreferenced blocs are
-     already shrunk to zero size.  */
-  if (!r_alloc_freeze_level)
-    {
-      bloc_ptr *b = &first_bloc;
-      while (*b)
-       if (!(*b)->variable)
-         free_bloc (*b);
-       else
-         b = &(*b)->next;
-    }
-}
-
 
 #if defined (emacs) && defined (DOUG_LEA_MALLOC)
 

=== modified file 'src/s/msdos.h'
--- src/s/msdos.h       2011-11-14 20:23:26 +0000
+++ src/s/msdos.h       2011-12-31 19:57:51 +0000
@@ -48,10 +48,6 @@
    different things on your system and must be used only through an
    encapsulation (which you should place, by convention, in sysdep.c).  */
 
-/* Avoid incompatibilities between gmalloc.c and system header files
-   in how to declare valloc.  */
-#define GMALLOC_INHIBIT_VALLOC
-
 /* This overrides the default value on editfns.c, since DJGPP
    does not have pw->pw_gecos.  */
 #define USER_FULL_NAME (getenv ("NAME"))

=== modified file 'src/unexcw.c'
--- src/unexcw.c        2011-08-16 13:27:12 +0000
+++ src/unexcw.c        2011-12-31 18:37:05 +0000
@@ -31,6 +31,8 @@
 
 #define DOTEXE ".exe"
 
+extern void report_sheap_usage (int);
+
 extern int bss_sbrk_did_unexec;
 
 extern int __malloc_initialized;




reply via email to

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