@@ -511,26 +511,17 @@ PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_richcompare(JSArrayProxy *
511
511
}
512
512
513
513
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
-
526
514
Py_ssize_t selfLength = JSArrayProxy_length (self);
527
515
528
516
if (selfLength == 0 ) {
529
- Py_ReprLeave (cyclicKey);
530
- PyDict_DelItem (tsDict, cyclicKey);
531
517
return PyUnicode_FromString (" []" );
532
518
}
533
519
520
+ Py_ssize_t i = Py_ReprEnter ((PyObject *)self);
521
+ if (i != 0 ) {
522
+ return i > 0 ? PyUnicode_FromString (" [...]" ) : NULL ;
523
+ }
524
+
534
525
_PyUnicodeWriter writer;
535
526
536
527
_PyUnicodeWriter_Init (&writer);
@@ -578,14 +569,12 @@ PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_repr(JSArrayProxy *self) {
578
569
goto error;
579
570
}
580
571
581
- Py_ReprLeave (cyclicKey);
582
- PyDict_DelItem (tsDict, cyclicKey);
572
+ Py_ReprLeave ((PyObject *)self);
583
573
return _PyUnicodeWriter_Finish (&writer);
584
574
585
575
error:
586
576
_PyUnicodeWriter_Dealloc (&writer);
587
- Py_ReprLeave (cyclicKey);
588
- PyDict_DelItem (tsDict, cyclicKey);
577
+ Py_ReprLeave ((PyObject *)self);
589
578
return NULL ;
590
579
}
591
580
0 commit comments