[issue44301] Is there a way to provide destructor for module written using C API?

2021-08-05 Thread Petr Viktorin
Petr Viktorin added the comment: I see that I wrote "counts" rather than "cycles" before; that line should be: The clear function is used to break reference cycles. In this case, there are no reference cycles to be broken, so it is not called. Thanks to Pablo for the review & Łukasz for

[issue44301] Is there a way to provide destructor for module written using C API?

2021-08-04 Thread Łukasz Langa
Łukasz Langa added the comment: Thanks for your report, Azat! ✨  ✨ -- nosy: +lukasz.langa ___ Python tracker ___ ___

[issue44301] Is there a way to provide destructor for module written using C API?

2021-08-04 Thread Łukasz Langa
Change by Łukasz Langa : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.10, Python 3.11 ___ Python tracker ___

[issue44301] Is there a way to provide destructor for module written using C API?

2021-08-04 Thread miss-islington
Change by miss-islington : -- nosy: +miss-islington nosy_count: 3.0 -> 4.0 pull_requests: +26097 pull_request: https://github.com/python/cpython/pull/27596 ___ Python tracker

[issue44301] Is there a way to provide destructor for module written using C API?

2021-08-04 Thread miss-islington
Change by miss-islington : -- pull_requests: +26098 pull_request: https://github.com/python/cpython/pull/27597 ___ Python tracker ___

[issue44301] Is there a way to provide destructor for module written using C API?

2021-08-03 Thread Petr Viktorin
Change by Petr Viktorin : -- keywords: +patch pull_requests: +26085 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27581 ___ Python tracker ___

[issue44301] Is there a way to provide destructor for module written using C API?

2021-08-03 Thread Petr Viktorin
Petr Viktorin added the comment: You are missing m_free. The clear function is used to break reference counts. In this case, there are no reference counts to be broken, so it is not called. Your custom_clear function is idempotent, so you can use it in both free and clear and let Python

[issue44301] Is there a way to provide destructor for module written using C API?

2021-06-04 Thread Terry J. Reedy
Change by Terry J. Reedy : -- versions: -Python 3.6, Python 3.7, Python 3.8 ___ Python tracker ___ ___ Python-bugs-list mailing

[issue44301] Is there a way to provide destructor for module written using C API?

2021-06-03 Thread Azat Ibrakov
Azat Ibrakov added the comment: With this setup https://gist.github.com/lycantropos/f9243dc98e104a13ddd991316e93d31a I get prompt about module being initialized but that's it: it never gets deleted and reference count for `Rational` keeps increasing. What am I missing? --

[issue44301] Is there a way to provide destructor for module written using C API?

2021-06-03 Thread STINNER Victor
STINNER Victor added the comment: Hi, you should use the multiphase initialization API which has clear and free functions. https://www.python.org/dev/peps/pep-0489/#the-proposal See for example the source code of the Modules/_abc.c extension. -- nosy: +vstinner

[issue44301] Is there a way to provide destructor for module written using C API?

2021-06-03 Thread Azat Ibrakov
New submission from Azat Ibrakov : I'm reimplementing `fractions.Fraction` class using C API (https://github.com/lycantropos/cfractions). And the problem is that I want to use `numbers.Rational` interface in my type checks to add support for user-defined rational numbers. I see how it's