mirror of https://github.com/aamine/cbc
* import/setjmp.hb: new file to support setjmp.
* test: test setjmp. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4113 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
parent
0d9cdf252d
commit
4cb2818d45
|
@ -1,3 +1,9 @@
|
|||
Wed Dec 24 02:54:06 2008 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* import/setjmp.hb: new file to support setjmp.
|
||||
|
||||
* test: test setjmp.
|
||||
|
||||
Mon Dec 15 00:05:16 2008 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* introduce virtual stack again, for only local variables and tmp
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// setjmp.hb
|
||||
|
||||
typedef char[160] jmp_buf;
|
||||
typedef char[160] sigjmp_buf;
|
||||
|
||||
extern int setjmp(jmp_buf buf);
|
||||
extern int sigsetjmp(sigjmp_buf buf, int savesigs);
|
||||
extern void longjmp(jmp_buf buf, int value);
|
||||
extern void siglongjmp(sigjmp_buf buf, int value);
|
|
@ -0,0 +1,34 @@
|
|||
import stdio;
|
||||
import setjmp;
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
func1();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static jmp_buf buf;
|
||||
|
||||
void
|
||||
func1(void)
|
||||
{
|
||||
if (setjmp(buf) == 0) {
|
||||
func2(buf);
|
||||
}
|
||||
puts("OK");
|
||||
}
|
||||
|
||||
void
|
||||
func2(jmp_buf buf)
|
||||
{
|
||||
func3(buf);
|
||||
puts("func2: NG");
|
||||
}
|
||||
|
||||
void
|
||||
func3(jmp_buf buf)
|
||||
{
|
||||
longjmp(buf, 1);
|
||||
puts("func3: NG");
|
||||
}
|
|
@ -323,6 +323,10 @@ test_36_alloca() {
|
|||
assert_out "17;17;17;17" ./alloca2
|
||||
}
|
||||
|
||||
test_37_setjmp() {
|
||||
assert_out "OK" ./setjmptest
|
||||
}
|
||||
|
||||
###
|
||||
### Local Assertions
|
||||
###
|
||||
|
|
Loading…
Reference in New Issue