From 9dc0fc2fd3b6caf4203eed4b3b60a6af63cfbedf Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 7 Aug 2022 13:15:38 +0200 Subject: [PATCH] fix deprecation warning about PyUnicode_AsUnicode() converting to ascii for the purpose of comparison is inefficient. --- alsaaudio.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/alsaaudio.c b/alsaaudio.c index 6472a6a..633ddd8 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -179,11 +179,18 @@ get_pcmtype(PyObject *obj) #endif if (PyUnicode_Check(obj)) { +#if PY_MAJOR_VERSION > 2 + if (PyUnicode_CompareWithASCIIString(obj, "playback") == 0) + return SND_PCM_STREAM_PLAYBACK; + else if (PyUnicode_CompareWithASCIIString(obj, "capture") == 0) + return SND_PCM_STREAM_CAPTURE; +#else const char *dirstr = PyUnicode_AS_DATA(obj); if (strcasecmp(dirstr, "playback")==0) return SND_PCM_STREAM_PLAYBACK; else if (strcasecmp(dirstr, "capture")==0) return SND_PCM_STREAM_CAPTURE; +#endif } PyErr_SetString(ALSAAudioError, "PCM type must be PCM_PLAYBACK (0) "