{"action":"created","issue":{"url":"https://api.github.com/repos/cython/cython/issues/535","repository_url":"https://api.github.com/repos/cython/cython","labels_url":"https://api.github.com/repos/cython/cython/issues/535/labels{/name}","comments_url":"https://api.github.com/repos/cython/cython/issues/535/comments","events_url":"https://api.github.com/repos/cython/cython/issues/535/events","html_url":"https://github.com/cython/cython/pull/535","id":167834191,"number":535,"title":"Add an include guard to Python type structs","user":{"login":"empyrical","id":2847127,"avatar_url":"https://avatars.githubusercontent.com/u/2847127?v=3","gravatar_id":"","url":"https://api.github.com/users/empyrical","html_url":"https://github.com/empyrical","followers_url":"https://api.github.com/users/empyrical/followers","following_url":"https://api.github.com/users/empyrical/following{/other_user}","gists_url":"https://api.github.com/users/empyrical/gists{/gist_id}","starred_url":"https://api.github.com/users/empyrical/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/empyrical/subscriptions","organizations_url":"https://api.github.com/users/empyrical/orgs","repos_url":"https://api.github.com/users/empyrical/repos","events_url":"https://api.github.com/users/empyrical/events{/privacy}","received_events_url":"https://api.github.com/users/empyrical/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-27T11:42:50Z","updated_at":"2016-07-27T20:00:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/cython/cython/pulls/535","html_url":"https://github.com/cython/cython/pull/535","diff_url":"https://github.com/cython/cython/pull/535.diff","patch_url":"https://github.com/cython/cython/pull/535.patch"},"body":"I've got a bit of non-Cython code that uses public extension types made in Cython, and would like to use it inside of a Cython module. However, if I use this code and `cimport` the module with the public extension type at the same time, then I run in to a problem where the `struct`s for the types are getting declared twice. This little include guard helps alleviate that problem."},"comment":{"url":"https://api.github.com/repos/cython/cython/issues/comments/235702325","html_url":"https://github.com/cython/cython/pull/535#issuecomment-235702325","issue_url":"https://api.github.com/repos/cython/cython/issues/535","id":235702325,"user":{"login":"empyrical","id":2847127,"avatar_url":"https://avatars.githubusercontent.com/u/2847127?v=3","gravatar_id":"","url":"https://api.github.com/users/empyrical","html_url":"https://github.com/empyrical","followers_url":"https://api.github.com/users/empyrical/followers","following_url":"https://api.github.com/users/empyrical/following{/other_user}","gists_url":"https://api.github.com/users/empyrical/gists{/gist_id}","starred_url":"https://api.github.com/users/empyrical/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/empyrical/subscriptions","organizations_url":"https://api.github.com/users/empyrical/orgs","repos_url":"https://api.github.com/users/empyrical/repos","events_url":"https://api.github.com/users/empyrical/events{/privacy}","received_events_url":"https://api.github.com/users/empyrical/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T20:00:23Z","updated_at":"2016-07-27T20:00:23Z","body":"I `include` those files in the header that I `cdef extern` from in Cython, as I would like to use some `public` types and methods both in the signatures of some pure C++ functions and the body of some template functions.\r\n\r\nHere's a really tiny example of what I mean\r\n\r\n`my_module.pxd`:\r\n\r\n```cython\r\ncdef public MyExtension[type MyExtension_Type, object MyExtension_Object]:\r\n    pass\r\n```\r\n\r\n`my_cpp.h`: (all it needs for the error)\r\n\r\n```cpp\r\n#include \"my_extension.h\"\r\n```\r\n\r\n`my_other_module.pyx`:\r\n\r\n```cython\r\ncdef extern from \"my_cpp.h\":\r\n    pass\r\nfrom my_module cimport MyExtension\r\n```\r\n\r\nSince Cython will already emit the struct definition in the module code if I `cimport` it, me `include`ing my header which then includes the Cython-generated header will result in a compilation error from the struct getting defined twice.\r\n\r\nI tried a quick patch that will emit `#define __PYX_HAVE__{module_name}` for all `cimported` modules before the part of the code where all the includes are emitted like it does already for the module itself, but that doesn't work right because the struct inside of the Cython module code is defined after the includes and not before so that would result in the code in my header failing to compile.\r\n\r\nAlternatively maybe Cython could be made so it won't emit the struct definitions in the module code for public types, and try to include the generated headers instead?"}}
{"actor":{"display_login":"empyrical"}}