Finding the module object in Python 3 C extensions (Posting On Python-List Prohibited)

Jon Ribbens jon+usenet at unequivocal.eu
Thu Nov 23 06:15:37 EST 2017


On 2017-11-23, Lawrence D’Oliveiro <lawrencedo99 at gmail.com> wrote:
> On Thursday, November 23, 2017 at 4:03:18 AM UTC+13, Jon Ribbens wrote:
>> In Python 3, you are supposed to store the global state in an
>> allocated memory area instead.
>
> Says who? Considering that this
> <https://docs.python.org/3/extending/extending.html#calling-python-functions-from-c>
> example uses a global variable.

Says Benjamin Peterson on docs.python.org:

https://docs.python.org/3/howto/cporting.html

    "Python 3 has a revamped extension module initialization system.
    (See PEP 3121.) Instead of storing module state in globals, they
    should be stored in an interpreter specific structure. Creating
    modules that act correctly in both Python 2 and Python 3 is
    tricky."

He's not kidding, not least because it appears that creating modules
that act correctly in Python 3 at all is tricky!



More information about the Python-list mailing list