|
From: <cli...@li...> - 2010-12-10 17:01:24
|
Send clisp-cvs mailing list submissions to cli...@li... To subscribe or unsubscribe via the World Wide Web, visit https://lists.sourceforge.net/lists/listinfo/clisp-cvs or, via email, send a message with subject or body 'help' to cli...@li... You can reach the person managing the list at cli...@li... When replying, please edit your Subject line so it is more specific than "Re: Contents of clisp-cvs digest..." CLISP CVS commits for today Today's Topics: 1. clisp Makefile.devel,1.286,1.287 (Sam Steingold) 2. clisp/src ChangeLog,1.7582,1.7583 (Sam Steingold) 3. clisp/emacs misc.el,1.8,1.9 (Sam Steingold) 4. clisp/modules/asdf asdf.lisp,1.1,1.2 (Sam Steingold) 5. clisp/src ChangeLog,1.7583,1.7584 (Sam Steingold) 6. clisp/src ChangeLog,1.7584,1.7585 gmalloc.c,1.1,1.2 (Sam Steingold) ---------------------------------------------------------------------- Message: 1 Date: Fri, 10 Dec 2010 16:55:33 +0000 From: Sam Steingold <sd...@us...> Subject: clisp Makefile.devel,1.286,1.287 To: cli...@li... Message-ID: <E1P...@sf...> Update of /cvsroot/clisp/clisp In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv7646 Modified Files: Makefile.devel Log Message: * Makefile.devel (update-gmalloc): new target: get gmalloc.c from emacs Index: Makefile.devel =================================================================== RCS file: /cvsroot/clisp/clisp/Makefile.devel,v retrieving revision 1.286 retrieving revision 1.287 diff -u -d -r1.286 -r1.287 --- Makefile.devel 29 Sep 2010 18:31:09 -0000 1.286 +++ Makefile.devel 10 Dec 2010 16:55:31 -0000 1.287 @@ -13,7 +13,7 @@ CTAGS = ctags .PHONY : all build-prerequisites htmldoc makefiles configures check-configures \ - update-ansi-tests update-asdf potfiles fixperms \ + update-ansi-tests update-asdf update-gmalloc potfiles fixperms \ view-man view-html check-sbcl install-gcc \ multibuild-linux-x86 multibuild-darwin-powerpc \ build-aux-update gnulib-imported distrib release pre-release \ @@ -338,6 +338,10 @@ update-asdf : force wget -O modules/asdf/asdf.lisp $(ASDF_URL) +GMALLOC_URL = http://git.savannah.gnu.org/cgit/emacs.git/plain/src/gmalloc.c +update-gmalloc : force + wget -O src/gmalloc.c $(GMALLOC_URL) + # it is important to get ltmain.sh and libtool.m4 from the same version of # libtool. Don't rely on what's installed in /usr/share or similar. LIBTOOL_VERSION = 2.2.8 @@ -437,7 +441,7 @@ # 2-3 weeks before a release # manually: check for new versions of # libsvm, netica api, postgresql, berkeley-db, dbus, pcre, readline -pre-release : gnulib-imported build-aux-update update-asdf tp-mail +pre-release : gnulib-imported build-aux-update update-asdf update-gmalloc tp-mail ## RELEASE TODO: # Before doing a "make distrib": ------------------------------ Message: 2 Date: Fri, 10 Dec 2010 16:55:34 +0000 From: Sam Steingold <sd...@us...> Subject: clisp/src ChangeLog,1.7582,1.7583 To: cli...@li... Message-ID: <E1P...@sf...> Update of /cvsroot/clisp/clisp/src In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv7646/src Modified Files: ChangeLog Log Message: * Makefile.devel (update-gmalloc): new target: get gmalloc.c from emacs Index: ChangeLog =================================================================== RCS file: /cvsroot/clisp/clisp/src/ChangeLog,v retrieving revision 1.7582 retrieving revision 1.7583 diff -u -d -r1.7582 -r1.7583 --- ChangeLog 2 Dec 2010 23:33:49 -0000 1.7582 +++ ChangeLog 10 Dec 2010 16:55:31 -0000 1.7583 @@ -1,3 +1,7 @@ +2010-12-10 Sam Steingold <sd...@gn...> + + * Makefile.devel (update-gmalloc): new target: get gmalloc.c from emacs + 2010-12-02 Sam Steingold <sd...@gn...> * defs1.lisp (load-path-augmentations): delete NILs ------------------------------ Message: 3 Date: Fri, 10 Dec 2010 16:56:30 +0000 From: Sam Steingold <sd...@us...> Subject: clisp/emacs misc.el,1.8,1.9 To: cli...@li... Message-ID: <E1P...@sf...> Update of /cvsroot/clisp/clisp/emacs In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv7784 Modified Files: misc.el Log Message: clisp-nxml-mode-hook: add Index: misc.el =================================================================== RCS file: /cvsroot/clisp/clisp/emacs/misc.el,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- misc.el 28 Apr 2010 16:12:56 -0000 1.8 +++ misc.el 10 Dec 2010 16:56:28 -0000 1.9 @@ -49,3 +49,24 @@ (t (error "unknown bug kind [%s]" kind)))))) (put 'clisp-bug-reference-url-format 'bug-reference-url-format t) + +(autoload 'rng-dtd-trivial-p "rng-valid") +(autoload 'nxml-parent-document-set "nxml-mode") +(defun clisp-nxml-mode-hook () + "Set `nxml-mode-hook' for clisp impnotes." + (when (and (null nxml-parent-document) + (rng-dtd-trivial-p rng-dtd) + (eq (vc-backend buffer-file-name) 'CVS)) + (let ((dir (file-name-directory buffer-file-name)) parent) + (when (clisp-repo-p dir) + (cond ((file-exists-p + (setq parent (expand-file-name "impnotes.xml.in" dir))) + (unless (string= parent buffer-file-name) + (nxml-parent-document-set parent))) + ((file-exists-p + (setq parent (expand-file-name "doc/impnotes.xml.in" + (locate-dominating-file + dir "ANNOUNCE")))) + (nxml-parent-document-set parent)) + (t (message "Cannot find parent document"))))))) +(add-hook 'nxml-mode-hook 'clisp-nxml-mode-hook) ------------------------------ Message: 4 Date: Fri, 10 Dec 2010 16:59:48 +0000 From: Sam Steingold <sd...@us...> Subject: clisp/modules/asdf asdf.lisp,1.1,1.2 To: cli...@li... Message-ID: <E1P...@sf...> Update of /cvsroot/clisp/clisp/modules/asdf In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv8253/modules/asdf Modified Files: asdf.lisp Log Message: update to upstream "2.011" Index: asdf.lisp =================================================================== RCS file: /cvsroot/clisp/clisp/modules/asdf/asdf.lisp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- asdf.lisp 14 Sep 2010 18:28:42 -0000 1.1 +++ asdf.lisp 10 Dec 2010 16:59:46 -0000 1.2 @@ -47,7 +47,9 @@ #+xcvb (module ()) -(cl:in-package :cl) +(cl:in-package :cl-user) + +#+gcl (defpackage :asdf (:use :cl)) ;; GCL treats defpackage magically and needs this (eval-when (:compile-toplevel :load-toplevel :execute) ;;; make package if it doesn't exist yet. @@ -55,7 +57,7 @@ [...1275 lines suppressed...] (setf *source-registry-exclusions* rest)) ((:also-exclude) @@ -3459,7 +3573,7 @@ (clear-output-translations)) ;;;; ----------------------------------------------------------------- -;;;; Hook into REQUIRE for ABCL, ClozureCL, CMUCL, ECL and SBCL +;;;; Hook into REQUIRE for ABCL, CLISP, ClozureCL, CMUCL, ECL and SBCL ;;;; (defun* module-provide-asdf (name) (handler-bind @@ -3475,7 +3589,7 @@ t)))) #+(or abcl clisp clozure cmu ecl sbcl) -(let ((x (and #+clisp (find-symbol "*MODULE-PROVIDER-FUNCTIONS*" :custom)))) +(let ((x (and #+clisp (find-symbol* '#:*module-provider-functions* :custom)))) (when x (eval `(pushnew 'module-provide-asdf #+abcl sys::*module-provider-functions* ------------------------------ Message: 5 Date: Fri, 10 Dec 2010 16:59:48 +0000 From: Sam Steingold <sd...@us...> Subject: clisp/src ChangeLog,1.7583,1.7584 To: cli...@li... Message-ID: <E1P...@sf...> Update of /cvsroot/clisp/clisp/src In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv8253/src Modified Files: ChangeLog Log Message: update to upstream "2.011" Index: ChangeLog =================================================================== RCS file: /cvsroot/clisp/clisp/src/ChangeLog,v retrieving revision 1.7583 retrieving revision 1.7584 diff -u -d -r1.7583 -r1.7584 --- ChangeLog 10 Dec 2010 16:55:31 -0000 1.7583 +++ ChangeLog 10 Dec 2010 16:59:46 -0000 1.7584 @@ -1,5 +1,9 @@ 2010-12-10 Sam Steingold <sd...@gn...> + * modules/asdf/asdf.lisp: update to upstream "2.011" + +2010-12-10 Sam Steingold <sd...@gn...> + * Makefile.devel (update-gmalloc): new target: get gmalloc.c from emacs 2010-12-02 Sam Steingold <sd...@gn...> ------------------------------ Message: 6 Date: Fri, 10 Dec 2010 17:01:14 +0000 From: Sam Steingold <sd...@us...> Subject: clisp/src ChangeLog,1.7584,1.7585 gmalloc.c,1.1,1.2 To: cli...@li... Message-ID: <E1P...@sf...> Update of /cvsroot/clisp/clisp/src In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv8850/src Modified Files: ChangeLog gmalloc.c Log Message: * src/gmalloc.c: update to upstream Index: gmalloc.c =================================================================== RCS file: /cvsroot/clisp/clisp/src/gmalloc.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- gmalloc.c 12 Oct 2010 16:51:26 -0000 1.1 +++ gmalloc.c 10 Dec 2010 17:01:12 -0000 1.2 @@ -1,15 +1,12 @@ /* This file is no longer automatically generated from libc. */ #define _MALLOC_INTERNAL -#ifdef HAVE_GTK_AND_PTHREAD -#define USE_PTHREAD -#endif /* The malloc headers and source files from the C library follow here. */ /* Declarations for `malloc' and friends. Copyright (C) 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2002, 2003, 2004, - 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + 2005, 2006, 2007 Free Software Foundation, Inc. Written May 1989 by Mike Haertel. This library is free software; you can redistribute it and/or @@ -40,13 +37,33 @@ #include <config.h> #endif -/* Assume C++ or ANSI C. */ +#ifdef HAVE_GTK_AND_PTHREAD +#define USE_PTHREAD +#endif + +#if ((defined __cplusplus || (defined (__STDC__) && __STDC__) \ + || defined STDC_HEADERS || defined PROTOTYPES)) #undef PP #define PP(args) args #undef __ptr_t #define __ptr_t void * +#else /* Not C++ or ANSI C. */ +#undef PP +#define PP(args) () +#undef __ptr_t +#define __ptr_t char * +#endif /* C++ or ANSI C. */ +#if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) #include <string.h> +#else +#ifndef memset +#define memset(s, zero, n) bzero ((s), (n)) +#endif +#ifndef memcpy +#define memcpy(d, s, n) bcopy ((s), (d), (n)) +#endif +#endif #ifdef HAVE_LIMITS_H #include <limits.h> @@ -71,18 +88,27 @@ { #endif +#ifdef STDC_HEADERS #include <stddef.h> #define __malloc_size_t size_t #define __malloc_ptrdiff_t ptrdiff_t +#else +#ifdef __GNUC__ +#include <stddef.h> +#ifdef __SIZE_TYPE__ +#define __malloc_size_t __SIZE_TYPE__ +#endif +#endif +#ifndef __malloc_size_t +#define __malloc_size_t unsigned int +#endif +#define __malloc_ptrdiff_t int +#endif #ifndef NULL #define NULL 0 #endif -#ifndef FREE_RETURN_TYPE -#define FREE_RETURN_TYPE void -#endif - /* Allocate SIZE bytes of memory. */ extern __ptr_t malloc PP ((__malloc_size_t __size)); @@ -92,12 +118,14 @@ /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ extern __ptr_t calloc PP ((__malloc_size_t __nmemb, __malloc_size_t __size)); /* Free a block allocated by `malloc', `realloc' or `calloc'. */ -extern FREE_RETURN_TYPE free PP ((__ptr_t __ptr)); +extern void free PP ((__ptr_t __ptr)); /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ -#if ! (defined (_MALLOC_INTERNAL) && __DJGPP__ - 0 == 1) /* Avoid conflict. */ +#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. */ @@ -105,6 +133,10 @@ extern __ptr_t valloc PP ((__malloc_size_t __size)); #endif +#ifdef USE_PTHREAD +/* Set up mutexes and make malloc etc. thread-safe. */ +extern void malloc_enable_thread PP ((void)); +#endif #ifdef _MALLOC_INTERNAL @@ -205,14 +237,38 @@ extern __ptr_t _malloc_internal PP ((__malloc_size_t __size)); extern __ptr_t _realloc_internal PP ((__ptr_t __ptr, __malloc_size_t __size)); extern void _free_internal PP ((__ptr_t __ptr)); +extern __ptr_t _malloc_internal_nolock PP ((__malloc_size_t __size)); +extern __ptr_t _realloc_internal_nolock PP ((__ptr_t __ptr, __malloc_size_t __size)); +extern void _free_internal_nolock PP ((__ptr_t __ptr)); #ifdef USE_PTHREAD -extern pthread_mutex_t _malloc_mutex; -#define LOCK() pthread_mutex_lock (&_malloc_mutex) -#define UNLOCK() pthread_mutex_unlock (&_malloc_mutex) +extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex; +extern int _malloc_thread_enabled_p; +#define LOCK() \ + do { \ + if (_malloc_thread_enabled_p) \ + pthread_mutex_lock (&_malloc_mutex); \ + } while (0) +#define UNLOCK() \ + do { \ + if (_malloc_thread_enabled_p) \ + pthread_mutex_unlock (&_malloc_mutex); \ + } while (0) +#define LOCK_ALIGNED_BLOCKS() \ + do { \ + if (_malloc_thread_enabled_p) \ + pthread_mutex_lock (&_aligned_blocks_mutex); \ + } while (0) +#define UNLOCK_ALIGNED_BLOCKS() \ + do { \ + if (_malloc_thread_enabled_p) \ + pthread_mutex_unlock (&_aligned_blocks_mutex); \ + } while (0) #else #define LOCK() #define UNLOCK() +#define LOCK_ALIGNED_BLOCKS() +#define UNLOCK_ALIGNED_BLOCKS() #endif #endif /* _MALLOC_INTERNAL. */ @@ -523,8 +579,49 @@ } #ifdef USE_PTHREAD -static pthread_once_t malloc_init_once_control = PTHREAD_ONCE_INIT; -pthread_mutex_t _malloc_mutex; +pthread_mutex_t _malloc_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER; +int _malloc_thread_enabled_p; + +static void +malloc_atfork_handler_prepare () +{ + LOCK (); + LOCK_ALIGNED_BLOCKS (); +} + +static void +malloc_atfork_handler_parent () +{ + UNLOCK_ALIGNED_BLOCKS (); + UNLOCK (); +} + +static void +malloc_atfork_handler_child () +{ + UNLOCK_ALIGNED_BLOCKS (); + UNLOCK (); +} + +/* Set up mutexes and make malloc etc. thread-safe. */ +void +malloc_enable_thread () +{ + if (_malloc_thread_enabled_p) + return; + + /* Some pthread implementations call malloc for statically + initialized mutexes when they are used first. To avoid such a + situation, we initialize mutexes here while their use is + disabled in malloc etc. */ + pthread_mutex_init (&_malloc_mutex, NULL); + pthread_mutex_init (&_aligned_blocks_mutex, NULL); + pthread_atfork (malloc_atfork_handler_prepare, + malloc_atfork_handler_parent, + malloc_atfork_handler_child); + _malloc_thread_enabled_p = 1; +} #endif static void @@ -537,17 +634,6 @@ if (__malloc_initialize_hook) (*__malloc_initialize_hook) (); -#ifdef USE_PTHREAD - { - pthread_mutexattr_t attr; - - pthread_mutexattr_init (&attr); - pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init (&_malloc_mutex, &attr); - pthread_mutexattr_destroy (&attr); - } -#endif - heapsize = HEAP / BLOCKSIZE; _heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info)); if (_heapinfo == NULL) @@ -566,18 +652,16 @@ return; } -/* Set everything up and remember that we have. */ +/* Set everything up and remember that we have. + 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 () { -#ifdef USE_PTHREAD - pthread_once (&malloc_init_once_control, malloc_initialize_1); -#else if (__malloc_initialized) return 0; malloc_initialize_1 (); -#endif return __malloc_initialized; } @@ -586,9 +670,9 @@ /* Get neatly aligned memory, initializing or growing the heap info table as necessary. */ -static __ptr_t morecore PP ((__malloc_size_t)); +static __ptr_t morecore_nolock PP ((__malloc_size_t)); static __ptr_t -morecore (size) +morecore_nolock (size) __malloc_size_t size; { __ptr_t result; @@ -631,7 +715,7 @@ `morecore_recursing' flag and return null. */ int save = errno; /* Don't want to clobber errno with ENOMEM. */ morecore_recursing = 1; - newinfo = (malloc_info *) _realloc_internal + newinfo = (malloc_info *) _realloc_internal_nolock (_heapinfo, newsize * sizeof (malloc_info)); morecore_recursing = 0; if (newinfo == NULL) @@ -687,7 +771,7 @@ /* Reset _heaplimit so _free_internal never decides it can relocate or resize the info table. */ _heaplimit = 0; - _free_internal (oldinfo); + _free_internal_nolock (oldinfo); PROTECT_MALLOC_STATE (0); /* The new heap limit includes the new table just allocated. */ @@ -702,7 +786,7 @@ /* Allocate memory from the heap. */ __ptr_t -_malloc_internal (size) +_malloc_internal_nolock (size) __malloc_size_t size; { __ptr_t result; @@ -722,17 +806,11 @@ return NULL; #endif - LOCK (); PROTECT_MALLOC_STATE (0); if (size < sizeof (struct list)) size = sizeof (struct list); -#ifdef SUNOS_LOCALTIME_BUG - if (size < 16) - size = 16; -#endif - /* Determine the allocation policy based on the request size. */ if (size <= BLOCKSIZE / 2) { @@ -772,8 +850,10 @@ /* No free fragments of the desired size, so get a new block and break it into fragments, returning the first. */ #ifdef GC_MALLOC_CHECK - result = _malloc_internal (BLOCKSIZE); + result = _malloc_internal_nolock (BLOCKSIZE); PROTECT_MALLOC_STATE (0); +#elif defined (USE_PTHREAD) + result = _malloc_internal_nolock (BLOCKSIZE); #else result = malloc (BLOCKSIZE); #endif @@ -830,7 +910,7 @@ final free block; if so we don't need to get as much. */ if (_heaplimit != 0 && block + lastblocks == _heaplimit && /* We can't do this if we will have to make the heap info - table bigger to accomodate the new space. */ + table bigger to accommodate the new space. */ block + wantblocks <= heapsize && get_contiguous_space ((wantblocks - lastblocks) * BLOCKSIZE, ADDRESS (block + lastblocks))) @@ -844,7 +924,7 @@ _heaplimit += wantblocks - lastblocks; continue; } - result = morecore (wantblocks * BLOCKSIZE); + result = morecore_nolock (wantblocks * BLOCKSIZE); if (result == NULL) goto out; block = BLOCK (result); @@ -902,7 +982,19 @@ PROTECT_MALLOC_STATE (1); out: + return result; +} + +__ptr_t +_malloc_internal (size) + __malloc_size_t size; +{ + __ptr_t result; + + LOCK (); + result = _malloc_internal_nolock (size); UNLOCK (); + return result; } @@ -910,10 +1002,21 @@ malloc (size) __malloc_size_t size; { + __ptr_t (*hook) (__malloc_size_t); + if (!__malloc_initialized && !__malloc_initialize ()) return NULL; - return (__malloc_hook != NULL ? *__malloc_hook : _malloc_internal) (size); + /* Copy the value of __malloc_hook to an automatic variable in case + __malloc_hook is modified in another thread between its + NULL-check and the use. + + Note: Strictly speaking, this is not a right solution. We should + use mutexes to access non-read-only variables that are shared + among multiple threads. We just leave it for compatibility with + glibc malloc (i.e., assignments to __malloc_hook) for now. */ + hook = __malloc_hook; + return (hook != NULL ? *hook : _malloc_internal) (size); } #ifndef _LIBC @@ -972,6 +1075,20 @@ #endif +/* Cope with systems lacking `memmove'. */ +#ifndef memmove +#if (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) +#ifdef emacs +#undef __malloc_safe_bcopy +#define __malloc_safe_bcopy safe_bcopy +#endif +/* This function is defined in realloc.c. */ +extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t)); +#define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) +#endif +#endif + + /* Debugging hook for free. */ void (*__free_hook) PP ((__ptr_t __ptr)); @@ -979,9 +1096,9 @@ struct alignlist *_aligned_blocks = NULL; /* Return memory to the heap. - Like `free' but don't call a __free_hook if there is one. */ + Like `_free_internal' but don't lock mutex. */ void -_free_internal (ptr) +_free_internal_nolock (ptr) __ptr_t ptr; { int type; @@ -998,9 +1115,9 @@ if (ptr == NULL) return; - LOCK (); PROTECT_MALLOC_STATE (0); + LOCK_ALIGNED_BLOCKS (); for (l = _aligned_blocks; l != NULL; l = l->next) if (l->aligned == ptr) { @@ -1008,6 +1125,7 @@ ptr = l->exact; break; } + UNLOCK_ALIGNED_BLOCKS (); block = BLOCK (ptr); @@ -1113,7 +1231,7 @@ table's blocks to the system before we have copied them to the new location. */ _heaplimit = 0; - _free_internal (_heapinfo); + _free_internal_nolock (_heapinfo); _heaplimit = oldlimit; /* Tell malloc to search from the beginning of the heap for @@ -1121,8 +1239,8 @@ _heapindex = 0; /* Allocate new space for the info table and move its data. */ - newinfo = (malloc_info *) _malloc_internal (info_blocks - * BLOCKSIZE); + newinfo = (malloc_info *) _malloc_internal_nolock (info_blocks + * BLOCKSIZE); PROTECT_MALLOC_STATE (0); memmove (newinfo, _heapinfo, info_blocks * BLOCKSIZE); _heapinfo = newinfo; @@ -1185,8 +1303,8 @@ _chunks_free -= BLOCKSIZE >> type; _bytes_free -= BLOCKSIZE; -#ifdef GC_MALLOC_CHECK - _free_internal (ADDRESS (block)); +#if defined (GC_MALLOC_CHECK) || defined (USE_PTHREAD) + _free_internal_nolock (ADDRESS (block)); #else free (ADDRESS (block)); #endif @@ -1224,17 +1342,29 @@ } PROTECT_MALLOC_STATE (1); +} + +/* 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; +{ + LOCK (); + _free_internal_nolock (ptr); UNLOCK (); } /* Return memory to the heap. */ -FREE_RETURN_TYPE +void free (ptr) __ptr_t ptr; { - if (__free_hook != NULL) - (*__free_hook) (ptr); + void (*hook) (__ptr_t) = __free_hook; + + if (hook != NULL) + (*hook) (ptr); else _free_internal (ptr); } @@ -1278,6 +1408,85 @@ #endif + +/* Cope with systems lacking `memmove'. */ +#if (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) + +#ifdef emacs +#undef __malloc_safe_bcopy +#define __malloc_safe_bcopy safe_bcopy +#else + +/* Snarfed directly from Emacs src/dispnew.c: + XXX Should use system bcopy if it handles overlap. */ + +/* Like bcopy except never gets confused by overlap. */ + +void +__malloc_safe_bcopy (afrom, ato, size) + __ptr_t afrom; + __ptr_t ato; + __malloc_size_t size; +{ + char *from = afrom, *to = ato; + + if (size <= 0 || from == to) + return; + + /* If the source and destination don't overlap, then bcopy can + handle it. If they do overlap, but the destination is lower in + memory than the source, we'll assume bcopy can handle that. */ + if (to < from || from + size <= to) + bcopy (from, to, size); + + /* Otherwise, we'll copy from the end. */ + else + { + register char *endf = from + size; + register char *endt = to + size; + + /* If TO - FROM is large, then we should break the copy into + nonoverlapping chunks of TO - FROM bytes each. However, if + TO - FROM is small, then the bcopy function call overhead + makes this not worth it. The crossover point could be about + anywhere. Since I don't think the obvious copy loop is too + bad, I'm trying to err in its favor. */ + if (to - from < 64) + { + do + *--endt = *--endf; + while (endf != from); + } + else + { + for (;;) + { + endt -= (to - from); + endf -= (to - from); + + if (endt < to) + break; + + bcopy (endf, endt, to - from); + } + + /* If SIZE wasn't a multiple of TO - FROM, there will be a + little left over. The amount left over is + (endt + (to - from)) - to, which is endt - from. */ + bcopy (from, to, endt - from); + } + } +} +#endif /* emacs */ + +#ifndef memmove +extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t)); +#define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) +#endif + +#endif + + #define min(A, B) ((A) < (B) ? (A) : (B)) /* Debugging hook for realloc. */ @@ -1290,7 +1499,7 @@ new region. This module has incestuous knowledge of the internals of both free and malloc. */ __ptr_t -_realloc_internal (ptr, size) +_realloc_internal_nolock (ptr, size) __ptr_t ptr; __malloc_size_t size; { @@ -1300,15 +1509,14 @@ if (size == 0) { - _free_internal (ptr); - return _malloc_internal (0); + _free_internal_nolock (ptr); + return _malloc_internal_nolock (0); } else if (ptr == NULL) - return _malloc_internal (size); + return _malloc_internal_nolock (size); block = BLOCK (ptr); - LOCK (); PROTECT_MALLOC_STATE (0); type = _heapinfo[block].busy.type; @@ -1318,11 +1526,11 @@ /* Maybe reallocate a large block to a small fragment. */ if (size <= BLOCKSIZE / 2) { - result = _malloc_internal (size); + result = _malloc_internal_nolock (size); if (result != NULL) { memcpy (result, ptr, size); - _free_internal (ptr); + _free_internal_nolock (ptr); goto out; } } @@ -1342,7 +1550,7 @@ Now we will free this chunk; increment the statistics counter so it doesn't become wrong when _free_internal decrements it. */ ++_chunks_used; - _free_internal (ADDRESS (block + blocks)); + _free_internal_nolock (ADDRESS (block + blocks)); result = ptr; } else if (blocks == _heapinfo[block].busy.info.size) @@ -1357,8 +1565,8 @@ /* Prevent free from actually returning memory to the system. */ oldlimit = _heaplimit; _heaplimit = 0; - _free_internal (ptr); - result = _malloc_internal (size); + _free_internal_nolock (ptr); + result = _malloc_internal_nolock (size); PROTECT_MALLOC_STATE (0); if (_heaplimit == 0) _heaplimit = oldlimit; @@ -1368,13 +1576,13 @@ the thing we just freed. Unfortunately it might have been coalesced with its neighbors. */ if (_heapindex == block) - (void) _malloc_internal (blocks * BLOCKSIZE); + (void) _malloc_internal_nolock (blocks * BLOCKSIZE); else { __ptr_t previous - = _malloc_internal ((block - _heapindex) * BLOCKSIZE); - (void) _malloc_internal (blocks * BLOCKSIZE); - _free_internal (previous); + = _malloc_internal_nolock ((block - _heapindex) * BLOCKSIZE); + (void) _malloc_internal_nolock (blocks * BLOCKSIZE); + _free_internal_nolock (previous); } goto out; } @@ -1394,18 +1602,31 @@ { /* The new size is different; allocate a new space, and copy the lesser of the new size and the old. */ - result = _malloc_internal (size); + result = _malloc_internal_nolock (size); if (result == NULL) goto out; memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type)); - _free_internal (ptr); + _free_internal_nolock (ptr); } break; } PROTECT_MALLOC_STATE (1); out: + return result; +} + +__ptr_t +_realloc_internal (ptr, size) + __ptr_t ptr; + __malloc_size_t size; +{ + __ptr_t result; + + LOCK(); + result = _realloc_internal_nolock (ptr, size); UNLOCK (); + return result; } @@ -1414,11 +1635,13 @@ __ptr_t ptr; __malloc_size_t size; { + __ptr_t (*hook) (__ptr_t, __malloc_size_t); + if (!__malloc_initialized && !__malloc_initialize ()) return NULL; - return (__realloc_hook != NULL ? *__realloc_hook : _realloc_internal) - (ptr, size); + hook = __realloc_hook; + return (hook != NULL ? *hook : _realloc_internal) (ptr, size); } /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc. @@ -1482,17 +1705,17 @@ #include <malloc.h> #endif -#ifndef __GNU_LIBRARY__ +/* uClibc defines __GNU_LIBRARY__, but it is not completely + compatible. */ +#if !defined(__GNU_LIBRARY__) || defined(__UCLIBC__) #define __sbrk sbrk -#endif - -#ifdef __GNU_LIBRARY__ +#else /* __GNU_LIBRARY__ && ! defined (__UCLIBC__) */ /* It is best not to declare this and cast its result on foreign operating systems with potentially hostile include files. */ #include <stddef.h> extern __ptr_t __sbrk PP ((ptrdiff_t increment)); -#endif +#endif /* __GNU_LIBRARY__ && ! defined (__UCLIBC__) */ #ifndef NULL #define NULL 0 @@ -1539,13 +1762,6 @@ #include <malloc.h> #endif -#if __DJGPP__ - 0 == 1 - -/* There is some problem with memalign in DJGPP v1 and we are supposed - to omit it. Noone told me why, they just told me to do it. */ - -#else - __ptr_t (*__memalign_hook) PP ((__malloc_size_t __size, __malloc_size_t __alignment)); @@ -1556,9 +1772,10 @@ { __ptr_t result; unsigned long int adj, lastadj; + __ptr_t (*hook) (__malloc_size_t, __malloc_size_t) = __memalign_hook; - if (__memalign_hook) - return (*__memalign_hook) (alignment, size); + if (hook) + return (*hook) (alignment, size); /* Allocate a block with enough extra space to pad the block with up to (ALIGNMENT - 1) bytes if necessary. */ @@ -1593,6 +1810,7 @@ of an allocated block. */ struct alignlist *l; + LOCK_ALIGNED_BLOCKS (); for (l = _aligned_blocks; l != NULL; l = l->next) if (l->aligned == NULL) /* This slot is free. Use it. */ @@ -1600,22 +1818,58 @@ if (l == NULL) { l = (struct alignlist *) malloc (sizeof (struct a... [truncated message content] |