@@ -6968,8 +6968,9 @@ create_timezone_from_delta(int days, int sec, int ms, int normalize)
6968
6968
}
6969
6969
6970
6970
static int
6971
- init_heap_types (datetime_state * st , PyObject * module )
6971
+ init_state (datetime_state * st , PyObject * module , PyObject * old_module )
6972
6972
{
6973
+ /* Each module gets its own heap types. */
6973
6974
#define ADD_TYPE (FIELD , SPEC , BASE ) \
6974
6975
do { \
6975
6976
PyObject *cls = PyType_FromModuleAndSpec( \
@@ -6983,14 +6984,22 @@ init_heap_types(datetime_state *st, PyObject *module)
6983
6984
ADD_TYPE (isocalendar_date_type , & isocal_spec , & PyTuple_Type );
6984
6985
#undef ADD_TYPE
6985
6986
6986
- return 0 ;
6987
- }
6988
-
6989
- static int
6990
- init_state (datetime_state * st )
6991
- {
6992
- /* st->isocalendar_date_type was set via init_heap_types(). */
6993
- assert (st -> isocalendar_date_type != NULL );
6987
+ if (old_module != NULL ) {
6988
+ assert (old_module != module );
6989
+ datetime_state * st_old = get_module_state (old_module );
6990
+ * st = (datetime_state ){
6991
+ .isocalendar_date_type = st -> isocalendar_date_type ,
6992
+ .us_per_ms = Py_NewRef (st_old -> us_per_ms ),
6993
+ .us_per_second = Py_NewRef (st_old -> us_per_second ),
6994
+ .us_per_minute = Py_NewRef (st_old -> us_per_minute ),
6995
+ .us_per_hour = Py_NewRef (st_old -> us_per_hour ),
6996
+ .us_per_day = Py_NewRef (st_old -> us_per_day ),
6997
+ .us_per_week = Py_NewRef (st_old -> us_per_week ),
6998
+ .seconds_per_day = Py_NewRef (st_old -> seconds_per_day ),
6999
+ .epoch = Py_NewRef (st_old -> epoch ),
7000
+ };
7001
+ return 0 ;
7002
+ }
6994
7003
6995
7004
st -> us_per_ms = PyLong_FromLong (1000 );
6996
7005
if (st -> us_per_ms == NULL ) {
@@ -7035,28 +7044,6 @@ init_state(datetime_state *st)
7035
7044
return 0 ;
7036
7045
}
7037
7046
7038
- static int
7039
- copy_state (datetime_state * st , datetime_state * from )
7040
- {
7041
- /* isocalendar_date_type is set via init_heap_types(). */
7042
- assert (st -> isocalendar_date_type != NULL );
7043
- assert (st -> isocalendar_date_type != from -> isocalendar_date_type );
7044
-
7045
- * st = (datetime_state ){
7046
- .isocalendar_date_type = st -> isocalendar_date_type ,
7047
- .us_per_ms = Py_NewRef (from -> us_per_ms ),
7048
- .us_per_second = Py_NewRef (from -> us_per_second ),
7049
- .us_per_minute = Py_NewRef (from -> us_per_minute ),
7050
- .us_per_hour = Py_NewRef (from -> us_per_hour ),
7051
- .us_per_day = Py_NewRef (from -> us_per_day ),
7052
- .us_per_week = Py_NewRef (from -> us_per_week ),
7053
- .seconds_per_day = Py_NewRef (from -> seconds_per_day ),
7054
- .epoch = Py_NewRef (from -> epoch ),
7055
- };
7056
-
7057
- return 0 ;
7058
- }
7059
-
7060
7047
static int
7061
7048
traverse_state (datetime_state * st , visitproc visit , void * arg )
7062
7049
{
@@ -7117,22 +7104,10 @@ _datetime_exec(PyObject *module)
7117
7104
}
7118
7105
}
7119
7106
7120
- if (init_heap_types (st , module ) < 0 ) {
7107
+ if (init_state (st , module , old_module ) < 0 ) {
7121
7108
goto error ;
7122
7109
}
7123
7110
7124
- if (old_module != NULL ) {
7125
- datetime_state * st_old = get_module_state (old_module );
7126
- if (copy_state (st , st_old ) < 0 ) {
7127
- goto error ;
7128
- }
7129
- }
7130
- else {
7131
- if (init_state (st ) < 0 ) {
7132
- goto error ;
7133
- }
7134
- }
7135
-
7136
7111
/* For now we only set the objects on the static types once.
7137
7112
* We will relax that once each types __dict__ is per-interpreter. */
7138
7113
#define DATETIME_ADD_MACRO (dict , c , value_expr ) \
0 commit comments