MCPcopy Create free account
hub / github.com/apache/arrow / run_debug_memory_pool

Function run_debug_memory_pool

python/pyarrow/tests/test_memory.py:185–212  ·  view source on GitHub ↗

Run a piece of code making an invalid memory write with the ARROW_DEBUG_MEMORY_POOL environment variable set to a specific value.

(pool_factory, env_value)

Source from the content-addressed store, hash-verified

183
184
185def run_debug_memory_pool(pool_factory, env_value):
186 """
187 Run a piece of code making an invalid memory write with the
188 ARROW_DEBUG_MEMORY_POOL environment variable set to a specific value.
189 """
190 code = f"""if 1:
191 import ctypes
192 import pyarrow as pa
193 # ARROW-16873: some Python installs enable faulthandler by default,
194 # which could dump a spurious stack trace if the following crashes
195 import faulthandler
196 faulthandler.disable()
197
198 pool = pa.{pool_factory}()
199 buf = pa.allocate_buffer(64, memory_pool=pool)
200
201 # Write memory out of bounds
202 ptr = ctypes.cast(buf.address, ctypes.POINTER(ctypes.c_ubyte))
203 ptr[64] = 0
204
205 del buf
206 """
207 env = dict(os.environ)
208 env['ARROW_DEBUG_MEMORY_POOL'] = env_value
209 res = subprocess.run([sys.executable, "-c", code], env=env,
210 universal_newlines=True, stderr=subprocess.PIPE)
211 print(res.stderr, file=sys.stderr)
212 return res
213
214
215@pytest.mark.parametrize('pool_factory', supported_factories())

Calls 1

runMethod · 0.45

Tested by

no test coverage detected