3
3
#endif
4
4
5
5
#include "Python.h"
6
+ #include "pycore_critical_section.h" // _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED()
6
7
#include "pycore_long.h" // _PyLong_GetOne()
7
8
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
8
9
@@ -298,15 +299,20 @@ get_weak_cache(zoneinfo_state *state, PyTypeObject *type)
298
299
}
299
300
}
300
301
302
+ /*[clinic input]
303
+ @critical_section
304
+ @classmethod
305
+ zoneinfo.ZoneInfo.__new__
306
+
307
+ key: object
308
+
309
+ Create a new ZoneInfo instance.
310
+ [clinic start generated code]*/
311
+
301
312
static PyObject *
302
- zoneinfo_new (PyTypeObject * type , PyObject * args , PyObject * kw )
313
+ zoneinfo_ZoneInfo_impl (PyTypeObject * type , PyObject * key )
314
+ /*[clinic end generated code: output=95e61dab86bb95c3 input=4619eb0305327e83]*/
303
315
{
304
- PyObject * key = NULL ;
305
- static char * kwlist [] = {"key" , NULL };
306
- if (PyArg_ParseTupleAndKeywords (args , kw , "O" , kwlist , & key ) == 0 ) {
307
- return NULL ;
308
- }
309
-
310
316
zoneinfo_state * state = zoneinfo_get_state_by_self (type );
311
317
PyObject * instance = zone_from_strong_cache (state , type , key );
312
318
if (instance != NULL || PyErr_Occurred ()) {
@@ -467,6 +473,7 @@ zoneinfo_ZoneInfo_no_cache_impl(PyTypeObject *type, PyTypeObject *cls,
467
473
}
468
474
469
475
/*[clinic input]
476
+ @critical_section
470
477
@classmethod
471
478
zoneinfo.ZoneInfo.clear_cache
472
479
@@ -481,7 +488,7 @@ Clear the ZoneInfo cache.
481
488
static PyObject *
482
489
zoneinfo_ZoneInfo_clear_cache_impl (PyTypeObject * type , PyTypeObject * cls ,
483
490
PyObject * only_keys )
484
- /*[clinic end generated code: output=114d9b7c8a22e660 input=e32ca3bb396788ba ]*/
491
+ /*[clinic end generated code: output=114d9b7c8a22e660 input=35944715df26d24e ]*/
485
492
{
486
493
zoneinfo_state * state = zoneinfo_get_state_by_cls (cls );
487
494
PyObject * weak_cache = get_weak_cache (state , type );
@@ -821,7 +828,7 @@ zoneinfo_ZoneInfo__unpickle_impl(PyTypeObject *type, PyTypeObject *cls,
821
828
return NULL ;
822
829
}
823
830
824
- PyObject * rv = zoneinfo_new (type , val_args , NULL );
831
+ PyObject * rv = zoneinfo_ZoneInfo (type , val_args , NULL );
825
832
826
833
Py_DECREF (val_args );
827
834
return rv ;
@@ -858,8 +865,7 @@ load_timedelta(zoneinfo_state *state, long seconds)
858
865
0 , seconds , 0 , 1 , PyDateTimeAPI -> DeltaType );
859
866
860
867
if (tmp != NULL ) {
861
- rv = PyDict_SetDefault (state -> TIMEDELTA_CACHE , pyoffset , tmp );
862
- Py_XINCREF (rv );
868
+ PyDict_SetDefaultRef (state -> TIMEDELTA_CACHE , pyoffset , tmp , & rv );
863
869
Py_DECREF (tmp );
864
870
}
865
871
}
@@ -2368,6 +2374,7 @@ strong_cache_free(StrongCacheNode *root)
2368
2374
static void
2369
2375
remove_from_strong_cache (zoneinfo_state * state , StrongCacheNode * node )
2370
2376
{
2377
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED (state -> ZoneInfoType );
2371
2378
if (state -> ZONEINFO_STRONG_CACHE == node ) {
2372
2379
state -> ZONEINFO_STRONG_CACHE = node -> next ;
2373
2380
}
@@ -2422,6 +2429,7 @@ eject_from_strong_cache(zoneinfo_state *state, const PyTypeObject *const type,
2422
2429
return 0 ;
2423
2430
}
2424
2431
2432
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED (state -> ZoneInfoType );
2425
2433
StrongCacheNode * cache = state -> ZONEINFO_STRONG_CACHE ;
2426
2434
StrongCacheNode * node = find_in_strong_cache (cache , key );
2427
2435
if (node != NULL ) {
@@ -2478,6 +2486,7 @@ zone_from_strong_cache(zoneinfo_state *state, const PyTypeObject *const type,
2478
2486
return NULL ; // Strong cache currently only implemented for base class
2479
2487
}
2480
2488
2489
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED (state -> ZoneInfoType );
2481
2490
StrongCacheNode * cache = state -> ZONEINFO_STRONG_CACHE ;
2482
2491
StrongCacheNode * node = find_in_strong_cache (cache , key );
2483
2492
@@ -2504,6 +2513,7 @@ update_strong_cache(zoneinfo_state *state, const PyTypeObject *const type,
2504
2513
return ;
2505
2514
}
2506
2515
2516
+ _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED (state -> ZoneInfoType );
2507
2517
StrongCacheNode * new_node = strong_cache_node_new (key , zone );
2508
2518
if (new_node == NULL ) {
2509
2519
return ;
@@ -2631,7 +2641,7 @@ static PyType_Slot zoneinfo_slots[] = {
2631
2641
{Py_tp_getattro , PyObject_GenericGetAttr },
2632
2642
{Py_tp_methods , zoneinfo_methods },
2633
2643
{Py_tp_members , zoneinfo_members },
2634
- {Py_tp_new , zoneinfo_new },
2644
+ {Py_tp_new , zoneinfo_ZoneInfo },
2635
2645
{Py_tp_dealloc , zoneinfo_dealloc },
2636
2646
{Py_tp_traverse , zoneinfo_traverse },
2637
2647
{Py_tp_clear , zoneinfo_clear },
0 commit comments