@needs_dlfcn
def test_dlfcn_varargs(self):
    self.prep_dlfcn_lib()
    lib_src = '\n      void print_ints(int n, ...);\n      extern "C" void func() {\n        print_ints(2, 13, 42);\n      }\n      '
    dirname = self.get_dir()
    filename = os.path.join(dirname, 'liblib.cpp')
    self.set_setting('EXPORTED_FUNCTIONS', ['_func'])
    self.build_dlfcn_lib(lib_src, dirname, filename)
    self.prep_dlfcn_main()
    src = '\n      #include <stdarg.h>\n      #include <stdio.h>\n      #include <dlfcn.h>\n      #include <assert.h>\n\n      void print_ints(int n, ...) {\n        va_list args;\n        va_start(args, n);\n        for (int i = 0; i < n; i++) {\n          printf("%d\\n", va_arg(args, int));\n        }\n        va_end(args);\n      }\n\n      int main() {\n        void* lib_handle;\n        void (*fptr)();\n\n        print_ints(2, 100, 200);\n\n        lib_handle = dlopen("liblib.so", RTLD_NOW);\n        assert(lib_handle);\n        fptr = (void (*)())dlsym(lib_handle, "func");\n        fptr();\n\n        return 0;\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_main'])
    self.do_run(src, '100\n200\n13\n42\n')
@needs_dlfcn
def test_dlfcn_varargs(self):
    self.prep_dlfcn_lib()
    lib_src = '\n      void print_ints(int n, ...);\n      extern "C" void func() {\n        print_ints(2, 13, 42);\n      }\n      '
    dirname = self.get_dir()
    filename = os.path.join(dirname, 'liblib.cpp')
    self.set_setting('EXPORTED_FUNCTIONS', ['_func'])
    self.build_dlfcn_lib(lib_src, dirname, filename)
    self.prep_dlfcn_main()
    src = '\n      #include <stdarg.h>\n      #include <stdio.h>\n      #include <dlfcn.h>\n      #include <assert.h>\n\n      void print_ints(int n, ...) {\n        va_list args;\n        va_start(args, n);\n        for (int i = 0; i < n; i++) {\n          printf("%d\\n", va_arg(args, int));\n        }\n        va_end(args);\n      }\n\n      int main() {\n        void* lib_handle;\n        void (*fptr)();\n\n        print_ints(2, 100, 200);\n\n        lib_handle = dlopen("liblib.so", RTLD_NOW);\n        assert(lib_handle);\n        fptr = (void (*)())dlsym(lib_handle, "func");\n        fptr();\n\n        return 0;\n      }\n      '
    self.set_setting('EXPORTED_FUNCTIONS', ['_main'])
    self.do_run(src, '100\n200\n13\n42\n')