cython

Форк
0
/
no_gc.pyx 
41 строка · 1.1 Кб
1
"""
2
Check that the @cython.no_gc decorator disables generation of the
3
tp_clear and tp_traverse slots, that is, disables cycle collection.
4
"""
5

6
cimport cython
7
from cpython.ref cimport PyObject, Py_TYPE
8

9
# Force non-gc'd PyTypeObject when safety is guaranteed by user but not provable
10

11
cdef extern from *:
12
    ctypedef struct PyTypeObject:
13
        void (*tp_clear)(object)
14
        void (*tp_traverse)(object)
15

16

17
def is_tp_clear_null(obj):
18
    return (<PyTypeObject*>Py_TYPE(obj)).tp_clear is NULL
19

20
def is_tp_traverse_null(obj):
21
    return (<PyTypeObject*>Py_TYPE(obj)).tp_traverse is NULL
22

23

24
@cython.no_gc
25
cdef class DisableGC:
26
    """
27
    An extension type that has tp_clear and tp_traverse methods generated 
28
    to test that it actually clears the references to NULL.
29

30
    >>> uut = DisableGC()
31
    >>> is_tp_clear_null(uut)
32
    True
33
    >>> is_tp_traverse_null(uut)
34
    True
35
    """
36

37
    cdef public object requires_cleanup
38

39
    def __cinit__(self):
40
        self.requires_cleanup = (
41
                "Tuples to strings don't really need cleanup, cannot take part of cycles",)
42

43

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.