diff --git a/hgext/fsmonitor/pywatchman/bser.c b/hgext/fsmonitor/pywatchman/bser.c --- a/hgext/fsmonitor/pywatchman/bser.c +++ b/hgext/fsmonitor/pywatchman/bser.c @@ -175,7 +175,15 @@ const char* item_name = NULL; PyObject* key = PyTuple_GET_ITEM(obj->keys, i); + // tuple keys should always be str. +#if PY_MAJOR_VERSION >= 3 + item_name = PyUnicode_AsUTF8(key); +#else item_name = PyBytes_AsString(key); +#endif + if (item_name == NULL) { + goto bail; + } if (!strcmp(item_name, namestr)) { ret = PySequence_GetItem(obj->values, i); goto bail;