{"action":"closed","issue":{"url":"https://api.github.com/repos/andrewrk/zig/issues/277","repository_url":"https://api.github.com/repos/andrewrk/zig","labels_url":"https://api.github.com/repos/andrewrk/zig/issues/277/labels{/name}","comments_url":"https://api.github.com/repos/andrewrk/zig/issues/277/comments","events_url":"https://api.github.com/repos/andrewrk/zig/issues/277/events","html_url":"https://github.com/andrewrk/zig/issues/277","id":216298964,"number":277,"title":"calling the same C function from 2 different C imports results in mangled symbol for one of them","user":{"login":"andrewrk","id":106511,"avatar_url":"https://avatars3.githubusercontent.com/u/106511?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewrk","html_url":"https://github.com/andrewrk","followers_url":"https://api.github.com/users/andrewrk/followers","following_url":"https://api.github.com/users/andrewrk/following{/other_user}","gists_url":"https://api.github.com/users/andrewrk/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewrk/subscriptions","organizations_url":"https://api.github.com/users/andrewrk/orgs","repos_url":"https://api.github.com/users/andrewrk/repos","events_url":"https://api.github.com/users/andrewrk/events{/privacy}","received_events_url":"https://api.github.com/users/andrewrk/received_events","type":"User","site_admin":false},"labels":[{"id":244683521,"url":"https://api.github.com/repos/andrewrk/zig/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/andrewrk/zig/milestones/1","html_url":"https://github.com/andrewrk/zig/milestone/1","labels_url":"https://api.github.com/repos/andrewrk/zig/milestones/1/labels","id":1513550,"number":1,"title":"0.1.0","description":"","creator":{"login":"andrewrk","id":106511,"avatar_url":"https://avatars3.githubusercontent.com/u/106511?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewrk","html_url":"https://github.com/andrewrk","followers_url":"https://api.github.com/users/andrewrk/followers","following_url":"https://api.github.com/users/andrewrk/following{/other_user}","gists_url":"https://api.github.com/users/andrewrk/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewrk/subscriptions","organizations_url":"https://api.github.com/users/andrewrk/orgs","repos_url":"https://api.github.com/users/andrewrk/repos","events_url":"https://api.github.com/users/andrewrk/events{/privacy}","received_events_url":"https://api.github.com/users/andrewrk/received_events","type":"User","site_admin":false},"open_issues":44,"closed_issues":81,"state":"open","created_at":"2016-01-18T21:44:08Z","updated_at":"2017-03-23T07:09:50Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2017-03-23T04:53:32Z","updated_at":"2017-03-23T07:09:50Z","closed_at":"2017-03-23T07:09:50Z","body":"```zig\r\nconst c1 = @cImport(@cInclude(\"a.h\"));\r\nconst c2 = @cImport(@cInclude(\"a.h\"));\r\nexport fn foo() {\r\n    c1.bar();\r\n    c2.bar();\r\n}\r\n```\r\n\r\na.h:\r\n```c\r\nvoid bar(void);\r\n```\r\n\r\nCompiling this results in one of the `bar` functions being mangled and then a linker error.\r\n\r\nWhat makes this non-trivial is that the .h files could provide conflicting prototypes of functions, and it's not necessarily an error when this is the case. For example, one could be `void bar(void);` and one could be `void bar(int);` and these are actually compatible, according to the ABI of the system.\r\n\r\nFor libc functions, one workaround is to use the `@import(\"std\").c` namespace, which has the libc function declarations in it. This is faster anyway since it skips the .h file parsing step.\r\n\r\nWe can resolve the problem more completely by tossing out one of the same-named functions, and bitcasting the function to the appropriate prototype at the callsite. Optionally we can compare the prototypes and maybe not even have to do this bitcasting, but maybe we don't even have to do that."}}
{"actor":{"display_login":"andrewrk"}}