prd

uEmacs macOS bug

January 28, 2018 · 2 minute read

I was looking at Linus Torvalds github and found his maintained fork of uEmacs/PK. I’ve never bothered trying to compile it before, but thought it might be worth a quick look. Emacs has never been my editor of choice* (too Escape-Meta-Alt-Control-Shift for my taste), but reading up on MicroEmacs flavours, it seemed like a small gentle subset of all that escape character madness.

Cloning his repo and running make worked without fixes and you end up with a em binary. However, it crashes with a SIGABRT if you try to give it a filename as argument from the commandline, like ./em ebind.h.

While trying to search for some workflows or howtos regarding this fork of MicroEmacs, I found a youtube clip from Rudá Moura, where he debugs this particular bug and fixes it. The video is from 2016, but the fix still stands on my macOS High Sierra 10.13.3.

The program crashes in file.c:249 and here is the fix:

uemacs [master] > git diff
diff --git a/file.c b/file.c
index 1feb97a..4dba37b 100644
--- a/file.c
+++ b/file.c
@@ -246,7 +246,8 @@ int readin(char *fname, int lockfl)
        if ((s = bclear(bp)) != TRUE)   /* Might be old.        */
                return s;
        bp->b_flag &= ~(BFINVS | BFCHG);
-       strcpy(bp->b_fname, fname);
+       if (bp->b_fname != fname)
+               strcpy(bp->b_fname, fname);
 
        /* let a user macro get hold of things...if he wants */
        execute(META | SPEC | 'R', FALSE, 1);

I do not have any plans of using uEmacs as my primary hammer any time soon, but it is fun to poke around in the editor that created Linux and git.

Just to be clear, Linus himself does not recommend anyone to try it and has on several occasions said he should learn another editor “instead of polishing this turd”.

*I went straight to vim a decade ago and switched to acme/sam from Plan 9 around 2016.