Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: atexit does not work when building a Windows DLL #1608

Merged
merged 3 commits into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
411 changes: 299 additions & 112 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion include/zsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ CZMQ_EXPORT void *
// Optionally shut down the CZMQ zsys layer; this normally happens automatically
// when the process exits; however this call lets you force a shutdown
// earlier, avoiding any potential problems with atexit() ordering, especially
// with Windows dlls.
// with Windows DLL builds, where atexit() does not work and zsys_shutdown has
// to be called manually.
CZMQ_EXPORT void
zsys_shutdown (void);

Expand Down
4 changes: 0 additions & 4 deletions src/czmq_selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ main (int argc, char **argv)
else
test_runall (verbose);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

return 0;
}
/*
Expand Down
4 changes: 4 additions & 0 deletions src/test_zgossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,9 @@ main (int argn, char *argv [])

printf ("(100%%) OK\n");

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

return 0;
}
4 changes: 4 additions & 0 deletions src/zactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ zactor_test (bool verbose)
assert (streq (string, "This is a string"));
free (string);
zactor_destroy (&actor);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zarmour.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ zarmour_test (bool verbose)
#endif

zarmour_destroy (&self);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
7 changes: 6 additions & 1 deletion src/zauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,12 @@ zauth_test (bool verbose)
assert (dir);
zdir_remove (dir, true);
zdir_destroy (&dir);
// @end
#endif

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zbeacon.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ zbeacon_test (bool verbose)
zactor_destroy (&node1);
zactor_destroy (&node2);
zactor_destroy (&node3);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zcert.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ zcert_test (bool verbose)
assert (dir);
zdir_remove (dir, true);
zdir_destroy (&dir);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zcertstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ zcertstore_test (bool verbose)
assert (dir);
zdir_remove (dir, true);
zdir_destroy (&dir);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ zchunk_test (bool verbose)
assert (memcmp (zchunk_data (chunk), "ghij", 4) == 0);
zchunk_destroy (&copy);
zchunk_destroy (&chunk);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ zclock_test (bool verbose)
if (verbose)
puts (timestr);
free (timestr);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,10 @@ zconfig_test (bool verbose)
assert (dir);
zdir_remove (dir, true);
zdir_destroy (&dir);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zdigest.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ zdigest_test (bool verbose)
"DEB23807D4FE025E900FE9A9C7D8410C3DDE9671"));
zdigest_destroy (&digest);
free (buffer);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ zdir_test (bool verbose)
zdir_t *testdir = zdir_new ("zdir-test-dir", NULL);
zdir_remove (testdir, true);
zdir_destroy (&testdir);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zdir_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ zdir_patch_test (bool verbose)
assert (streq (zfile_filename (file, "."), "bilbo"));
assert (streq (zdir_patch_vpath (patch), "/bilbo"));
zdir_patch_destroy (&patch);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
7 changes: 6 additions & 1 deletion src/zfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,14 @@ zfile_test (bool verbose)
assert (zchunk_streq (chunk, "6789"));
zchunk_destroy (&chunk);
zfile_remove (file);
// @end
zfile_close (file);
zfile_destroy (&file);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

// @end

printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ zframe_test (bool verbose)
zsock_destroy (&radio);
#endif

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zgossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ zgossip_test (bool verbose)
zactor_destroy (&alpha);
zactor_destroy (&beta);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zgossip_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,10 @@ zgossip_msg_test (bool verbose)
zgossip_msg_destroy (&self);
zsock_destroy (&input);
zsock_destroy (&output);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ zhash_test (bool verbose)
assert (streq ((char *) zhash_lookup (hash, "key1"), "This is a string"));
assert (streq ((char *) zhash_lookup (hash, "key2"), "Ring a ding ding"));
zhash_destroy (&hash);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zhashx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,10 @@ zhashx_test (bool verbose)
assert (streq ((char *) zhashx_lookup (hash, "key1"), "This is a string"));
assert (streq ((char *) zhashx_lookup (hash, "key2"), "Ring a ding ding"));
zhashx_destroy (&hash);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/ziflist.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ ziflist_test (bool verbose)
ziflist_reload (iflist);
assert (items == ziflist_size (iflist));
ziflist_destroy (&iflist);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ zlist_test (bool verbose)

zlist_destroy (&list);
assert (list == NULL);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zlistx.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ zlistx_test (bool verbose)

zlistx_purge (list);
zlistx_destroy (&list);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,10 @@ zloop_test (bool verbose)

zsock_destroy (&input);
zsock_destroy (&output);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zmonitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ zmonitor_test (bool verbose)
zsock_destroy (&client);
zsock_destroy (&server);
#endif

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,10 @@ zmsg_test (bool verbose)
zframe_destroy (&frame);
zmsg_destroy (&msg);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zpoller.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ zpoller_test (bool verbose)
zsock_destroy (&client);
zsock_destroy (&server);
#endif

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
12 changes: 8 additions & 4 deletions src/zproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,11 @@ zproxy_test (bool verbose)
proxy = zactor_new (zproxy, NULL);
assert (proxy);

#ifdef WIN32
#ifdef WIN32
sink = zsock_new_sub(">inproc://backend", "whatever");
#else
sink = zsock_new_sub (">ipc://backend", "whatever");
#endif // WIN32
#else
sink = zsock_new_sub (">ipc://backend", "whatever");
#endif // WIN32
assert (sink);

#ifdef WIN32
Expand Down Expand Up @@ -731,6 +731,10 @@ zproxy_test (bool verbose)
zsys_file_delete (TESTDIR "/mycert.txt");
zsys_dir_delete (TESTDIR);
#endif

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end
printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/zrex.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ zrex_test (bool verbose)
assert (streq (zrex_hit (rex, 1), "CURVE"));
assert (streq (mechanism, "CURVE"));
zrex_destroy (&rex);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

// @end
printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2184,4 +2184,8 @@ zsock_test (bool verbose)
// @end
printf ("OK\n");
zsock_option_test (verbose);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
}
4 changes: 4 additions & 0 deletions src/zstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ zstr_test (bool verbose)
zsock_destroy (&client);
zsock_destroy (&server);
#endif

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end

printf ("OK\n");
Expand Down
4 changes: 4 additions & 0 deletions src/zsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1881,5 +1881,9 @@ zsys_test (bool verbose)
zsys_set_max_msgsz (-1);
assert (zsys_max_msgsz () == 2000);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

printf ("OK\n");
}
4 changes: 4 additions & 0 deletions src/ztimerset.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ ztimerset_test (bool verbose)
assert (timeout2 > timeout);

ztimerset_destroy (&self);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif
// @end
printf ("OK\n");
#endif
Expand Down
Loading