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