Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 19301:b9701538f827 legacy-trunk
Patch #427190: Implement and use METH_NOARGS and METH_O.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Thu, 16 Aug 2001 13:15:00 +0000 |
| parents | 4462c57f6c94 |
| children | 7257e87e0720 |
comparison
equal
deleted
inserted
replaced
| 19300:81440dd326bb | 19301:b9701538f827 |
|---|---|
| 66 else | 66 else |
| 67 return PyDict_SetItemString(sd, name, v); | 67 return PyDict_SetItemString(sd, name, v); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static PyObject * | 70 static PyObject * |
| 71 sys_displayhook(PyObject *self, PyObject *args) | 71 sys_displayhook(PyObject *self, PyObject *o) |
| 72 { | 72 { |
| 73 PyObject *o, *outf; | 73 PyObject *outf; |
| 74 PyInterpreterState *interp = PyThreadState_Get()->interp; | 74 PyInterpreterState *interp = PyThreadState_Get()->interp; |
| 75 PyObject *modules = interp->modules; | 75 PyObject *modules = interp->modules; |
| 76 PyObject *builtins = PyDict_GetItemString(modules, "__builtin__"); | 76 PyObject *builtins = PyDict_GetItemString(modules, "__builtin__"); |
| 77 | 77 |
| 78 if (builtins == NULL) { | 78 if (builtins == NULL) { |
| 79 PyErr_SetString(PyExc_RuntimeError, "lost __builtin__"); | 79 PyErr_SetString(PyExc_RuntimeError, "lost __builtin__"); |
| 80 return NULL; | 80 return NULL; |
| 81 } | 81 } |
| 82 | |
| 83 /* parse arguments */ | |
| 84 if (!PyArg_ParseTuple(args, "O:displayhook", &o)) | |
| 85 return NULL; | |
| 86 | 82 |
| 87 /* Print value except if None */ | 83 /* Print value except if None */ |
| 88 /* After printing, also assign to '_' */ | 84 /* After printing, also assign to '_' */ |
| 89 /* Before, set '_' to None to avoid recursion */ | 85 /* Before, set '_' to None to avoid recursion */ |
| 90 if (o == Py_None) { | 86 if (o == Py_None) { |
| 131 "excepthook(exctype, value, traceback) -> None\n" | 127 "excepthook(exctype, value, traceback) -> None\n" |
| 132 "\n" | 128 "\n" |
| 133 "Handle an exception by displaying it with a traceback on sys.stderr.\n"; | 129 "Handle an exception by displaying it with a traceback on sys.stderr.\n"; |
| 134 | 130 |
| 135 static PyObject * | 131 static PyObject * |
| 136 sys_exc_info(PyObject *self, PyObject *args) | 132 sys_exc_info(PyObject *self) |
| 137 { | 133 { |
| 138 PyThreadState *tstate; | 134 PyThreadState *tstate; |
| 139 if (!PyArg_ParseTuple(args, ":exc_info")) | |
| 140 return NULL; | |
| 141 tstate = PyThreadState_Get(); | 135 tstate = PyThreadState_Get(); |
| 142 return Py_BuildValue( | 136 return Py_BuildValue( |
| 143 "(OOO)", | 137 "(OOO)", |
| 144 tstate->exc_type != NULL ? tstate->exc_type : Py_None, | 138 tstate->exc_type != NULL ? tstate->exc_type : Py_None, |
| 145 tstate->exc_value != NULL ? tstate->exc_value : Py_None, | 139 tstate->exc_value != NULL ? tstate->exc_value : Py_None, |
| 169 If the status numeric, it will be used as the system exit status.\n\ | 163 If the status numeric, it will be used as the system exit status.\n\ |
| 170 If it is another kind of object, it will be printed and the system\n\ | 164 If it is another kind of object, it will be printed and the system\n\ |
| 171 exit status will be one (i.e., failure)."; | 165 exit status will be one (i.e., failure)."; |
| 172 | 166 |
| 173 static PyObject * | 167 static PyObject * |
| 174 sys_getdefaultencoding(PyObject *self, PyObject *args) | 168 sys_getdefaultencoding(PyObject *self) |
| 175 { | 169 { |
| 176 if (!PyArg_ParseTuple(args, ":getdefaultencoding")) | |
| 177 return NULL; | |
| 178 return PyString_FromString(PyUnicode_GetDefaultEncoding()); | 170 return PyString_FromString(PyUnicode_GetDefaultEncoding()); |
| 179 } | 171 } |
| 180 | 172 |
| 181 static char getdefaultencoding_doc[] = | 173 static char getdefaultencoding_doc[] = |
| 182 "getdefaultencoding() -> string\n\ | 174 "getdefaultencoding() -> string\n\ |
| 383 limit prevents infinite recursion from causing an overflow of the C\n\ | 375 limit prevents infinite recursion from causing an overflow of the C\n\ |
| 384 stack and crashing Python. The highest possible limit is platform-\n\ | 376 stack and crashing Python. The highest possible limit is platform-\n\ |
| 385 dependent."; | 377 dependent."; |
| 386 | 378 |
| 387 static PyObject * | 379 static PyObject * |
| 388 sys_getrecursionlimit(PyObject *self, PyObject *args) | 380 sys_getrecursionlimit(PyObject *self) |
| 389 { | 381 { |
| 390 if (!PyArg_ParseTuple(args, ":getrecursionlimit")) | |
| 391 return NULL; | |
| 392 return PyInt_FromLong(Py_GetRecursionLimit()); | 382 return PyInt_FromLong(Py_GetRecursionLimit()); |
| 393 } | 383 } |
| 394 | 384 |
| 395 static char getrecursionlimit_doc[] = | 385 static char getrecursionlimit_doc[] = |
| 396 "getrecursionlimit()\n\ | 386 "getrecursionlimit()\n\ |
| 425 | 415 |
| 426 static PyObject * | 416 static PyObject * |
| 427 sys_getdlopenflags(PyObject *self, PyObject *args) | 417 sys_getdlopenflags(PyObject *self, PyObject *args) |
| 428 { | 418 { |
| 429 PyThreadState *tstate = PyThreadState_Get(); | 419 PyThreadState *tstate = PyThreadState_Get(); |
| 430 if (!PyArg_ParseTuple(args, ":getdlopenflags")) | |
| 431 return NULL; | |
| 432 if (!tstate) | 420 if (!tstate) |
| 433 return NULL; | 421 return NULL; |
| 434 return PyInt_FromLong(tstate->interp->dlopenflags); | 422 return PyInt_FromLong(tstate->interp->dlopenflags); |
| 435 } | 423 } |
| 436 | 424 |
| 466 return PyInt_FromLong(arg->ob_refcnt); | 454 return PyInt_FromLong(arg->ob_refcnt); |
| 467 } | 455 } |
| 468 | 456 |
| 469 #ifdef Py_TRACE_REFS | 457 #ifdef Py_TRACE_REFS |
| 470 static PyObject * | 458 static PyObject * |
| 471 sys_gettotalrefcount(PyObject *self, PyObject *args) | 459 sys_gettotalrefcount(PyObject *self) |
| 472 { | 460 { |
| 473 extern long _Py_RefTotal; | 461 extern long _Py_RefTotal; |
| 474 if (!PyArg_ParseTuple(args, ":gettotalrefcount")) | |
| 475 return NULL; | |
| 476 return PyInt_FromLong(_Py_RefTotal); | 462 return PyInt_FromLong(_Py_RefTotal); |
| 477 } | 463 } |
| 478 | 464 |
| 479 #endif /* Py_TRACE_REFS */ | 465 #endif /* Py_TRACE_REFS */ |
| 480 | 466 |
| 484 Return the current reference count for the object. This includes the\n\ | 470 Return the current reference count for the object. This includes the\n\ |
| 485 temporary reference in the argument list, so it is at least 2."; | 471 temporary reference in the argument list, so it is at least 2."; |
| 486 | 472 |
| 487 #ifdef COUNT_ALLOCS | 473 #ifdef COUNT_ALLOCS |
| 488 static PyObject * | 474 static PyObject * |
| 489 sys_getcounts(PyObject *self, PyObject *args) | 475 sys_getcounts(PyObject *self) |
| 490 { | 476 { |
| 491 extern PyObject *get_counts(void); | 477 extern PyObject *get_counts(void); |
| 492 | 478 |
| 493 if (!PyArg_ParseTuple(args, ":getcounts")) | |
| 494 return NULL; | |
| 495 return get_counts(); | 479 return get_counts(); |
| 496 } | 480 } |
| 497 #endif | 481 #endif |
| 498 | 482 |
| 499 static char getframe_doc[] = | 483 static char getframe_doc[] = |
| 540 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); | 524 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); |
| 541 #endif | 525 #endif |
| 542 | 526 |
| 543 static PyMethodDef sys_methods[] = { | 527 static PyMethodDef sys_methods[] = { |
| 544 /* Might as well keep this in alphabetic order */ | 528 /* Might as well keep this in alphabetic order */ |
| 545 {"displayhook", sys_displayhook, 1, displayhook_doc}, | 529 {"displayhook", sys_displayhook, METH_O, displayhook_doc}, |
| 546 {"exc_info", sys_exc_info, 1, exc_info_doc}, | 530 {"exc_info", (PyCFunction)sys_exc_info, METH_NOARGS, exc_info_doc}, |
| 547 {"excepthook", sys_excepthook, 1, excepthook_doc}, | 531 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, |
| 548 {"exit", sys_exit, 0, exit_doc}, | 532 {"exit", sys_exit, METH_OLDARGS, exit_doc}, |
| 549 {"getdefaultencoding", sys_getdefaultencoding, 1, | 533 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS, |
| 550 getdefaultencoding_doc}, | 534 getdefaultencoding_doc}, |
| 551 #ifdef HAVE_DLOPEN | 535 #ifdef HAVE_DLOPEN |
| 552 {"getdlopenflags", sys_getdlopenflags, 1, | 536 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, |
| 553 getdlopenflags_doc}, | 537 getdlopenflags_doc}, |
| 554 #endif | 538 #endif |
| 555 #ifdef COUNT_ALLOCS | 539 #ifdef COUNT_ALLOCS |
| 556 {"getcounts", sys_getcounts, 1}, | 540 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, |
| 557 #endif | 541 #endif |
| 558 #ifdef DYNAMIC_EXECUTION_PROFILE | 542 #ifdef DYNAMIC_EXECUTION_PROFILE |
| 559 {"getdxp", _Py_GetDXProfile, 1}, | 543 {"getdxp", _Py_GetDXProfile, METH_VARARGS}, |
| 560 #endif | 544 #endif |
| 561 #ifdef Py_TRACE_REFS | 545 #ifdef Py_TRACE_REFS |
| 562 {"getobjects", _Py_GetObjects, 1}, | 546 {"getobjects", _Py_GetObjects, METH_VARARGS}, |
| 563 {"gettotalrefcount", sys_gettotalrefcount, 1}, | 547 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS}, |
| 564 #endif | 548 #endif |
| 565 {"getrefcount", sys_getrefcount, 1, getrefcount_doc}, | 549 {"getrefcount", sys_getrefcount, METH_VARARGS, getrefcount_doc}, |
| 566 {"getrecursionlimit", sys_getrecursionlimit, 1, | 550 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS, |
| 567 getrecursionlimit_doc}, | 551 getrecursionlimit_doc}, |
| 568 {"_getframe", sys_getframe, 1, getframe_doc}, | 552 {"_getframe", sys_getframe, METH_VARARGS, getframe_doc}, |
| 569 #ifdef USE_MALLOPT | 553 #ifdef USE_MALLOPT |
| 570 {"mdebug", sys_mdebug, 1}, | 554 {"mdebug", sys_mdebug, METH_VARARGS}, |
| 571 #endif | 555 #endif |
| 572 {"setdefaultencoding", sys_setdefaultencoding, 1, | 556 {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS, |
| 573 setdefaultencoding_doc}, | 557 setdefaultencoding_doc}, |
| 574 {"setcheckinterval", sys_setcheckinterval, 1, | 558 {"setcheckinterval", sys_setcheckinterval, METH_VARARGS, |
| 575 setcheckinterval_doc}, | 559 setcheckinterval_doc}, |
| 576 #ifdef HAVE_DLOPEN | 560 #ifdef HAVE_DLOPEN |
| 577 {"setdlopenflags", sys_setdlopenflags, 1, | 561 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS, |
| 578 setdlopenflags_doc}, | 562 setdlopenflags_doc}, |
| 579 #endif | 563 #endif |
| 580 {"setprofile", sys_setprofile, 0, setprofile_doc}, | 564 {"setprofile", sys_setprofile, METH_OLDARGS, setprofile_doc}, |
| 581 {"setrecursionlimit", sys_setrecursionlimit, 1, | 565 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS, |
| 582 setrecursionlimit_doc}, | 566 setrecursionlimit_doc}, |
| 583 {"settrace", sys_settrace, 0, settrace_doc}, | 567 {"settrace", sys_settrace, METH_OLDARGS, settrace_doc}, |
| 584 {NULL, NULL} /* sentinel */ | 568 {NULL, NULL} /* sentinel */ |
| 585 }; | 569 }; |
| 586 | 570 |
| 587 static PyObject * | 571 static PyObject * |
| 588 list_builtin_module_names(void) | 572 list_builtin_module_names(void) |
