summaryrefslogtreecommitdiff
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-04-17 23:02:26 +0200
committerGitHub <noreply@github.com>2019-04-17 23:02:26 +0200
commit5c75f37d473140f0e0b7d9bf3a8c08343447ded1 (patch)
tree9c2ce8ff92bf17d73dfe14c7d7027a36693b590d /Include
parent3092d6b2630e4d2bd200fbc3231c27a7cba4d6b2 (diff)
downloadcpython-git-5c75f37d473140f0e0b7d9bf3a8c08343447ded1.tar.gz
bpo-36635: Change pyport.h for Py_BUILD_CORE_MODULE define (GH-12853)
Change PyAPI_FUNC(type), PyAPI_DATA(type) and PyMODINIT_FUNC macros of pyport.h when Py_BUILD_CORE_MODULE is defined. The Py_BUILD_CORE_MODULE define must be now be used to build a C extension as a dynamic library accessing Python internals: export the PyInit_xxx() function in DLL exports on Windows. Changes: * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE now imply Py_BUILD_CORE directy in pyport.h. * ceval.c compilation now fails with an error if Py_BUILD_CORE is not defined, just to ensure that Python is build with the correct defines. * setup.py now compiles _pickle.c with Py_BUILD_CORE_MODULE define. * setup.py compiles _json.c with Py_BUILD_CORE_MODULE define, rather than Py_BUILD_CORE_BUILTIN define * PCbuild/pythoncore.vcxproj: Add Py_BUILD_CORE_BUILTIN define.
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_accu.h4
-rw-r--r--Include/internal/pycore_atomic.h4
-rw-r--r--Include/internal/pycore_ceval.h4
-rw-r--r--Include/internal/pycore_condvar.h4
-rw-r--r--Include/internal/pycore_context.h4
-rw-r--r--Include/internal/pycore_coreconfig.h4
-rw-r--r--Include/internal/pycore_getopt.h4
-rw-r--r--Include/internal/pycore_gil.h4
-rw-r--r--Include/internal/pycore_hamt.h4
-rw-r--r--Include/internal/pycore_object.h4
-rw-r--r--Include/internal/pycore_pathconfig.h4
-rw-r--r--Include/internal/pycore_pyhash.h4
-rw-r--r--Include/internal/pycore_pylifecycle.h4
-rw-r--r--Include/internal/pycore_pymem.h4
-rw-r--r--Include/internal/pycore_pystate.h4
-rw-r--r--Include/internal/pycore_tupleobject.h4
-rw-r--r--Include/internal/pycore_warnings.h4
-rw-r--r--Include/pyport.h25
18 files changed, 57 insertions, 36 deletions
diff --git a/Include/internal/pycore_accu.h b/Include/internal/pycore_accu.h
index 4350db58a2..d346222e4d 100644
--- a/Include/internal/pycore_accu.h
+++ b/Include/internal/pycore_accu.h
@@ -9,8 +9,8 @@ extern "C" {
*** Its definition may be changed or removed at any moment.
***/
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
/*
diff --git a/Include/internal/pycore_atomic.h b/Include/internal/pycore_atomic.h
index 7aa7eed6f7..b3ec44c1bc 100644
--- a/Include/internal/pycore_atomic.h
+++ b/Include/internal/pycore_atomic.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "dynamic_annotations.h"
diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h
index 2ead96c7ab..0bb19f1aa3 100644
--- a/Include/internal/pycore_ceval.h
+++ b/Include/internal/pycore_ceval.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_atomic.h"
diff --git a/Include/internal/pycore_condvar.h b/Include/internal/pycore_condvar.h
index a12b6994ad..8b89d70951 100644
--- a/Include/internal/pycore_condvar.h
+++ b/Include/internal/pycore_condvar.h
@@ -1,8 +1,8 @@
#ifndef Py_INTERNAL_CONDVAR_H
#define Py_INTERNAL_CONDVAR_H
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#ifndef _POSIX_THREADS
diff --git a/Include/internal/pycore_context.h b/Include/internal/pycore_context.h
index 70701cdd11..5e1ba0d039 100644
--- a/Include/internal/pycore_context.h
+++ b/Include/internal/pycore_context.h
@@ -1,8 +1,8 @@
#ifndef Py_INTERNAL_CONTEXT_H
#define Py_INTERNAL_CONTEXT_H
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_hamt.h"
diff --git a/Include/internal/pycore_coreconfig.h b/Include/internal/pycore_coreconfig.h
index 3a27628aa7..3353844204 100644
--- a/Include/internal/pycore_coreconfig.h
+++ b/Include/internal/pycore_coreconfig.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
diff --git a/Include/internal/pycore_getopt.h b/Include/internal/pycore_getopt.h
index 0d1897c75a..834b8c8a14 100644
--- a/Include/internal/pycore_getopt.h
+++ b/Include/internal/pycore_getopt.h
@@ -1,8 +1,8 @@
#ifndef Py_INTERNAL_PYGETOPT_H
#define Py_INTERNAL_PYGETOPT_H
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
extern int _PyOS_opterr;
diff --git a/Include/internal/pycore_gil.h b/Include/internal/pycore_gil.h
index 014e75fd18..7de316397b 100644
--- a/Include/internal/pycore_gil.h
+++ b/Include/internal/pycore_gil.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_condvar.h"
diff --git a/Include/internal/pycore_hamt.h b/Include/internal/pycore_hamt.h
index 8b2ce1fc96..e65aef5e21 100644
--- a/Include/internal/pycore_hamt.h
+++ b/Include/internal/pycore_hamt.h
@@ -1,8 +1,8 @@
#ifndef Py_INTERNAL_HAMT_H
#define Py_INTERNAL_HAMT_H
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#define _Py_HAMT_MAX_TREE_DEPTH 7
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index c95595358a..81548f8191 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_pystate.h" /* _PyRuntime */
diff --git a/Include/internal/pycore_pathconfig.h b/Include/internal/pycore_pathconfig.h
index 80d86a0dd1..9eb8e88df7 100644
--- a/Include/internal/pycore_pathconfig.h
+++ b/Include/internal/pycore_pathconfig.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
typedef struct _PyPathConfig {
diff --git a/Include/internal/pycore_pyhash.h b/Include/internal/pycore_pyhash.h
index babbc95b87..a229f8d8b7 100644
--- a/Include/internal/pycore_pyhash.h
+++ b/Include/internal/pycore_pyhash.h
@@ -1,8 +1,8 @@
#ifndef Py_INTERNAL_HASH_H
#define Py_INTERNAL_HASH_H
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
uint64_t _Py_KeyedHash(uint64_t, const char *, Py_ssize_t);
diff --git a/Include/internal/pycore_pylifecycle.h b/Include/internal/pycore_pylifecycle.h
index d837ea4fb3..bfff24b80a 100644
--- a/Include/internal/pycore_pylifecycle.h
+++ b/Include/internal/pycore_pylifecycle.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
/* True if the main interpreter thread exited due to an unhandled
diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h
index 8da1bd9e30..20f3b5e400 100644
--- a/Include/internal/pycore_pymem.h
+++ b/Include/internal/pycore_pymem.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "objimpl.h"
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index df3730f801..e1ce08d335 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "cpython/coreconfig.h"
diff --git a/Include/internal/pycore_tupleobject.h b/Include/internal/pycore_tupleobject.h
index d0c5b620d3..9fcfc5c6ec 100644
--- a/Include/internal/pycore_tupleobject.h
+++ b/Include/internal/pycore_tupleobject.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "tupleobject.h"
diff --git a/Include/internal/pycore_warnings.h b/Include/internal/pycore_warnings.h
index 91bf90232f..73e5350aff 100644
--- a/Include/internal/pycore_warnings.h
+++ b/Include/internal/pycore_warnings.h
@@ -4,8 +4,8 @@
extern "C" {
#endif
-#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
-# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
#endif
#include "object.h"
diff --git a/Include/pyport.h b/Include/pyport.h
index 4971a493cc..075b36028b 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -5,6 +5,27 @@
#include <inttypes.h>
+
+/* Defines to build Python and its standard library:
+ *
+ * - Py_BUILD_CORE: Build Python core. Give access to Python internals, but
+ * should not be used by third-party modules.
+ * - Py_BUILD_CORE_BUILTIN: Build a Python stdlib module as a built-in module.
+ * - Py_BUILD_CORE_MODULE: Build a Python stdlib module as a dynamic library.
+ *
+ * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE imply Py_BUILD_CORE.
+ *
+ * On Windows, Py_BUILD_CORE_MODULE exports "PyInit_xxx" symbol, whereas
+ * Py_BUILD_CORE_BUILTIN does not.
+ */
+#if defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE)
+# define Py_BUILD_CORE
+#endif
+#if defined(Py_BUILD_CORE_MODULE) && !defined(Py_BUILD_CORE)
+# define Py_BUILD_CORE
+#endif
+
+
/**************************************************************************
Symbols and macros to supply platform-independent interfaces to basic
C language & library operations whose spellings vary across platforms.
@@ -623,7 +644,7 @@ extern char * _getpty(int *, int, mode_t, int);
/* only get special linkage if built as shared or platform is Cygwin */
#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
# if defined(HAVE_DECLSPEC_DLL)
-# if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_BUILTIN)
+# if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
/* module init functions inside the core need no external linkage */
@@ -755,7 +776,7 @@ extern char * _getpty(int *, int, mode_t, int);
#define PY_LITTLE_ENDIAN 1
#endif
-#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_BUILTIN)
+#ifdef Py_BUILD_CORE
/*
* Macros to protect CRT calls against instant termination when passed an
* invalid parameter (issue23524).