@needs_dlfcn
def test_dlfcn_longjmp(self):
    self.prep_dlfcn_lib()
    lib_src = '\n      #include <setjmp.h>\n      #include <stdio.h>\n\n      void jumpy(jmp_buf buf) {\n        static int i = 0;\n        i++;\n        if (i == 10) longjmp(buf, i);\n        printf("pre %d\\n", i);\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_jumpy'])
    dirname = self.get_dir()
    filename = os.path.join(dirname, 'liblib.c')
    self.build_dlfcn_lib(lib_src, dirname, filename)
    self.prep_dlfcn_main()
    src = '\n      #include <assert.h>\n      #include <stdio.h>\n      #include <dlfcn.h>\n      #include <setjmp.h>\n\n      typedef void (*jumpfunc)(jmp_buf);\n\n      int main() {\n        printf("go!\\n");\n\n        void *lib_handle;\n        lib_handle = dlopen("liblib.so", RTLD_NOW);\n        assert(lib_handle != NULL);\n\n        jumpfunc jumpy = (jumpfunc)dlsym(lib_handle, "jumpy");\n        assert(jumpy);\n\n        jmp_buf buf;\n        int jmpval = setjmp(buf);\n        if (jmpval == 0) {\n          while (1) jumpy(buf);\n        } else {\n          printf("out!\\n");\n        }\n\n        return 0;\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free'])
    self.do_run(src, 'go!\npre 1\npre 2\npre 3\npre 4\npre 5\npre 6\npre 7\npre 8\npre 9\nout!\n', force_c=True)
@needs_dlfcn
def test_dlfcn_longjmp(self):
    self.prep_dlfcn_lib()
    lib_src = '\n      #include <setjmp.h>\n      #include <stdio.h>\n\n      void jumpy(jmp_buf buf) {\n        static int i = 0;\n        i++;\n        if (i == 10) longjmp(buf, i);\n        printf("pre %d\\n", i);\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_jumpy'])
    dirname = self.get_dir()
    filename = os.path.join(dirname, 'liblib.c')
    self.build_dlfcn_lib(lib_src, dirname, filename)
    self.prep_dlfcn_main()
    src = '\n      #include <assert.h>\n      #include <stdio.h>\n      #include <dlfcn.h>\n      #include <setjmp.h>\n\n      typedef void (*jumpfunc)(jmp_buf);\n\n      int main() {\n        printf("go!\\n");\n\n        void *lib_handle;\n        lib_handle = dlopen("liblib.so", RTLD_NOW);\n        assert(lib_handle != NULL);\n\n        jumpfunc jumpy = (jumpfunc)dlsym(lib_handle, "jumpy");\n        assert(jumpy);\n\n        jmp_buf buf;\n        int jmpval = setjmp(buf);\n        if (jmpval == 0) {\n          while (1) jumpy(buf);\n        } else {\n          printf("out!\\n");\n        }\n\n        return 0;\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free'])
    self.do_run(src, 'go!\npre 1\npre 2\npre 3\npre 4\npre 5\npre 6\npre 7\npre 8\npre 9\nout!\n', force_c=True)