summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Ganssle <pganssle@users.noreply.github.com>2018-11-13 08:02:25 (GMT)
committerVictor Stinner <vstinner@redhat.com>2018-11-13 08:02:25 (GMT)
commit0d12672b30b8c6c992bef7564581117ae83e11ad (patch)
treed2b7a03d5264c1d4cf3b5f786ca15ef9fb1cad44
parent3015fb8ce4d25603434b9b44bb7effb98a481532 (diff)
downloadcpython-0d12672b30b8c6c992bef7564581117ae83e11ad.zip
cpython-0d12672b30b8c6c992bef7564581117ae83e11ad.tar.gz
cpython-0d12672b30b8c6c992bef7564581117ae83e11ad.tar.bz2
bpo-35081: Remove Py_BUILD_CORE from datetime.h (GH-10416)
Datetime macros like PyDate_Check() have two implementations, one using the C API capsule and one using direct access to the datetime type symbols defined in _datetimemodule.c. Since the direct access versions of the macros are only used in _datetimemodule.c, they have been moved out of "datetime.h" and into _datetimemodule.c. The _PY_DATETIME_IMPL macro is currently necessary in order to avoid both duplicate definitions of these macros in _datetimemodule.c and unnecessary declarations of C API capsule-related macros and varibles in datetime.h. Co-Authored-By: Victor Stinner <vstinner@redhat.com>
-rw-r--r--Include/datetime.h28
-rw-r--r--Modules/_datetimemodule.c29
2 files changed, 28 insertions, 29 deletions
diff --git a/Include/datetime.h b/Include/datetime.h
index 059d5ec..00507cb 100644
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -180,26 +180,11 @@ 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
-
+/* This block is only used as part of the public API and should not be
+ * included in _datetimemodule.c, which does not use the C API capsule.
+ * See bpo-35081 for more details.
+ * */
+#ifndef _PY_DATETIME_IMPL
/* Define global variable for the C API and a macro for setting it. */
static PyDateTime_CAPI *PyDateTimeAPI = NULL;
@@ -225,6 +210,7 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType)
+
/* Macros for accessing constructors in a simplified fashion. */
#define PyDate_FromDate(year, month, day) \
PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
@@ -264,7 +250,7 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
PyDateTimeAPI->Date_FromTimestamp( \
(PyObject*) (PyDateTimeAPI->DateType), args)
-#endif /* Py_BUILD_CORE */
+#endif /* !defined(_PY_DATETIME_IMPL) */
#ifdef __cplusplus
}
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 2db95b4..02c510f 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -2,7 +2,13 @@
* http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage
*/
+/* bpo-35081: Defining this prevents including the C API capsule;
+ * internal versions of the Py*_Check macros which do not require
+ * the capsule are defined below */
+#define _PY_DATETIME_IMPL
+
#include "Python.h"
+#include "datetime.h"
#include "structmember.h"
#include <time.h>
@@ -11,14 +17,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
+#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