Skip to content

Commit 962ef4a

Browse files
committed
Test more singletons
1 parent c8dd591 commit 962ef4a

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

Objects/object.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3601,15 +3601,19 @@ _Py_CheckSingletons(void)
36013601
assert(!PyErr_Occurred());
36023602
PyObject *obj;
36033603
long ival;
3604+
PyInterpreterState *interp = _PyInterpreterState_GET();
36043605

36053606
// None
36063607
obj = Py_None;
36073608
check_singleton(obj, &_PyNone_Type);
36083609

3609-
// Ellipsis (...)
3610+
// Ellipsis (...), Py_NotImplemented
36103611
obj = Py_Ellipsis;
36113612
check_singleton(obj, &PyEllipsis_Type);
36123613

3614+
obj = Py_NotImplemented;
3615+
check_singleton(obj, &_PyNotImplemented_Type);
3616+
36133617
// False, True
36143618
check_singleton_long(Py_False, 0, 1);
36153619
check_singleton_long(Py_True, 1, 1);
@@ -3624,6 +3628,7 @@ _Py_CheckSingletons(void)
36243628
obj = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
36253629
check_singleton_bytes(obj, 0, '\0');
36263630

3631+
// 1-character bytes strings
36273632
for (ival=0; ival <= 255; ival++) {
36283633
obj = (PyObject*)&_Py_SINGLETON(bytes_characters)[ival];
36293634
check_singleton_bytes(obj, 1, (unsigned char)ival);
@@ -3633,6 +3638,9 @@ _Py_CheckSingletons(void)
36333638
obj = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
36343639
check_singleton_unicode(obj, 0, 0);
36353640

3641+
// Do not tests _Py_STR() strings since there is no API to list them
3642+
3643+
// 1-character Unicode strings
36363644
for (ival=0; ival <= 255; ival++) {
36373645
obj = _Py_LATIN1_CHR(ival);
36383646
check_singleton_unicode(obj, 1, ival);
@@ -3644,6 +3652,15 @@ _Py_CheckSingletons(void)
36443652
_PyObject_ASSERT(obj, PyTuple_GET_SIZE(obj) == 0);
36453653
_PyObject_ASSERT(obj, ((PyTupleObject*)obj)->ob_hash == _PyTuple_HASH_EMPTY);
36463654

3655+
// Do not test less commoly used singletons to reduce the overhead
3656+
// of calling _Py_CheckSingletons():
3657+
//
3658+
// - PyDateTime_TimeZone_UTC
3659+
// - context_token_missing
3660+
// - hamt_bitmap_node_empty
3661+
// - interp hamt_empty
3662+
// - interp last_resort_memory_error
3663+
36473664
assert(!PyErr_Occurred());
36483665
}
36493666
#endif

0 commit comments

Comments
 (0)