From 691c1d9b23dd738ff2e50d4f5ed1e25d51ad59dc Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 2 Feb 2024 13:22:17 +0100 Subject: [PATCH] fix return value of PCM.write() on success (#137) the `else` branch of the return value handling cascade got lost in commit 438e52e, leading to us returning None on success. rather than restoring the old code exactly, delay the construction of the final return code object. this is more consistent with alsapcm_read() and overall nicer. --- alsaaudio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/alsaaudio.c b/alsaaudio.c index db99616..780b1e3 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -1436,7 +1436,6 @@ static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args) { int datalen; char *data; - PyObject *rc = NULL; #if PY_MAJOR_VERSION < 3 if (!PyArg_ParseTuple(args,"s#:write", &data, &datalen)) @@ -1493,7 +1492,7 @@ static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args) } if (res == -EAGAIN) { - rc = PyLong_FromLong(0); + res = 0; } else if (res < 0) { @@ -1511,7 +1510,7 @@ static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args) PyBuffer_Release(&buf); #endif - return rc; + return PyLong_FromLong(res); } static PyObject *