1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 19:52:20 +00:00

Disable vmalloc by default; fix build on Cygwin

Vmalloc is incompatible with Cygwin, but the code to disable it on
Cygwin did not work properly, somehow causing the build to freeze
at a seemingly unrelated point (i.e., when iffe feature tests
attempt to write to sfstdout).

Vmalloc has wasted my time for the last time, so now it's getting
disabled by default even on development builds and you'll have to
pass -D_AST_vmalloc in CCFLAGS to enable it for testing purposes.

This commit has a few other build tweaks as well.

src/lib/libast/features/vmalloc:
- tst map_malloc: Remove no-op #if __CYGWIN__ block which was in
  the #else clause of another #if __CYGWIN__ block.
- Output block ('cat{'):
  - Instead of disabling vmalloc for certain systems, disable it
    unless _AST_vmalloc is defined.
  - To disable it, set _AST_std_malloc as well as _std_malloc, just
    to be sure.

src/lib/libast/vmalloc/malloc.c:
- Remove ineffective Cygwin special-casing.

src/lib/libcmd/vmstate.c:
- This is only useful for vmalloc, so do not pointlessly compile it
  if vmalloc is disabled.

src/lib/libast/man/vmalloc.3:
- Add deprecation notice.

Resolves: https://github.com/ksh93/ksh/issues/360
This commit is contained in:
Martijn Dekker 2021-12-05 19:00:11 +01:00
parent 6e1e9b738b
commit 6faf43791b
5 changed files with 21 additions and 12 deletions

View file

@ -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?

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -21,6 +21,12 @@
***********************************************************************/
#pragma prototyped
#include <cmd.h>
#include <vmalloc.h>
#include <sfdisc.h>
#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 <cmd.h>
#include <vmalloc.h>
#include <sfdisc.h>
typedef struct State_s
{
char* format;
@ -200,3 +202,5 @@ b_vmstate(int argc, char** argv, Shbltin_t* context)
}
return 0;
}
#endif /* !_std_malloc */