Skip to content

Commit 77d117c

Browse files
committed
Load _datetime during interpreter initialization
1 parent 5a20e79 commit 77d117c

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

Include/internal/pycore_pylifecycle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern PyStatus _Py_HashRandomization_Init(const PyConfig *);
4141

4242
extern PyStatus _PyGC_Init(PyInterpreterState *interp);
4343
extern PyStatus _PyAtExit_Init(PyInterpreterState *interp);
44+
extern PyStatus _PyDateTime_Init(PyInterpreterState *interp);
4445

4546
/* Various internal finalizers */
4647

Modules/Setup.bootstrap.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ posix posixmodule.c
1212
_signal signalmodule.c
1313
_tracemalloc _tracemalloc.c
1414
_suggestions _suggestions.c
15+
# needs libm and on some platforms librt
16+
_datetime _datetimemodule.c
1517

1618
# modules used by importlib, deepfreeze, freeze, runpy, and sysconfig
1719
_codecs _codecsmodule.c

Modules/Setup.stdlib.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@
5656
@MODULE_CMATH_TRUE@cmath cmathmodule.c
5757
@MODULE__STATISTICS_TRUE@_statistics _statisticsmodule.c
5858

59-
# needs libm and on some platforms librt
60-
@MODULE__DATETIME_TRUE@_datetime _datetimemodule.c
61-
6259
# _decimal uses libmpdec
6360
# either static libmpdec.a from Modules/_decimal/libmpdec or libmpdec.so
6461
# with ./configure --with-system-libmpdec

Modules/_datetimemodule.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "pycore_object.h" // _PyObject_Init()
1515
#include "pycore_time.h" // _PyTime_ObjectToTime_t()
1616
#include "pycore_unicodeobject.h" // _PyUnicode_Copy()
17+
#include "pycore_initconfig.h" // _PyStatus_OK()
1718

1819
#include "datetime.h"
1920

@@ -7329,13 +7330,9 @@ clear_state(datetime_state *st)
73297330
}
73307331

73317332

7332-
static int
7333-
init_static_types(PyInterpreterState *interp, int reloading)
7333+
PyStatus
7334+
_PyDateTime_Init(PyInterpreterState *interp)
73347335
{
7335-
if (reloading) {
7336-
return 0;
7337-
}
7338-
73397336
// `&...` is not a constant expression according to a strict reading
73407337
// of C standards. Fill tp_base at run-time rather than statically.
73417338
// See https://bugs.python.org/issue40777
@@ -7347,11 +7344,11 @@ init_static_types(PyInterpreterState *interp, int reloading)
73477344
for (size_t i = 0; i < Py_ARRAY_LENGTH(capi_types); i++) {
73487345
PyTypeObject *type = capi_types[i];
73497346
if (_PyStaticType_InitForExtension(interp, type) < 0) {
7350-
return -1;
7347+
return _PyStatus_ERR("could not initialize static types");
73517348
}
73527349
}
73537350

7354-
return 0;
7351+
return _PyStatus_OK();
73557352
}
73567353

73577354

@@ -7379,10 +7376,6 @@ _datetime_exec(PyObject *module)
73797376
}
73807377
/* We actually set the "current" module right before a successful return. */
73817378

7382-
if (init_static_types(interp, reloading) < 0) {
7383-
goto error;
7384-
}
7385-
73867379
for (size_t i = 0; i < Py_ARRAY_LENGTH(capi_types); i++) {
73877380
PyTypeObject *type = capi_types[i];
73887381
const char *name = _PyType_Name(type);

Python/pylifecycle.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,11 @@ pycore_interp_init(PyThreadState *tstate)
915915
goto done;
916916
}
917917

918+
status = _PyDateTime_Init(tstate->interp);
919+
if (_PyStatus_EXCEPTION(status)) {
920+
goto done;
921+
}
922+
918923
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
919924

920925
status = _PyImport_InitCore(tstate, sysmod, config->_install_importlib);

0 commit comments

Comments
 (0)