diff --git a/src/cmd/ksh93/tests/leaks.sh b/src/cmd/ksh93/tests/leaks.sh index 5af1f5b3f..256cb4644 100755 --- a/src/cmd/ksh93/tests/leaks.sh +++ b/src/cmd/ksh93/tests/leaks.sh @@ -23,6 +23,7 @@ # Determine method for running tests. # The 'vmstate' builtin can be used if ksh was compiled with vmalloc. +# (Pass -D_AST_vmalloc in CCFLAGS; for testing only as it's deprecated) if builtin vmstate 2>/dev/null && n=$(vmstate --format='%(busy_size)u') && let "($n) == ($n) && n > 0" # non-zero number? diff --git a/src/lib/libast/features/vmalloc b/src/lib/libast/features/vmalloc index 177d3e6fb..ba68abd5a 100644 --- a/src/lib/libast/features/vmalloc +++ b/src/lib/libast/features/vmalloc @@ -57,9 +57,6 @@ tst map_malloc note{ map malloc to _ast_malloc }end noexecute{ extern void* calloc _ARG_((unsigned int, unsigned int)); #define LOCAL() calloc(1,1) #endif - #if __CYGWIN__ - #define extern __declspec(dllexport) - #endif #define HT double static HT heap[1024 * 4]; static HT* hp = &heap[1]; @@ -207,9 +204,13 @@ tst malloc_hook note{ gnu malloc hooks work }end execute{ cat{ #include "FEATURE/mmap" - #if _AST_ksh_release || _BLD_INSTRUMENT || cray || _UWIN && _BLD_ast + /* AST vmalloc is deprecated for being crashy and wasteful; ksh 93u+m uses the OS's malloc by default */ + #undef _std_malloc + #undef _AST_std_malloc + #if !_AST_vmalloc #undef _map_malloc #define _std_malloc 1 /* defer to standard malloc */ + #define _AST_std_malloc 1 #endif #if _mmap_anon #define _mem_mmap_anon 1 diff --git a/src/lib/libast/man/vmalloc.3 b/src/lib/libast/man/vmalloc.3 index 75d4f585f..e9c60b99e 100644 --- a/src/lib/libast/man/vmalloc.3 +++ b/src/lib/libast/man/vmalloc.3 @@ -66,6 +66,13 @@ vmalloc \- virtual memory allocation .MW "Void_t* valloc(size_t size);" .MW "int setregmax(int regmax);" .fi +.SH DEPRECATION NOTICE +In the 2021 ksh 93u+m distribution, \fIvmalloc\fP(3) was deprecated for +being unstable and wasteful in comparison to \fImalloc\fP(3) implementations +that come with modern operating systems. +By default, the interfaces described here map to the OS's standard +\fImalloc\fP(3) implementation. \fIvmalloc\fP can be enabled at compile time +by passing \fB-D_AST_vmalloc\fP in \fBCCFLAGS\fP. .SH DESCRIPTION These functions for dynamic storage allocation work in \fIregions\fP of memory. diff --git a/src/lib/libast/vmalloc/malloc.c b/src/lib/libast/vmalloc/malloc.c index 8abbc0c37..090d10b83 100644 --- a/src/lib/libast/vmalloc/malloc.c +++ b/src/lib/libast/vmalloc/malloc.c @@ -85,10 +85,6 @@ typedef struct ______mstats Mstats_t; * will simply call malloc etc. */ -#if !defined(_AST_std_malloc) && __CYGWIN__ -#define _AST_std_malloc 1 -#endif - /* malloc compatibility functions ** ** These are aware of debugging/profiling and are driven by the diff --git a/src/lib/libcmd/vmstate.c b/src/lib/libcmd/vmstate.c index d0b16f281..92381c9b6 100644 --- a/src/lib/libcmd/vmstate.c +++ b/src/lib/libcmd/vmstate.c @@ -21,6 +21,12 @@ ***********************************************************************/ #pragma prototyped +#include +#include +#include + +#if !_std_malloc /* do not pointlessly compile this if vmalloc is disabled */ + #define FORMAT "region=%(region)p method=%(method)s flags=%(flags)s size=%(size)d segments=%(segments)d busy=(%(busy_size)d,%(busy_blocks)d,%(busy_max)d) free=(%(free_size)d,%(free_blocks)d,%(free_max)d)" static const char usage[] = @@ -49,10 +55,6 @@ static const char usage[] = "[+SEE ALSO?\bvmalloc\b(3)]" ; -#include -#include -#include - typedef struct State_s { char* format; @@ -200,3 +202,5 @@ b_vmstate(int argc, char** argv, Shbltin_t* context) } return 0; } + +#endif /* !_std_malloc */