[Python-checkins] bpo-36641: Add "const" to PyDoc_VAR macro (GH-12854)

Inada Naoki webhook-mailer at python.org
Tue Apr 16 19:39:59 EDT 2019


https://github.com/python/cpython/commit/926b0cb5f688808dc11448a0bf3e452d1b92c232
commit: 926b0cb5f688808dc11448a0bf3e452d1b92c232
branch: master
author: Inada Naoki <songofacandy at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-04-17T08:39:46+09:00
summary:

bpo-36641: Add "const" to PyDoc_VAR macro (GH-12854)

It reduces "data" segment in python about 200KB.

files:
A Misc/NEWS.d/next/C API/2019-04-16-21-18-19.bpo-36641.pz-DIR.rst
M Include/pymacro.h
M Modules/_ssl.c

diff --git a/Include/pymacro.h b/Include/pymacro.h
index 3f6ddbe9977a..546f9c6e7020 100644
--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -67,7 +67,7 @@
 
 
 /* Define macros for inline documentation. */
-#define PyDoc_VAR(name) static char name[]
+#define PyDoc_VAR(name) static const char name[]
 #define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
 #ifdef WITH_DOC_STRINGS
 #define PyDoc_STR(str) str
diff --git a/Misc/NEWS.d/next/C API/2019-04-16-21-18-19.bpo-36641.pz-DIR.rst b/Misc/NEWS.d/next/C API/2019-04-16-21-18-19.bpo-36641.pz-DIR.rst
new file mode 100644
index 000000000000..f92af63029be
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2019-04-16-21-18-19.bpo-36641.pz-DIR.rst	
@@ -0,0 +1,2 @@
+:c:macro:`PyDoc_VAR(name)` and :c:macro:`PyDoc_STRVAR(name,str)` now create
+``static const char name[]`` instead of ``static char name[]``.  Patch by Inada Naoki.
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index f8ae916735f4..e75e3466dd3f 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -557,7 +557,7 @@ SSLError_str(PyOSErrorObject *self)
 
 static PyType_Slot sslerror_type_slots[] = {
     {Py_tp_base, NULL},  /* Filled out in module init as it's not a constant */
-    {Py_tp_doc, SSLError_doc},
+    {Py_tp_doc, (void*)SSLError_doc},
     {Py_tp_str, SSLError_str},
     {0, 0},
 };



More information about the Python-checkins mailing list