Merge pull request #1012 from xexyl/1989-westley
This commit is contained in:
4 files changed
+134
-29
No files matched your search
+32
-15
@@ -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:
|
||||
|
||||
|
||||
|
||||
Executable
+77
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
+11
-4
@@ -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]))
|
||||
|
||||
Reference in new issue
Block a user