Patchwork D7210: fsmonitor: handle unicode keys in tuples

login
register
mail settings
Submitter phabricator
Date Nov. 4, 2019, 4:28 p.m.
Message ID <b10ebe416e74b6f8b6a5667d1edc89e9@localhost.localdomain>
Download mbox | patch
Permalink /patch/42721/
State Not Applicable
Headers show

Comments

phabricator - Nov. 4, 2019, 4:28 p.m.
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




To: indygreg, #hg-reviewers
Cc: durin42, mercurial-devel

Patch

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;