Skip to content

Commit

Permalink
New semantic versioning scheme; disable vmalloc in release builds
Browse files Browse the repository at this point in the history
As of this commit, ksh 93u+m has a standard semantic version number
<https://semver.org/>, beginning with 1.0.0-alpha. This is added to
the version string in a way that should be compatible with scripts
parsing ${.sh.version} or $(ksh --version). This addition does not
replace the release date and does not affect $((.sh.version)).

For non-release builds, the version string will be:
	FORK/VERSION+HASH YYYY-MM-DD
e.g.:	93u+m/1.0.0-alpha+41ef7f76 2021-01-03

For release builds, it will be:
	FORK/VERSION YYYY-MM-DD
e.g.:	93u+m/1.0.0 2021-01-03

It is now automatically decided by bin/package whether to build a
release or development build. When building from a directory that
is not a git repository, or if the current git branch name starts
with a number (e.g. '1.0'), the release build is enabled; otherwise
a development build is the default. This is arranged by adding -D
flags to $CCFLAGS as described below. These flags are prepended to
$CCFLAGS, so they can be overridden by adding your own -D or -U
flags via the environment.

In addition, AST vmalloc is disabled for release builds as of this
commit, forcing the use of the OS's standard malloc(3). In 2021,
this is generally more reliable, faster, and more economical with
memory than AST vmalloc. Several memory leaks and crashing bugs are
avoided, e.g.: <#95>.

For development builds, vmalloc stays enabled (along with its known
bugs) because this allows the use of the vmstat builtin, making it
much more efficient to test for memory leaks. For more info, see
the regression test script: src/cmd/ksh93/tests/leaks.sh

bin/package, src/cmd/INIT/package.sh:
- Add flags for build type. In $CCFLAGS, define _AST_ksh_release if
  we're not on any git branch or on a git branch whose name starts
  with a number. Otherwise, define _AST_git_commit as the first 8
  characters of the current git commit hash.

src/lib/libast/features/vmalloc:
- If _AST_ksh_release is defined, disable vmalloc and force use of
  the operating system's malloc. Discussion:
  #95

src/cmd/ksh93/include/version.h:
- Define new format for version string, adding a semantic version
  number as well as (for non-release builds) the git commit hash.

src/cmd/ksh93/sh/init.c: e_version[]:
- Add a 'v' to the ${.sh.version} feature string if ksh was
  compiled with vmalloc enabled. This allows scripts, such as
  regression tests, to detect this.

src/cmd/ksh93/data/builtins.c: sh_optksh[]:
- Add a copyright line crediting the contributors to ksh 93u+m.

Resolves: #95
  • Loading branch information
McDutchie committed Jan 5, 2021
1 parent 41ef7f7 commit 3567220
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
19 changes: 19 additions & 0 deletions bin/package
Original file line number Diff line number Diff line change
Expand Up @@ -5411,6 +5411,25 @@ license)# all work in $PACKAGESRC/LICENSES
;;

make|view)
# Add flags for build type
case `git branch 2>/dev/null` in
'' | *\*\ [0-9]*.[0-9]*)
# If we're not on a git branch (tarball) or on a branch that starts
# with a number (release branch), then compile as a release version
CCFLAGS="-D_AST_ksh_release${CCFLAGS:+ $CCFLAGS}" # prefix it to allow override with -U
export CCFLAGS
;;
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
case $git_commit in
????????)
CCFLAGS="-D_AST_git_commit=\\\"$git_commit\\\"${CCFLAGS:+ $CCFLAGS}"
export CCFLAGS
;;
esac
unset git_commit
;;
esac
# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
case `uname` in
NetBSD | SunOS)
Expand Down
19 changes: 19 additions & 0 deletions src/cmd/INIT/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5410,6 +5410,25 @@ license)# all work in $PACKAGESRC/LICENSES
;;

make|view)
# Add flags for build type
case `git branch 2>/dev/null` in
'' | *\*\ [0-9]*.[0-9]*)
# If we're not on a git branch (tarball) or on a branch that starts
# with a number (release branch), then compile as a release version
CCFLAGS="-D_AST_ksh_release${CCFLAGS:+ $CCFLAGS}" # prefix it to allow override with -U
export CCFLAGS
;;
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
case $git_commit in
????????)
CCFLAGS="-D_AST_git_commit=\\\"$git_commit\\\"${CCFLAGS:+ $CCFLAGS}"
export CCFLAGS
;;
esac
unset git_commit
;;
esac
# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
case `uname` in
NetBSD | SunOS)
Expand Down
1 change: 1 addition & 0 deletions src/cmd/ksh93/data/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ USAGE_LICENSE
const char sh_optksh[] =
"+[-1?\n@(#)$Id: sh (AT&T Research) "SH_RELEASE" $\n]"
USAGE_LICENSE
"[-copyright?(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK "]"
"[+NAME?\b\f?\f\b - Shell, the standard command language interpreter]"
"[+DESCRIPTION?\b\f?\f\b is a command language interpreter that "
"executes commands read from a command line string, the "
Expand Down
17 changes: 16 additions & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@
* David Korn <[email protected]> *
* *
***********************************************************************/
#define SH_RELEASE "93u+m 2021-01-03"

#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2021-01-03" /* must be in this format for $((.sh.version)) */

/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
/* Arithmetic $((.sh.version)) uses the last 10 chars, so the date must be at the end. */
#if _AST_ksh_release
# define SH_RELEASE SH_RELEASE_FORK "/" SH_RELEASE_SVER " " SH_RELEASE_DATE
#else
# ifdef _AST_git_commit
# define SH_RELEASE SH_RELEASE_FORK "/" SH_RELEASE_SVER "+" _AST_git_commit " " SH_RELEASE_DATE
# else
# define SH_RELEASE SH_RELEASE_FORK "/" SH_RELEASE_SVER "+dev " SH_RELEASE_DATE
# endif
#endif
4 changes: 4 additions & 0 deletions src/cmd/ksh93/sh/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ char e_version[] = "\n@(#)$Id: Version "
#define ATTRS 1
"R"
#endif
#if !_std_malloc && !_AST_std_malloc
#define ATTRS 1
"v" /* uses vmalloc */
#endif
#if ATTRS
" "
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/features/vmalloc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ tst malloc_hook note{ gnu malloc hooks work }end execute{

cat{
#include "FEATURE/mmap"
#if _BLD_INSTRUMENT || cray || _UWIN && _BLD_ast
#if _AST_ksh_release || _BLD_INSTRUMENT || cray || _UWIN && _BLD_ast
#undef _map_malloc
#define _std_malloc 1 /* defer to standard malloc */
#endif
Expand Down

0 comments on commit 3567220

Please sign in to comment.