8000 gh-117398: datetime: Use wrappers for C-API functions by neonene · Pull Request #118115 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117398: datetime: Use wrappers for C-API functions #118115

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
wants to merge 9 commits into from
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
43 changes: 37 additions & 6 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,24 @@ new_datetime_ex(int year, int month, int day, int hour, int minute,
tzinfo, 0, type);
}

static PyObject *
new_datetime_ex_capi(int year, int month, int day, int hour, int minute,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that "_ex" is useful. Just rename it to "new_datetime_capi", no? Same remark for other functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion includes non-capi functions?

int second, int usecond, PyObject *tzinfo,
PyTypeObject *type)
{
return new_datetime_ex(year, month, day, hour, minute, second,
usecond, tzinfo, type);
}

static PyObject *
new_datetime_ex2_capi(int year, int month, int day, int hour, int minute,
int second, int usecond, PyObject *tzinfo, int fold,
PyTypeObject *type)
{
return new_datetime_ex2(year, month, day, hour, minute, second,
usecond, tzinfo, fold, type);
}

#define new_datetime(y, m, d, hh, mm, ss, us, tzinfo, fold) \
new_datetime_ex2(y, m, d, hh, mm, ss, us, tzinfo, fold, \
&PyDateTime_DateTimeType)
Expand Down Expand Up @@ -1145,12 +1163,19 @@ new_time_ex2(int hour, int minute, int second, int usecond,
}

static PyObject *
new_time_ex(int hour, int minute, int second, int usecond,
new_time_ex_capi(int hour, int minute, int second, int usecond,
PyObject *tzinfo, PyTypeObject *type)
{
return new_time_ex2(hour, minute, second, usecond, tzinfo, 0, type);
}

static PyObject *
new_time_ex2_capi(int hour, int minute, int second, int usecond,
PyObject *tzinfo, int fold, PyTypeObject *type)
{
return new_time_ex2(hour, minute, second, usecond, tzinfo, fold, type);
}

#define new_time(hh, mm, ss, us, tzinfo, fold) \
new_time_ex2(hh, mm, ss, us, tzinfo, fold, &PyDateTime_TimeType)

Expand Down Expand Up @@ -1263,6 +1288,12 @@ new_timezone(PyObject *offset, PyObject *name)
return create_timezone(offset, name);
}

static PyObject *
new_timezone_capi(PyObject *offset, PyObject *name)
{
return new_timezone(offset, name);
}

/* ---------------------------------------------------------------------------
* tzinfo helpers.
*/
Expand Down Expand Up @@ -6723,14 +6754,14 @@ get_datetime_capi(void)
capi->DeltaType = &PyDateTime_DeltaType;
capi->TZInfoType = &PyDateTime_TZInfoType;
capi->Date_FromDate = new_date_ex;
capi->DateTime_FromDateAndTime = new_datetime_ex;
capi->Time_FromTime = new_time_ex;
capi->DateTime_FromDateAndTime = new_datetime_ex_capi;
capi->Time_FromTime = new_time_ex_capi;
capi->Delta_FromDelta = new_delta_ex;
capi->TimeZone_FromTimeZone = new_timezone;
capi->TimeZone_FromTimeZone = new_timezone_capi;
capi->DateTime_FromTimestamp = datetime_fromtimestamp;
capi->Date_FromTimestamp = datetime_date_fromtimestamp_capi;
capi->DateTime_FromDateAndTimeAndFold = new_datetime_ex2;
capi->Time_FromTimeAndFold = new_time_ex2;
capi->DateTime_FromDateAndTimeAndFold = new_datetime_ex2_capi;
capi->Time_FromTimeAndFold = new_time_ex2_capi;
// Make sure this function is called after utc has
// been initialized.
datetime_state *st = STATIC_STATE();
Expand Down
0