Commit Graph

17187 Commits

Author SHA1 Message Date
rillig
2cab38691c lint: reduce duplicate code in check for getopt
This also changes the conditions to their positive form, which is easier
to read.

No functional change.  The resulting binary would have been the same as
before, were it not for the changed line numbers in the lint_assert
calls further down in the code.
2021-02-20 10:12:52 +00:00
rillig
7f300e59ba lint: clean up check for getopt
The original options string is not needed during the check.  Having only
the unhandled options suffices.

No functional change.
2021-02-20 10:01:27 +00:00
rillig
46a713f776 lint: fix crash from ckgetopt.c 1.2 and document the data structures 2021-02-20 09:57:02 +00:00
nia
fe9db1e16f fix URL 2021-02-20 09:31:51 +00:00
nia
894dfd713b patch(1): use PATH_MAX for the size of rejname
via freebsd, openbsd
2021-02-20 09:17:13 +00:00
christos
fc13bd7d09 Prevent crashing when options are NULL in libc while linting
src/lib/libc/posix1e/acl_from_text.c
2021-02-20 01:18:02 +00:00
rillig
4e5ad049a7 lint: remove gcov results on "make clean" 2021-02-19 23:25:26 +00:00
rillig
90c29d8403 lint: shorten code in check-msgs.lua
No functional change.
2021-02-19 23:22:19 +00:00
rillig
9c0f980ca3 lint: rename storage class constants to be more expressive
No functional change.
2021-02-19 22:35:42 +00:00
rillig
32266a1930 lint: rename t_isenum and t_aincompl to be more expressive
No functional change.
2021-02-19 22:27:49 +00:00
rillig
468e9e00fb lint: rename tenum_t and its members to be more expressive 2021-02-19 22:20:18 +00:00
rillig
e55559f87e lint: rename str_t and its members to be more expressive
No functional change.
2021-02-19 22:16:12 +00:00
rillig
3fe220d520 lint: replace cryptic sym.s_rimpl with expressive name
No functional change.
2021-02-19 21:35:44 +00:00
nia
8b022a822c patch: make '-V none' work in the expected way
Internally the code confuses the concept of "the user doesn't want
a backup file" and "the user hasn't defined a type of backup file".

Introduce a new "undefined" backup type to serve the purpose "none"
previously did, and make "none" not generate backup files, as expected.

http://mail-index.netbsd.org/tech-userlevel/2021/02/19/msg012901.html

XXX pullup?
2021-02-19 17:46:53 +00:00
rillig
dbf7816e85 lint: fix build in tools mode 2021-02-19 14:44:29 +00:00
rillig
746e9c89cf lint: warn about mismatch in getopt handling 2021-02-19 12:28:56 +00:00
rillig
ded935ea33 videoctl: remove unnecessary code for unknown option -h
The generated binary stays the same.
2021-02-19 11:39:11 +00:00
christos
28a08f1a77 Add examples (Fernando Apesteguía at FreeBSD) 2021-02-18 18:27:24 +00:00
christos
f6eeb08754 Remove the "original line"
Fix lint comment
2021-02-18 18:06:02 +00:00
wiz
6e7948c2ad New sentence, new line. 2021-02-18 18:02:09 +00:00
christos
ca4875f097 Add support for password protected zip files (Alex Kozlov)
Also some KNF
2021-02-18 17:58:51 +00:00
christos
f821809059 Build with linux/glibc (Alex Kozlov) 2021-02-18 17:05:51 +00:00
christos
6dd7d998a4 mention zipx, from Alex Kozlov 2021-02-18 17:04:39 +00:00
christos
af632fea2b add O_CLOEXEC 2021-02-17 21:09:39 +00:00
rillig
e14d525678 make: clean up VarAdd, Var_Delete, Var_ReexportVars
No functional change.
2021-02-16 19:46:15 +00:00
rillig
d78a4ea36f make: document the bad state in which the test varcmd.mk is 2021-02-16 19:43:09 +00:00
rillig
458f6744b0 make: test exporting a variable that itself depends on a subprocess
When the point that "isn't going to end well" is reached, the stacktrace
is quite long but still reasonable:

main
main_ReadFiles
ReadAllMakefiles
ReadMakefile		directive-export.mk
Parse_File
ParseLine				# line 3 has: _!= :;:
ParseVarassign
Parse_DoVar
VarAssign_Eval
VarAssign_EvalShell			# because of the '!='
Cmd_Exec		:;:
Var_ReexportVars			# before starting the subprocess
ExportVar		EMPTY_SHELL
ExportVarEnv				# was only marked for export
Var_Subst		${EMPTY_SHELL}	# to get the value to export
VarSubstExpr		${EMPTY_SHELL}
Var_Parse		${EMPTY_SHELL}
Var_Subst		${:sh}		# since EMPTY_SHELL= ${:sh}
VarSubstExpr		${:sh}
Var_Parse		${:sh}
ApplyModifiers
ApplySingleModifier	:sh
ApplyModifier
ApplyModifier_SunShell	:sh
Cmd_Exec		""		# empty command
Var_ReexportVars
ExportVar		EMPTY_SHELL
ExportVarEnv				# skipping this edge case
2021-02-16 19:01:18 +00:00
rillig
f04cb12800 make: clarify what .export ${:U} means 2021-02-16 18:12:46 +00:00
rillig
a017c69c81 make: demonstrate inconsistency in .undef of an exported variable 2021-02-16 18:02:19 +00:00
rillig
a75802fa16 make: clean up and update comments in var.c
During the refactorings of the last months, several comments have become
outdated, some are now redundant since the code is as clear as the
comment, and some code benefits from a bit of explanation.
2021-02-16 17:41:23 +00:00
rillig
b3224a45e4 make: use bit-shift expressions for VarFlags constants
These are easier to read than hex constants.

There was no need to skip bits 2 and 3 (there were no constants for 0x04
and 0x08).  Close this gap, to avoid confusing future readers.  Keep the
relative order of the flags since that affects the debug output of -dv.

No functional change.
2021-02-16 16:33:40 +00:00
rillig
6e5fc7f457 make: rename constants for VarFlags
The old prefix was "VAR_" and this prefix is used for several other
constants as well, which made it ambiguous.
2021-02-16 16:28:41 +00:00
rillig
6544f8c037 make: sync comment about duplicated code with reality
There are only very few places in var.c that contain really duplicate
code anymore.

There is still lots of _almost_ duplicate, for example the code for
parsing variable modifiers.  It differs subtly in behavior:

*   The modifiers ':M' and ':N' use '$$' to escape a '$' sign, while
    almost all other modifiers use '\$' for this purpose.

*   The modifiers ':M', ':N', ':S', ':@' and several others parse
    balanced parentheses and braces, allowing '(' to '}' to match.
    The modifiers ':D' and ':U' only treat the end character special but
    not the other 3 of '(){}'.

*   When parsing the modifier ':S' but not evaluating it, the code for
    nested variable expressions is parsed differently from when it is in
    evaluation mode (VARE_WANTRES).  This applies to an outer ':S'
    modifier and an inner ':D' or ':M' modifier.

Since these inconsistencies affect the behavior in edge cases and some
users of make might depend on it, they cannot be fixed by
behavior-preserving refactorings.
2021-02-16 16:14:27 +00:00
rillig
ffd4a447e8 make: rename ExprDefined constants for debug logging 2021-02-15 18:23:32 +00:00
rillig
70b237ca8a make: rename ExprStatus to ExprDefined
The type describes the definedness of an expression, not a general
status, therefore the new name is more precise.

The constants are renamed as well since their prefix 'VES' does not
match the type name anymore, it was correct 3 days ago when the type was
still named VarExprStatus.  The name VES_NONE was misleading since
'none' does not describe its actual effect.  That name came from the
time when the status was a bit set, and 'none' simply meant 'none of the
bits are set'.

The names used in debug logging will be renamed in a follow-up commit,
to demonstrate that the changes in this commit indeed have no functional
change, especially not the change from '!=' to '==' in line 4304.

No functional change.
2021-02-15 18:21:13 +00:00
rillig
2be3d48f35 make: update comments for Expr, amending the previous commit 2021-02-15 17:59:08 +00:00
rillig
8c6543bd32 make: split parameters for evaluating variable expressions
The details of how variable expressions are evaluated is controlled by
several parameters: startc and endc differ for $(VAR) and ${VAR}, the
value of the expression can be interpreted as a single big word, and
when joining several words (such as with ':M' or ':S'), there may be a
custom word separator (defined with ':ts*').

The scope of half of these parameters is the whole variable expression,
the other half of the parameters are reset after each chain of indirect
modifiers.  To make this distinction obvious in the code, extract Expr
from ApplyModifiersState.  Previously, these details were hidden in how
parameters are passed and restored among ApplyModifiersIndirect and
ApplyModifiers.

The changes in the individual ApplyModifier functions are numerous but
straight-forward.  They mostly replace 'st' with 'expr'.

The changes in ApplyModifiers and ApplyModifiersIndirect are more
subtle.  The value of the expression is no longer passed around but is
stored in a fixed location, in Expr, which makes it easier to reason
about memory management.

The code in ApplyModifiers after 'cleanup' looks quite different but
preserves the existing behavior.  Expr_SetValueRefer is nothing else
than the combination of FStr_Done followed by FStr_InitRefer.  Storing
exprStatus back at the end was responsible for passing the definedness
of the expression after applying the indirect modifiers back to the
outer ApplyModifiersState.  The same effect is now achieved by having
Expr.status with a wider scope.

No functional change.
2021-02-15 17:44:09 +00:00
rillig
a82a3ee139 make: improve comments in test for expansions in .for loops 2021-02-15 07:58:19 +00:00
rillig
9478d5a896 make: fix typo in comment 2021-02-15 07:42:35 +00:00
rillig
5dd7b87974 lint: remove redundant comment
That comment was useful when there was no function is_null_pointer.
Back then, the code for testing a null pointer was written in-line,
which made it really hard to see what's going on.  This is no longer the
case.
2021-02-15 07:40:18 +00:00
rillig
db5ee305d0 lint: extract typeok_colon_pointer from typeok_colon
The subtype information is now only accessed if both operands are
actually pointers.

No functional change.
2021-02-15 07:36:40 +00:00
rillig
0308def1fc make: clean up code and comments around ModifyWord
In ModifyWords, there is no "passed string" anymore since that function
now directly operates on the expression value.

While here, improve the documentation of ModifyWordsCallback and rename
it to ModifyWordProc, focusing on its purpose instead of where it is
used.
2021-02-15 06:46:01 +00:00
rillig
449355e949 make: clean up memory management in evaluation of expressions
The condition "st->newValue.str != val" in ApplySingleModifier made the
memory management look more complicated than it really was.  Freeing an
object based on another object's value is harder to understand than
necessary.

To fix this, the "current value" of the expression is now stored in
ApplyModifiersState, and it gets updated in-place by the ApplyModifier
functions.  This reduces the number of parameters for the ApplyModifier
functions.

Accessing the current value of the expression is now more verbose than
before (st->value.str instead of the simple val).  To compensate for
this verbosity, ApplyModifiersIndirect is now much easier to understand
since there is no extra "current value" floating around.

There is still room for improvement.  In ApplyModifiers, passing an FStr
in and returning another (or possibly the same) makes it difficult to
understand memory management.  Adding a separate Expr type that outlives
the ApplyModifiersState will make this easier, in a follow-up commit.
2021-02-14 22:48:17 +00:00
rillig
6118cc0289 make: reduce redundant code around ModifyWords
The result of ModifyWords had been passed to Expr_SetValueOwn in all
cases.  The last argument to ModifyWords had always been st->sep.
2021-02-14 21:54:42 +00:00
rillig
370ad03170 make: clean up FStr and MFStr memory in cleanup mode 2021-02-14 21:32:58 +00:00
rillig
f9dcbbe347 make: print error about failed shell command before overwriting variable
Memory management of the value of variable expressions is currently more
complicated than necessary.  It is the responsibility of ApplyModifiers,
even though conceptually the value belongs to an expression, so it
should rather be in Expr.  Right now, this is an alias for
ApplyModifiersState, but that will change soon.

When that is done, there will no longer be a "current value" and a "new
value", only a single "value" of an expression.  At that point, before
Expr_SetValueOwn will overwrite the old value with the output of the
shell command, the error message needs to refer to the latter.
2021-02-14 20:22:30 +00:00
rillig
fe211a10c7 make: add test for the variable modifier ':sh' 2021-02-14 20:16:17 +00:00
rillig
bc023be5d8 make: clean up ValidShortVarname
The switch statement was hard to read, especially the "break" that
needed a comment since it was effectively a "continue".
2021-02-14 18:59:36 +00:00
rillig
d0e45fa73b make: clean up ParseVarnameShort
Single-character short variable expressions such as $V neither have a
starting character nor an ending character.  The only interesting
character forms the complete variable name.

No functional change.
2021-02-14 18:55:51 +00:00
rillig
52e5117b68 make: rename VarExprStatus to ExprStatus
It is only used in var.c so there is no need to use a prefix.
2021-02-14 18:21:31 +00:00