PSA: avoiding the "ucontext routines are deprecated" error on Mac OS X Snow Leopard

August 28, 2009

Recently I upgraded to the new version of Mac OS X. I tried compiling Factor on it, but got this error:

In file included from vm/os-macosx-x86.64.hpp:1,
                 from vm/platform.hpp:38,
                 from vm/master.hpp:36,
                 from vm/os-unix.cpp:1:
/usr/include/ucontext.h:42:2: error: #error ucontext routines are
    deprecated, and require _XOPEN_SOURCE to be defined

I googled this error, and I found that users of SBCL, V8, and boehm gc ran into the same problem, but the ensuing bug tracker and mailing list discussions didn't turn up any robust solutions. So I looked at Apple's ucontext.h header, and it turns out the only thing they are deprecating are the context manipulation functions from the old X/Open standard: getcontext, makecontext, setcontext, and swapcontext. Factor doesn't use these functions; it only needs the ucontext_t structure, which is defined in the non-deprecated header sys/ucontext.h. By changing Factor's C++ core to include sys/ucontext.h instead of ucontext.h on Mac OS X, the error goes away, and you don't need to define _XOPEN_SOURCE or leave yourself vulnerable to Apple's aggressive deprecated API elimination when OS X Def Leppard comes out in a couple of years.