@@ -49,12 +49,12 @@ static PyObjectProxyHandler pyObjectProxyHandler;
4949static PyListProxyHandler pyListProxyHandler;
5050static PyIterableProxyHandler pyIterableProxyHandler;
5151
52- std::unordered_map<PyObject *, size_t > jsExternalStringPyObjects ;// a map of python string objects to the number of JSExternalStrings that depend on it, used when finalizing JSExternalStrings
52+ std::unordered_map<PyObject *, size_t > externalStringObjToRefCountMap ;// a map of python string objects to the number of JSExternalStrings that depend on it, used when finalizing JSExternalStrings
5353
5454PyObject *PythonExternalString::getPyString (const char16_t *chars)
5555{
56- for (auto it: jsExternalStringPyObjects ) {
57- if (PyUnicode_DATA (it.first ) == (void *)chars) {
56+ for (auto it: externalStringObjToRefCountMap ) {
57+ if (PyUnicode_DATA (it.first ) == (void *)chars) { // PyUnicode_<2/1>BYTE_DATA are just type casts of PyUnicode_DATA
5858 return it.first ;
5959 }
6060 }
@@ -75,14 +75,14 @@ void PythonExternalString::finalize(char16_t *chars) const
7575 // to free the object since the entire process memory is being released.
7676 if (_Py_IsFinalizing ()) { return ; }
7777
78- for (auto it = jsExternalStringPyObjects .cbegin (), next_it = it; it != jsExternalStringPyObjects .cend (); it = next_it) {
78+ for (auto it = externalStringObjToRefCountMap .cbegin (), next_it = it; it != externalStringObjToRefCountMap .cend (); it = next_it) {
7979 next_it++;
8080 if (PyUnicode_DATA (it->first ) == (void *)chars) {
8181 Py_DECREF (it->first );
82- jsExternalStringPyObjects [it->first ] = jsExternalStringPyObjects [it->first ] - 1 ;
82+ externalStringObjToRefCountMap [it->first ] = externalStringObjToRefCountMap [it->first ] - 1 ;
8383
84- if (jsExternalStringPyObjects [it->first ] == 0 ) {
85- jsExternalStringPyObjects .erase (it);
84+ if (externalStringObjToRefCountMap [it->first ] == 0 ) {
85+ externalStringObjToRefCountMap .erase (it);
8686 }
8787 }
8888 }
@@ -95,7 +95,7 @@ void PythonExternalString::finalize(JS::Latin1Char *chars) const
9595
9696size_t PythonExternalString::sizeOfBuffer (const char16_t *chars, mozilla::MallocSizeOf mallocSizeOf) const
9797{
98- for (auto it: jsExternalStringPyObjects ) {
98+ for (auto it: externalStringObjToRefCountMap ) {
9999 if (PyUnicode_DATA (it.first ) == (void *)chars) {
100100 return PyUnicode_GetLength (it.first );
101101 }
@@ -169,14 +169,14 @@ JS::Value jsTypeFactory(JSContext *cx, PyObject *object) {
169169 break ;
170170 }
171171 case (PyUnicode_2BYTE_KIND): {
172- jsExternalStringPyObjects [object] = jsExternalStringPyObjects [object] + 1 ;
172+ externalStringObjToRefCountMap [object] = externalStringObjToRefCountMap [object] + 1 ;
173173 Py_INCREF (object);
174174 JSString *str = JS_NewExternalUCString (cx, (char16_t *)PyUnicode_2BYTE_DATA (object), PyUnicode_GET_LENGTH (object), &PythonExternalStringCallbacks);
175175 returnType.setString (str);
176176 break ;
177177 }
178178 case (PyUnicode_1BYTE_KIND): {
179- jsExternalStringPyObjects [object] = jsExternalStringPyObjects [object] + 1 ;
179+ externalStringObjToRefCountMap [object] = externalStringObjToRefCountMap [object] + 1 ;
180180 Py_INCREF (object);
181181 JSString *str = JS_NewExternalStringLatin1 (cx, (JS::Latin1Char *)PyUnicode_1BYTE_DATA (object), PyUnicode_GET_LENGTH (object), &PythonExternalStringCallbacks);
182182 // JSExternalString can now be properly treated as either one-byte or two-byte strings when GCed
0 commit comments