Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Error: Cannot allocate write+execute memory for ffi.callback() #143

Open
DrMarc opened this issue Feb 21, 2022 · 1 comment
Open

Comments

@DrMarc
Copy link

DrMarc commented Feb 21, 2022

Hi Bastian,

SoundCard has been extremely helpful in running hearing experiments in our lab. MacOS (since BigSur) and some Linux variants are unhappy with the implementation of the cffi callbacks, in that memory protection disallows these callbacks. Any call to soundcard.default_speaker().play results in the following error:

File ~/miniconda3/lib/python3.10/site-packages/soundcard/coreaudio.py:322, in _Player.__enter__(self)
    318 def __enter__(self):
    319     self._queue = collections.deque()
    321     @_ffi.callback("AURenderCallback")
--> 322     def render_callback(userdata, actionflags, timestamp,
    323                         busnumber, numframes, bufferlist):
    324         for bufferidx in range(bufferlist.mNumberBuffers):
    325             dest = bufferlist.mBuffers[bufferidx]

MemoryError: Cannot allocate write+execute memory for ffi.callback(). You might be running on a system that prevents this. For more information, see https://cffi.readthedocs.io/en/latest/using.html#callbacks

The suggested solution is to refactor the code so that it does not use ffi.callback(). The new callback style seems easy enough (using another decorator @ffi.def_extern()), but a change to the builder script is required, and I don't know what that is...

Would you be able to have a look at that? I'm happy to help in any way I can if you point me in the right direction.

Thanks for your work on this module and on SoundFile! Both have been super helpful.

@bastibe
Copy link
Owner

bastibe commented Feb 23, 2022

Interesting! I was not aware of that. Thank you for your analysis!

To tell you the truth, I don't have much time to invest into Open Source these days. So I'd be super grateful if you could take a stab at implementing the fix yourself. I'll help you as much as I can, but I only have a scant few hours a week available for things like this.

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

No branches or pull requests

2 participants