@@ -49,12 +49,12 @@ static PyObjectProxyHandler pyObjectProxyHandler;
49
49
static PyListProxyHandler pyListProxyHandler;
50
50
static PyIterableProxyHandler pyIterableProxyHandler;
51
51
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
53
53
54
54
PyObject *PythonExternalString::getPyString (const char16_t *chars)
55
55
{
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
58
58
return it.first ;
59
59
}
60
60
}
@@ -75,14 +75,14 @@ void PythonExternalString::finalize(char16_t *chars) const
75
75
// to free the object since the entire process memory is being released.
76
76
if (_Py_IsFinalizing ()) { return ; }
77
77
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) {
79
79
next_it++;
80
80
if (PyUnicode_DATA (it->first ) == (void *)chars) {
81
81
Py_DECREF (it->first );
82
- jsExternalStringPyObjects [it->first ] = jsExternalStringPyObjects [it->first ] - 1 ;
82
+ externalStringObjToRefCountMap [it->first ] = externalStringObjToRefCountMap [it->first ] - 1 ;
83
83
84
- if (jsExternalStringPyObjects [it->first ] == 0 ) {
85
- jsExternalStringPyObjects .erase (it);
84
+ if (externalStringObjToRefCountMap [it->first ] == 0 ) {
85
+ externalStringObjToRefCountMap .erase (it);
86
86
}
87
87
}
88
88
}
@@ -95,7 +95,7 @@ void PythonExternalString::finalize(JS::Latin1Char *chars) const
95
95
96
96
size_t PythonExternalString::sizeOfBuffer (const char16_t *chars, mozilla::MallocSizeOf mallocSizeOf) const
97
97
{
98
- for (auto it: jsExternalStringPyObjects ) {
98
+ for (auto it: externalStringObjToRefCountMap ) {
99
99
if (PyUnicode_DATA (it.first ) == (void *)chars) {
100
100
return PyUnicode_GetLength (it.first );
101
101
}
@@ -169,14 +169,14 @@ JS::Value jsTypeFactory(JSContext *cx, PyObject *object) {
169
169
break ;
170
170
}
171
171
case (PyUnicode_2BYTE_KIND): {
172
- jsExternalStringPyObjects [object] = jsExternalStringPyObjects [object] + 1 ;
172
+ externalStringObjToRefCountMap [object] = externalStringObjToRefCountMap [object] + 1 ;
173
173
Py_INCREF (object);
174
174
JSString *str = JS_NewExternalUCString (cx, (char16_t *)PyUnicode_2BYTE_DATA (object), PyUnicode_GET_LENGTH (object), &PythonExternalStringCallbacks);
175
175
returnType.setString (str);
176
176
break ;
177
177
}
178
178
case (PyUnicode_1BYTE_KIND): {
179
- jsExternalStringPyObjects [object] = jsExternalStringPyObjects [object] + 1 ;
179
+ externalStringObjToRefCountMap [object] = externalStringObjToRefCountMap [object] + 1 ;
180
180
Py_INCREF (object);
181
181
JSString *str = JS_NewExternalStringLatin1 (cx, (JS::Latin1Char *)PyUnicode_1BYTE_DATA (object), PyUnicode_GET_LENGTH (object), &PythonExternalStringCallbacks);
182
182
// JSExternalString can now be properly treated as either one-byte or two-byte strings when GCed
0 commit comments