Conversation
Part of the next PR...
MAINT: Try using standard memory allocators
| @@ -1,4 +1,6 @@ | |||
| ctypedef void* (*malloc_t)(size_t n) | |||
| ctypedef void* (*calloc_t)(size_t n) | |||
| ctypedef void* (*realloc_t)(size_t n) | |||
There was a problem hiding this comment.
If you're adding to the public API, you should explain in the PR description why. Also, calloc method is added to the implementation but not here.
|
Can you turn actions on for your fork to make sure CI passes? |
|
Did you try running e.g. the example use-case from the readme on the GIL-enabled and free-threaded build? |
I had built the example and tested it a bit before these changes but since it doesn't actually have any methods defined on the sparse matrix I basically checked that creation of a bunch of sparse matrices in a list comprehension works. No failure then. With this PR I'll double check but I think it was "working" the same way (i.e. no confidence in it either way). I'll try to flesh out the sparse matrix example with a few operations. |
|
Looking at the reverse dependencies, I only recognize thinc. You could look at how that library is using cymem. The original comment was just towards making sure this is getting tested for a real-ish use-case, given the lack of tests for most functionality, |
Sadly Will go through the rest :) EDIT: Bit of a trend here, most of the libraries don't seem to use it at all, e.g. mdparse, etk |
| self.addresses = {} | ||
| self.refs = [] | ||
| self.pymalloc = pymalloc | ||
| self.pycalloc = pycalloc |
There was a problem hiding this comment.
Unfortunately this will be more disruptive than a reasonable person would expect.
We build against cymem across our dependency tree (we cimport cymem), and in order to add a member, you need to add a cdef in the .pxd.
If a public class changes size in Cython, it's no longer binary-compatible. This means we'll need to make this a major version increment, and we'd need to do updates across our dependency chain to use the new version.
| """ | ||
|
|
||
| def __cinit__(self, PyMalloc pymalloc=Default_Malloc, | ||
| PyCalloc pycalloc = Default_Calloc, |
There was a problem hiding this comment.
This is backwards incompatible. A user who was instantiated the class with something like mem = Pool(pymalloc=Default_Malloc, pyfree=Default_Free) would suffer segfaults.
When adding new arguments to a function with defaults, the new arguments need to be placed after the current ones.
I think the backwards-compatible way to do this, assuming it's actually necessary to do this and to support a single |
cc @ngoldbaum
The main changes here are basically due to not trying to mix C allocator and Python memory allocator via
memsetormemcpy.Pool.allocto usePyMem_Calloc, removingmemsetPool.reallocto usePyMem_ReallocThis PR is a draft until:
[ ] CI for testing and building wheels with Python 3.13t is fully green.
[ ] More static audits of the code