Phil Elson schrieb am 12.09.2017 um 08:22:
>> On Fri, Sep 8, 2017 at 9:34 AM, Jeroen Demeyer wrote:
>>> See
>>>
http://cython.readthedocs.io/en/latest/src/userguide/external_C_code.html#public-declarations
>
> Jeroen - thanks. I'd missed the external_c_code content, and was mostly
> referencing the extension_types docs, so that was a helpful pointer.
>
> I've been looking at the output from the public / extern / api
> cythonisation, and it would suggest that the docs are a little out of date
> wrt. Python 3. In particular, I believe I need to call a function called
> "init{funcname}" in Python 2, and "PyInit_{funcname}" in Python 3.
That part is outdated, yes. The module init function was renamed and now
returns the module reference. Thus, I would suggest that users should not
call it directly at all, but instead use Cython's "embed" option. It
generates a C main() function from the template file Embed.c. The example
in the docs is more description than recommendation.
I doubt that you would have to do that in your case, though. Just because
you're exporting something to C doesn't mean that your code controls the
startup of the CPython runtime. That's unrelated [1]. You would probably
just need to implement a normal Cython extension module and provide some C
interface to it. Whether you need "public" declarations for that or "api",
I can't say. That depends on the way you want to integrate it with the
external C code.
BTW, are you even sure that you need that external C code? What is going to
use and call your code? NumPy? If so, then that would suggest to me that
you probably don't need any C (or public/api exports) at all, and can do
everything from Cython directly.
Maybe you should try to further explain your use case here, and the API
that you are programming against. That way, it might become clearer to
yourself what you actually want and need, and easier for us to push you
into the right direction.
> I'm keen to document any successful findings, and will happily submit a PR
> to the docs once I have a (minimal) working prototype.
Please do.
Stefan
[1] The CPython documentation forces you to decide early whether
"embedding" or "extending" is your goal, but the only difference between
the two is really what starts up the CPython runtime. Once you are beyond
that, both are exactly the same.