simon-git: putty (main): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sun Nov 21 18:46:56 GMT 2021
TL;DR:
1847ab28 testcrypt: fix param name in ssh_cipher_setiv_wrapper.
3743859f Rewrite the testcrypt.c macro system.
3153f3ef testcrypt.h: invent FUNC_WRAPPED.
aaaf11d7 testcrypt.py: use parameter names in diagnostics.
1cf04cf0 Run testcrypt.h through clang-format.
Repository: https://git.tartarus.org/simon/putty.git
On the web: https://git.tartarus.org/?p=simon/putty.git
Branch updated: main
Committer: Simon Tatham <anakin at pobox.com>
Date: 2021-11-21 18:46:56
commit 1847ab282d384a069dc5afa5aedbdca148897cca
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=1847ab282d384a069dc5afa5aedbdca148897cca;hp=60377a09b47668a84a569dfcdb6a6a002791b39f
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Nov 21 11:46:00 2021 +0000
testcrypt: fix param name in ssh_cipher_setiv_wrapper.
Spotted in passing that a cut-and-paste error made the parameter name
'key' rather than 'iv'. Harmless, but wrong.
testcrypt.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
commit 3743859f971439db33968cc19e1e69866440c1a3
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=3743859f971439db33968cc19e1e69866440c1a3;hp=1847ab282d384a069dc5afa5aedbdca148897cca
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Nov 21 10:27:30 2021 +0000
Rewrite the testcrypt.c macro system.
Yesterday's commit 52ee636b092c199 which further extended the huge
pile of arity-specific annoying wrapper macros pushed me over the edge
and inspired me to give some harder thought to finding a way to handle
all arities at once. And this time I found one!
The new technique changes the syntax of the function specifications in
testcrypt.h. In particular, they now have to specify a _name_ for each
parameter as well as a type, because the macros generating the C
marshalling wrappers will need a structure field for each parameter
and cpp isn't flexible enough to generate names for those fields
automatically. Rather than tediously name them arg1, arg2 etc, I've
reused the names of the parameters from the prototypes or definitions
of the underlying real functions (via a one-off auto-extraction
process starting from the output of 'clang -Xclang -dump-ast' plus
some manual polishing), which means testcrypt.h is now a bit more
self-documenting.
The testcrypt.py end of the mechanism is rewritten to eat the new
format. Since it's got more complicated syntax and nested parens and
things, I've written something a bit like a separated lexer/parser
system in place of the previous crude regex matcher, which should
enforce that the whole header file really does conform to the
restricted syntax it has to fit into.
The new system uses a lot less code in testcrypt.c, but I've made up
for that by also writing a long comment explaining how it works, which
was another thing the previous system lacked! Similarly, the new
testcrypt.h has some long-overdue instructions at the top.
test/testcrypt.py | 150 +++++++++++----
testcrypt.c | 419 +++++++++++++++++++++--------------------
testcrypt.h | 542 ++++++++++++++++++++++++++++++------------------------
3 files changed, 642 insertions(+), 469 deletions(-)
commit 3153f3ef39c0be57b4d16f442b3f1a5e6b4fa186
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=3153f3ef39c0be57b4d16f442b3f1a5e6b4fa186;hp=3743859f971439db33968cc19e1e69866440c1a3
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Nov 21 13:03:34 2021 +0000
testcrypt.h: invent FUNC_WRAPPED.
FUNC_WRAPPED is an alternative keyword to FUNC which you can use to
introduce a function specification in testcrypt.h, indicating that the
function is _not_ the one of the same name used in the main PuTTY
code, but instead a wrapper on it in testcrypt.c whose API was
reworked to be more friendly to translation into Python.
There are a lot of those wrappers already, and previously they passed
without comment in testcrypt.h, and were put into service by #defining
over the top of each name before expanding the marshalling functions.
Now, all those #defines are gone, because the use of FUNC_WRAPPED in
testcrypt.h is enough to clue in the marshalling wrapper to be
generated with a call to foo_wrapper() instead of foo().
Mostly the purpose of this is to make testcrypt.h a bit more
self-documenting: if you see FUNC_WRAPPED, you know not to be confused
by the Python and C function definitions totally failing to match.
test/testcrypt.py | 3 ++-
testcrypt.c | 71 +++++++++++++---------------------------------------
testcrypt.h | 74 ++++++++++++++++++++++++++++++-------------------------
3 files changed, 59 insertions(+), 89 deletions(-)
commit aaaf11d7fb9d8fa3a3992d35000b5428c6bcce71
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=aaaf11d7fb9d8fa3a3992d35000b5428c6bcce71;hp=3153f3ef39c0be57b4d16f442b3f1a5e6b4fa186
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Nov 21 13:21:01 2021 +0000
testcrypt.py: use parameter names in diagnostics.
Making a virtue of the necessity of adding parameter names to
testcrypt.h a couple of commits ago, we can now use those names to
improve diagnostics, so that if you use the wrong type in a Python
function call the error message will tell you the name as well as the
index of the offending argument.
Also, the repr() text for the function itself will now print a full
prototype (albeit in a nasty hybrid of C, Python and testcrypt.h
syntax) which shows all the parameter names. That should be handy when
trying to remember the order of arguments at the REPL prompt.
test/testcrypt.py | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
commit 1cf04cf01d1255c39776f9f23f0712deb7f96b5c
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=1cf04cf01d1255c39776f9f23f0712deb7f96b5c;hp=aaaf11d7fb9d8fa3a3992d35000b5428c6bcce71
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Nov 21 15:01:58 2021 +0000
Run testcrypt.h through clang-format.
Now that testcrypt.py parses it using a C-like lexer, we don't have
the constraint any more that each function definition has to live on
exactly one source line for the sake of the previous line-by-line
parser. So we can put whitespace wherever we like, and reformat for
legibility!
I've done the initial pass of this using clang-format, which will
optimise for (a) everything fitting in 80 columns, and (b) individual
ARG(...) specifications generally not being broken across lines. Those
seem like a good combination to me.
testcrypt.h | 389 ++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 274 insertions(+), 115 deletions(-)
More information about the tartarus-commits
mailing list