Skip to content

Commit a3fb4f7

Browse files
committed
Patch #505375: Make doc strings optional.
1 parent ec5d6b9 commit a3fb4f7

6 files changed

Lines changed: 111 additions & 31 deletions

File tree

‎Include/Python.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,14 @@
146146
/* GNU pth user-space thread support */
147147
#include <pth.h>
148148
#endif
149+
150+
/* Define macros for inline documentation. */
151+
#define PyDoc_VAR(name) static char name[]
152+
#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
153+
#ifdef WITH_DOC_STRINGS
154+
#define PyDoc_STR(str) str
155+
#else
156+
#define PyDoc_STR(str) ""
157+
#endif
158+
149159
#endif /* !Py_PYTHON_H */

‎Misc/NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ Tools/Demos
240240

241241
Build
242242

243+
- The configure option --without-doc-strings can be used to remove the
244+
doc strings from the builtin functions and modules; this reduces the
245+
size of the executable.
246+
243247
- XXX WITH_UNIVERSAL_NEWLINES Somebody fill this in; the PEP doesn't
244248
say how or when to configure it, or how to turn it off.
245249

‎Python/sysmodule.c‎

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ sys_displayhook(PyObject *self, PyObject *o)
103103
return Py_None;
104104
}
105105

106-
static char displayhook_doc[] =
106+
PyDoc_STRVAR(displayhook_doc,
107107
"displayhook(object) -> None\n"
108108
"\n"
109-
"Print an object to sys.stdout and also save it in __builtin__._\n";
109+
"Print an object to sys.stdout and also save it in __builtin__._\n"
110+
);
110111

111112
static PyObject *
112113
sys_excepthook(PyObject* self, PyObject* args)
@@ -119,10 +120,11 @@ sys_excepthook(PyObject* self, PyObject* args)
119120
return Py_None;
120121
}
121122

122-
static char excepthook_doc[] =
123+
PyDoc_STRVAR(excepthook_doc,
123124
"excepthook(exctype, value, traceback) -> None\n"
124125
"\n"
125-
"Handle an exception by displaying it with a traceback on sys.stderr.\n";
126+
"Handle an exception by displaying it with a traceback on sys.stderr.\n"
127+
);
126128

127129
static PyObject *
128130
sys_exc_info(PyObject *self)
@@ -137,11 +139,12 @@ sys_exc_info(PyObject *self)
137139
tstate->exc_traceback : Py_None);
138140
}
139141

140-
static char exc_info_doc[] =
142+
PyDoc_STRVAR(exc_info_doc,
141143
"exc_info() -> (type, value, traceback)\n\
142144
\n\
143145
Return information about the exception that is currently being handled.\n\
144-
This should be called from inside an except clause only.";
146+
This should be called from inside an except clause only."
147+
);
145148

146149
static PyObject *
147150
sys_exit(PyObject *self, PyObject *args)
@@ -154,14 +157,15 @@ sys_exit(PyObject *self, PyObject *args)
154157
return NULL;
155158
}
156159

157-
static char exit_doc[] =
160+
PyDoc_STRVAR(exit_doc,
158161
"exit([status])\n\
159162
\n\
160163
Exit the interpreter by raising SystemExit(status).\n\
161164
If the status is omitted or None, it defaults to zero (i.e., success).\n\
162165
If the status is numeric, it will be used as the system exit status.\n\
163166
If it is another kind of object, it will be printed and the system\n\
164-
exit status will be one (i.e., failure).";
167+
exit status will be one (i.e., failure)."
168+
);
165169

166170
#ifdef Py_USING_UNICODE
167171

@@ -171,11 +175,12 @@ sys_getdefaultencoding(PyObject *self)
171175
return PyString_FromString(PyUnicode_GetDefaultEncoding());
172176
}
173177

174-
static char getdefaultencoding_doc[] =
178+
PyDoc_STRVAR(getdefaultencoding_doc,
175179
"getdefaultencoding() -> string\n\
176180
\n\
177181
Return the current default string encoding used by the Unicode \n\
178-
implementation.";
182+
implementation."
183+
);
179184

180185
static PyObject *
181186
sys_setdefaultencoding(PyObject *self, PyObject *args)
@@ -189,10 +194,11 @@ sys_setdefaultencoding(PyObject *self, PyObject *args)
189194
return Py_None;
190195
}
191196

192-
static char setdefaultencoding_doc[] =
197+
PyDoc_STRVAR(setdefaultencoding_doc,
193198
"setdefaultencoding(encoding)\n\
194199
\n\
195-
Set the current default string encoding used by the Unicode implementation.";
200+
Set the current default string encoding used by the Unicode implementation."
201+
);
196202

197203
#endif
198204

@@ -316,11 +322,12 @@ sys_settrace(PyObject *self, PyObject *args)
316322
return Py_None;
317323
}
318324

319-
static char settrace_doc[] =
325+
PyDoc_STRVAR(settrace_doc,
320326
"settrace(function)\n\
321327
\n\
322328
Set the global debug tracing function. It will be called on each\n\
323-
function call. See the debugger chapter in the library manual.";
329+
function call. See the debugger chapter in the library manual."
330+
);
324331

325332
static PyObject *
326333
sys_setprofile(PyObject *self, PyObject *args)
@@ -335,11 +342,12 @@ sys_setprofile(PyObject *self, PyObject *args)
335342
return Py_None;
336343
}
337344

338-
static char setprofile_doc[] =
345+
PyDoc_STRVAR(setprofile_doc,
339346
"setprofile(function)\n\
340347
\n\
341348
Set the profiling function. It will be called on each function call\n\
342-
and return. See the profiler chapter in the library manual.";
349+
and return. See the profiler chapter in the library manual."
350+
);
343351

344352
static PyObject *
345353
sys_setcheckinterval(PyObject *self, PyObject *args)
@@ -351,11 +359,12 @@ sys_setcheckinterval(PyObject *self, PyObject *args)
351359
return Py_None;
352360
}
353361

354-
static char setcheckinterval_doc[] =
362+
PyDoc_STRVAR(setcheckinterval_doc,
355363
"setcheckinterval(n)\n\
356364
\n\
357365
Tell the Python interpreter to check for asynchronous events every\n\
358-
n instructions. This also affects how often thread switches occur.";
366+
n instructions. This also affects how often thread switches occur."
367+
);
359368

360369
static PyObject *
361370
sys_setrecursionlimit(PyObject *self, PyObject *args)
@@ -373,26 +382,28 @@ sys_setrecursionlimit(PyObject *self, PyObject *args)
373382
return Py_None;
374383
}
375384

376-
static char setrecursionlimit_doc[] =
385+
PyDoc_STRVAR(setrecursionlimit_doc,
377386
"setrecursionlimit(n)\n\
378387
\n\
379388
Set the maximum depth of the Python interpreter stack to n. This\n\
380389
limit prevents infinite recursion from causing an overflow of the C\n\
381390
stack and crashing Python. The highest possible limit is platform-\n\
382-
dependent.";
391+
dependent."
392+
);
383393

384394
static PyObject *
385395
sys_getrecursionlimit(PyObject *self)
386396
{
387397
return PyInt_FromLong(Py_GetRecursionLimit());
388398
}
389399

390-
static char getrecursionlimit_doc[] =
400+
PyDoc_STRVAR(getrecursionlimit_doc,
391401
"getrecursionlimit()\n\
392402
\n\
393403
Return the current value of the recursion limit, the maximum depth\n\
394404
of the Python interpreter stack. This limit prevents infinite\n\
395405
recursion from causing an overflow of the C stack and crashing Python.";
406+
);
396407

397408
#ifdef HAVE_DLOPEN
398409
static PyObject *
@@ -409,14 +420,15 @@ sys_setdlopenflags(PyObject *self, PyObject *args)
409420
return Py_None;
410421
}
411422

412-
static char setdlopenflags_doc[] =
423+
PyDoc_STRVAR(setdlopenflags_doc,
413424
"setdlopenflags(n) -> None\n\
414425
\n\
415426
Set the flags that will be used for dlopen() calls. Among other\n\
416427
things, this will enable a lazy resolving of symbols when importing\n\
417428
a module, if called as sys.setdlopenflags(0)\n\
418429
To share symbols across extension modules, call as\n\
419-
sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)";
430+
sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)"
431+
);
420432

421433
static PyObject *
422434
sys_getdlopenflags(PyObject *self, PyObject *args)
@@ -427,11 +439,12 @@ sys_getdlopenflags(PyObject *self, PyObject *args)
427439
return PyInt_FromLong(tstate->interp->dlopenflags);
428440
}
429441

430-
static char getdlopenflags_doc[] =
442+
PyDoc_STRVAR(getdlopenflags_doc,
431443
"getdlopenflags() -> int\n\
432444
\n\
433445
Return the current value of the flags that are used for dlopen()\n\
434-
calls. The flag constants are defined in the dl module.";
446+
calls. The flag constants are defined in the dl module."
447+
);
435448
#endif
436449

437450
#ifdef USE_MALLOPT
@@ -466,11 +479,12 @@ sys_gettotalrefcount(PyObject *self)
466479

467480
#endif /* Py_TRACE_REFS */
468481

469-
static char getrefcount_doc[] =
482+
PyDoc_STRVAR(getrefcount_doc,
470483
"getrefcount(object) -> integer\n\
471484
\n\
472485
Return the current reference count for the object. This includes the\n\
473-
temporary reference in the argument list, so it is at least 2.";
486+
temporary reference in the argument list, so it is at least 2."
487+
);
474488

475489
#ifdef COUNT_ALLOCS
476490
static PyObject *
@@ -482,7 +496,7 @@ sys_getcounts(PyObject *self)
482496
}
483497
#endif
484498

485-
static char getframe_doc[] =
499+
PyDoc_STRVAR(getframe_doc,
486500
"_getframe([depth]) -> frameobject\n\
487501
\n\
488502
Return a frame object from the call stack. If optional integer depth is\n\
@@ -491,7 +505,8 @@ If that is deeper than the call stack, ValueError is raised. The default\n\
491505
for depth is zero, returning the frame at the top of the call stack.\n\
492506
\n\
493507
This function should be used for internal and specialized\n\
494-
purposes only.";
508+
purposes only."
509+
);
495510

496511
static PyObject *
497512
sys_getframe(PyObject *self, PyObject *args)
@@ -633,7 +648,8 @@ PySys_AddWarnOption(char *s)
633648
Two literals concatenated works just fine. If you have a K&R compiler
634649
or other abomination that however *does* understand longer strings,
635650
get rid of the !!! comment in the middle and the quotes that surround it. */
636-
static char sys_doc[] =
651+
PyDoc_VAR(sys_doc) =
652+
PyDoc_STR(
637653
"This module provides access to some objects used or maintained by the\n\
638654
interpreter and to functions that interact strongly with the interpreter.\n\
639655
\n\
@@ -669,8 +685,10 @@ exc_traceback -- traceback of exception currently being handled\n\
669685
The function exc_info() should be used instead of these three,\n\
670686
because it is thread-safe.\n\
671687
"
688+
)
672689
#ifndef MS_WIN16
673690
/* concatenating string here */
691+
PyDoc_STR(
674692
"\n\
675693
Static objects:\n\
676694
\n\
@@ -686,12 +704,16 @@ executable -- pathname of this Python interpreter\n\
686704
prefix -- prefix used to find the Python library\n\
687705
exec_prefix -- prefix used to find the machine-specific Python library\n\
688706
"
707+
)
689708
#ifdef MS_WINDOWS
690709
/* concatenating string here */
710+
PyDoc_STR(
691711
"dllhandle -- [Windows only] integer handle of the Python DLL\n\
692712
winver -- [Windows only] version number of the Python DLL\n\
693713
"
714+
)
694715
#endif /* MS_WINDOWS */
716+
PyDoc_STR(
695717
"__stdin__ -- the original stdin; don't touch!\n\
696718
__stdout__ -- the original stdout; don't touch!\n\
697719
__stderr__ -- the original stderr; don't touch!\n\
@@ -713,6 +735,7 @@ setprofile() -- set the global profiling function\n\
713735
setrecursionlimit() -- set the max recursion depth for the interpreter\n\
714736
settrace() -- set the global debug tracing function\n\
715737
"
738+
)
716739
#endif /* MS_WIN16 */
717740
/* end of sys_doc */ ;
718741

‎configure‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 1.320 .
2+
# From configure.in Revision: 1.321 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.53.
55
#
@@ -845,6 +845,7 @@ Optional Packages:
845845
--with-pth use GNU pth threading libraries
846846
--with(out)-cycle-gc disable/enable garbage collection
847847
--with(out)-universal-newlines disable/enable foreign newlines
848+
--with(out)-doc-strings disable/enable documentation strings
848849
--with(out)-pymalloc disable/enable specialized mallocs
849850
--with-wctype-functions use wctype.h functions
850851
--with-sgi-dl=DIRECTORY IRIX 4 dynamic linking
@@ -10964,6 +10965,30 @@ fi
1096410965
echo "$as_me:$LINENO: result: $with_universal_newlines" >&5
1096510966
echo "${ECHO_T}$with_universal_newlines" >&6
1096610967
10968+
# Check for --with-doc-strings
10969+
echo "$as_me:$LINENO: checking for --with-doc-strings" >&5
10970+
echo $ECHO_N "checking for --with-doc-strings... $ECHO_C" >&6
10971+
10972+
# Check whether --with-doc-strings or --without-doc-strings was given.
10973+
if test "${with_doc_strings+set}" = set; then
10974+
withval="$with_doc_strings"
10975+
10976+
fi;
10977+
10978+
if test -z "$with_doc_strings"
10979+
then with_doc_strings="yes"
10980+
fi
10981+
if test "$with_doc_strings" != "no"
10982+
then
10983+
10984+
cat >>confdefs.h <<\_ACEOF
10985+
#define WITH_DOC_STRINGS 1
10986+
_ACEOF
10987+
10988+
fi
10989+
echo "$as_me:$LINENO: result: $with_doc_strings" >&5
10990+
echo "${ECHO_T}$with_doc_strings" >&6
10991+
1096710992
# Check for Python-specific malloc support
1096810993
echo "$as_me:$LINENO: checking for --with-pymalloc" >&5
1096910994
echo $ECHO_N "checking for --with-pymalloc... $ECHO_C" >&6

‎configure.in‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,21 @@ then
14551455
fi
14561456
AC_MSG_RESULT($with_universal_newlines)
14571457

1458+
# Check for --with-doc-strings
1459+
AC_MSG_CHECKING(for --with-doc-strings)
1460+
AC_ARG_WITH(doc-strings,
1461+
[ --with(out)-doc-strings disable/enable documentation strings])
1462+
1463+
if test -z "$with_doc_strings"
1464+
then with_doc_strings="yes"
1465+
fi
1466+
if test "$with_doc_strings" != "no"
1467+
then
1468+
AC_DEFINE(WITH_DOC_STRINGS, 1,
1469+
[Define if you want documentation strings in extension modules])
1470+
fi
1471+
AC_MSG_RESULT($with_doc_strings)
1472+
14581473
# Check for Python-specific malloc support
14591474
AC_MSG_CHECKING(for --with-pymalloc)
14601475
AC_ARG_WITH(pymalloc,

‎pyconfig.h.in‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,9 @@
726726
SunOS 4 or 5, they already have dynamic linking using shared libraries. */
727727
#undef WITH_DL_DLD
728728

729+
/* Define if you want documentation strings in extension modules */
730+
#undef WITH_DOC_STRINGS
731+
729732
/* Define if you want to use the new-style (Openstep, Rhapsody, MacOS) dynamic
730733
linker (dyld) instead of the old-style (NextStep) dynamic linker (rld).
731734
Dyld is necessary to support frameworks. */

0 commit comments

Comments
 (0)