D7210: fsmonitor: handle unicode keys in tuples
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Sat Nov 2 22:15:16 UTC 2019
indygreg edited the summary of this revision.
indygreg updated this revision to Diff 17513.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D7210?vs=17508&id=17513
BRANCH
stable
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D7210/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D7210
AFFECTED FILES
hgext/fsmonitor/pywatchman/bser.c
CHANGE DETAILS
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,22 @@
const char* item_name = NULL;
PyObject* key = PyTuple_GET_ITEM(obj->keys, i);
- item_name = PyBytes_AsString(key);
+ if (PyUnicode_Check(key)) {
+#if PY_MAJOR_VERSION >= 3
+ item_name = PyUnicode_AsUTF8(key);
+#else
+ PyObject* utf = PyUnicode_AsEncodedString(sval, "utf-8", "ignore");
+ if (utf == NULL) {
+ goto bail;
+ }
+ item_name = PyBytes_AsString(utf);
+#endif
+ } else {
+ item_name = PyBytes_AsString(key);
+ }
+ if (item_name == NULL) {
+ goto bail;
+ }
if (!strcmp(item_name, namestr)) {
ret = PySequence_GetItem(obj->values, i);
goto bail;
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list