Skip to content

Commit b54d92a

Browse files
author
Jonathan Kliem
committed
more generic failure for memory overflow
1 parent e892fa4 commit b54d92a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
pip freeze
4343
- name: Local build
4444
run: |
45+
set -e
4546
python setup.py build_ext -i
46-
python test.py || exit 1
47+
python test.py
4748
git clean -xfd

memory_allocator/test.pyx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ cdef class TestMemoryAllocator():
1414
>>> from memory_allocator.test import TestMemoryAllocator
1515
>>> mem = TestMemoryAllocator()
1616
>>> _ = mem.malloc(100)
17-
>>> mem.malloc(2**63)
17+
>>> mem.malloc(mem.size_t_max())
1818
Traceback (most recent call last):
1919
...
20-
MemoryError: failed to allocate 9223372036854775808 bytes
20+
MemoryError: failed to allocate ... bytes
2121
"""
2222
return <size_t> self.mem.malloc(size)
2323

@@ -28,10 +28,10 @@ cdef class TestMemoryAllocator():
2828
>>> from memory_allocator.test import TestMemoryAllocator
2929
>>> mem = TestMemoryAllocator()
3030
>>> _ = mem.calloc(100, 10)
31-
>>> mem.calloc(2**63, 1)
31+
>>> mem.calloc(mem.size_t_max(), 1)
3232
Traceback (most recent call last):
3333
...
34-
MemoryError: failed to allocate 9223372036854775808 * 1 bytes
34+
MemoryError: failed to allocate ... * 1 bytes
3535
"""
3636
return <size_t> self.mem.calloc(nmemb, size)
3737

@@ -42,10 +42,10 @@ cdef class TestMemoryAllocator():
4242
>>> from memory_allocator.test import TestMemoryAllocator
4343
>>> mem = TestMemoryAllocator()
4444
>>> _ = mem.allocarray(100, 10)
45-
>>> mem.allocarray(2**63, 1)
45+
>>> mem.allocarray(size_t_max(), 1)
4646
Traceback (most recent call last):
4747
...
48-
MemoryError: failed to allocate 9223372036854775808 * 1 bytes
48+
MemoryError: failed to allocate ... * 1 bytes
4949
"""
5050
return <size_t> self.mem.allocarray(nmemb, size)
5151

@@ -142,3 +142,6 @@ cdef class TestMemoryAllocator():
142142

143143
def size(self):
144144
return self.mem.size
145+
146+
def size_t_max(self):
147+
return <size_t> -1

0 commit comments

Comments
 (0)