File: utils.py

package info (click to toggle)
python-moderngl 5.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,700 kB
  • sloc: python: 15,758; cpp: 14,665; makefile: 14
file content (28 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
This modules is really unisable for ref counting. Just an experiment!
"""
import gc
import sys
import ctypes

def print_referrers(obj):
    refs = gc.get_referrers(obj)
    for ref in refs:
        if is_module(ref):
            print("-->", is_module(ref))
        else:
            print("--> ", type(ref), ref)


def is_module(obj):
    if isinstance(obj, dict) and obj.get("__name__"):
        return obj.get("__name__")
    return None

def ref_c_1(obj):
    """+ 1"""
    return ctypes.c_long.from_address(id(obj)).value

def ref_c_2(obj):
    """+ 2"""
    return sys.getrefcount(obj)