@@ -511,26 +511,17 @@ PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_richcompare(JSArrayProxy *
511511}
512512
513513PyObject *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
585575error:
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