D7210: fsmonitor: handle unicode keys in tuples
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Mon Nov 4 16:28:10 UTC 2019
Closed by commit rHGd359dfc15aca: fsmonitor: handle unicode keys in tuples (authored by indygreg).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".
CHANGED PRIOR TO COMMIT
https://phab.mercurial-scm.org/D7210?vs=17513&id=17526#toc
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D7210?vs=17513&id=17526
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(key, "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: durin42, mercurial-devel
More information about the Mercurial-devel
mailing list