Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 14308:b8b3f76ffd51 legacy-trunk
add user-modifiable recursion_limit
ceval.c:
define recurion_limit (static), default value is 2500
define Py_GetRecursionLimit and Py_SetRecursionLimit
raise RuntimeError if limit is exceeded
PC/config.h:
remove plat-specific definition
sysmodule.c:
add sys.(get|set)recursionlimit
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Thu, 31 Aug 2000 19:23:01 +0000 |
| parents | e5253b692e9f |
| children | 6f6f965c5e2d |
comparison
equal
deleted
inserted
replaced
| 14307:b24db770dffd | 14308:b8b3f76ffd51 |
|---|---|
| 197 "setcheckinterval(n)\n\ | 197 "setcheckinterval(n)\n\ |
| 198 \n\ | 198 \n\ |
| 199 Tell the Python interpreter to check for asynchronous events every\n\ | 199 Tell the Python interpreter to check for asynchronous events every\n\ |
| 200 n instructions. This also affects how often thread switches occur."; | 200 n instructions. This also affects how often thread switches occur."; |
| 201 | 201 |
| 202 static PyObject * | |
| 203 sys_setrecursionlimit(PyObject *self, PyObject *args) | |
| 204 { | |
| 205 int new_limit; | |
| 206 if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit)) | |
| 207 return NULL; | |
| 208 if (new_limit <= 0) { | |
| 209 PyErr_SetString(PyExc_ValueError, | |
| 210 "recursion limit must be positive"); | |
| 211 return NULL; | |
| 212 } | |
| 213 Py_SetRecursionLimit(new_limit); | |
| 214 Py_INCREF(Py_None); | |
| 215 return Py_None; | |
| 216 } | |
| 217 | |
| 218 static char setrecursionlimit_doc[] = | |
| 219 "setrecursionlimit(n)\n\ | |
| 220 \n\ | |
| 221 Set the maximum depth of the Python interpreter stack to n. This\n\ | |
| 222 limit prevents infinite recursion from causing an overflow of the C\n\ | |
| 223 stack and crashing Python. The highest possible limit is platform-\n\ | |
| 224 dependent."; | |
| 225 | |
| 226 static PyObject * | |
| 227 sys_getrecursionlimit(PyObject *self, PyObject *args) | |
| 228 { | |
| 229 if (!PyArg_ParseTuple(args, ":getrecursionlimit")) | |
| 230 return NULL; | |
| 231 return PyInt_FromLong(Py_GetRecursionLimit()); | |
| 232 } | |
| 233 | |
| 234 static char getrecursionlimit_doc[] = | |
| 235 "getrecursionlimit()\n\ | |
| 236 \n\ | |
| 237 Return the current value of the recursion limit, the maximum depth\n\ | |
| 238 of the Python interpreter stack. This limit prevents infinite\n\ | |
| 239 recursion from causing an overflow of the C stack and crashing Python."; | |
| 240 | |
| 202 #ifdef USE_MALLOPT | 241 #ifdef USE_MALLOPT |
| 203 /* Link with -lmalloc (or -lmpc) on an SGI */ | 242 /* Link with -lmalloc (or -lmpc) on an SGI */ |
| 204 #include <malloc.h> | 243 #include <malloc.h> |
| 205 | 244 |
| 206 static PyObject * | 245 static PyObject * |
| 266 | 305 |
| 267 static PyMethodDef sys_methods[] = { | 306 static PyMethodDef sys_methods[] = { |
| 268 /* Might as well keep this in alphabetic order */ | 307 /* Might as well keep this in alphabetic order */ |
| 269 {"exc_info", sys_exc_info, 1, exc_info_doc}, | 308 {"exc_info", sys_exc_info, 1, exc_info_doc}, |
| 270 {"exit", sys_exit, 0, exit_doc}, | 309 {"exit", sys_exit, 0, exit_doc}, |
| 271 {"getdefaultencoding", sys_getdefaultencoding, 1, getdefaultencoding_doc}, | 310 {"getdefaultencoding", sys_getdefaultencoding, 1, |
| 311 getdefaultencoding_doc}, | |
| 272 #ifdef COUNT_ALLOCS | 312 #ifdef COUNT_ALLOCS |
| 273 {"getcounts", sys_getcounts, 1}, | 313 {"getcounts", sys_getcounts, 1}, |
| 274 #endif | 314 #endif |
| 275 #ifdef DYNAMIC_EXECUTION_PROFILE | 315 #ifdef DYNAMIC_EXECUTION_PROFILE |
| 276 {"getdxp", _Py_GetDXProfile, 1}, | 316 {"getdxp", _Py_GetDXProfile, 1}, |
| 278 #ifdef Py_TRACE_REFS | 318 #ifdef Py_TRACE_REFS |
| 279 {"getobjects", _Py_GetObjects, 1}, | 319 {"getobjects", _Py_GetObjects, 1}, |
| 280 {"gettotalrefcount", sys_gettotalrefcount, 1}, | 320 {"gettotalrefcount", sys_gettotalrefcount, 1}, |
| 281 #endif | 321 #endif |
| 282 {"getrefcount", sys_getrefcount, 1, getrefcount_doc}, | 322 {"getrefcount", sys_getrefcount, 1, getrefcount_doc}, |
| 323 {"getrecursionlimit", sys_getrecursionlimit, 1, | |
| 324 getrecursionlimit_doc}, | |
| 283 #ifdef USE_MALLOPT | 325 #ifdef USE_MALLOPT |
| 284 {"mdebug", sys_mdebug, 1}, | 326 {"mdebug", sys_mdebug, 1}, |
| 285 #endif | 327 #endif |
| 286 {"setdefaultencoding", sys_setdefaultencoding, 1, setdefaultencoding_doc}, | 328 {"setdefaultencoding", sys_setdefaultencoding, 1, |
| 287 {"setcheckinterval", sys_setcheckinterval, 1, setcheckinterval_doc}, | 329 setdefaultencoding_doc}, |
| 330 {"setcheckinterval", sys_setcheckinterval, 1, | |
| 331 setcheckinterval_doc}, | |
| 288 {"setprofile", sys_setprofile, 0, setprofile_doc}, | 332 {"setprofile", sys_setprofile, 0, setprofile_doc}, |
| 333 {"setrecursionlimit", sys_setrecursionlimit, 1, | |
| 334 setrecursionlimit_doc}, | |
| 289 {"settrace", sys_settrace, 0, settrace_doc}, | 335 {"settrace", sys_settrace, 0, settrace_doc}, |
| 290 {NULL, NULL} /* sentinel */ | 336 {NULL, NULL} /* sentinel */ |
| 291 }; | 337 }; |
| 292 | 338 |
| 293 static PyObject * | 339 static PyObject * |
| 374 Functions:\n\ | 420 Functions:\n\ |
| 375 \n\ | 421 \n\ |
| 376 exc_info() -- return thread-safe information about the current exception\n\ | 422 exc_info() -- return thread-safe information about the current exception\n\ |
| 377 exit() -- exit the interpreter by raising SystemExit\n\ | 423 exit() -- exit the interpreter by raising SystemExit\n\ |
| 378 getrefcount() -- return the reference count for an object (plus one :-)\n\ | 424 getrefcount() -- return the reference count for an object (plus one :-)\n\ |
| 425 getrecursionlimit() -- return the max recursion depth for the interpreter\n\ | |
| 379 setcheckinterval() -- control how often the interpreter checks for events\n\ | 426 setcheckinterval() -- control how often the interpreter checks for events\n\ |
| 380 setprofile() -- set the global profiling function\n\ | 427 setprofile() -- set the global profiling function\n\ |
| 428 setrecursionlimit() -- set the max recursion depth for the interpreter\n\ | |
| 381 settrace() -- set the global debug tracing function\n\ | 429 settrace() -- set the global debug tracing function\n\ |
| 382 " | 430 " |
| 383 #endif | 431 #endif |
| 384 /* end of sys_doc */ ; | 432 /* end of sys_doc */ ; |
| 385 | 433 |
