@needs_dlfcn
def test_dlfcn_stacks(self):
    self.prep_dlfcn_lib()
    lib_src = '\n      #include <assert.h>\n      #include <stdio.h>\n      #include <string.h>\n\n      int myfunc(const char *input) {\n        char bigstack[1024] = { 0 };\n\n        // make sure we didn\'t just trample the stack!\n        assert(!strcmp(input, "foobar"));\n\n        snprintf(bigstack, sizeof(bigstack), input);\n        return strlen(bigstack);\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc'])
    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 <string.h>\n\n      typedef int (*FUNCTYPE)(const char *);\n\n      int main() {\n        void *lib_handle;\n        FUNCTYPE func_ptr;\n        char str[128];\n\n        snprintf(str, sizeof(str), "foobar");\n\n        // HACK: Use strcmp in the main executable so that it doesn\'t get optimized out and the dynamic library\n        //       is able to use it.\n        assert(!strcmp(str, "foobar"));\n\n        lib_handle = dlopen("liblib.so", RTLD_NOW);\n        assert(lib_handle != NULL);\n\n        func_ptr = (FUNCTYPE)dlsym(lib_handle, "myfunc");\n        assert(func_ptr != NULL);\n        assert(func_ptr(str) == 6);\n\n        puts("success");\n\n        return 0;\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_strcmp'])
    self.do_run(src, 'success', force_c=True)
@needs_dlfcn
def test_dlfcn_stacks(self):
    self.prep_dlfcn_lib()
    lib_src = '\n      #include <assert.h>\n      #include <stdio.h>\n      #include <string.h>\n\n      int myfunc(const char *input) {\n        char bigstack[1024] = { 0 };\n\n        // make sure we didn\'t just trample the stack!\n        assert(!strcmp(input, "foobar"));\n\n        snprintf(bigstack, sizeof(bigstack), input);\n        return strlen(bigstack);\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc'])
    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 <string.h>\n\n      typedef int (*FUNCTYPE)(const char *);\n\n      int main() {\n        void *lib_handle;\n        FUNCTYPE func_ptr;\n        char str[128];\n\n        snprintf(str, sizeof(str), "foobar");\n\n        // HACK: Use strcmp in the main executable so that it doesn\'t get optimized out and the dynamic library\n        //       is able to use it.\n        assert(!strcmp(str, "foobar"));\n\n        lib_handle = dlopen("liblib.so", RTLD_NOW);\n        assert(lib_handle != NULL);\n\n        func_ptr = (FUNCTYPE)dlsym(lib_handle, "myfunc");\n        assert(func_ptr != NULL);\n        assert(func_ptr(str) == 6);\n\n        puts("success");\n\n        return 0;\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_strcmp'])
    self.do_run(src, 'success', force_c=True)