[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] setjmp.h and csetjmp



Hello.

I've just tried to compile the latest MiNTLib from CVS with GCC 4.2.2, and it works without additional modification !

The only remaining issue is about the compilation of libstdc++-v3, provided with GCC. The header <csetjmp> is incompatible with <setjmp.h> provided by the MiNTLib.

The attached program lj.cpp shows the problem.
$ m68k-atari-mint-gcc lj.cpp -o lj.tos
In file included from lj.cpp:2:
/usr/local/m68k-atari-mint/lib/gcc/m68k-atari-mint/4.2.2/../../../../m68k-atari-mint/include/c++/4.2.2/csetjmp:64: error: '::longjmp' has not been declared
lj.cpp: In function 'int main(int, char**)':
lj.cpp:12: error: 'longjmp' is not a member of 'std'

The problem:
When __USE_BSD is defined (it is - don't know why), longjmp() is implemented as a macro calling siglongjmp().
But the code inside <csetjmp> is :

#include <setjmp.h>

// Get rid of those macros defined in <setjmp.h> in lieu of real functions.
#undef longjmp

// Adhere to section 17.4.1.2 clause 5 of ISO 14882:1998
#ifndef setjmp
#define setjmp(env) setjmp (env)
#endif

_GLIBCXX_BEGIN_NAMESPACE(std)

  using ::jmp_buf;
  using ::longjmp;

_GLIBCXX_END_NAMESPACE


We can see here that :
- longjmp can't be a define, because <csetjmp> undefines it.
- longjmp must be a global function, in order to be included inside the namespace std.

The only valid fix I was able to imagine is to patch <setjmp.h> by replacing the longjmp() macro by a non-portable inline function (see attached patch). It is ugly. However, it works, and after that, the whole libstdc++-v3 is compatible with the MiNTLib without any modification.

Does anyone have a better idea to fix the longjmp problem ?

Vincent
#include <cstdio>
#include <csetjmp>

int main(int argc, char* argv[])
{
        jmp_buf env;

        int ret = setjmp(env);
        std::printf("After setjmp: ret == %d\n", ret);
        if (ret == 0)
        {
                std::longjmp(env, 3);
        }

        return 0;
}
--- mintlib-CVS/include/setjmp.h	2007-12-09 22:29:12.187500000 +0100
+++ mintlib-CVS-patch-20071209/include/setjmp.h	2007-12-09 23:16:02.734375000 +0100
@@ -24,7 +24,15 @@
 #define _setjmp(__jb)		(sigsetjmp(__jb, 0))
 #define _longjmp(__jb,__v)	(siglongjmp(__jb, __v))
 #define setjmp(__jb)		(sigsetjmp(__jb, 1))
-#define longjmp(__jb,__v)	(siglongjmp(__jb, __v))
+/*#define longjmp(__jb,__v)	(siglongjmp(__jb, __v))*/
+
+/* <csetjmp> needs a real function */
+static __inline__ void
+longjmp (sigjmp_buf env, int val)
+{
+	siglongjmp(env, val);
+}
+
 #endif /* __USE_BSD */
 
 #endif /* __STRICT_ANSI__ */