Skip to content

Conversation

@skirpichev
Copy link
Member

No description provided.

This permits to prevent loading of the hypothesis plugin, if
it's disabled by -p no:hypothesispytest.
@skirpichev skirpichev added this to the 0.5 milestone Feb 2, 2026
@skirpichev
Copy link
Member Author

test_fac_outofmem() on pypy crashes even for builtin int's, for following diff:

diff --git a/tests/test_memory.py b/tests/test_memory.py
index d19a14b..4402cf5 100644
--- a/tests/test_memory.py
+++ b/tests/test_memory.py
@@ -3,9 +3,11 @@ import platform
 import random
 import threading
 from concurrent.futures import ThreadPoolExecutor
+from math import factorial as fac
 
 import pytest
-from gmp import fac, mpz
+
+mpz = int
 
 if platform.system() != "Linux":
     pytest.skip("FIXME: setrlimit fails with ValueError on MacOS",
Stack (most recent call first, approximate line numbers):
  File "<builtin>/math/app_math.py", line 36 in _fac1
  File "<builtin>/math/app_math.py", line 7 in factorial
  File "/home/sk/src/python-gmp/tests/test_memory.py", line 25 in test_fac_outofmem
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/python.py", line 159 in pytest_pyfunc_call
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_callers.py", line 76 in _multicall
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_manager.py", line 111 in _hookexec
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_hooks.py", line 497 in __call__
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/python.py", line 1718 in runtest
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/runner.py", line 168 in pytest_runtest_call
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_callers.py", line 76 in _multicall
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_manager.py", line 111 in _hookexec
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_hooks.py", line 497 in __call__
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/runner.py", line 245 in <lambda>
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/runner.py", line 332 in from_call
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/runner.py", line 231 in call_and_report
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/runner.py", line 123 in runtestprotocol
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/runner.py", line 115 in pytest_runtest_protocol
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_callers.py", line 76 in _multicall
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_manager.py", line 111 in _hookexec
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_hooks.py", line 497 in __call__
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/main.py", line 385 in pytest_runtestloop
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_callers.py", line 76 in _multicall
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_manager.py", line 111 in _hookexec
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_hooks.py", line 497 in __call__
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/main.py", line 368 in _main
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/main.py", line 305 in wrap_session
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/main.py", line 364 in pytest_cmdline_main
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_callers.py", line 76 in _multicall
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_manager.py", line 111 in _hookexec
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/pluggy/_hooks.py", line 497 in __call__
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/config/__init__.py", line 170 in main
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/lib/pypy3.11/site-packages/_pytest/config/__init__.py", line 216 in console_main
  File "/home/sk/src/python-gmp/.venv/pypy3.11-7.3.20/bin/pytest", line 1 in <module>
  File "<builtin>/app_main.py", line 1081 in execfile
  File "<builtin>/app_main.py", line 144 in run_toplevel
  File "<builtin>/app_main.py", line 784 in run_command_line
  File "<builtin>/app_main.py", line 1195 in entry_point
Aborted

@skirpichev
Copy link
Member Author

Pure-python code in PyPy:

# a.py

import gc
import platform
import random
import resource
from math import factorial as fac

VMEM_LIMIT = 64*1000**2
if platform.python_implementation() == "PyPy":
    VMEM_LIMIT = 128*1000**2

mpz = int

def test_fac_outofmem():
    for _ in range(20):
        x = random.randint(12811, 24984)
        soft, hard = resource.getrlimit(resource.RLIMIT_AS)
        resource.setrlimit(resource.RLIMIT_AS, (VMEM_LIMIT, hard))
        a = mpz(x)
        while True:
            try:
                fac(a)
                a *= 2
            except MemoryError:
                del a
                gc.collect()
                break
        resource.setrlimit(resource.RLIMIT_AS, (soft, hard))


test_fac_outofmem()
$ python --version
Python 3.11.13 (413c9b7f57f5, Jul 03 2025, 18:03:56)
[PyPy 7.3.20 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)]
$ python a.py
RPython traceback:
  File "pypy_module_pypyjit.c", line 955, in portal_13
  File "pypy_interpreter_2.c", line 58300, in handle_bytecode__AccessDirect_None
  File "pypy_interpreter_3.c", line 40858, in dispatch_bytecode__AccessDirect_None
out of memory: couldn't allocate a few KB more
Aborted

Another:

# b.py

import gc
import platform
import random
import resource
from math import factorial as fac

VMEM_LIMIT = 64*1000**2
if platform.python_implementation() == "PyPy":
    VMEM_LIMIT = 128*1000**2

mpz = int


def test_square_outofmem():
    for _ in range(20):
        x = random.randint(49846727467293, 249846727467293)
        soft, hard = resource.getrlimit(resource.RLIMIT_AS)
        resource.setrlimit(resource.RLIMIT_AS, (VMEM_LIMIT, hard))
        mx = mpz(x)
        i = 1
        while True:
            try:
                mx = mx*mx
            except MemoryError:
                del mx
                gc.collect()
                assert i > 5
                break
            i += 1
        resource.setrlimit(resource.RLIMIT_AS, (soft, hard))


test_square_outofmem()
$ python b.py
RPython traceback:
  File "pypy_objspace_std.c", line 25071, in W_IntObject_descr_mul
  File "rpython_rlib.c", line 17439, in rbigint__toint_helper
  File "rpython_rlib.c", line 15560, in rbigint__touint_helper
out of memory: couldn't allocate a few KB more
Aborted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant