{"action":"closed","number":2747,"pull_request":{"url":"https://api.github.com/repos/mruby/mruby/pulls/2747","id":31486493,"html_url":"https://github.com/mruby/mruby/pull/2747","diff_url":"https://github.com/mruby/mruby/pull/2747.diff","patch_url":"https://github.com/mruby/mruby/pull/2747.patch","issue_url":"https://api.github.com/repos/mruby/mruby/issues/2747","number":2747,"state":"closed","locked":false,"title":"Fix exceptions for visualcpp","user":{"login":"jbreeden","id":4704574,"avatar_url":"https://avatars.githubusercontent.com/u/4704574?v=3","gravatar_id":"","url":"https://api.github.com/users/jbreeden","html_url":"https://github.com/jbreeden","followers_url":"https://api.github.com/users/jbreeden/followers","following_url":"https://api.github.com/users/jbreeden/following{/other_user}","gists_url":"https://api.github.com/users/jbreeden/gists{/gist_id}","starred_url":"https://api.github.com/users/jbreeden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbreeden/subscriptions","organizations_url":"https://api.github.com/users/jbreeden/orgs","repos_url":"https://api.github.com/users/jbreeden/repos","events_url":"https://api.github.com/users/jbreeden/events{/privacy}","received_events_url":"https://api.github.com/users/jbreeden/received_events","type":"User","site_admin":false},"body":"Exception handling is broken for visualcpp toolchain, if using C++ source files.\r\n\r\nThe issue is the the `/EHsc` cxx flag. From [MSDN /EH docs](https://msdn.microsoft.com/en-us/library/1deeycx5.aspx), this <i>'tells the compiler to assume that functions declared as extern \"C\" never throw a C++ exception.'</i>\r\n\r\nThe problem with that is that all of the functions in vm.c *are* extern \"C\". See this block from `mrb_funcall_with_block`\r\n\r\n```C\r\n   MRB_TRY(&c_jmp) {\r\n      mrb->jmp = &c_jmp;\r\n      /* recursive call */\r\n      val = mrb_funcall_with_block(mrb, self, mid, argc, argv, blk);\r\n      mrb->jmp = 0;\r\n    }\r\n    MRB_CATCH(&c_jmp) { /* error */\r\n      while (old_ci != mrb->c->ci) {\r\n        mrb->c->stack = mrb->c->ci->stackent;\r\n        cipop(mrb);\r\n      }\r\n      mrb->jmp = 0;\r\n      val = mrb_obj_value(mrb->exc);\r\n    }\r\n    MRB_END_EXC(&c_jmp);\r\n```\r\n\r\n`cl.exe` (Microsoft C/C++ Version 18.00.31101 for x86) looks at this block, sees that `mrb_funcall_with_block` is `extern \"C\"` and assumes - like it's been told - that this function cannot throw a C++ exception. The exception handler is then removed from the generated code.\r\n\r\nHowever, MRB_THROW is defined to throw an exception with the cxx_abi is enabled. The effect is that at runtime an exception is thrown out of this block. The stack is not processed, and mrb->jmp is not cleared.\r\n\r\nChanging the flag to `/EHs` allows the exception handling to work as intended.\r\n\r\nI have run `ruby ./minirake test` with both GCC & VisualCPP, and all tests pass with this change.\r\nI don't have a test written for this change, but you can see my usage here:\r\n - [lamina](https://github.com/jbreeden/lamina) commit  [e9dec24](https://github.com/jbreeden/lamina/commit/e9dec2431241019612be3339a4f3837a8277de4b) changes the toolchain flag\r\n- [mruby-cef](https://github.com/jbreeden/mruby-cef) (used by lamina) commit [d25e436](https://github.com/jbreeden/mruby-cef/commit/d25e4369ea2c1c30711d470fd4e3dd4efbeeb098) shows how I am able to handle exceptions with the change\r\n  + In this commit, you can see I was catching the exceptions before, that should never have been making it out to my code.\r\n  + Now, I'm able to check the return value (or mrb->exc) as expected.","created_at":"2015-03-19T00:41:52Z","updated_at":"2015-03-19T15:28:46Z","closed_at":"2015-03-19T15:28:46Z","merged_at":"2015-03-19T15:28:46Z","merge_commit_sha":"3df53dc4e0efde2d362a5be78e295943268e772a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mruby/mruby/pulls/2747/commits","review_comments_url":"https://api.github.com/repos/mruby/mruby/pulls/2747/comments","review_comment_url":"https://api.github.com/repos/mruby/mruby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mruby/mruby/issues/2747/comments","statuses_url":"https://api.github.com/repos/mruby/mruby/statuses/f6f70c86dba4917b1d5088fa61483fc1adf5d39d","head":{"label":"jbreeden:vcpp_exceptions","ref":"vcpp_exceptions","sha":"f6f70c86dba4917b1d5088fa61483fc1adf5d39d","user":{"login":"jbreeden","id":4704574,"avatar_url":"https://avatars.githubusercontent.com/u/4704574?v=3","gravatar_id":"","url":"https://api.github.com/users/jbreeden","html_url":"https://github.com/jbreeden","followers_url":"https://api.github.com/users/jbreeden/followers","following_url":"https://api.github.com/users/jbreeden/following{/other_user}","gists_url":"https://api.github.com/users/jbreeden/gists{/gist_id}","starred_url":"https://api.github.com/users/jbreeden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbreeden/subscriptions","organizations_url":"https://api.github.com/users/jbreeden/orgs","repos_url":"https://api.github.com/users/jbreeden/repos","events_url":"https://api.github.com/users/jbreeden/events{/privacy}","received_events_url":"https://api.github.com/users/jbreeden/received_events","type":"User","site_admin":false},"repo":{"id":32491289,"name":"mruby","full_name":"jbreeden/mruby","owner":{"login":"jbreeden","id":4704574,"avatar_url":"https://avatars.githubusercontent.com/u/4704574?v=3","gravatar_id":"","url":"https://api.github.com/users/jbreeden","html_url":"https://github.com/jbreeden","followers_url":"https://api.github.com/users/jbreeden/followers","following_url":"https://api.github.com/users/jbreeden/following{/other_user}","gists_url":"https://api.github.com/users/jbreeden/gists{/gist_id}","starred_url":"https://api.github.com/users/jbreeden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbreeden/subscriptions","organizations_url":"https://api.github.com/users/jbreeden/orgs","repos_url":"https://api.github.com/users/jbreeden/repos","events_url":"https://api.github.com/users/jbreeden/events{/privacy}","received_events_url":"https://api.github.com/users/jbreeden/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbreeden/mruby","description":"Lightweight Ruby","fork":true,"url":"https://api.github.com/repos/jbreeden/mruby","forks_url":"https://api.github.com/repos/jbreeden/mruby/forks","keys_url":"https://api.github.com/repos/jbreeden/mruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbreeden/mruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbreeden/mruby/teams","hooks_url":"https://api.github.com/repos/jbreeden/mruby/hooks","issue_events_url":"https://api.github.com/repos/jbreeden/mruby/issues/events{/number}","events_url":"https://api.github.com/repos/jbreeden/mruby/events","assignees_url":"https://api.github.com/repos/jbreeden/mruby/assignees{/user}","branches_url":"https://api.github.com/repos/jbreeden/mruby/branches{/branch}","tags_url":"https://api.github.com/repos/jbreeden/mruby/tags","blobs_url":"https://api.github.com/repos/jbreeden/mruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbreeden/mruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbreeden/mruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbreeden/mruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbreeden/mruby/statuses/{sha}","languages_url":"https://api.github.com/repos/jbreeden/mruby/languages","stargazers_url":"https://api.github.com/repos/jbreeden/mruby/stargazers","contributors_url":"https://api.github.com/repos/jbreeden/mruby/contributors","subscribers_url":"https://api.github.com/repos/jbreeden/mruby/subscribers","subscription_url":"https://api.github.com/repos/jbreeden/mruby/subscription","commits_url":"https://api.github.com/repos/jbreeden/mruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbreeden/mruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbreeden/mruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbreeden/mruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbreeden/mruby/contents/{+path}","compare_url":"https://api.github.com/repos/jbreeden/mruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbreeden/mruby/merges","archive_url":"https://api.github.com/repos/jbreeden/mruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbreeden/mruby/downloads","issues_url":"https://api.github.com/repos/jbreeden/mruby/issues{/number}","pulls_url":"https://api.github.com/repos/jbreeden/mruby/pulls{/number}","milestones_url":"https://api.github.com/repos/jbreeden/mruby/milestones{/number}","notifications_url":"https://api.github.com/repos/jbreeden/mruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbreeden/mruby/labels{/name}","releases_url":"https://api.github.com/repos/jbreeden/mruby/releases{/id}","created_at":"2015-03-19T00:09:04Z","updated_at":"2015-03-19T00:09:05Z","pushed_at":"2015-03-19T00:15:12Z","git_url":"git://github.com/jbreeden/mruby.git","ssh_url":"git@github.com:jbreeden/mruby.git","clone_url":"https://github.com/jbreeden/mruby.git","svn_url":"https://github.com/jbreeden/mruby","homepage":null,"size":20453,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mruby:master","ref":"master","sha":"0e218f53569002f8f5979629ae91f5fb28544251","user":{"login":"mruby","id":1796512,"avatar_url":"https://avatars.githubusercontent.com/u/1796512?v=3","gravatar_id":"","url":"https://api.github.com/users/mruby","html_url":"https://github.com/mruby","followers_url":"https://api.github.com/users/mruby/followers","following_url":"https://api.github.com/users/mruby/following{/other_user}","gists_url":"https://api.github.com/users/mruby/gists{/gist_id}","starred_url":"https://api.github.com/users/mruby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mruby/subscriptions","organizations_url":"https://api.github.com/users/mruby/orgs","repos_url":"https://api.github.com/users/mruby/repos","events_url":"https://api.github.com/users/mruby/events{/privacy}","received_events_url":"https://api.github.com/users/mruby/received_events","type":"Organization","site_admin":false},"repo":{"id":4073516,"name":"mruby","full_name":"mruby/mruby","owner":{"login":"mruby","id":1796512,"avatar_url":"https://avatars.githubusercontent.com/u/1796512?v=3","gravatar_id":"","url":"https://api.github.com/users/mruby","html_url":"https://github.com/mruby","followers_url":"https://api.github.com/users/mruby/followers","following_url":"https://api.github.com/users/mruby/following{/other_user}","gists_url":"https://api.github.com/users/mruby/gists{/gist_id}","starred_url":"https://api.github.com/users/mruby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mruby/subscriptions","organizations_url":"https://api.github.com/users/mruby/orgs","repos_url":"https://api.github.com/users/mruby/repos","events_url":"https://api.github.com/users/mruby/events{/privacy}","received_events_url":"https://api.github.com/users/mruby/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mruby/mruby","description":"Lightweight Ruby","fork":false,"url":"https://api.github.com/repos/mruby/mruby","forks_url":"https://api.github.com/repos/mruby/mruby/forks","keys_url":"https://api.github.com/repos/mruby/mruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mruby/mruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mruby/mruby/teams","hooks_url":"https://api.github.com/repos/mruby/mruby/hooks","issue_events_url":"https://api.github.com/repos/mruby/mruby/issues/events{/number}","events_url":"https://api.github.com/repos/mruby/mruby/events","assignees_url":"https://api.github.com/repos/mruby/mruby/assignees{/user}","branches_url":"https://api.github.com/repos/mruby/mruby/branches{/branch}","tags_url":"https://api.github.com/repos/mruby/mruby/tags","blobs_url":"https://api.github.com/repos/mruby/mruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mruby/mruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mruby/mruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/mruby/mruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mruby/mruby/statuses/{sha}","languages_url":"https://api.github.com/repos/mruby/mruby/languages","stargazers_url":"https://api.github.com/repos/mruby/mruby/stargazers","contributors_url":"https://api.github.com/repos/mruby/mruby/contributors","subscribers_url":"https://api.github.com/repos/mruby/mruby/subscribers","subscription_url":"https://api.github.com/repos/mruby/mruby/subscription","commits_url":"https://api.github.com/repos/mruby/mruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/mruby/mruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/mruby/mruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/mruby/mruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/mruby/mruby/contents/{+path}","compare_url":"https://api.github.com/repos/mruby/mruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mruby/mruby/merges","archive_url":"https://api.github.com/repos/mruby/mruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mruby/mruby/downloads","issues_url":"https://api.github.com/repos/mruby/mruby/issues{/number}","pulls_url":"https://api.github.com/repos/mruby/mruby/pulls{/number}","milestones_url":"https://api.github.com/repos/mruby/mruby/milestones{/number}","notifications_url":"https://api.github.com/repos/mruby/mruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mruby/mruby/labels{/name}","releases_url":"https://api.github.com/repos/mruby/mruby/releases{/id}","created_at":"2012-04-19T09:11:15Z","updated_at":"2015-03-18T02:40:35Z","pushed_at":"2015-03-19T15:28:46Z","git_url":"git://github.com/mruby/mruby.git","ssh_url":"git@github.com:mruby/mruby.git","clone_url":"https://github.com/mruby/mruby.git","svn_url":"https://github.com/mruby/mruby","homepage":null,"size":20453,"stargazers_count":2985,"watchers_count":2985,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":456,"mirror_url":null,"open_issues_count":127,"forks":456,"open_issues":127,"watchers":2985,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mruby/mruby/pulls/2747"},"html":{"href":"https://github.com/mruby/mruby/pull/2747"},"issue":{"href":"https://api.github.com/repos/mruby/mruby/issues/2747"},"comments":{"href":"https://api.github.com/repos/mruby/mruby/issues/2747/comments"},"review_comments":{"href":"https://api.github.com/repos/mruby/mruby/pulls/2747/comments"},"review_comment":{"href":"https://api.github.com/repos/mruby/mruby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mruby/mruby/pulls/2747/commits"},"statuses":{"href":"https://api.github.com/repos/mruby/mruby/statuses/f6f70c86dba4917b1d5088fa61483fc1adf5d39d"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"matz","id":30733,"avatar_url":"https://avatars.githubusercontent.com/u/30733?v=3","gravatar_id":"","url":"https://api.github.com/users/matz","html_url":"https://github.com/matz","followers_url":"https://api.github.com/users/matz/followers","following_url":"https://api.github.com/users/matz/following{/other_user}","gists_url":"https://api.github.com/users/matz/gists{/gist_id}","starred_url":"https://api.github.com/users/matz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matz/subscriptions","organizations_url":"https://api.github.com/users/matz/orgs","repos_url":"https://api.github.com/users/matz/repos","events_url":"https://api.github.com/users/matz/events{/privacy}","received_events_url":"https://api.github.com/users/matz/received_events","type":"User","site_admin":false},"comments":1,"review_comments":0,"commits":1,"additions":1,"deletions":1,"changed_files":1}}