@@ -56,6 +56,8 @@ typedef struct {
56
56
unsigned char source ;
57
57
} PyZoneInfo_ZoneInfo ;
58
58
59
+ #define PyZoneInfo_ZoneInfo_CAST (op ) ((PyZoneInfo_ZoneInfo *)(op))
60
+
59
61
struct TransitionRuleType {
60
62
int64_t (* year_to_timestamp )(TransitionRuleType * , int );
61
63
};
@@ -238,7 +240,7 @@ zoneinfo_new_instance(zoneinfo_state *state, PyTypeObject *type, PyObject *key)
238
240
}
239
241
}
240
242
241
- PyObject * self = ( PyObject * )( type -> tp_alloc (type , 0 ) );
243
+ PyObject * self = type -> tp_alloc (type , 0 );
242
244
if (self == NULL ) {
243
245
goto error ;
244
246
}
@@ -251,7 +253,8 @@ zoneinfo_new_instance(zoneinfo_state *state, PyTypeObject *type, PyObject *key)
251
253
}
252
254
}
253
255
254
- if (load_data (state , (PyZoneInfo_ZoneInfo * )self , file_obj )) {
256
+ PyZoneInfo_ZoneInfo * self_zinfo = (PyZoneInfo_ZoneInfo * )self ;
257
+ if (load_data (state , self_zinfo , file_obj )) {
255
258
goto error ;
256
259
}
257
260
@@ -262,7 +265,7 @@ zoneinfo_new_instance(zoneinfo_state *state, PyTypeObject *type, PyObject *key)
262
265
}
263
266
Py_DECREF (rv );
264
267
265
- (( PyZoneInfo_ZoneInfo * ) self ) -> key = Py_NewRef (key );
268
+ self_zinfo -> key = Py_NewRef (key );
266
269
267
270
goto cleanup ;
268
271
error :
@@ -346,16 +349,18 @@ zoneinfo_ZoneInfo_impl(PyTypeObject *type, PyObject *key)
346
349
}
347
350
348
351
static int
349
- zoneinfo_traverse (PyZoneInfo_ZoneInfo * self , visitproc visit , void * arg )
352
+ zoneinfo_traverse (PyObject * op , visitproc visit , void * arg )
350
353
{
354
+ PyZoneInfo_ZoneInfo * self = PyZoneInfo_ZoneInfo_CAST (op );
351
355
Py_VISIT (Py_TYPE (self ));
352
356
Py_VISIT (self -> key );
353
357
return 0 ;
354
358
}
355
359
356
360
static int
357
- zoneinfo_clear (PyZoneInfo_ZoneInfo * self )
361
+ zoneinfo_clear (PyObject * op )
358
362
{
363
+ PyZoneInfo_ZoneInfo * self = PyZoneInfo_ZoneInfo_CAST (op );
359
364
Py_CLEAR (self -> key );
360
365
Py_CLEAR (self -> file_repr );
361
366
return 0 ;
@@ -364,7 +369,7 @@ zoneinfo_clear(PyZoneInfo_ZoneInfo *self)
364
369
static void
365
370
zoneinfo_dealloc (PyObject * obj_self )
366
371
{
367
- PyZoneInfo_ZoneInfo * self = ( PyZoneInfo_ZoneInfo * ) obj_self ;
372
+ PyZoneInfo_ZoneInfo * self = PyZoneInfo_ZoneInfo_CAST ( obj_self ) ;
368
373
PyTypeObject * tp = Py_TYPE (self );
369
374
PyObject_GC_UnTrack (self );
370
375
@@ -395,7 +400,7 @@ zoneinfo_dealloc(PyObject *obj_self)
395
400
396
401
free_tzrule (& (self -> tzrule_after ));
397
402
398
- zoneinfo_clear (self );
403
+ ( void ) zoneinfo_clear (obj_self );
399
404
tp -> tp_free (obj_self );
400
405
Py_DECREF (tp );
401
406
}
@@ -420,8 +425,7 @@ zoneinfo_ZoneInfo_from_file_impl(PyTypeObject *type, PyTypeObject *cls,
420
425
PyObject * file_repr = NULL ;
421
426
PyZoneInfo_ZoneInfo * self = NULL ;
422
427
423
- PyObject * obj_self = (PyObject * )(type -> tp_alloc (type , 0 ));
424
- self = (PyZoneInfo_ZoneInfo * )obj_self ;
428
+ self = (PyZoneInfo_ZoneInfo * )type -> tp_alloc (type , 0 );
425
429
if (self == NULL ) {
426
430
return NULL ;
427
431
}
@@ -439,7 +443,7 @@ zoneinfo_ZoneInfo_from_file_impl(PyTypeObject *type, PyTypeObject *cls,
439
443
self -> source = SOURCE_FILE ;
440
444
self -> file_repr = file_repr ;
441
445
self -> key = Py_NewRef (key );
442
- return obj_self ;
446
+ return ( PyObject * ) self ;
443
447
444
448
error :
445
449
Py_XDECREF (file_repr );
@@ -466,7 +470,7 @@ zoneinfo_ZoneInfo_no_cache_impl(PyTypeObject *type, PyTypeObject *cls,
466
470
zoneinfo_state * state = zoneinfo_get_state_by_cls (cls );
467
471
PyObject * out = zoneinfo_new_instance (state , type , key );
468
472
if (out != NULL ) {
469
- (( PyZoneInfo_ZoneInfo * ) out )-> source = SOURCE_NOCACHE ;
473
+ PyZoneInfo_ZoneInfo_CAST ( out )-> source = SOURCE_NOCACHE ;
470
474
}
471
475
472
476
return out ;
@@ -558,7 +562,7 @@ zoneinfo_ZoneInfo_utcoffset_impl(PyObject *self, PyTypeObject *cls,
558
562
/*[clinic end generated code: output=b71016c319ba1f91 input=2bb6c5364938f19c]*/
559
563
{
560
564
zoneinfo_state * state = zoneinfo_get_state_by_cls (cls );
561
- _ttinfo * tti = find_ttinfo (state , ( PyZoneInfo_ZoneInfo * ) self , dt );
565
+ _ttinfo * tti = find_ttinfo (state , PyZoneInfo_ZoneInfo_CAST ( self ) , dt );
562
566
if (tti == NULL ) {
563
567
return NULL ;
564
568
}
@@ -580,7 +584,7 @@ zoneinfo_ZoneInfo_dst_impl(PyObject *self, PyTypeObject *cls, PyObject *dt)
580
584
/*[clinic end generated code: output=cb6168d7723a6ae6 input=2167fb80cf8645c6]*/
581
585
{
582
586
zoneinfo_state * state = zoneinfo_get_state_by_cls (cls );
583
- _ttinfo * tti = find_ttinfo (state , ( PyZoneInfo_ZoneInfo * ) self , dt );
587
+ _ttinfo * tti = find_ttinfo (state , PyZoneInfo_ZoneInfo_CAST ( self ) , dt );
584
588
if (tti == NULL ) {
585
589
return NULL ;
586
590
}
@@ -603,7 +607,7 @@ zoneinfo_ZoneInfo_tzname_impl(PyObject *self, PyTypeObject *cls,
603
607
/*[clinic end generated code: output=3b6ae6c3053ea75a input=15a59a4f92ed1f1f]*/
604
608
{
605
609
zoneinfo_state * state = zoneinfo_get_state_by_cls (cls );
606
- _ttinfo * tti = find_ttinfo (state , ( PyZoneInfo_ZoneInfo * ) self , dt );
610
+ _ttinfo * tti = find_ttinfo (state , PyZoneInfo_ZoneInfo_CAST ( self ) , dt );
607
611
if (tti == NULL ) {
608
612
return NULL ;
609
613
}
@@ -627,7 +631,7 @@ zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)
627
631
return NULL ;
628
632
}
629
633
630
- PyZoneInfo_ZoneInfo * self = ( PyZoneInfo_ZoneInfo * ) obj_self ;
634
+ PyZoneInfo_ZoneInfo * self = PyZoneInfo_ZoneInfo_CAST ( obj_self ) ;
631
635
632
636
int64_t timestamp ;
633
637
if (get_local_timestamp (dt , & timestamp )) {
@@ -736,31 +740,24 @@ zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)
736
740
}
737
741
738
742
static PyObject *
739
- zoneinfo_repr (PyZoneInfo_ZoneInfo * self )
743
+ zoneinfo_repr (PyObject * op )
740
744
{
741
- PyObject * rv = NULL ;
742
- const char * type_name = Py_TYPE ((PyObject * )self )-> tp_name ;
743
- if (!(self -> key == Py_None )) {
744
- rv = PyUnicode_FromFormat ("%s(key=%R)" , type_name , self -> key );
745
- }
746
- else {
747
- assert (PyUnicode_Check (self -> file_repr ));
748
- rv = PyUnicode_FromFormat ("%s.from_file(%U)" , type_name ,
749
- self -> file_repr );
745
+ PyZoneInfo_ZoneInfo * self = PyZoneInfo_ZoneInfo_CAST (op );
746
+ if (self -> key != Py_None ) {
747
+ return PyUnicode_FromFormat ("%T(key=%R)" , self , self -> key );
750
748
}
751
-
752
- return rv ;
749
+ assert ( PyUnicode_Check ( self -> file_repr ));
750
+ return PyUnicode_FromFormat ( "%T.from_file(%U)" , self , self -> file_repr ) ;
753
751
}
754
752
755
753
static PyObject *
756
- zoneinfo_str (PyZoneInfo_ZoneInfo * self )
754
+ zoneinfo_str (PyObject * op )
757
755
{
758
- if (!(self -> key == Py_None )) {
756
+ PyZoneInfo_ZoneInfo * self = PyZoneInfo_ZoneInfo_CAST (op );
757
+ if (self -> key != Py_None ) {
759
758
return Py_NewRef (self -> key );
760
759
}
761
- else {
762
- return zoneinfo_repr (self );
763
- }
760
+ return zoneinfo_repr (op );
764
761
}
765
762
766
763
/* Pickles the ZoneInfo object by key and source.
@@ -776,9 +773,9 @@ zoneinfo_str(PyZoneInfo_ZoneInfo *self)
776
773
* Objects constructed from ZoneInfo.from_file cannot be pickled.
777
774
*/
778
775
static PyObject *
779
- zoneinfo_reduce (PyObject * obj_self , PyObject * unused )
776
+ zoneinfo_reduce (PyObject * obj_self , PyObject * Py_UNUSED ( dummy ) )
780
777
{
781
- PyZoneInfo_ZoneInfo * self = ( PyZoneInfo_ZoneInfo * ) obj_self ;
778
+ PyZoneInfo_ZoneInfo * self = PyZoneInfo_ZoneInfo_CAST ( obj_self ) ;
782
779
if (self -> source == SOURCE_FILE ) {
783
780
// Objects constructed from files cannot be pickled.
784
781
PyObject * pickle_error =
0 commit comments