Skip to content

Fix GIL handling in picosat memory allocators.#198

Open
ykazakov wants to merge 1 commit intocjdrake:mainfrom
ykazakov:fix-picosat-gil-issue
Open

Fix GIL handling in picosat memory allocators.#198
ykazakov wants to merge 1 commit intocjdrake:mainfrom
ykazakov:fix-picosat-gil-issue

Conversation

@ykazakov
Copy link
Copy Markdown

@ykazakov ykazakov commented Jun 25, 2025

The custom memory allocators in picosatmodule.c were calling PyMem_Malloc, PyMem_Realloc, and PyMem_Free without holding the GIL. This could lead to a segfault when picosat_sat, which releases the GIL, calls these allocators.

This commit fixes the issue by acquiring the GIL before calling PyMem_ functions and releasing it afterwards in the custom memory allocators.

Fixes #195

The custom memory allocators in `picosatmodule.c` were calling PyMem_Malloc, PyMem_Realloc, and PyMem_Free without holding the GIL. This could lead to a segfault when picosat_sat, which releases the GIL, calls these allocators.

This commit fixes the issue by acquiring the GIL before calling PyMem_ functions and releasing it afterwards in the custom memory allocators.
@ykazakov ykazakov changed the title Fix GIL handling in picosat memory allocators #195 Fix GIL handling in picosat memory allocators. Fixes #195 Jun 25, 2025
@ykazakov ykazakov changed the title Fix GIL handling in picosat memory allocators. Fixes #195 Fix GIL handling in picosat memory allocators. Jun 25, 2025
@ykazakov
Copy link
Copy Markdown
Author

The fix was generated using an AI tool (jules). I verified that it works for Python 3.12.2 and Python 3.13.5 (tests do not fail) on MacOS 18.5 (Macbook Pro M1), but I am not an expert on Python memory allocators.

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.

Segfault on python version 3.13

1 participant