@@ -11,20 +11,35 @@ index 46ea021..58a3fb5 100644
11
11
SendSignal(exc_value.signum)
12
12
else:
13
13
SendSignalToThread(exc_value.signum,
14
- diff --git a/pyarrow/tests/test_memory.py b/pyarrow/tests/test_memory.py
15
- index 092c50d..931b3fa 100644
16
- --- a/pyarrow/tests/test_memory.py
17
- +++ b/pyarrow/tests/test_memory.py
18
- @@ -44,6 +44,9 @@ def allocate_bytes(pool, nbytes):
19
- """
20
- Temporarily allocate *nbytes* from the given *pool*.
14
+ diff --git a/pyarrow/memory.pxi b/pyarrow/memory.pxi
15
+ index 1ddcb01..6805e42 100644
16
+ --- a/pyarrow/memory.pxi
17
+ +++ b/pyarrow/memory.pxi
18
+ @@ -20,6 +20,10 @@
19
+ # cython: embedsignature = True
20
+
21
+
22
+ + cdef extern from "Python.h":
23
+ + void Py_INCREF(object)
24
+ +
25
+ +
26
+ cdef class MemoryPool(_Weakrefable):
21
27
"""
22
- + # GraalPy change: the buffers don't maintain a python reference to their
23
- + # pool, so they may get destroyed after their pool, which segfaults
24
- + raise RuntimeError("GraalPy: destructors segfault")
25
- arr = pa.array([b"x" * nbytes], type=pa.binary(), memory_pool=pool)
26
- # Fetch the values buffer from the varbinary array and release the rest,
27
- # to get the desired allocation amount
28
+ Base class for memory allocation.
29
+ @@ -35,6 +39,13 @@ cdef class MemoryPool(_Weakrefable):
30
+
31
+ cdef void init(self, CMemoryPool* pool):
32
+ self.pool = pool
33
+ + # GraalPy change: pyarrow doesn't maintain python references from
34
+ + # buffers to pools, but they dereference the pointer to the pool in the
35
+ + # destructor. They just assume buffers will get GC'ed before their
36
+ + # pools. You can easily get a segfault even on CPython if you make
37
+ + # a buffer outlive its pool. Since we can't guarantee destruction
38
+ + # order, we just leak the pool.
39
+ + Py_INCREF(self)
40
+
41
+ def release_unused(self):
42
+ """
28
43
diff --git a/pyarrow_build_backend.py b/pyarrow_build_backend.py
29
44
new file mode 100644
30
45
index 0000000..c9826ce
0 commit comments