Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-117398: Add datetime Module State #119640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add module state.
  • Loading branch information
ericsnowcurrently committed May 28, 2024
commit 330a9a704e518713bbc87ccee927ba8ffaf3c389
15 changes: 14 additions & 1 deletion 15 Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ static inline datetime_state* get_datetime_state(void)
return &_datetime_global_state;
}

static datetime_state *
get_module_state(PyObject *module)
{
void *state = _PyModule_GetState(module);
assert(state != NULL);
return (datetime_state *)state;
}

#define PyDate_Check(st, op) PyObject_TypeCheck(op, st->date_type)
#define PyDate_CheckExact(st, op) Py_IS_TYPE(op, st->date_type)

Expand Down Expand Up @@ -7070,6 +7078,11 @@ _datetime_exec(PyObject *module)
goto error;
}

st = get_module_state(module);
if (init_state(st, PyDateTime_IsoCalendarDateType) < 0) {
goto error;
}

#define DATETIME_ADD_MACRO(dict, c, value_expr) \
do { \
PyObject *value = (value_expr); \
Expand Down Expand Up @@ -7191,7 +7204,7 @@ static PyModuleDef datetimemodule = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_datetime",
.m_doc = "Fast implementation of the datetime type.",
.m_size = 0,
.m_size = sizeof(datetime_state),
.m_methods = module_methods,
.m_slots = module_slots,
};
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.