~ubuntu-branches/ubuntu/trusty/emscripten/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/core/test_longjmp2.in

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140119141240-jg1l42cc158j59tn
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <setjmp.h>
 
2
#include <stdio.h>
 
3
 
 
4
typedef struct {
 
5
  jmp_buf* jmp;
 
6
} jmp_state;
 
7
 
 
8
void stack_manipulate_func(jmp_state* s, int level) {
 
9
  jmp_buf buf;
 
10
 
 
11
  printf("Entering stack_manipulate_func, level: %d\n", level);
 
12
 
 
13
  if (level == 0) {
 
14
    s->jmp = &buf;
 
15
    if (setjmp(*(s->jmp)) == 0) {
 
16
      printf("Setjmp normal execution path, level: %d\n", level);
 
17
      stack_manipulate_func(s, level + 1);
 
18
    } else {
 
19
      printf("Setjmp error execution path, level: %d\n", level);
 
20
    }
 
21
  } else {
 
22
    printf("Perform longjmp at level %d\n", level);
 
23
    longjmp(*(s->jmp), 1);
 
24
  }
 
25
 
 
26
  printf("Exiting stack_manipulate_func, level: %d\n", level);
 
27
}
 
28
 
 
29
int main(int argc, char* argv[]) {
 
30
  jmp_state s;
 
31
  s.jmp = NULL;
 
32
  stack_manipulate_func(&s, 0);
 
33
 
 
34
  return 0;
 
35
}