
Nat Goodspeed wrote:
banana.cpp now runs on my Mac! For closure, here's what I found.
I also got it to run on Debian sarge (linux32), Debian etch (linux64), Mac OS X 10.5 and Windows XP Pro. My internal #include reordering turned up another couple of dependencies on BOOST_ASSERT without the corresponding #include; I've added those to the attached cumulative patch file. This cumulative patch file also incorporates the gcc 3.3 workaround mentioned in an earlier mail, but omitted from the previous boost-coroutine.patch. Finally -- the Windows Fiber API isn't visible in <windows.h> unless you tweak _WIN32_WINNT to a magic number. This too is included in the attached patch file. diff -rc orig/boost-coroutine/boost/coroutine/coroutine.hpp ./boost/coroutine/coroutine.hpp *** orig/boost-coroutine/boost/coroutine/coroutine.hpp Sun Aug 20 13:11:16 2006 --- ./boost/coroutine/coroutine.hpp Tue Apr 7 23:38:11 2009 *************** *** 28,33 **** --- 28,35 ---- #ifndef BOOST_COROUTINE_COROUTINE_HPP_20060512 #define BOOST_COROUTINE_COROUTINE_HPP_20060512 + // default_context_impl.hpp must be first for weird Apple bug + #include <boost/coroutine/detail/default_context_impl.hpp> #include <cstddef> #include <boost/preprocessor/repetition.hpp> #include <boost/tuple/tuple.hpp> *************** *** 37,43 **** #include <boost/call_traits.hpp> #include <boost/coroutine/detail/arg_max.hpp> #include <boost/coroutine/detail/coroutine_impl.hpp> - #include <boost/coroutine/detail/default_context_impl.hpp> #include <boost/coroutine/detail/is_callable.hpp> #include <boost/coroutine/detail/argument_packer.hpp> #include <boost/coroutine/detail/argument_unpacker.hpp> --- 39,44 ---- diff -rc orig/boost-coroutine/boost/coroutine/detail/context_linux.hpp ./boost/coroutine/detail/context_linux.hpp *** orig/boost-coroutine/boost/coroutine/detail/context_linux.hpp Sun Aug 20 13:11:09 2006 --- ./boost/coroutine/detail/context_linux.hpp Wed Apr 8 01:10:03 2009 *************** *** 34,39 **** --- 34,40 ---- #include <cstddef> #include <boost/coroutine/detail/posix_utility.hpp> #include <boost/coroutine/detail/swap_context.hpp> + #include <boost/assert.hpp> /* * Defining BOOST_COROUTINE_INLINE_ASM will enable the inlin3 diff -rc orig/boost-coroutine/boost/coroutine/detail/context_posix.hpp ./boost/coroutine/detail/context_posix.hpp *** orig/boost-coroutine/boost/coroutine/detail/context_posix.hpp Sun Aug 20 13:11:09 2006 --- ./boost/coroutine/detail/context_posix.hpp Tue Apr 7 23:40:17 2009 *************** *** 28,39 **** #ifndef BOOST_COROUTINE_CONTEXT_POSIX_HPP_20060601 #define BOOST_COROUTINE_CONTEXT_POSIX_HPP_20060601 #include <boost/config.hpp> #if defined(_XOPEN_UNIX) && defined(_XOPEN_VERSION) && _XOPEN_VERSION >= 500 /* ! * makecontex based context implementation. Should be available on all * SuSv2 compliant UNIX systems. * NOTE: this implementation is not * optimal as the makecontext API saves and restore the signal mask. --- 28,55 ---- #ifndef BOOST_COROUTINE_CONTEXT_POSIX_HPP_20060601 #define BOOST_COROUTINE_CONTEXT_POSIX_HPP_20060601 + + // NOTE (per http://lists.apple.com/archives/darwin-dev/2008/Jan/msg00232.html): + // > Why the bus error? What am I doing wrong? + // This is a known issue where getcontext(3) is writing past the end of the + // ucontext_t struct when _XOPEN_SOURCE is not defined (rdar://problem/5578699 ). + // As a workaround, define _XOPEN_SOURCE before including ucontext.h. + #if defined(__APPLE__) && ! defined(_XOPEN_SOURCE) + #define _XOPEN_SOURCE + // However, the above #define will only affect <ucontext.h> if it has not yet + // been #included by something else! + #if defined(_STRUCT_UCONTEXT) + #error You must #include coroutine headers before anything that #includes <ucontext.h> + #endif + #endif + #include <boost/config.hpp> + #include <boost/assert.hpp> #if defined(_XOPEN_UNIX) && defined(_XOPEN_VERSION) && _XOPEN_VERSION >= 500 /* ! * makecontext based context implementation. Should be available on all * SuSv2 compliant UNIX systems. * NOTE: this implementation is not * optimal as the makecontext API saves and restore the signal mask. *************** *** 43,48 **** --- 59,65 ---- * it is unlikely that they will be removed any time soon. */ #include <ucontext.h> + #include <signal.h> // SIGSTKSZ #include <boost/noncopyable.hpp> #include <boost/coroutine/exception.hpp> #include <boost/coroutine/detail/posix_utility.hpp> *************** *** 83,89 **** public: typedef ucontext_context_impl_base context_impl_base; ! enum {default_stack_size = 8192}; /** --- 100,106 ---- public: typedef ucontext_context_impl_base context_impl_base; ! enum {default_stack_size = SIGSTKSZ}; /** diff -rc orig/boost-coroutine/boost/coroutine/detail/context_windows.hpp ./boost/coroutine/detail/context_windows.hpp *** orig/boost-coroutine/boost/coroutine/detail/context_windows.hpp Sun Aug 20 13:11:09 2006 --- ./boost/coroutine/detail/context_windows.hpp Wed Apr 8 01:06:37 2009 *************** *** 28,37 **** #ifndef BOOST_COROUTINE_CONTEXT_WINDOWS_HPP_20060625 #define BOOST_COROUTINE_CONTEXT_WINDOWS_HPP_20060625 #include <windows.h> #include <winnt.h> #include <boost/config.hpp> ! #include <boost/config.hpp> #include <boost/noncopyable.hpp> #include <boost/coroutine/exception.hpp> #include <boost/coroutine/detail/swap_context.hpp> --- 28,40 ---- #ifndef BOOST_COROUTINE_CONTEXT_WINDOWS_HPP_20060625 #define BOOST_COROUTINE_CONTEXT_WINDOWS_HPP_20060625 + // This kludge is necessary to make CreateFiber, etc., visible + #define WIN32_LEAN_AND_MEAN + #define _WIN32_WINNT 0x0400 #include <windows.h> #include <winnt.h> #include <boost/config.hpp> ! #include <boost/assert.hpp> #include <boost/noncopyable.hpp> #include <boost/coroutine/exception.hpp> #include <boost/coroutine/detail/swap_context.hpp> diff -rc orig/boost-coroutine/boost/coroutine/detail/noreturn.hpp ./boost/coroutine/detail/noreturn.hpp *** orig/boost-coroutine/boost/coroutine/detail/noreturn.hpp Sun Aug 20 13:11:09 2006 --- ./boost/coroutine/detail/noreturn.hpp Wed Apr 8 01:07:46 2009 *************** *** 40,48 **** --- 40,54 ---- #if defined(__GNUC__) + #if __GNUC_MAJOR__ > 3 || (__GNUC_MAJOR__ == 3 && __GNUC_MINOR__ > 3) #define BOOST_COROUTINE_NORETURN(function) \ function __attribute__((__noreturn__)) \ /**/ + #else // gcc 3.3 + #define BOOST_COROUTINE_NORETURN(function) \ + function + /**/ + #endif // gcc 3.3 #elif defined (BOOST_MSVC) diff -rc orig/boost-coroutine/boost/coroutine/detail/posix_utility.hpp ./boost/coroutine/detail/posix_utility.hpp *** orig/boost-coroutine/boost/coroutine/detail/posix_utility.hpp Sun Aug 20 13:11:09 2006 --- ./boost/coroutine/detail/posix_utility.hpp Wed Apr 1 09:57:03 2009 *************** *** 129,135 **** --- 129,139 ---- void * stack = ::mmap(NULL, size, PROT_EXEC|PROT_READ|PROT_WRITE, + #if defined(__APPLE__) + MAP_PRIVATE|MAP_ANON, + #else // ! __APPLE__ MAP_PRIVATE|MAP_ANONYMOUS, + #endif // ! __APPLE__ -1, 0 ); diff -rc orig/boost-coroutine/boost/coroutine/future.hpp ./boost/coroutine/future.hpp *** orig/boost-coroutine/boost/coroutine/future.hpp Sun Aug 20 13:11:16 2006 --- ./boost/coroutine/future.hpp Tue Apr 7 23:38:42 2009 *************** *** 33,38 **** --- 33,40 ---- #ifndef BOOST_COROUTINE_WAIT_MAX #define BOOST_COROUTINE_WAIT_MAX 10 #endif + // default_context_impl.hpp must be first for weird Apple bug + #include <boost/coroutine/detail/default_context_impl.hpp> #include <boost/none.hpp> #include <boost/config.hpp> #include <boost/tuple/tuple.hpp> *************** *** 48,54 **** #include <boost/coroutine/detail/call_impl.hpp> #include <boost/coroutine/detail/wait_impl.hpp> #include <boost/coroutine/detail/future_impl.hpp> - #include <boost/coroutine/detail/default_context_impl.hpp> namespace boost { namespace coroutines { --- 50,55 ---- diff -rc orig/boost-coroutine/libs/coroutine/example/banana.cpp ./libs/coroutine/example/banana.cpp *** orig/boost-coroutine/libs/coroutine/example/banana.cpp Sun Aug 20 13:12:02 2006 --- ./libs/coroutine/example/banana.cpp Tue Apr 7 23:40:46 2009 *************** *** 26,35 **** // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include <iostream> #include <string> #include <boost/bind.hpp> - #include <boost/coroutine/coroutine.hpp> namespace coroutines = boost::coroutines; using coroutines::coroutine; --- 26,35 ---- // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) + #include <boost/coroutine/coroutine.hpp> #include <iostream> #include <string> #include <boost/bind.hpp> namespace coroutines = boost::coroutines; using coroutines::coroutine;