Skip to content

Commit 09c92ad

Browse files
Revert "detect cycles in JS Arrays as well"
This reverts commit dc11625.
1 parent dc11625 commit 09c92ad

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/JSArrayProxy.cc

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -511,26 +511,17 @@ PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_richcompare(JSArrayProxy *
511511
}
512512

513513
PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_repr(JSArrayProxy *self) {
514-
// Detect cyclic objects
515-
PyObject *objPtr = PyLong_FromVoidPtr(self->jsArray->get());
516-
// For `Py_ReprEnter`, we must get a same PyObject when visiting the same JSObject.
517-
// We cannot simply use the object returned by `PyLong_FromVoidPtr` because it won't reuse the PyLongObjects for ints not between -5 and 256.
518-
// Instead, we store this PyLongObject in a global dict, using itself as the hashable key, effectively interning the PyLongObject.
519-
PyObject *tsDict = PyThreadState_GetDict();
520-
PyObject *cyclicKey = PyDict_SetDefault(tsDict, /*key*/ objPtr, /*value*/ objPtr); // cyclicKey = (tsDict[objPtr] ??= objPtr)
521-
int i = Py_ReprEnter(cyclicKey);
522-
if (i != 0) {
523-
return i > 0 ? PyUnicode_FromString("[...]") : NULL;
524-
}
525-
526514
Py_ssize_t selfLength = JSArrayProxy_length(self);
527515

528516
if (selfLength == 0) {
529-
Py_ReprLeave(cyclicKey);
530-
PyDict_DelItem(tsDict, cyclicKey);
531517
return PyUnicode_FromString("[]");
532518
}
533519

520+
Py_ssize_t i = Py_ReprEnter((PyObject *)self);
521+
if (i != 0) {
522+
return i > 0 ? PyUnicode_FromString("[...]") : NULL;
523+
}
524+
534525
_PyUnicodeWriter writer;
535526

536527
_PyUnicodeWriter_Init(&writer);
@@ -578,14 +569,12 @@ PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_repr(JSArrayProxy *self) {
578569
goto error;
579570
}
580571

581-
Py_ReprLeave(cyclicKey);
582-
PyDict_DelItem(tsDict, cyclicKey);
572+
Py_ReprLeave((PyObject *)self);
583573
return _PyUnicodeWriter_Finish(&writer);
584574

585575
error:
586576
_PyUnicodeWriter_Dealloc(&writer);
587-
Py_ReprLeave(cyclicKey);
588-
PyDict_DelItem(tsDict, cyclicKey);
577+
Py_ReprLeave((PyObject *)self);
589578
return NULL;
590579
}
591580

0 commit comments

Comments
 (0)