-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
bpo-35081: Remove Py_BUILD_CORE from datetime.h #10238
Changes from all commits
2f7832f
1858252
22abaee
8a11d06
a2750c6
69a455d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,26 +180,9 @@ typedef struct { | |
#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI" | ||
|
||
|
||
#ifdef Py_BUILD_CORE | ||
|
||
/* Macros for type checking when building the Python core. */ | ||
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType) | ||
#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType) | ||
|
||
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType) | ||
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateTimeType) | ||
|
||
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType) | ||
#define PyTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TimeType) | ||
|
||
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType) | ||
#define PyDelta_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DeltaType) | ||
|
||
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType) | ||
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType) | ||
|
||
#else | ||
|
||
/* When datetime.h is included from _datetimemodule.c, | ||
the macros are defined in _datetimemodule.c. */ | ||
#ifndef _PY_DATETIME_IMPL | ||
/* Define global variable for the C API and a macro for setting it. */ | ||
static PyDateTime_CAPI *PyDateTimeAPI = NULL; | ||
|
||
|
@@ -224,6 +207,8 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL; | |
|
||
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why these macros are defined for non-core C API at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what you mean, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand. In which case PyDate_Check() is not defined when you include datetime.h? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry, I was confused by changes in this PR. Now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _PY_DATETIME_IMPL is only used when datetime.h is included from _datetimemodule.c. In this case, PyDate_Check() and PyTZInfo_Check() are defined in _datetimemodule.c. Previously, I always defined these macros, and then used #undef in _datetimemodule.c. But this approach doesn't work if tomorrow these macros are converted to static inline functions. @serhiy-storchaka: do you prefer the #undef approach, and only exclude "static PyDateTime_CAPI *PyDateTimeAPI = NULL;" using _PY_DATETIME_IMPL? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before Victor's PR, all of these macros are defined here, twice - they have different definitions when built as part of CPython than when built as part of an extension module. The reason they are different is that the datetime module exposes all of its functionality via a capsule ( Victor's PR takes the "CPython only" builds and moves them out of There's probably a case to be made in favor of dropping the macros defined in I think Victor's current proposed changes are an improvement over the current state of things and unless we missed something, should have no change in behavior for end users while making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, hopefully I understood your comment correctly. If you meant that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add that currently, including datetime.h in a C file which defines Py_BUILD_CORE doesn't work, since it uses types which are only exported by an external library... (_datetime is compared as a shared library by default on Linux) |
||
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType) | ||
#endif /* !defined(_PY_DATETIME_IMPL) */ | ||
|
||
|
||
/* Macros for accessing constructors in a simplified fashion. */ | ||
#define PyDate_FromDate(year, month, day) \ | ||
|
@@ -264,8 +249,6 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL; | |
PyDateTimeAPI->Date_FromTimestamp( \ | ||
(PyObject*) (PyDateTimeAPI->DateType), args) | ||
|
||
#endif /* Py_BUILD_CORE */ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,12 @@ | |
* http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage | ||
*/ | ||
|
||
/* When datetime.h is included from _datetimemodule.c, | ||
the macros are defines in _datetimemodule.c. */ | ||
#define _PY_DATETIME_IMPL | ||
|
||
#include "Python.h" | ||
#include "datetime.h" | ||
#include "structmember.h" | ||
|
||
#include <time.h> | ||
|
@@ -11,14 +16,21 @@ | |
# include <winsock2.h> /* struct timeval */ | ||
#endif | ||
|
||
/* Differentiate between building the core module and building extension | ||
* modules. | ||
*/ | ||
#ifndef Py_BUILD_CORE | ||
#define Py_BUILD_CORE | ||
#endif | ||
#include "datetime.h" | ||
#undef Py_BUILD_CORE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes no difference in this case, but it's somewhat interesting that in the old version, I think this means that if |
||
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType) | ||
#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType) | ||
|
||
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType) | ||
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateTimeType) | ||
|
||
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType) | ||
#define PyTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TimeType) | ||
|
||
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType) | ||
#define PyDelta_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DeltaType) | ||
|
||
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType) | ||
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType) | ||
|
||
|
||
/*[clinic input] | ||
module datetime | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable will be created in every compilation unit that includes "datetime.h".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was that already a problem for the C API? this was a pre-existing part of the public API.
At the moment, within CPython, this is only included in
_datetimemodule.c
and_testcapimodule.c
. The latter was, according to Victor, already being compiled withoutPy_BUILD_CORE
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it's a little bit strange to use static here. But my PR doesn't change that, and I don't see how to change the API to avoid it.
@serhiy-storchaka: Would you mind to open a new issue to track this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vstinner I think your PR does change one thing, which is that this static variable is now created even when
Py_BUILD_CORE
is on, right? I don't think that there are any major negative consequences, though, and I don't see a way around it without either changing the public interface or re-introducingPy_BUILD_CORE
to this file, which I gather was the aim of this PR.