comparison Python/sysmodule.c @ 23746:43ddcdcd3c71 legacy-trunk

Patch #505375: Make doc strings optional.
author Martin v. Löwis <martin@v.loewis.de>
date Sun, 09 Jun 2002 13:33:54 +0000
parents 3f4b2f93e8b5
children 37118b6e5f46
comparison
equal deleted inserted replaced
23745:38832000f7e9 23746:43ddcdcd3c71
101 return NULL; 101 return NULL;
102 Py_INCREF(Py_None); 102 Py_INCREF(Py_None);
103 return Py_None; 103 return Py_None;
104 } 104 }
105 105
106 static char displayhook_doc[] = 106 PyDoc_STRVAR(displayhook_doc,
107 "displayhook(object) -> None\n" 107 "displayhook(object) -> None\n"
108 "\n" 108 "\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 );
110 111
111 static PyObject * 112 static PyObject *
112 sys_excepthook(PyObject* self, PyObject* args) 113 sys_excepthook(PyObject* self, PyObject* args)
113 { 114 {
114 PyObject *exc, *value, *tb; 115 PyObject *exc, *value, *tb;
117 PyErr_Display(exc, value, tb); 118 PyErr_Display(exc, value, tb);
118 Py_INCREF(Py_None); 119 Py_INCREF(Py_None);
119 return Py_None; 120 return Py_None;
120 } 121 }
121 122
122 static char excepthook_doc[] = 123 PyDoc_STRVAR(excepthook_doc,
123 "excepthook(exctype, value, traceback) -> None\n" 124 "excepthook(exctype, value, traceback) -> None\n"
124 "\n" 125 "\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 );
126 128
127 static PyObject * 129 static PyObject *
128 sys_exc_info(PyObject *self) 130 sys_exc_info(PyObject *self)
129 { 131 {
130 PyThreadState *tstate; 132 PyThreadState *tstate;
135 tstate->exc_value != NULL ? tstate->exc_value : Py_None, 137 tstate->exc_value != NULL ? tstate->exc_value : Py_None,
136 tstate->exc_traceback != NULL ? 138 tstate->exc_traceback != NULL ?
137 tstate->exc_traceback : Py_None); 139 tstate->exc_traceback : Py_None);
138 } 140 }
139 141
140 static char exc_info_doc[] = 142 PyDoc_STRVAR(exc_info_doc,
141 "exc_info() -> (type, value, traceback)\n\ 143 "exc_info() -> (type, value, traceback)\n\
142 \n\ 144 \n\
143 Return information about the exception that is currently being handled.\n\ 145 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 );
145 148
146 static PyObject * 149 static PyObject *
147 sys_exit(PyObject *self, PyObject *args) 150 sys_exit(PyObject *self, PyObject *args)
148 { 151 {
149 PyObject *exit_code = 0; 152 PyObject *exit_code = 0;
152 /* Raise SystemExit so callers may catch it or clean up. */ 155 /* Raise SystemExit so callers may catch it or clean up. */
153 PyErr_SetObject(PyExc_SystemExit, exit_code); 156 PyErr_SetObject(PyExc_SystemExit, exit_code);
154 return NULL; 157 return NULL;
155 } 158 }
156 159
157 static char exit_doc[] = 160 PyDoc_STRVAR(exit_doc,
158 "exit([status])\n\ 161 "exit([status])\n\
159 \n\ 162 \n\
160 Exit the interpreter by raising SystemExit(status).\n\ 163 Exit the interpreter by raising SystemExit(status).\n\
161 If the status is omitted or None, it defaults to zero (i.e., success).\n\ 164 If the status is omitted or None, it defaults to zero (i.e., success).\n\
162 If the status is numeric, it will be used as the system exit status.\n\ 165 If the status is numeric, it will be used as the system exit status.\n\
163 If it is another kind of object, it will be printed and the system\n\ 166 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 );
165 169
166 #ifdef Py_USING_UNICODE 170 #ifdef Py_USING_UNICODE
167 171
168 static PyObject * 172 static PyObject *
169 sys_getdefaultencoding(PyObject *self) 173 sys_getdefaultencoding(PyObject *self)
170 { 174 {
171 return PyString_FromString(PyUnicode_GetDefaultEncoding()); 175 return PyString_FromString(PyUnicode_GetDefaultEncoding());
172 } 176 }
173 177
174 static char getdefaultencoding_doc[] = 178 PyDoc_STRVAR(getdefaultencoding_doc,
175 "getdefaultencoding() -> string\n\ 179 "getdefaultencoding() -> string\n\
176 \n\ 180 \n\
177 Return the current default string encoding used by the Unicode \n\ 181 Return the current default string encoding used by the Unicode \n\
178 implementation."; 182 implementation."
183 );
179 184
180 static PyObject * 185 static PyObject *
181 sys_setdefaultencoding(PyObject *self, PyObject *args) 186 sys_setdefaultencoding(PyObject *self, PyObject *args)
182 { 187 {
183 char *encoding; 188 char *encoding;
187 return NULL; 192 return NULL;
188 Py_INCREF(Py_None); 193 Py_INCREF(Py_None);
189 return Py_None; 194 return Py_None;
190 } 195 }
191 196
192 static char setdefaultencoding_doc[] = 197 PyDoc_STRVAR(setdefaultencoding_doc,
193 "setdefaultencoding(encoding)\n\ 198 "setdefaultencoding(encoding)\n\
194 \n\ 199 \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 );
196 202
197 #endif 203 #endif
198 204
199 /* 205 /*
200 * Cached interned string objects used for calling the profile and 206 * Cached interned string objects used for calling the profile and
314 PyEval_SetTrace(trace_trampoline, args); 320 PyEval_SetTrace(trace_trampoline, args);
315 Py_INCREF(Py_None); 321 Py_INCREF(Py_None);
316 return Py_None; 322 return Py_None;
317 } 323 }
318 324
319 static char settrace_doc[] = 325 PyDoc_STRVAR(settrace_doc,
320 "settrace(function)\n\ 326 "settrace(function)\n\
321 \n\ 327 \n\
322 Set the global debug tracing function. It will be called on each\n\ 328 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 );
324 331
325 static PyObject * 332 static PyObject *
326 sys_setprofile(PyObject *self, PyObject *args) 333 sys_setprofile(PyObject *self, PyObject *args)
327 { 334 {
328 if (trace_init() == -1) 335 if (trace_init() == -1)
333 PyEval_SetProfile(profile_trampoline, args); 340 PyEval_SetProfile(profile_trampoline, args);
334 Py_INCREF(Py_None); 341 Py_INCREF(Py_None);
335 return Py_None; 342 return Py_None;
336 } 343 }
337 344
338 static char setprofile_doc[] = 345 PyDoc_STRVAR(setprofile_doc,
339 "setprofile(function)\n\ 346 "setprofile(function)\n\
340 \n\ 347 \n\
341 Set the profiling function. It will be called on each function call\n\ 348 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 );
343 351
344 static PyObject * 352 static PyObject *
345 sys_setcheckinterval(PyObject *self, PyObject *args) 353 sys_setcheckinterval(PyObject *self, PyObject *args)
346 { 354 {
347 PyThreadState *tstate = PyThreadState_Get(); 355 PyThreadState *tstate = PyThreadState_Get();
349 return NULL; 357 return NULL;
350 Py_INCREF(Py_None); 358 Py_INCREF(Py_None);
351 return Py_None; 359 return Py_None;
352 } 360 }
353 361
354 static char setcheckinterval_doc[] = 362 PyDoc_STRVAR(setcheckinterval_doc,
355 "setcheckinterval(n)\n\ 363 "setcheckinterval(n)\n\
356 \n\ 364 \n\
357 Tell the Python interpreter to check for asynchronous events every\n\ 365 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 );
359 368
360 static PyObject * 369 static PyObject *
361 sys_setrecursionlimit(PyObject *self, PyObject *args) 370 sys_setrecursionlimit(PyObject *self, PyObject *args)
362 { 371 {
363 int new_limit; 372 int new_limit;
371 Py_SetRecursionLimit(new_limit); 380 Py_SetRecursionLimit(new_limit);
372 Py_INCREF(Py_None); 381 Py_INCREF(Py_None);
373 return Py_None; 382 return Py_None;
374 } 383 }
375 384
376 static char setrecursionlimit_doc[] = 385 PyDoc_STRVAR(setrecursionlimit_doc,
377 "setrecursionlimit(n)\n\ 386 "setrecursionlimit(n)\n\
378 \n\ 387 \n\
379 Set the maximum depth of the Python interpreter stack to n. This\n\ 388 Set the maximum depth of the Python interpreter stack to n. This\n\
380 limit prevents infinite recursion from causing an overflow of the C\n\ 389 limit prevents infinite recursion from causing an overflow of the C\n\
381 stack and crashing Python. The highest possible limit is platform-\n\ 390 stack and crashing Python. The highest possible limit is platform-\n\
382 dependent."; 391 dependent."
392 );
383 393
384 static PyObject * 394 static PyObject *
385 sys_getrecursionlimit(PyObject *self) 395 sys_getrecursionlimit(PyObject *self)
386 { 396 {
387 return PyInt_FromLong(Py_GetRecursionLimit()); 397 return PyInt_FromLong(Py_GetRecursionLimit());
388 } 398 }
389 399
390 static char getrecursionlimit_doc[] = 400 PyDoc_STRVAR(getrecursionlimit_doc,
391 "getrecursionlimit()\n\ 401 "getrecursionlimit()\n\
392 \n\ 402 \n\
393 Return the current value of the recursion limit, the maximum depth\n\ 403 Return the current value of the recursion limit, the maximum depth\n\
394 of the Python interpreter stack. This limit prevents infinite\n\ 404 of the Python interpreter stack. This limit prevents infinite\n\
395 recursion from causing an overflow of the C stack and crashing Python."; 405 recursion from causing an overflow of the C stack and crashing Python.";
406 );
396 407
397 #ifdef HAVE_DLOPEN 408 #ifdef HAVE_DLOPEN
398 static PyObject * 409 static PyObject *
399 sys_setdlopenflags(PyObject *self, PyObject *args) 410 sys_setdlopenflags(PyObject *self, PyObject *args)
400 { 411 {
407 tstate->interp->dlopenflags = new_val; 418 tstate->interp->dlopenflags = new_val;
408 Py_INCREF(Py_None); 419 Py_INCREF(Py_None);
409 return Py_None; 420 return Py_None;
410 } 421 }
411 422
412 static char setdlopenflags_doc[] = 423 PyDoc_STRVAR(setdlopenflags_doc,
413 "setdlopenflags(n) -> None\n\ 424 "setdlopenflags(n) -> None\n\
414 \n\ 425 \n\
415 Set the flags that will be used for dlopen() calls. Among other\n\ 426 Set the flags that will be used for dlopen() calls. Among other\n\
416 things, this will enable a lazy resolving of symbols when importing\n\ 427 things, this will enable a lazy resolving of symbols when importing\n\
417 a module, if called as sys.setdlopenflags(0)\n\ 428 a module, if called as sys.setdlopenflags(0)\n\
418 To share symbols across extension modules, call as\n\ 429 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 );
420 432
421 static PyObject * 433 static PyObject *
422 sys_getdlopenflags(PyObject *self, PyObject *args) 434 sys_getdlopenflags(PyObject *self, PyObject *args)
423 { 435 {
424 PyThreadState *tstate = PyThreadState_Get(); 436 PyThreadState *tstate = PyThreadState_Get();
425 if (!tstate) 437 if (!tstate)
426 return NULL; 438 return NULL;
427 return PyInt_FromLong(tstate->interp->dlopenflags); 439 return PyInt_FromLong(tstate->interp->dlopenflags);
428 } 440 }
429 441
430 static char getdlopenflags_doc[] = 442 PyDoc_STRVAR(getdlopenflags_doc,
431 "getdlopenflags() -> int\n\ 443 "getdlopenflags() -> int\n\
432 \n\ 444 \n\
433 Return the current value of the flags that are used for dlopen()\n\ 445 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 );
435 #endif 448 #endif
436 449
437 #ifdef USE_MALLOPT 450 #ifdef USE_MALLOPT
438 /* Link with -lmalloc (or -lmpc) on an SGI */ 451 /* Link with -lmalloc (or -lmpc) on an SGI */
439 #include <malloc.h> 452 #include <malloc.h>
464 return PyInt_FromLong(_Py_RefTotal); 477 return PyInt_FromLong(_Py_RefTotal);
465 } 478 }
466 479
467 #endif /* Py_TRACE_REFS */ 480 #endif /* Py_TRACE_REFS */
468 481
469 static char getrefcount_doc[] = 482 PyDoc_STRVAR(getrefcount_doc,
470 "getrefcount(object) -> integer\n\ 483 "getrefcount(object) -> integer\n\
471 \n\ 484 \n\
472 Return the current reference count for the object. This includes the\n\ 485 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 );
474 488
475 #ifdef COUNT_ALLOCS 489 #ifdef COUNT_ALLOCS
476 static PyObject * 490 static PyObject *
477 sys_getcounts(PyObject *self) 491 sys_getcounts(PyObject *self)
478 { 492 {
480 494
481 return get_counts(); 495 return get_counts();
482 } 496 }
483 #endif 497 #endif
484 498
485 static char getframe_doc[] = 499 PyDoc_STRVAR(getframe_doc,
486 "_getframe([depth]) -> frameobject\n\ 500 "_getframe([depth]) -> frameobject\n\
487 \n\ 501 \n\
488 Return a frame object from the call stack. If optional integer depth is\n\ 502 Return a frame object from the call stack. If optional integer depth is\n\
489 given, return the frame object that many calls below the top of the stack.\n\ 503 given, return the frame object that many calls below the top of the stack.\n\
490 If that is deeper than the call stack, ValueError is raised. The default\n\ 504 If that is deeper than the call stack, ValueError is raised. The default\n\
491 for depth is zero, returning the frame at the top of the call stack.\n\ 505 for depth is zero, returning the frame at the top of the call stack.\n\
492 \n\ 506 \n\
493 This function should be used for internal and specialized\n\ 507 This function should be used for internal and specialized\n\
494 purposes only."; 508 purposes only."
509 );
495 510
496 static PyObject * 511 static PyObject *
497 sys_getframe(PyObject *self, PyObject *args) 512 sys_getframe(PyObject *self, PyObject *args)
498 { 513 {
499 PyFrameObject *f = PyThreadState_Get()->frame; 514 PyFrameObject *f = PyThreadState_Get()->frame;
631 646
632 /* XXX This doc string is too long to be a single string literal in VC++ 5.0. 647 /* XXX This doc string is too long to be a single string literal in VC++ 5.0.
633 Two literals concatenated works just fine. If you have a K&R compiler 648 Two literals concatenated works just fine. If you have a K&R compiler
634 or other abomination that however *does* understand longer strings, 649 or other abomination that however *does* understand longer strings,
635 get rid of the !!! comment in the middle and the quotes that surround it. */ 650 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(
637 "This module provides access to some objects used or maintained by the\n\ 653 "This module provides access to some objects used or maintained by the\n\
638 interpreter and to functions that interact strongly with the interpreter.\n\ 654 interpreter and to functions that interact strongly with the interpreter.\n\
639 \n\ 655 \n\
640 Dynamic objects:\n\ 656 Dynamic objects:\n\
641 \n\ 657 \n\
667 exc_value -- value of exception currently being handled\n\ 683 exc_value -- value of exception currently being handled\n\
668 exc_traceback -- traceback of exception currently being handled\n\ 684 exc_traceback -- traceback of exception currently being handled\n\
669 The function exc_info() should be used instead of these three,\n\ 685 The function exc_info() should be used instead of these three,\n\
670 because it is thread-safe.\n\ 686 because it is thread-safe.\n\
671 " 687 "
688 )
672 #ifndef MS_WIN16 689 #ifndef MS_WIN16
673 /* concatenating string here */ 690 /* concatenating string here */
691 PyDoc_STR(
674 "\n\ 692 "\n\
675 Static objects:\n\ 693 Static objects:\n\
676 \n\ 694 \n\
677 maxint -- the largest supported integer (the smallest is -maxint-1)\n\ 695 maxint -- the largest supported integer (the smallest is -maxint-1)\n\
678 maxunicode -- the largest supported character\n\ 696 maxunicode -- the largest supported character\n\
684 platform -- platform identifier\n\ 702 platform -- platform identifier\n\
685 executable -- pathname of this Python interpreter\n\ 703 executable -- pathname of this Python interpreter\n\
686 prefix -- prefix used to find the Python library\n\ 704 prefix -- prefix used to find the Python library\n\
687 exec_prefix -- prefix used to find the machine-specific Python library\n\ 705 exec_prefix -- prefix used to find the machine-specific Python library\n\
688 " 706 "
707 )
689 #ifdef MS_WINDOWS 708 #ifdef MS_WINDOWS
690 /* concatenating string here */ 709 /* concatenating string here */
710 PyDoc_STR(
691 "dllhandle -- [Windows only] integer handle of the Python DLL\n\ 711 "dllhandle -- [Windows only] integer handle of the Python DLL\n\
692 winver -- [Windows only] version number of the Python DLL\n\ 712 winver -- [Windows only] version number of the Python DLL\n\
693 " 713 "
714 )
694 #endif /* MS_WINDOWS */ 715 #endif /* MS_WINDOWS */
716 PyDoc_STR(
695 "__stdin__ -- the original stdin; don't touch!\n\ 717 "__stdin__ -- the original stdin; don't touch!\n\
696 __stdout__ -- the original stdout; don't touch!\n\ 718 __stdout__ -- the original stdout; don't touch!\n\
697 __stderr__ -- the original stderr; don't touch!\n\ 719 __stderr__ -- the original stderr; don't touch!\n\
698 __displayhook__ -- the original displayhook; don't touch!\n\ 720 __displayhook__ -- the original displayhook; don't touch!\n\
699 __excepthook__ -- the original excepthook; don't touch!\n\ 721 __excepthook__ -- the original excepthook; don't touch!\n\
711 setdlopenflags() -- set the flags to be used for dlopen() calls\n\ 733 setdlopenflags() -- set the flags to be used for dlopen() calls\n\
712 setprofile() -- set the global profiling function\n\ 734 setprofile() -- set the global profiling function\n\
713 setrecursionlimit() -- set the max recursion depth for the interpreter\n\ 735 setrecursionlimit() -- set the max recursion depth for the interpreter\n\
714 settrace() -- set the global debug tracing function\n\ 736 settrace() -- set the global debug tracing function\n\
715 " 737 "
738 )
716 #endif /* MS_WIN16 */ 739 #endif /* MS_WIN16 */
717 /* end of sys_doc */ ; 740 /* end of sys_doc */ ;
718 741
719 PyObject * 742 PyObject *
720 _PySys_Init(void) 743 _PySys_Init(void)