File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 3333 #define PY_UNICODE_OBJECT_READY (op ) (PY_ASCII_OBJECT_CAST(op)->state.ready)
3434#endif
3535
36+ /* *
37+ * @brief check if UTF-16 encoded `chars` contain a surrogate pair
38+ */
3639static bool containsSurrogatePair (const char16_t *chars, size_t length) {
3740 for (size_t i = 0 ; i < length; i++) {
3841 if (Py_UNICODE_IS_SURROGATE (chars[i])) {
@@ -109,7 +112,8 @@ StrType::StrType(JSContext *cx, JSString *str) {
109112 return ;
110113 }
111114 Py_DECREF (pyObject); // cleanup the old `pyObject`
112- pyObject = Py_NewRef (ucs4Obj);
115+ Py_INCREF (ucs4Obj); // XXX: Same as the above `Py_INCREF(pyObject);`. Why double freed on GC?
116+ pyObject = ucs4Obj;
113117 }
114118 }
115119}
@@ -121,7 +125,9 @@ const char *StrType::getValue() const {
121125/* static */
122126PyObject *StrType::asUCS4 (PyObject *pyObject) {
123127 if (PyUnicode_KIND (pyObject) != PyUnicode_2BYTE_KIND) {
124- return Py_NewRef (pyObject);
128+ // return a new reference to match the behaviour of `PyUnicode_FromKindAndData`
129+ Py_INCREF (pyObject);
130+ return pyObject;
125131 }
126132
127133 uint16_t *chars = PY_UNICODE_OBJECT_DATA_UCS2 (pyObject);
You can’t perform that action at this time.
0 commit comments