pyo3/pytests/tests/test_objstore.py

29 lines
727 B
Python
Raw Normal View History

2020-03-26 05:50:00 +00:00
import gc
import sys
from pyo3_pytests.objstore import ObjStore
2020-03-26 05:50:00 +00:00
def test_objstore_doesnot_leak_memory():
N = 10000
message = b'\\(-"-;) Praying that memory leak would not happen..'
2021-07-18 18:30:30 +00:00
# PyPy does not have sys.getrefcount, provide a no-op lambda and don't
# check refcount on PyPy
getrefcount = getattr(sys, "getrefcount", lambda obj: 0)
Basic GraalPy Support (#3247) * graalpy: recognize graalpy implementation when building * graalpy: global Ellipse, None, NotImplemented, True, and False are only available as pointers * graalpy: PyObject struct is opaque, use functions for everything * graalpy: missing many of the same functions as pypy * graalpy: do not have 128bit conversion functions * graalpy: add functions for datetime accessor macros * graalpy: add implementations for list macro functions * graalpy: skip tuple macros * graalpy: always use extern Py_CompileString function * graalpy: disable assertion that does not apply to graalpy * graalpy: floatobject structure is opaque on graalpy * graalpy: ignore gc dependent test * graalpy: add CI config * graalpy: run rust fmt * graalpy: add changelog entry * graalpy: discover interpreter on PATH * graalpy: interpreter id is not applicable to graalpy (just like pypy) * graalpy: skip tests that cannot work on GraalPy * graalpy: fix constructing normalized Err instances Co-authored-by: David Hewitt <mail@davidhewitt.dev> * graalpy: correct capi library name, but skip rust tests due to missing symbols * graalpy: no support for C extensions on windows in latest release * graalpy: declare support versions * graalpy: frame, code, method, and function objects access from C API is mostly missing * graalpy: take care only to expose C structure that GraalPy allocates * graalpy: Bail out if graalpy version is less than what we support --------- Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-25 18:54:52 +00:00
if sys.implementation.name == "graalpy":
# GraalPy has an incomplete sys.getrefcount implementation
def getrefcount(obj):
return 0
2021-07-18 18:30:30 +00:00
before = getrefcount(message)
2020-03-26 05:50:00 +00:00
store = ObjStore()
for _ in range(N):
store.push(message)
del store
gc.collect()
2021-07-18 18:30:30 +00:00
after = getrefcount(message)
2020-03-26 05:50:00 +00:00
assert after - before == 0