Skip to content

Fix callback handling and flag initialization#629

Open
ThatOneFBIAgent wants to merge 1 commit intospatialaudio:masterfrom
ThatOneFBIAgent:master
Open

Fix callback handling and flag initialization#629
ThatOneFBIAgent wants to merge 1 commit intospatialaudio:masterfrom
ThatOneFBIAgent:master

Conversation

@ThatOneFBIAgent
Copy link
Copy Markdown

Problem

On Python 3.14, cffi changed how it passes arguments to native callbacks
and how it validates __init__ return values. This caused two distinct errors:

  1. TypeError: __init__() should return None, not 'NoneType'
    cffi now intercepts and validates the return of __init__ at a lower
    level, causing it to spuriously reject the standard None return.

  2. TypeError: unsupported operand type(s) for &: '_CDataBase' and 'int'
    The status argument now arrives as a raw _CDataBase object instead
    of a plain Python int, breaking bitwise operations in _hasflag.

Both errors surface in _wrap_callback and occur unpredictably during
stream callbacks, including during silence and active playback.

Fix

Bypass CallbackFlags.__init__ entirely in _wrap_callback using
__new__, then set _flags directly via int() cast. This avoids
the cffi __init__ interception and the _CDataBase bitwise issue
in one shot.

Changes

In _wrap_callback, replace:
args = args[:-1] + (CallbackFlags(args[-1]),)
With:
cf = CallbackFlags.new(CallbackFlags)
cf._flags = int(status)

Tested on

  • Python 3.14.4, Sounddevice 0.5.5
  • Extended idle periods (no audio) no longer trigger the error
  • Active playback confirmed working after fix

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.

1 participant