@needs_dlfcn
def test_dlfcn_handle_alloc(self):
    dirname = self.get_dir()

    def indir(name):
        return os.path.join(dirname, name)
    libecho = '\n      #include <stdio.h>\n\n      static struct %(libname)s {\n        %(libname)s() {\n          puts("%(libname)s: loaded");\n        }\n      } _;\n    '
    self.prep_dlfcn_lib()
    self.build_dlfcn_lib((libecho % {'libname': 'a'}), dirname, indir('a.cpp'))
    shutil.move(indir('liblib.so'), indir('liba.so'))
    self.build_dlfcn_lib((libecho % {'libname': 'b'}), dirname, indir('b.cpp'))
    shutil.move(indir('liblib.so'), indir('libb.so'))
    self.set_setting('MAIN_MODULE')
    self.clear_setting('SIDE_MODULE')
    self.set_setting('EXPORT_ALL')
    self.emcc_args += ['--embed-file', '.@/']
    self.set_setting('INITIAL_MEMORY', ((32 * 1024) * 1024))
    src = '\n      #include <dlfcn.h>\n      #include <assert.h>\n      #include <stddef.h>\n\n      int main() {\n        void *liba, *libb, *liba2;\n        int err;\n\n        liba = dlopen("liba.so", RTLD_NOW);\n        assert(liba != NULL);\n        libb = dlopen("libb.so", RTLD_NOW);\n        assert(liba != NULL);\n\n        err = dlclose(liba);\n        assert(!err);\n\n        liba2 = dlopen("liba.so", RTLD_NOW);\n        assert(liba2 != libb);\n\n        return 0;\n      }\n      '
    self.do_run(src, 'a: loaded\nb: loaded\na: loaded\n')
@needs_dlfcn
def test_dlfcn_handle_alloc(self):
    dirname = self.get_dir()

    def indir(name):
        return os.path.join(dirname, name)
    libecho = '\n      #include <stdio.h>\n\n      static struct %(libname)s {\n        %(libname)s() {\n          puts("%(libname)s: loaded");\n        }\n      } _;\n    '
    self.prep_dlfcn_lib()
    self.build_dlfcn_lib((libecho % {'libname': 'a'}), dirname, indir('a.cpp'))
    shutil.move(indir('liblib.so'), indir('liba.so'))
    self.build_dlfcn_lib((libecho % {'libname': 'b'}), dirname, indir('b.cpp'))
    shutil.move(indir('liblib.so'), indir('libb.so'))
    self.set_setting('MAIN_MODULE')
    self.clear_setting('SIDE_MODULE')
    self.set_setting('EXPORT_ALL')
    self.emcc_args += ['--embed-file', '.@/']
    self.set_setting('INITIAL_MEMORY', ((32 * 1024) * 1024))
    src = '\n      #include <dlfcn.h>\n      #include <assert.h>\n      #include <stddef.h>\n\n      int main() {\n        void *liba, *libb, *liba2;\n        int err;\n\n        liba = dlopen("liba.so", RTLD_NOW);\n        assert(liba != NULL);\n        libb = dlopen("libb.so", RTLD_NOW);\n        assert(liba != NULL);\n\n        err = dlclose(liba);\n        assert(!err);\n\n        liba2 = dlopen("liba.so", RTLD_NOW);\n        assert(liba2 != libb);\n\n        return 0;\n      }\n      '
    self.do_run(src, 'a: loaded\nb: loaded\na: loaded\n')