PyObject_Dump() encodes unicode objects to utf8 with backslashreplace (instead
of strict) error handler to escape surrogates
diff --git a/Objects/object.c b/Objects/object.c
index 8ddc7ec..1f4e3dd 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -303,7 +303,9 @@
             }
             else if (PyUnicode_Check(s)) {
                 PyObject *t;
-                t = _PyUnicode_AsDefaultEncodedString(s, NULL);
+                t = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(s),
+                                         PyUnicode_GET_SIZE(s),
+                                         "backslashreplace");
                 if (t == NULL)
                     ret = 0;
                 else {