Fix 1996/jonth for macOS

The problem was the function pointer w(), which points to
XCreateWindow(), did not have the parameters and this caused a segfault
in macOS. Because it takes a lot of parameters I split the line up to
multiple lines by having a '\' at the end of lines (the entire code is
in #defined macros and two #includes).
This commit is contained in:
Cody Boone Ferguson committed 2023-08-01 07:28:06 -07:00
1 parent 6966c6f6be
commit 39143fc6bc
4 files changed
+10 -97

No files matched your search

+1 -2
View File
@@ -16,8 +16,7 @@ make all
NOTE: this entry requires `X11/Xlib.h` header file and the X11 library to
compile. macOS users running Mountain Lion and later will need to download and
install [XQuartz](https://www.xquartz.org) in order to compile and run this
entry. But see [bugs.md](/bugs.md) for a known problem with running this under
macOS and with a workaround of sorts plus more information on where it fails.
entry.
## To run:
+3 -1
View File
@@ -2,7 +2,9 @@
#define I 8;}t(p){r(p?W:o);XClearWindow(V,m);}main(i,f)char**f;{M((T(h=f),
#define K Y(o,XMapRaised(V,e);)x=3;x--;)for(y=3;y--;r(G))XMapRaised(V,R[D]
#define N z(x+i,(z(H-x-i,x),x)))x<i||z(x-i,x)|z(H-x+i,x)Y(W,)l=k;l>20&&l>x
#define XIMOfIC Z;XID(*w)()=XCreateWindow,m,e,o[2],W[2],G[2],R[2][O]);}GC*g
#define XIMOfIC Z;XID(*w)(Display*,Window,int,int,unsigned,unsigned,unsigned,\
int,unsigned, Visual*,unsigned long,XSetWindowAttributes*)=XCreateWindow,\
m,e,o[2],W[2],G[2],R[2][O]);}GC*g
#define E (++D)));}r(XID*z){XSetWindowBackgroundPixmap(V=d[D],m=R[D][x][y],z[
#define L ;XStoreName(V,e=w(V,RootWindow(V,s),0,0,152,152,2,0,1,0,0,0),"II"+D
#define B 3][3];Display*V,*d[2];char**h,k=25,b[2500],H=50,D,s,x,y,i;T(){float
-94
View File
@@ -930,100 +930,6 @@ it was instead requiring a login / password.
Do you have an updated link? We welcome your help!
## [1996/jonth](1996/jonth/jonth.c) ([README.md](1996/jonth/README.md))
## STATUS: doesn't work with some platforms - please help us fix
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) noted that this does
not work properly in macOS (at least Ventura). He did some debugging and has
determined where the crash occurs (depending on invocation of the program) and
came up with a workaround of sorts but if you have a fix we welcome your help.
With this you'll need XQuartz as described in the [FAQ](faq.md) and the
[1996/jonth/README.md](1996/jonth/README.md) file.
Notes from Cody:
Depending on invocation it appeared to have more than one crash location. It
appears that the correct invocation might be `./jonth :0 :0` but it still
crashes. Earlier invocations it would crash at
```c
s=XDefaultScreen(V=d[D]=XOpenDisplay(*(h+=!! *h)));
```
because `XOpenDisplay()` returned NULL. But using `:0 :0` _appears_ to resolve
that problem. However instead it crashes at this code:
```c
XMapRaised(V,R[D][x][y]=w(V,e,H*x,H*y,H,H,1,0,1,0,2048,&c));
```
This is formed through the macros `K` and what appears to be `S` (but maybe
others?):
```c
#define K Y(o,XMapRaised(V,e);)x=3;x--;)for(y=3;y--;r(G))XMapRaised(V,R[D]
#define S +k),z(k-P=w(V,e,H*x,H*y,H,H,1,0,1,0,2048,&c));}XEvent J;M(){XFlush(
```
and the code surrounding it will look something like:
```c
for (o[D]=XCreatePixmapFromBitmapData(V,e,b,H,H,BlackPixel(V,s),
WhitePixel(V,s),DefaultDepth(V,s)),memset(b,x=0,H*H); x<H; x++)
XMapRaised(V,e);
for(x=3; x--;)
for(y=3; y--; r(G))
XMapRaised(V,R[D][x][y]=w(V,e,H*x,H*y,H,H,1,0,1,0,2048,&c));
```
In particular it is this part of the code that crashes: `w(...)`. But what is
that? According to `lldb` it is:
```
(lldb) p w
(XID (*)(...)) $0 = 0x00000001003cd374 (libX11.6.dylib`XCreateWindow)
```
so `w == XCreateWindow()` (which can also be seen in the code). But it never
actually finishes its call; modifying the code a bit and we see that it crashes
before it returns:
```
(lldb) up
frame #1: 0x0000000100003af4 jonth`T at jonth.c:40:16
37 r(G)
38 )
39 {
-> 40 Window ww = w(V,e,H*x,H*y,H,H,1,0,1,0,2048,&c);
41 XMapRaised(V,R[D][x][y]=ww);
42 }
```
...so it never reaches the call that should be using its return value.
Unfortunately if XQuartz has debug symbols I don't have access to them so I'm at
a loss at this time.
A C pre-processed version of the code is below in case this helps you find the
problem:
```c
#include <math.h>
#include <X11/Xlib.h>
extern XIM Z;XID(*w)()=XCreateWindow,m,e,o[2],W[2],G[2],R[2][3][3];Display*V,*d[2];char**h,k=25,b[2500],H=50,D,s,x,y,i;T(){float l;XSetWindowAttributes c;s=XDefaultScreen(V=d[D]=XOpenDisplay(*(h+=!! *h)));XStoreName(V,e=w(V,RootWindow(V,s),0,0,152,152,2,0,1,0,0,0),"II"+D);for(G[D]=XCreatePixmapFromBitmapData(V,e,b,H,H,BlackPixel(V,s),WhitePixel(V,s),DefaultDepth(V,s)),memset(b,x=0,H*H);x<H;x++) for(i=c.event_mask=4;i--;x+i>H||z(x+i,(z(H-x-i,x),x)))x<i||z(x-i,x)|z(H-x+i,x);for(W[D]=XCreatePixmapFromBitmapData(V,e,b,H,H,BlackPixel(V,s),WhitePixel(V,s),DefaultDepth(V,s)),memset(b,x=0,H*H);x<H;x++) for(l=k;l>20&&l>x;l-=.5)z(x+k,y=sqrt(l*l-x*x) +k),z(k-x,y)-z(y,x+k)+z(y,k-x)*z(x+k,y=H-y),z(k-x,y),z(y,k-x),z(y,k+x);for(o[D]=XCreatePixmapFromBitmapData(V,e,b,H,H,BlackPixel(V,s),WhitePixel(V,s),DefaultDepth(V,s)),memset(b,x=0,H*H);x<H;x++)XMapRaised(V,e); for(x=3;x--;)for(y=3;y--;r(G))XMapRaised(V,R[D][x][y]=w(V,e,H*x,H*y,H,H,1,0,1,0,2048,&c));}XEvent J;M(){XFlush( d[!D]);x=3;for(XNextEvent(V,&J);x--;)for(y=3;y--;J.xany.window==R[D][ x][y]&&!b[x+k*y]++?t(D),t(!(D^=1)):D);M();}z(x,y){b[x/8+y*7]|=1<<x%8;}t(p){r(p?W:o);XClearWindow(V,m);}main(i,f)char**f;{M((T(h=f), T (++D)));}r(XID*z){XSetWindowBackgroundPixmap(V=d[D],m=R[D][x][y],z[ D]);}GC*g(
XIC
);
```
### Workaround for macOS (if you have another X capable box like linux)
If you have X forward functionality enabled if you put in your `~/.ssh/config`
file (in the macOS) the line: `ForwardX11 yes` and have XQuartz open and ssh
into that other box by `ssh -X` it appears that you can run the program but it
does appear to not register the `O` move. Not sure if that's just doing
something wrong or not.
## STATUS: missing or dead link - please provide them
As well the link which was http://www.uio.no/~jonth is no longer valid and
+6
View File
@@ -717,6 +717,12 @@ Cody fixed this to compile and work with modern systems. As he loved the
references in the code that could not compile he just commented out as little as
possible to get this to compile.
## [1996/jonth](1996/jonth/jonth.c) ([README.md](1996/jonth/README.md]))
Cody fixed this to not segfault under macOS. The problem was that the function
pointer `w`, which points to `XCreateWindow()`, did not specify the parameters of
the function in the pointer assignment.
## [1996/westley](1996/westley/westley.c) ([README.md](1996/westley/README.md]))