[Python-Dev] Using Cython for the stdlib (was: Let's change to C API!)

Stefan Behnel stefan_ml at behnel.de
Wed Aug 1 16:01:55 EDT 2018


Brett Cannon schrieb am 01.08.2018 um 18:17:
> On Tue, 31 Jul 2018 at 13:42 Stefan Behnel wrote:
>> Antoine Pitrou schrieb am 31.07.2018 um 09:45:
>>> Also, a C extension can be built-in (linked statically into the
>>> interpreter), which I think would be hard to do with Cython.
>>
>> Someone recently contributed a feature of hiding the pyinit function for
>> the embedding case, so people do these things already. This could use the
>> normal inittab mechanism, for example. What I think you might be referring
>> to is that Cython modules require the CPython runtime to be initialised to
>> a certain extent, so you couldn't implement "sys" in Cython, for example.
> 
> I think the key thing is that on Windows all extension modules are built-in
> modules, so that use-case would need to be supported (I don't know Cython
> well enough to know whether this would be doable if we converted as much as
> possible to Cython itself).

As Steve noted, this is probably easy. What Cython produces is just the C
code file for an extension module. Whether you turn that into a shared
library or statically link it into something else (that knows how to
initialise an extension module) is up to you.

I would say, from the point on where CPython is ready to initialise its own
extension modules, it can also initialise Cython generated modules. So,
just to give an example, if you want to compile difflib.py into an
accelerator module and link that into the core, that's probably fine, as
long as you first initialise everything that difflib needs in its module
init code (such as importlib to execute the module level imports) before
you initialise the compiled difflib module.

Stefan



More information about the Python-Dev mailing list