{"action":"created","issue":{"url":"https://api.github.com/repos/sofa-framework/sofa/issues/168","repository_url":"https://api.github.com/repos/sofa-framework/sofa","labels_url":"https://api.github.com/repos/sofa-framework/sofa/issues/168/labels{/name}","comments_url":"https://api.github.com/repos/sofa-framework/sofa/issues/168/comments","events_url":"https://api.github.com/repos/sofa-framework/sofa/issues/168/events","html_url":"https://github.com/sofa-framework/sofa/pull/168","id":206806426,"number":168,"title":"[All] auto-init/cleanup libraries","user":{"login":"maxime-tournier","id":3356385,"avatar_url":"https://avatars.githubusercontent.com/u/3356385?v=3","gravatar_id":"","url":"https://api.github.com/users/maxime-tournier","html_url":"https://github.com/maxime-tournier","followers_url":"https://api.github.com/users/maxime-tournier/followers","following_url":"https://api.github.com/users/maxime-tournier/following{/other_user}","gists_url":"https://api.github.com/users/maxime-tournier/gists{/gist_id}","starred_url":"https://api.github.com/users/maxime-tournier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxime-tournier/subscriptions","organizations_url":"https://api.github.com/users/maxime-tournier/orgs","repos_url":"https://api.github.com/users/maxime-tournier/repos","events_url":"https://api.github.com/users/maxime-tournier/events{/privacy}","received_events_url":"https://api.github.com/users/maxime-tournier/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-02-10T14:16:28Z","updated_at":"2017-02-11T23:16:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/sofa-framework/sofa/pulls/168","html_url":"https://github.com/sofa-framework/sofa/pull/168","diff_url":"https://github.com/sofa-framework/sofa/pull/168.diff","patch_url":"https://github.com/sofa-framework/sofa/pull/168.patch"},"body":"I am unsure this PR is correct, so it really needs a green light from others before merge.\r\n\r\nWhen trying to call `std::exit` in some plugin, I had a segfault in cleanup code similar to this one:\r\n\r\n```c++\r\n// Detect missing cleanup() call.\r\nstatic const struct CleanupCheck\r\n{\r\n    CleanupCheck() {\r\n    }\r\n    \r\n    ~CleanupCheck() {\r\n        if (core::isInitialized() && !core::isCleanedUp())\r\n            helper::printLibraryNotCleanedUpWarning(\"SofaCore\", \"sofa::core::cleanup()\"); // segfault\r\n    }\r\n} check;\r\n```\r\n\r\nIn fact, most `init.cpp` files in SOFA have code similar to this one. In my case, `MessageDispatcher::LoggerStream::~LoggerStream` caused a call to `MessageDispatcher::process` which would then cause a segfault.\r\n\r\nWhat I don't understand is *why* the above code snipped does not simply `cleanup()` the library in the destructor, since the latter is being called while the library unloads and this is the last chance to actually clean things up, instead of (trying to) emit a warning while the whole program is being terminated.\r\n\r\nSo unless there is a compelling reason to leave it this way (and I would really like to know it), I suggest the above to be changed to:\r\n\r\n```c++\r\nstatic const struct CleanupCheck\r\n{\r\n    CleanupCheck() {\r\n        init();\r\n    }\r\n    \r\n    ~CleanupCheck() {\r\n        cleanup();\r\n        // leaving the warning if for some reason cleanup failed\r\n        if (core::isInitialized() && !core::isCleanedUp())\r\n            helper::printLibraryNotCleanedUpWarning(\"SofaCore\", \"sofa::core::cleanup()\");\r\n    }\r\n} check;\r\n```\r\n\r\nso that the library automatically `init()` and `cleanup()` upon `dlopen`/`exit`.\r\n\r\n\r\n<!--- Please leave this at the end of your message -->\r\nThis PR: \r\n- [ ] builds with SUCCESS for all platforms on the CI.\r\n- [ ] does not generate new warnings nor unit test failures.\r\n- [ ] does not break existing scenes.\r\n- [ ] does not break API compatibility.\r\n- [ ] has been reviewed and agreed to be transitional.\r\n- [ ] is more than 1 week old.\r\n**Reviewers will merge only if all this checks are true.**"},"comment":{"url":"https://api.github.com/repos/sofa-framework/sofa/issues/comments/279182985","html_url":"https://github.com/sofa-framework/sofa/pull/168#issuecomment-279182985","issue_url":"https://api.github.com/repos/sofa-framework/sofa/issues/168","id":279182985,"user":{"login":"damienmarchal","id":12644882,"avatar_url":"https://avatars.githubusercontent.com/u/12644882?v=3","gravatar_id":"","url":"https://api.github.com/users/damienmarchal","html_url":"https://github.com/damienmarchal","followers_url":"https://api.github.com/users/damienmarchal/followers","following_url":"https://api.github.com/users/damienmarchal/following{/other_user}","gists_url":"https://api.github.com/users/damienmarchal/gists{/gist_id}","starred_url":"https://api.github.com/users/damienmarchal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damienmarchal/subscriptions","organizations_url":"https://api.github.com/users/damienmarchal/orgs","repos_url":"https://api.github.com/users/damienmarchal/repos","events_url":"https://api.github.com/users/damienmarchal/events{/privacy}","received_events_url":"https://api.github.com/users/damienmarchal/received_events","type":"User","site_admin":false},"created_at":"2017-02-11T23:16:14Z","updated_at":"2017-02-11T23:16:14Z","body":"[ci-build]"}}
{"actor":{"display_login":"damienmarchal"}}