From 4ef3afcd74357e0ea3cf74b3e5e2cfd43c3c46d3 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 7 Oct 2023 07:04:32 -0700 Subject: [PATCH] Updates to 1989/westley I have tried to make the README.md file less cluttered wrt the clang defects and instead just show how to use the entry, referring to the bugs.md for those who need to know. Added script compile.sh which generates the files and tries to compile them. The script sleeps (by default approximately 1 second) in between commands but this can be changed to another value (including 0). One can also change the compiler path in case their compiler is clang or in the case of macOS gcc IS clang. The README.md refers to this and gives examples. The bugs.md and the thanks-for-fixes.md files have been updated for these changes and additions. For those who do not know of the clang defects it is discussed in the bugs.md and unfortunately for this entry there might be little that can be done. I haven't tried to understand the entry deeply and maybe doing so would give some ideas for fixes (beyond what I already did which lets the main program compile with clang - or at least versions that allow a fourth arg to main()) but this seems less important for now. --- 1989/westley/README.md | 47 +++++++++++++++++-------- 1989/westley/compile.sh | 77 +++++++++++++++++++++++++++++++++++++++++ bugs.md | 24 +++++++------ thanks-for-fixes.md | 15 +++++--- 4 files changed, 134 insertions(+), 29 deletions(-) create mode 100755 1989/westley/compile.sh diff --git a/1989/westley/README.md b/1989/westley/README.md index 29a5e6c01..7d5269cee 100644 --- a/1989/westley/README.md +++ b/1989/westley/README.md @@ -11,36 +11,42 @@ make all ``` -NOTE: this entry only partly works with clang; clang requires that the second, third and -fourth args to `main()` be `char **`. Only `westley.c` and `ver0.c` (see below) will -compile with clang. It's possible to get `ver1.c` to compile too but this causes -problems with generating the output of the remaining files so we have opted, at -least for now, to not do that, as it does not have to output just source code. -The original source code sometimes segfaults with `ver2` which also happens with -the fix but it'll only compile with a compiler that does not require the second, -third and fourth args of `main()` to be a `char **`. - +NOTE: this entry only partly works with clang and only some versions of clang, +due to defects in the compiler. See [bugs.md](/bugs.md) for more details. ## Try: +Try compiling and running the 4 resulting programs like: + ```sh +./compile.sh +``` + +This will remove the programs and then run: + +``` ./westley < westley.c > ver0.c ./westley 1 < westley.c > ver1.c ./westley 1 2 < westley.c > ver2.c ./westley 1 2 3 < westley.c > ver3.c ``` +followed by compiling each version. -Try compiling and running the 4 resulting programs. To compile try: +If you need to specify an alternate compiler path, say because your default +compiler is clang (or in the case of macOS gcc is clang) you can do so like: ```sh -make ver0 -make ver1 -make ver2 -make ver3 +CC=/opt/local/bin/gcc-mp-12 ./compile.sh ``` -Then run: +If you wish to delay the script or remove the delay you can do so like: + +```sh +DELAY=0 ./compile.sh +``` + +Finally try: ```sh ./westley @@ -51,6 +57,17 @@ echo Version 2 | ./ver2 echo Version 3 | ./ver3 ``` + +### INAFIAB - it's not a feature it's a bug :-( + +There might have been a segfault that was fixed in the original code but as we +no longer know what condition or conditions caused this we cannot be sure. It +seems like, according to various files, that `ver1` and/or `ver2` also have this +problem but we also do not know about the status of this. See +[bugs.md](/bugs.md) for more information. + + + ## Judges' remarks: diff --git a/1989/westley/compile.sh b/1989/westley/compile.sh new file mode 100755 index 000000000..b4d497d72 --- /dev/null +++ b/1989/westley/compile.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# +# compile.sh - compile westley.c, generate the alt versions and then attempt to +# compile them. +# +# To change what compiler is used you can do something like: +# +# CC=/path/to/cc ./compile.sh +# +# The following example was run on a MacBook Pro with the M1 Max which which +# could not normally compile everything because macOS's compiler, even when run +# as gcc, is actually clang: +# +# CC=/opt/local/bin/gcc-mp-12 ./compile.sh +# +# We sleep (by default) for approximately 1 second after each command so that +# the you can read what is being done. If this is too fast you can change it in +# a similar way to the above but using the variable DELAY like so: +# +# DELAY=2 ./compile.sh +# +# You can of course use both variables in the same command line like: +# +# CC=/opt/local/bin/gcc-mp-12 DELAY=2 ./compile.sh +# DELAY=2 CC=/opt/local/bin/gcc-mp-12 ./compile.sh +# +# ...and so on. + +# get the compiler using default cc if not specified in the command line +# +# we cannot use the form '${CC:=cc}' because at least in some versions of bash +# it tries to invoke the command which would be an error by itself. Thus we just +# check if it's empty before we set it. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +# get sleep duration +# we cannot use the form '${DELAY:=5}' because at least in some versions of bash +# it tries to invoke the command and obviously that won't work. Thus we check if +# it's empty before setting the default. +if [[ -z "$DELAY" ]]; then + DELAY=2 +fi + +# make clobber to make the directory clean and then compile westley which we +# need to run everything else. Exit if make westley fails as there would be +# nothing further that could be done in that case: +echo "$ make clobber westley" +sleep "$DELAY" +make CC="$CC" clobber westley || exit 1 +sleep "$DELAY" + +# run commands previously in the try section of the README.md, showing what the +# commands are as we go: + +echo "$ ./westley < westley.c > ver0.c" 1>&2 +./westley < westley.c > ver0.c +sleep "$DELAY" +echo "$ ./westley 1 < westley.c > ver1.c" 1>&2 +./westley 1 < westley.c > ver1.c +sleep "$DELAY" +echo "$ ./westley 1 2 < westley.c > ver2.c" 1>&2 +./westley 1 2 < westley.c > ver2.c +sleep "$DELAY" +echo "$ ./westley 1 2 3 < westley.c > ver3.c" 1>&2 +./westley 1 2 3 < westley.c > ver3.c +sleep "$DELAY" + +# now compile the files by running make alt +# + +echo "Compiling alt versions ..." 1>&2 +sleep "$DELAY" +echo "$ make CC=$CC alt" 1>&2 +sleep "$DELAY" +make CC="$CC" alt diff --git a/bugs.md b/bugs.md index 8d6fa91db..4d797ca63 100644 --- a/bugs.md +++ b/bugs.md @@ -565,9 +565,12 @@ This program will crash with numbers with non-binary digits. Although [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this for some of the versions that are generated (see below tip) it will not work for all -with the clang compiler (gcc works fine). Cody noted that trying to fix it in -some cases causes a segfault and in other cases it fails to generate some of the -files (others are okay) at all (empty files). +with the clang compiler (gcc works fine) and in some versions of clang it will +not work at all due to yet another defect (see below also). + +Cody noted that trying to fix it in some cases causes a segfault and in other +cases it fails to generate some of the files (others are okay) at all (empty +files). There is another change that was thought up on 08 July 2023 which allows for another version to be compiled with clang but it causes some of the versions to @@ -579,19 +582,20 @@ Some versions of clang have an additional defect where in additional to forcing the args of `main()` to be of type `int` (for first arg) and the rest to be `char **` it also does not allow a fourth arg to main(). This in fact is part of the change thought up on 08 July 2023: main() calls a function which has the old -types of variables. More will be done with this in time. +types of variables. Cody gives these tips on the problem: `main()`'s second, third and fourth args (but on fourth arg see above) are supposed to be a `char **`. This didn't use to be the case and some compilers like gcc don't complain. `clang` however does. Cody was able to get `main()` to be correct BUT a feature is that it uses ROT13 to decrypt the function `znva` to be main in _generated files_ (see the -[README.md](1989/westley/README.md) for details). Since that function does not -have the correct types when converted to main() it fails to compile. But as he -said changing the type causes either a segfault or files not generated at all. -`ver1`, `ver2` and `ver3` are the problematic ones. The segfault happens when -running the main program. Cody fixed that but as noted as for the generated -files only `ver0` will compile with clang. +[README.md](1989/westley/README.md) for details). + +Since that function does not have the correct types when converted to main() it +fails to compile. But as he said changing the type causes either a segfault or +files not generated at all. `ver1`, `ver2` and `ver3` are the problematic ones. +The segfault happens when running the main program. Cody fixed that but as noted +as for the generated files only `ver0` will compile with clang. ## STATUS: known bug - please help us fix diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index e7728e1a0..953a14ba8 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -408,10 +408,17 @@ his only reason :-) ) ## [1989/westley](1989/westley/westley.c) ([README.md](1989/westley/README.md])) -Cody got some of the versions (the original and `ver0`) to work with clang. As -there are some important notes on this in the README.md file we have left the -details in that file, at least for now. Perhaps the [bugs.md](bugs.md) file is a -better place but this can be decided later. +Cody got some of the versions (the original and `ver0`) to work with some +versions of `clang`. Unfortunately there are some defects in `clang` that break +this entry either in full or in part. + +Cody provided the compile.sh script to generate the files and then try and +compile them (which ones succeed depend on whether or not clang is the +compiler). The script allows one to change the path of the compiler if they have +another one. See the README.md for details. + +As there are some important notes on this in the README.md file we have left the +details in that file and further details are in the [bugs.md](bugs.md) file. ## [1990/baruch](1990/baruch/baruch.c) ([README.md](1990/baruch/README.md]))