<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src-test2/bin/sh/expand.h, branch releng/11.2</title>
<subtitle>FreeBSD source tree</subtitle>
<id>https://cgit-dev.freebsd.org/src-test2/atom?h=releng%2F11.2</id>
<link rel='self' href='https://cgit-dev.freebsd.org/src-test2/atom?h=releng%2F11.2'/>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/'/>
<updated>2015-12-31T18:47:54Z</updated>
<entry>
<title>sh: Perform pathname generation during the first expansion phases.</title>
<updated>2015-12-31T18:47:54Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2015-12-31T18:47:54Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=0e39c931e219daa9b410c0606acd51e054575419'/>
<id>urn:sha1:0e39c931e219daa9b410c0606acd51e054575419</id>
<content type='text'>
This avoids the need to add and remove CTLESC bytes if pathname generation
will not be performed (set -f).

Side effect: the order of operations is slightly different: pathname
generation in ${$+* $(CMD)} will not see filesystem changes from CMD.
</content>
</entry>
<entry>
<title>sh: Avoid copying argv for simple commands.</title>
<updated>2015-11-01T22:07:40Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2015-11-01T22:07:40Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=046bfe52403416c6c40db2c73009dbb360257631'/>
<id>urn:sha1:046bfe52403416c6c40db2c73009dbb360257631</id>
<content type='text'>
Add dummy entries before and after so arglist's array is directly usable as
argv.
</content>
</entry>
<entry>
<title>sh: Make struct arglist an array instead of a linked list.</title>
<updated>2015-10-11T21:33:00Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2015-10-11T21:33:00Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=8ef0ae8a8f64fa14dc67c8c3caba2f7b1b6681f5'/>
<id>urn:sha1:8ef0ae8a8f64fa14dc67c8c3caba2f7b1b6681f5</id>
<content type='text'>
This simplifies the code (e.g. allowing use of qsort(3) instead of a
hand-rolled mergesort) and should have better cache properties.

The waste of unused args arrays after resizes is approximately the same as
the savings from getting rid of the next pointers.

At the same time, remove a piece of global state and move some duplicated
code into a function.
</content>
</entry>
<entry>
<title>sh: Remove EXP_REDIR.</title>
<updated>2014-12-21T22:18:30Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2014-12-21T22:18:30Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=f649ab8b15b86b697b7c678fa34235f08be041de'/>
<id>urn:sha1:f649ab8b15b86b697b7c678fa34235f08be041de</id>
<content type='text'>
EXP_REDIR was supposed to generate pathnames in redirection if exactly one
file matches, as permitted but not required by POSIX in interactive mode. It
is unlikely this will be implemented.

No functional change is intended.

MFC after:	1 week
</content>
</entry>
<entry>
<title>sh: Make expari() static.</title>
<updated>2014-02-26T21:38:42Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2014-02-26T21:38:42Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=85bf1d2f07cbab4936820178338f5873f7e74b87'/>
<id>urn:sha1:85bf1d2f07cbab4936820178338f5873f7e74b87</id>
<content type='text'>
</content>
</entry>
<entry>
<title>sh: Expand here documents in the current process.</title>
<updated>2013-02-03T15:54:57Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2013-02-03T15:54:57Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=4dc6bdd3e7e670c195cd66b9319b4059f572cdfc'/>
<id>urn:sha1:4dc6bdd3e7e670c195cd66b9319b4059f572cdfc</id>
<content type='text'>
Expand here documents at the same point other redirections are expanded but
use a non-fork subshell environment (like simple command substitutions) for
compatibility. Substitition errors result in an empty here document like
before.

As a result, a fork is avoided for short (&lt;4K) expanded here documents.

Unexpanded here documents (with quoted end marker after &lt;&lt;) are not affected
by this change. They already only forked when &gt;4K.

Side effects:
* Order of expansion is slightly different.
* Slow expansions are not executed in parallel with the redirected command.
* A non-fork subshell environment is subtly different from a forked process.
</content>
</entry>
<entry>
<title>sh: Make various functions static.</title>
<updated>2012-01-01T22:17:12Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2012-01-01T22:17:12Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=260fc3f4d26a8b25e824c0baa4a77b0f4cada631'/>
<id>urn:sha1:260fc3f4d26a8b25e824c0baa4a77b0f4cada631</id>
<content type='text'>
</content>
</entry>
<entry>
<title>sh: Fix duplicate prototypes for builtins.</title>
<updated>2011-06-13T21:03:27Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2011-06-13T21:03:27Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=454a02b3728543503f2f30771a867148a27f71b3'/>
<id>urn:sha1:454a02b3728543503f2f30771a867148a27f71b3</id>
<content type='text'>
Have mkbuiltins write the prototypes for the *cmd functions to builtins.h
instead of builtins.c and include builtins.h in more .c files instead of
duplicating prototypes for *cmd functions in other headers.
</content>
</entry>
<entry>
<title>sh: Save/restore changed variables in optimized command substitution.</title>
<updated>2011-06-12T23:06:04Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2011-06-12T23:06:04Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=c543e1ae9e9b0ae7a83bd6ce410df9ccbf169067'/>
<id>urn:sha1:c543e1ae9e9b0ae7a83bd6ce410df9ccbf169067</id>
<content type='text'>
In optimized command substitution, save and restore any variables changed by
expansions (${var=value} and $((var=assigned))), instead of trying to
determine if an expansion may cause such changes.

If $! is referenced in optimized command substitution, do not cause jobs to
be remembered longer.

This fixes $(jobs $!) again, simplifies the man page and shortens the code.
</content>
</entry>
<entry>
<title>sh: Don't do optimized command substitution if expansions have side effects.</title>
<updated>2010-12-28T21:27:08Z</updated>
<author>
<name>Jilles Tjoelker</name>
<email>jilles@FreeBSD.org</email>
</author>
<published>2010-12-28T21:27:08Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src-test2/commit/?id=acd7984f961a69d9e6d6d908f85737d2a9a08cb5'/>
<id>urn:sha1:acd7984f961a69d9e6d6d908f85737d2a9a08cb5</id>
<content type='text'>
Before considering to execute a command substitution in the same process,
check if any of the expansions may have a side effect; if so, execute it in
a new process just like happens if it is not a single simple command.

Although the check happens at run time, it is a static check that does not
depend on current state. It is triggered by:
- expanding $! (which may cause the job to be remembered)
- ${var=value} default value assignment
- assignment operators in arithmetic
- parameter substitutions in arithmetic except ${#param}, $$, $# and $?
- command substitutions in arithmetic

This means that $((v+1)) does not prevent optimized command substitution,
whereas $(($v+1)) does, because $v might expand to something containing
assignment operators.

Scripts should not depend on these exact details for correctness. It is also
imaginable to have the shell fork if and when a side effect is encountered
or to create a new temporary namespace for variables.

Due to the $! change, the construct $(jobs $!) no longer works. The value of
$! should be stored in a variable outside command substitution first.
</content>
</entry>
</feed>
