diff -r 1638360eea41 Python/sysmodule.c --- a/Python/sysmodule.c Sat Jan 11 22:22:21 2014 -0800 +++ b/Python/sysmodule.c Sun Jan 12 12:19:00 2014 +0100 @@ -37,6 +37,11 @@ extern const char *PyWin_DLLVersionStrin #include #endif +/*[clinic input] +module sys +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + _Py_IDENTIFIER(_); _Py_IDENTIFIER(__sizeof__); _Py_IDENTIFIER(buffer); @@ -159,8 +164,25 @@ finally: return ret; } +/*[clinic input] +sys.displayhook + + object: 'O' + / + +Print an object to sys.stdout and also save it in builtins._ +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_displayhook__doc__, +"displayhook(object)\n" +"Print an object to sys.stdout and also save it in builtins._"); + +#define SYS_DISPLAYHOOK_METHODDEF \ + {"displayhook", (PyCFunction)sys_displayhook, METH_O, sys_displayhook__doc__}, + static PyObject * -sys_displayhook(PyObject *self, PyObject *o) +sys_displayhook(PyModuleDef *module, PyObject *object) +/*[clinic end generated code: checksum=b7e504788a4da17cdadee42be5cbd96059b1526e]*/ { PyObject *outf; PyInterpreterState *interp = PyThreadState_GET()->interp; @@ -178,7 +200,7 @@ sys_displayhook(PyObject *self, PyObject /* Print value except if None */ /* After printing, also assign to '_' */ /* Before, set '_' to None to avoid recursion */ - if (o == Py_None) { + if (object == Py_None) { Py_INCREF(Py_None); return Py_None; } @@ -189,12 +211,12 @@ sys_displayhook(PyObject *self, PyObject PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; } - if (PyFile_WriteObject(o, outf, 0) != 0) { + if (PyFile_WriteObject(object, outf, 0) != 0) { if (PyErr_ExceptionMatches(PyExc_UnicodeEncodeError)) { - /* repr(o) is not encodable to sys.stdout.encoding with + /* repr(object) is not encodable to sys.stdout.encoding with * sys.stdout.errors error handler (which is probably 'strict') */ PyErr_Clear(); - err = sys_displayhook_unencodable(outf, o); + err = sys_displayhook_unencodable(outf, object); if (err) return NULL; } @@ -209,37 +231,97 @@ sys_displayhook(PyObject *self, PyObject } if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0) return NULL; - if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0) + if (_PyObject_SetAttrId(builtins, &PyId__, object) != 0) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } -PyDoc_STRVAR(displayhook_doc, -"displayhook(object) -> None\n" + +/*[clinic input] +sys.excepthook + + exctype: 'O' + value: 'O' + traceback: 'O' + / + +Handle an exception by displaying it with a traceback on sys.stderr. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_excepthook__doc__, +"excepthook(exctype, value, traceback)\n" +"Handle an exception by displaying it with a traceback on sys.stderr."); + +#define SYS_EXCEPTHOOK_METHODDEF \ + {"excepthook", (PyCFunction)sys_excepthook, METH_VARARGS, sys_excepthook__doc__}, + +static PyObject * +sys_excepthook_impl(PyModuleDef *module, PyObject *exctype, PyObject *value, PyObject *traceback); + +static PyObject * +sys_excepthook(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *exctype; + PyObject *value; + PyObject *traceback; + + if (!PyArg_ParseTuple(args, + "OOO:excepthook", + &exctype, &value, &traceback)) + goto exit; + return_value = sys_excepthook_impl(module, exctype, value, traceback); + +exit: + return return_value; +} + +static PyObject * +sys_excepthook_impl(PyModuleDef *module, PyObject *exctype, PyObject *value, PyObject *traceback) +/*[clinic end generated code: checksum=8097306a8d8ec07d74adc4e902af54dd74d3b5bf]*/ +{ + PyErr_Display(exctype, value, traceback); + Py_RETURN_NONE; +} + + +/*[clinic input] +sys.exc_info + +Return current exception information. + +This is the type, value and traceback of the most recent exception +caught by an except clause in the current stack frame or +in an older stack frame. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_exc_info__doc__, +"exc_info()\n" +"Return current exception information.\n" "\n" -"Print an object to sys.stdout and also save it in builtins._\n" -); +"This is the type, value and traceback of the most recent exception\n" +"caught by an except clause in the current stack frame or\n" +"in an older stack frame."); + +#define SYS_EXC_INFO_METHODDEF \ + {"exc_info", (PyCFunction)sys_exc_info, METH_NOARGS, sys_exc_info__doc__}, static PyObject * -sys_excepthook(PyObject* self, PyObject* args) +sys_exc_info_impl(PyModuleDef *module); + +static PyObject * +sys_exc_info(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) { - PyObject *exc, *value, *tb; - if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb)) - return NULL; - PyErr_Display(exc, value, tb); - Py_INCREF(Py_None); - return Py_None; + PyObject *return_value = NULL; + + return_value = sys_exc_info_impl(module); + + return return_value; } -PyDoc_STRVAR(excepthook_doc, -"excepthook(exctype, value, traceback) -> None\n" -"\n" -"Handle an exception by displaying it with a traceback on sys.stderr.\n" -); - static PyObject * -sys_exc_info(PyObject *self, PyObject *noargs) +sys_exc_info_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=69a1f22b8b3a6d934354032cddba0e754ca52d32]*/ { PyThreadState *tstate; tstate = PyThreadState_GET(); @@ -251,50 +333,107 @@ sys_exc_info(PyObject *self, PyObject *n tstate->exc_traceback : Py_None); } -PyDoc_STRVAR(exc_info_doc, -"exc_info() -> (type, value, traceback)\n\ -\n\ -Return information about the most recent exception caught by an except\n\ -clause in the current stack frame or in an older stack frame." -); + +/*[clinic input] +sys.exit + + status: 'O' + / + +Exit the interpreter by raising SystemExit(status). + +If the status is omitted or None, it defaults to zero (i.e., success). +If the status is an integer, it will be used as the system exit status. +If it is another kind of object, it will be printed and the system +exit status will be one (i.e., failure). +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_exit__doc__, +"exit(status)\n" +"Exit the interpreter by raising SystemExit(status).\n" +"\n" +"If the status is omitted or None, it defaults to zero (i.e., success).\n" +"If the status is an integer, it will be used as the system exit status.\n" +"If it is another kind of object, it will be printed and the system\n" +"exit status will be one (i.e., failure)."); + +#define SYS_EXIT_METHODDEF \ + {"exit", (PyCFunction)sys_exit, METH_O, sys_exit__doc__}, static PyObject * -sys_exit(PyObject *self, PyObject *args) +sys_exit(PyModuleDef *module, PyObject *status) +/*[clinic end generated code: checksum=dffe56b2c4dc7caf5eb9ec1c244c0851bf0a1d2e]*/ { - PyObject *exit_code = 0; - if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code)) - return NULL; /* Raise SystemExit so callers may catch it or clean up. */ - PyErr_SetObject(PyExc_SystemExit, exit_code); + PyErr_SetObject(PyExc_SystemExit, status); return NULL; } -PyDoc_STRVAR(exit_doc, -"exit([status])\n\ -\n\ -Exit the interpreter by raising SystemExit(status).\n\ -If the status is omitted or None, it defaults to zero (i.e., success).\n\ -If the status is an integer, it will be used as the system exit status.\n\ -If it is another kind of object, it will be printed and the system\n\ -exit status will be one (i.e., failure)." -); - + + +/*[clinic input] +sys.getdefaultencoding + +Return the current default string encoding used by the Unicode implementation. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getdefaultencoding__doc__, +"getdefaultencoding()\n" +"Return the current default string encoding used by the Unicode implementation."); + +#define SYS_GETDEFAULTENCODING_METHODDEF \ + {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS, sys_getdefaultencoding__doc__}, static PyObject * -sys_getdefaultencoding(PyObject *self) +sys_getdefaultencoding_impl(PyModuleDef *module); + +static PyObject * +sys_getdefaultencoding(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getdefaultencoding_impl(module); + + return return_value; +} + +static PyObject * +sys_getdefaultencoding_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=2c130f2056ee57c4b947cd380d8bc26a81f4c829]*/ { return PyUnicode_FromString(PyUnicode_GetDefaultEncoding()); } -PyDoc_STRVAR(getdefaultencoding_doc, -"getdefaultencoding() -> string\n\ -\n\ -Return the current default string encoding used by the Unicode \n\ -implementation." -); + +/*[clinic input] +sys.getfilesystemencoding + +Return the encoding used to convert Unicode filenames in operating system filenames. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getfilesystemencoding__doc__, +"getfilesystemencoding()\n" +"Return the encoding used to convert Unicode filenames in operating system filenames."); + +#define SYS_GETFILESYSTEMENCODING_METHODDEF \ + {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding, METH_NOARGS, sys_getfilesystemencoding__doc__}, static PyObject * -sys_getfilesystemencoding(PyObject *self) +sys_getfilesystemencoding_impl(PyModuleDef *module); + +static PyObject * +sys_getfilesystemencoding(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getfilesystemencoding_impl(module); + + return return_value; +} + +static PyObject * +sys_getfilesystemencoding_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=756ec0c84b8b3d471e5fb6ca2dc3884cbd1629e1]*/ { if (Py_FileSystemDefaultEncoding) return PyUnicode_FromString(Py_FileSystemDefaultEncoding); @@ -303,39 +442,68 @@ sys_getfilesystemencoding(PyObject *self return NULL; } -PyDoc_STRVAR(getfilesystemencoding_doc, -"getfilesystemencoding() -> string\n\ -\n\ -Return the encoding used to convert Unicode filenames in\n\ -operating system filenames." -); + +/*[clinic input] +sys.intern + + string: 'U' + / + +``Intern'' the given string. + +This enters the string in the (global) table of interned strings whose purpose +is to speed up dictionary lookups. +Return the string itself or the previously interned string object with the +same value. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_intern__doc__, +"intern(string)\n" +"``Intern\'\' the given string.\n" +"\n" +"This enters the string in the (global) table of interned strings whose purpose\n" +"is to speed up dictionary lookups.\n" +"Return the string itself or the previously interned string object with the\n" +"same value."); + +#define SYS_INTERN_METHODDEF \ + {"intern", (PyCFunction)sys_intern, METH_VARARGS, sys_intern__doc__}, static PyObject * -sys_intern(PyObject *self, PyObject *args) +sys_intern_impl(PyModuleDef *module, PyObject *string); + +static PyObject * +sys_intern(PyModuleDef *module, PyObject *args) { - PyObject *s; - if (!PyArg_ParseTuple(args, "U:intern", &s)) - return NULL; - if (PyUnicode_CheckExact(s)) { - Py_INCREF(s); - PyUnicode_InternInPlace(&s); - return s; + PyObject *return_value = NULL; + PyObject *string; + + if (!PyArg_ParseTuple(args, + "U:intern", + &string)) + goto exit; + return_value = sys_intern_impl(module, string); + +exit: + return return_value; +} + +static PyObject * +sys_intern_impl(PyModuleDef *module, PyObject *string) +/*[clinic end generated code: checksum=ed3ae3a42cf8272a9648ff4d9a573c2e0c9530f6]*/ +{ + if (PyUnicode_CheckExact(string)) { + Py_INCREF(string); + PyUnicode_InternInPlace(&string); + return string; } else { PyErr_Format(PyExc_TypeError, - "can't intern %.400s", s->ob_type->tp_name); + "can't intern %.400s", string->ob_type->tp_name); return NULL; } } -PyDoc_STRVAR(intern_doc, -"intern(string) -> string\n\ -\n\ -``Intern'' the given string. This enters the string in the (global)\n\ -table of interned strings whose purpose is to speed up dictionary lookups.\n\ -Return the string itself or the previously interned string object with the\n\ -same value."); - /* * Cached interned string objects used for calling the profile and @@ -446,28 +614,76 @@ trace_trampoline(PyObject *self, PyFrame return 0; } + +/*[clinic input] +sys.settrace + + function: 'O' + / + +Set the global debug tracing function. + +It will be called on each function call. +See the debugger chapter in the library manual. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_settrace__doc__, +"settrace(function)\n" +"Set the global debug tracing function.\n" +"\n" +"It will be called on each function call.\n" +"See the debugger chapter in the library manual."); + +#define SYS_SETTRACE_METHODDEF \ + {"settrace", (PyCFunction)sys_settrace, METH_O, sys_settrace__doc__}, + static PyObject * -sys_settrace(PyObject *self, PyObject *args) +sys_settrace(PyModuleDef *module, PyObject *function) +/*[clinic end generated code: checksum=100a87c90105c5373ca043036bafbda0ba81a487]*/ { if (trace_init() == -1) return NULL; - if (args == Py_None) + if (function == Py_None) PyEval_SetTrace(NULL, NULL); else - PyEval_SetTrace(trace_trampoline, args); - Py_INCREF(Py_None); - return Py_None; + PyEval_SetTrace(trace_trampoline, function); + Py_RETURN_NONE; } -PyDoc_STRVAR(settrace_doc, -"settrace(function)\n\ -\n\ -Set the global debug tracing function. It will be called on each\n\ -function call. See the debugger chapter in the library manual." -); + +/*[clinic input] +sys.gettrace + +Return the global debug tracing function set with sys.settrace(). + +See the debugger chapter in the library manual. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_gettrace__doc__, +"gettrace()\n" +"Return the global debug tracing function set with sys.settrace().\n" +"\n" +"See the debugger chapter in the library manual."); + +#define SYS_GETTRACE_METHODDEF \ + {"gettrace", (PyCFunction)sys_gettrace, METH_NOARGS, sys_gettrace__doc__}, static PyObject * -sys_gettrace(PyObject *self, PyObject *args) +sys_gettrace_impl(PyModuleDef *module); + +static PyObject * +sys_gettrace(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_gettrace_impl(module); + + return return_value; +} + +static PyObject * +sys_gettrace_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=781877b9f1d66cacc12d9265448725995fafd90f]*/ { PyThreadState *tstate = PyThreadState_GET(); PyObject *temp = tstate->c_traceobj; @@ -478,35 +694,76 @@ sys_gettrace(PyObject *self, PyObject *a return temp; } -PyDoc_STRVAR(gettrace_doc, -"gettrace()\n\ -\n\ -Return the global debug tracing function set with sys.settrace.\n\ -See the debugger chapter in the library manual." -); + +/*[clinic input] +sys.setprofile + + function: 'O' + / + +Set the profiling function. + +It will be called on each function call and return. +See the profiler chapter in the library manual. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_setprofile__doc__, +"setprofile(function)\n" +"Set the profiling function.\n" +"\n" +"It will be called on each function call and return.\n" +"See the profiler chapter in the library manual."); + +#define SYS_SETPROFILE_METHODDEF \ + {"setprofile", (PyCFunction)sys_setprofile, METH_O, sys_setprofile__doc__}, static PyObject * -sys_setprofile(PyObject *self, PyObject *args) +sys_setprofile(PyModuleDef *module, PyObject *function) +/*[clinic end generated code: checksum=0b028aa374c9946cdd1fdbebe11ad740503910a5]*/ { if (trace_init() == -1) return NULL; - if (args == Py_None) + if (function == Py_None) PyEval_SetProfile(NULL, NULL); else - PyEval_SetProfile(profile_trampoline, args); - Py_INCREF(Py_None); - return Py_None; + PyEval_SetProfile(profile_trampoline, function); + Py_RETURN_NONE; } -PyDoc_STRVAR(setprofile_doc, -"setprofile(function)\n\ -\n\ -Set the profiling function. It will be called on each function call\n\ -and return. See the profiler chapter in the library manual." -); + +/*[clinic input] +sys.getprofile + +Return the profiling function set with sys.setprofile(). + +See the profiler chapter in the library manual. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getprofile__doc__, +"getprofile()\n" +"Return the profiling function set with sys.setprofile().\n" +"\n" +"See the profiler chapter in the library manual."); + +#define SYS_GETPROFILE_METHODDEF \ + {"getprofile", (PyCFunction)sys_getprofile, METH_NOARGS, sys_getprofile__doc__}, static PyObject * -sys_getprofile(PyObject *self, PyObject *args) +sys_getprofile_impl(PyModuleDef *module); + +static PyObject * +sys_getprofile(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getprofile_impl(module); + + return return_value; +} + +static PyObject * +sys_getprofile_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=18e95ad527901b05a8f965bfa56859a43d47db19]*/ { PyThreadState *tstate = PyThreadState_GET(); PyObject *temp = tstate->c_profileobj; @@ -517,38 +774,91 @@ sys_getprofile(PyObject *self, PyObject return temp; } -PyDoc_STRVAR(getprofile_doc, -"getprofile()\n\ -\n\ -Return the profiling function set with sys.setprofile.\n\ -See the profiler chapter in the library manual." -); static int _check_interval = 100; +/*[clinic input] +sys.setcheckinterval + + n: 'i' + / + +Tell the Python interpreter to check for asynchronous events every n instructions. + +This also affects how often thread switches occur. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_setcheckinterval__doc__, +"setcheckinterval(n)\n" +"Tell the Python interpreter to check for asynchronous events every n instructions.\n" +"\n" +"This also affects how often thread switches occur."); + +#define SYS_SETCHECKINTERVAL_METHODDEF \ + {"setcheckinterval", (PyCFunction)sys_setcheckinterval, METH_VARARGS, sys_setcheckinterval__doc__}, + static PyObject * -sys_setcheckinterval(PyObject *self, PyObject *args) +sys_setcheckinterval_impl(PyModuleDef *module, int n); + +static PyObject * +sys_setcheckinterval(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int n; + + if (!PyArg_ParseTuple(args, + "i:setcheckinterval", + &n)) + goto exit; + return_value = sys_setcheckinterval_impl(module, n); + +exit: + return return_value; +} + +static PyObject * +sys_setcheckinterval_impl(PyModuleDef *module, int n) +/*[clinic end generated code: checksum=420da0ad4a9d31d249f05dcbd360a9ac778ec08b]*/ { if (PyErr_WarnEx(PyExc_DeprecationWarning, "sys.getcheckinterval() and sys.setcheckinterval() " "are deprecated. Use sys.setswitchinterval() " "instead.", 1) < 0) return NULL; - if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_check_interval)) - return NULL; - Py_INCREF(Py_None); - return Py_None; + _check_interval = n; + Py_RETURN_NONE; } -PyDoc_STRVAR(setcheckinterval_doc, -"setcheckinterval(n)\n\ -\n\ -Tell the Python interpreter to check for asynchronous events every\n\ -n instructions. This also affects how often thread switches occur." -); + +/*[clinic input] +sys.getcheckinterval + +Return the current check interval; see sys.setcheckinterval(). +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getcheckinterval__doc__, +"getcheckinterval()\n" +"Return the current check interval; see sys.setcheckinterval()."); + +#define SYS_GETCHECKINTERVAL_METHODDEF \ + {"getcheckinterval", (PyCFunction)sys_getcheckinterval, METH_NOARGS, sys_getcheckinterval__doc__}, static PyObject * -sys_getcheckinterval(PyObject *self, PyObject *args) +sys_getcheckinterval_impl(PyModuleDef *module); + +static PyObject * +sys_getcheckinterval(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getcheckinterval_impl(module); + + return return_value; +} + +static PyObject * +sys_getcheckinterval_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=9102bf2d40bc23155aba6e48dda786242d13cde9]*/ { if (PyErr_WarnEx(PyExc_DeprecationWarning, "sys.getcheckinterval() and sys.setcheckinterval() " @@ -558,102 +868,224 @@ sys_getcheckinterval(PyObject *self, PyO return PyLong_FromLong(_check_interval); } -PyDoc_STRVAR(getcheckinterval_doc, -"getcheckinterval() -> current check interval; see setcheckinterval()." -); #ifdef WITH_THREAD + +/*[clinic input] +sys.setswitchinterval + + interval: 'd' + / + +Set the ideal thread switching delay inside the Python interpreter. + +The actual frequency of switching threads can be lower if the +interpreter executes long sequences of uninterruptible code +(this is implementation-specific and workload-dependent). + +The parameter must represent the desired switching delay in seconds +A typical value is 0.005 (5 milliseconds). +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_setswitchinterval__doc__, +"setswitchinterval(interval)\n" +"Set the ideal thread switching delay inside the Python interpreter.\n" +"\n" +"The actual frequency of switching threads can be lower if the\n" +"interpreter executes long sequences of uninterruptible code\n" +"(this is implementation-specific and workload-dependent).\n" +"\n" +"The parameter must represent the desired switching delay in seconds\n" +"A typical value is 0.005 (5 milliseconds)."); + +#define SYS_SETSWITCHINTERVAL_METHODDEF \ + {"setswitchinterval", (PyCFunction)sys_setswitchinterval, METH_VARARGS, sys_setswitchinterval__doc__}, + static PyObject * -sys_setswitchinterval(PyObject *self, PyObject *args) +sys_setswitchinterval_impl(PyModuleDef *module, double interval); + +static PyObject * +sys_setswitchinterval(PyModuleDef *module, PyObject *args) { - double d; - if (!PyArg_ParseTuple(args, "d:setswitchinterval", &d)) - return NULL; - if (d <= 0.0) { + PyObject *return_value = NULL; + double interval; + + if (!PyArg_ParseTuple(args, + "d:setswitchinterval", + &interval)) + goto exit; + return_value = sys_setswitchinterval_impl(module, interval); + +exit: + return return_value; +} + +static PyObject * +sys_setswitchinterval_impl(PyModuleDef *module, double interval) +/*[clinic end generated code: checksum=166cf973cf81578b01ca42f15add07e8969af89b]*/ +{ + if (interval <= 0.0) { PyErr_SetString(PyExc_ValueError, "switch interval must be strictly positive"); return NULL; } - _PyEval_SetSwitchInterval((unsigned long) (1e6 * d)); - Py_INCREF(Py_None); - return Py_None; + _PyEval_SetSwitchInterval((unsigned long) (1e6 * interval)); + Py_RETURN_NONE; } -PyDoc_STRVAR(setswitchinterval_doc, -"setswitchinterval(n)\n\ -\n\ -Set the ideal thread switching delay inside the Python interpreter\n\ -The actual frequency of switching threads can be lower if the\n\ -interpreter executes long sequences of uninterruptible code\n\ -(this is implementation-specific and workload-dependent).\n\ -\n\ -The parameter must represent the desired switching delay in seconds\n\ -A typical value is 0.005 (5 milliseconds)." -); + +/*[clinic input] +sys.getswitchinterval + +Return the current thread switch interval; see sys.setswitchinterval(). +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getswitchinterval__doc__, +"getswitchinterval()\n" +"Return the current thread switch interval; see sys.setswitchinterval()."); + +#define SYS_GETSWITCHINTERVAL_METHODDEF \ + {"getswitchinterval", (PyCFunction)sys_getswitchinterval, METH_NOARGS, sys_getswitchinterval__doc__}, static PyObject * -sys_getswitchinterval(PyObject *self, PyObject *args) +sys_getswitchinterval_impl(PyModuleDef *module); + +static PyObject * +sys_getswitchinterval(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getswitchinterval_impl(module); + + return return_value; +} + +static PyObject * +sys_getswitchinterval_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=45465a30be3f522a15cb92391bc5e230bb525719]*/ { return PyFloat_FromDouble(1e-6 * _PyEval_GetSwitchInterval()); } -PyDoc_STRVAR(getswitchinterval_doc, -"getswitchinterval() -> current thread switch interval; see setswitchinterval()." -); - #endif /* WITH_THREAD */ + #ifdef WITH_TSC + +/*[clinic input] +sys.settscdump + + on: 'i' + / + +If on is true, tell the Python interpreter to dump VM measurements to stderr. + +If on is false, turn off dump. The measurements are based on the +processor's time-stamp counter. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_settscdump__doc__, +"settscdump(on)\n" +"If on is true, tell the Python interpreter to dump VM measurements to stderr.\n" +"\n" +"If on is false, turn off dump. The measurements are based on the\n" +"processor\'s time-stamp counter."); + +#define SYS_SETTSCDUMP_METHODDEF \ + {"settscdump", (PyCFunction)sys_settscdump, METH_VARARGS, sys_settscdump__doc__}, + static PyObject * -sys_settscdump(PyObject *self, PyObject *args) +sys_settscdump_impl(PyModuleDef *module, int on); + +static PyObject * +sys_settscdump(PyModuleDef *module, PyObject *args) { - int bool; + PyObject *return_value = NULL; + int on; + + if (!PyArg_ParseTuple(args, + "i:settscdump", + &on)) + goto exit; + return_value = sys_settscdump_impl(module, on); + +exit: + return return_value; +} + +static PyObject * +sys_settscdump_impl(PyModuleDef *module, int on) +/*[clinic end generated code: checksum=214b9f621d49c8e864e38ed774a1466adb47ba34]*/ +{ PyThreadState *tstate = PyThreadState_Get(); - if (!PyArg_ParseTuple(args, "i:settscdump", &bool)) - return NULL; - if (bool) + if (on) tstate->interp->tscdump = 1; else tstate->interp->tscdump = 0; - Py_INCREF(Py_None); - return Py_None; - + Py_RETURN_NONE; } -PyDoc_STRVAR(settscdump_doc, -"settscdump(bool)\n\ -\n\ -If true, tell the Python interpreter to dump VM measurements to\n\ -stderr. If false, turn off dump. The measurements are based on the\n\ -processor's time-stamp counter." -); #endif /* TSC */ + +/*[clinic input] +sys.setrecursionlimit + + limit: 'i' + / + +Set the maximum depth of the Python interpreter stack to limit. + +This limit prevents infinite recursion from causing an overflow of the C +stack and crashing Python. The highest possible limit is platform-dependent. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_setrecursionlimit__doc__, +"setrecursionlimit(limit)\n" +"Set the maximum depth of the Python interpreter stack to limit.\n" +"\n" +"This limit prevents infinite recursion from causing an overflow of the C\n" +"stack and crashing Python. The highest possible limit is platform-dependent."); + +#define SYS_SETRECURSIONLIMIT_METHODDEF \ + {"setrecursionlimit", (PyCFunction)sys_setrecursionlimit, METH_VARARGS, sys_setrecursionlimit__doc__}, + static PyObject * -sys_setrecursionlimit(PyObject *self, PyObject *args) +sys_setrecursionlimit_impl(PyModuleDef *module, int limit); + +static PyObject * +sys_setrecursionlimit(PyModuleDef *module, PyObject *args) { - int new_limit; - if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit)) - return NULL; - if (new_limit <= 0) { + PyObject *return_value = NULL; + int limit; + + if (!PyArg_ParseTuple(args, + "i:setrecursionlimit", + &limit)) + goto exit; + return_value = sys_setrecursionlimit_impl(module, limit); + +exit: + return return_value; +} + +static PyObject * +sys_setrecursionlimit_impl(PyModuleDef *module, int limit) +/*[clinic end generated code: checksum=0c7f94c077eef3109b1525390a9164672afac0ca]*/ +{ + if (limit <= 0) { PyErr_SetString(PyExc_ValueError, "recursion limit must be positive"); return NULL; } - Py_SetRecursionLimit(new_limit); - Py_INCREF(Py_None); - return Py_None; + Py_SetRecursionLimit(limit); + Py_RETURN_NONE; } + static PyTypeObject Hash_InfoType; -PyDoc_STRVAR(hash_info_doc, -"hash_info\n\ -\n\ -A struct sequence providing parameters used for computing\n\ -hashes. The attributes are read only."); - static PyStructSequence_Field hash_info_fields[] = { {"width", "width of the type used for hashing, in bits"}, {"modulus", "prime number giving the modulus on which the hash " @@ -669,6 +1101,12 @@ static PyStructSequence_Field hash_info_ {NULL, NULL} }; +PyDoc_STRVAR(hash_info_doc, +"hash_info\n\ +\n\ +A struct sequence providing parameters used for computing\n\ +hashes. The attributes are read only."); + static PyStructSequence_Desc hash_info_desc = { "sys.hash_info", hash_info_doc, @@ -712,35 +1150,47 @@ get_hash_info(void) } -PyDoc_STRVAR(setrecursionlimit_doc, -"setrecursionlimit(n)\n\ -\n\ -Set the maximum depth of the Python interpreter stack to n. This\n\ -limit prevents infinite recursion from causing an overflow of the C\n\ -stack and crashing Python. The highest possible limit is platform-\n\ -dependent." -); +/*[clinic input] +sys.getrecursionlimit + +Return the current value of the recursion limit. + +See sys.setrecursionlimit() for details. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getrecursionlimit__doc__, +"getrecursionlimit()\n" +"Return the current value of the recursion limit.\n" +"\n" +"See sys.setrecursionlimit() for details."); + +#define SYS_GETRECURSIONLIMIT_METHODDEF \ + {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS, sys_getrecursionlimit__doc__}, static PyObject * -sys_getrecursionlimit(PyObject *self) +sys_getrecursionlimit_impl(PyModuleDef *module); + +static PyObject * +sys_getrecursionlimit(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getrecursionlimit_impl(module); + + return return_value; +} + +static PyObject * +sys_getrecursionlimit_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=5837f140506ea95e747843897d1c27914fd3d855]*/ { return PyLong_FromLong(Py_GetRecursionLimit()); } -PyDoc_STRVAR(getrecursionlimit_doc, -"getrecursionlimit()\n\ -\n\ -Return the current value of the recursion limit, the maximum depth\n\ -of the Python interpreter stack. This limit prevents infinite\n\ -recursion from causing an overflow of the C stack and crashing Python." -); #ifdef MS_WINDOWS -PyDoc_STRVAR(getwindowsversion_doc, -"getwindowsversion()\n\ -\n\ -Return information about the running version of Windows as a named tuple.\n\ -The members are named: major, minor, build, platform, service_pack,\n\ +PyDoc_STRVAR(windows_version_doc, +"The members are named: major, minor, build, platform, service_pack,\n\ service_pack_major, service_pack_minor, suite_mask, and product_type. For\n\ backward compatibility, only the first 5 items are available by indexing.\n\ All elements are numbers, except service_pack which is a string. Platform\n\ @@ -766,15 +1216,58 @@ static PyStructSequence_Field windows_ve static PyStructSequence_Desc windows_version_desc = { "sys.getwindowsversion", /* name */ - getwindowsversion_doc, /* doc */ + windows_version_doc, /* doc */ windows_version_fields, /* fields */ 5 /* For backward compatibility, only the first 5 items are accessible via indexing, the rest are name only */ }; +/*[clinic input] +sys.getwindowsversion + +Return information about the running version of Windows as a named tuple. + +The members are named: major, minor, build, platform, service_pack, +service_pack_major, service_pack_minor, suite_mask, and product_type. For +backward compatibility, only the first 5 items are available by indexing. +All elements are numbers, except service_pack which is a string. Platform +may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP/Vista/7, +3 for Windows CE. Product_type may be 1 for a workstation, 2 for a domain +controller, 3 for a server. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getwindowsversion__doc__, +"getwindowsversion()\n" +"Return information about the running version of Windows as a named tuple.\n" +"\n" +"The members are named: major, minor, build, platform, service_pack,\n" +"service_pack_major, service_pack_minor, suite_mask, and product_type. For\n" +"backward compatibility, only the first 5 items are available by indexing.\n" +"All elements are numbers, except service_pack which is a string. Platform\n" +"may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP/Vista/7,\n" +"3 for Windows CE. Product_type may be 1 for a workstation, 2 for a domain\n" +"controller, 3 for a server."); + +#define SYS_GETWINDOWSVERSION_METHODDEF \ + {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, sys_getwindowsversion__doc__}, + static PyObject * -sys_getwindowsversion(PyObject *self) +sys_getwindowsversion_impl(PyModuleDef *module); + +static PyObject * +sys_getwindowsversion(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getwindowsversion_impl(module); + + return return_value; +} + +static PyObject * +sys_getwindowsversion_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=741d2461c10ada26ba15453b012eea471c7ee5e0]*/ { PyObject *version; int pos = 0; @@ -807,32 +1300,101 @@ sys_getwindowsversion(PyObject *self) #endif /* MS_WINDOWS */ #ifdef HAVE_DLOPEN + +/*[clinic input] +sys.setdlopenflags + + flags: 'i' + / + +Set the flags used by the interpreter for dlopen calls. + +This is used for example when the interpreter loads extension modules. +Among other things, this will enable a lazy resolving of symbols when +importing a module, if called as sys.setdlopenflags(0). To share symbols +across extension modules, call as sys.setdlopenflags(os.RTLD_GLOBAL). +Symbolic names for the flag modules can be found in the os module +(RTLD_xxx constants, e.g. os.RTLD_LAZY). +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_setdlopenflags__doc__, +"setdlopenflags(flags)\n" +"Set the flags used by the interpreter for dlopen calls.\n" +"\n" +"This is used for example when the interpreter loads extension modules.\n" +"Among other things, this will enable a lazy resolving of symbols when\n" +"importing a module, if called as sys.setdlopenflags(0). To share symbols\n" +"across extension modules, call as sys.setdlopenflags(os.RTLD_GLOBAL).\n" +"Symbolic names for the flag modules can be found in the os module\n" +"(RTLD_xxx constants, e.g. os.RTLD_LAZY)."); + +#define SYS_SETDLOPENFLAGS_METHODDEF \ + {"setdlopenflags", (PyCFunction)sys_setdlopenflags, METH_VARARGS, sys_setdlopenflags__doc__}, + static PyObject * -sys_setdlopenflags(PyObject *self, PyObject *args) +sys_setdlopenflags_impl(PyModuleDef *module, int flags); + +static PyObject * +sys_setdlopenflags(PyModuleDef *module, PyObject *args) { - int new_val; + PyObject *return_value = NULL; + int flags; + + if (!PyArg_ParseTuple(args, + "i:setdlopenflags", + &flags)) + goto exit; + return_value = sys_setdlopenflags_impl(module, flags); + +exit: + return return_value; +} + +static PyObject * +sys_setdlopenflags_impl(PyModuleDef *module, int flags) +/*[clinic end generated code: checksum=2a821e14ddd6643292beba377e513980b98816fb]*/ +{ PyThreadState *tstate = PyThreadState_GET(); - if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val)) - return NULL; if (!tstate) return NULL; - tstate->interp->dlopenflags = new_val; - Py_INCREF(Py_None); - return Py_None; + tstate->interp->dlopenflags = flags; + Py_RETURN_NONE; } -PyDoc_STRVAR(setdlopenflags_doc, -"setdlopenflags(n) -> None\n\ -\n\ -Set the flags used by the interpreter for dlopen calls, such as when the\n\ -interpreter loads extension modules. Among other things, this will enable\n\ -a lazy resolving of symbols when importing a module, if called as\n\ -sys.setdlopenflags(0). To share symbols across extension modules, call as\n\ -sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag modules\n\ -can be found in the os module (RTLD_xxx constants, e.g. os.RTLD_LAZY)."); + +/*[clinic input] +sys.getdlopenflags + +Return the current value of the flags that are used for dlopen calls. + +The flag constants are defined in the os module. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getdlopenflags__doc__, +"getdlopenflags()\n" +"Return the current value of the flags that are used for dlopen calls.\n" +"\n" +"The flag constants are defined in the os module."); + +#define SYS_GETDLOPENFLAGS_METHODDEF \ + {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, sys_getdlopenflags__doc__}, static PyObject * -sys_getdlopenflags(PyObject *self, PyObject *args) +sys_getdlopenflags_impl(PyModuleDef *module); + +static PyObject * +sys_getdlopenflags(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getdlopenflags_impl(module); + + return return_value; +} + +static PyObject * +sys_getdlopenflags_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=27abfaec6064a30560b11fd623d2495a671c4c17]*/ { PyThreadState *tstate = PyThreadState_GET(); if (!tstate) @@ -840,43 +1402,100 @@ sys_getdlopenflags(PyObject *self, PyObj return PyLong_FromLong(tstate->interp->dlopenflags); } -PyDoc_STRVAR(getdlopenflags_doc, -"getdlopenflags() -> int\n\ -\n\ -Return the current value of the flags that are used for dlopen calls.\n\ -The flag constants are defined in the os module."); - #endif /* HAVE_DLOPEN */ + #ifdef USE_MALLOPT /* Link with -lmalloc (or -lmpc) on an SGI */ #include +/*[clinic input] +sys.mdebug + + flag: 'i' + / +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_mdebug__doc__, +"mdebug(flag)"); + +#define SYS_MDEBUG_METHODDEF \ + {"mdebug", (PyCFunction)sys_mdebug, METH_VARARGS, sys_mdebug__doc__}, + static PyObject * -sys_mdebug(PyObject *self, PyObject *args) +sys_mdebug_impl(PyModuleDef *module, int flag); + +static PyObject * +sys_mdebug(PyModuleDef *module, PyObject *args) { + PyObject *return_value = NULL; int flag; - if (!PyArg_ParseTuple(args, "i:mdebug", &flag)) - return NULL; + + if (!PyArg_ParseTuple(args, + "i:mdebug", + &flag)) + goto exit; + return_value = sys_mdebug_impl(module, flag); + +exit: + return return_value; +} + +static PyObject * +sys_mdebug_impl(PyModuleDef *module, int flag) +/*[clinic end generated code: checksum=3b05d2e7cebec87ff3708d239b51fac960dfddcb]*/ +{ mallopt(M_DEBUG, flag); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #endif /* USE_MALLOPT */ + +/*[clinic input] +sys.getsizeof + + object: 'O' + default: 'O' = NULL + +Return the size of object in bytes. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getsizeof__doc__, +"getsizeof(object, default=None)\n" +"Return the size of object in bytes."); + +#define SYS_GETSIZEOF_METHODDEF \ + {"getsizeof", (PyCFunction)sys_getsizeof, METH_VARARGS|METH_KEYWORDS, sys_getsizeof__doc__}, + static PyObject * -sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) +sys_getsizeof_impl(PyModuleDef *module, PyObject *object, PyObject *default_value); + +static PyObject * +sys_getsizeof(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"object", "default", NULL}; + PyObject *object; + PyObject *default_value = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O|O:getsizeof", _keywords, + &object, &default_value)) + goto exit; + return_value = sys_getsizeof_impl(module, object, default_value); + +exit: + return return_value; +} + +static PyObject * +sys_getsizeof_impl(PyModuleDef *module, PyObject *object, PyObject *default_value) +/*[clinic end generated code: checksum=50061680d59da82816905e962e99e8c0a82f4366]*/ { PyObject *res = NULL; static PyObject *gc_head_size = NULL; - static char *kwlist[] = {"object", "default", 0}; - PyObject *o, *dflt = NULL; PyObject *method; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof", - kwlist, &o, &dflt)) - return NULL; - /* Initialize static variable for GC head size */ if (gc_head_size == NULL) { gc_head_size = PyLong_FromSsize_t(sizeof(PyGC_Head)); @@ -885,15 +1504,15 @@ sys_getsizeof(PyObject *self, PyObject * } /* Make sure the type is initialized. float gets initialized late */ - if (PyType_Ready(Py_TYPE(o)) < 0) + if (PyType_Ready(Py_TYPE(object)) < 0) return NULL; - method = _PyObject_LookupSpecial(o, &PyId___sizeof__); + method = _PyObject_LookupSpecial(object, &PyId___sizeof__); if (method == NULL) { if (!PyErr_Occurred()) PyErr_Format(PyExc_TypeError, "Type %.100s doesn't define __sizeof__", - Py_TYPE(o)->tp_name); + Py_TYPE(object)->tp_name); } else { res = PyObject_CallFunctionObjArgs(method, NULL); @@ -901,18 +1520,18 @@ sys_getsizeof(PyObject *self, PyObject * } /* Has a default value been given */ - if ((res == NULL) && (dflt != NULL) && + if ((res == NULL) && (default_value != NULL) && PyErr_ExceptionMatches(PyExc_TypeError)) { PyErr_Clear(); - Py_INCREF(dflt); - return dflt; + Py_INCREF(default_value); + return default_value; } else if (res == NULL) return res; /* add gc_head size */ - if (PyObject_IS_GC(o)) { + if (PyObject_IS_GC(object)) { PyObject *tmp = res; res = PyNumber_Add(tmp, gc_head_size); Py_DECREF(tmp); @@ -920,49 +1539,135 @@ sys_getsizeof(PyObject *self, PyObject * return res; } -PyDoc_STRVAR(getsizeof_doc, -"getsizeof(object, default) -> int\n\ -\n\ -Return the size of object in bytes."); + +/*[clinic input] +sys.getrefcount + + object: 'O' + / + +Return the reference count of object. + +The count returned is generally one higher than you might expect, +because it includes the (temporary) reference as an argument to +getrefcount(). +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getrefcount__doc__, +"getrefcount(object)\n" +"Return the reference count of object.\n" +"\n" +"The count returned is generally one higher than you might expect,\n" +"because it includes the (temporary) reference as an argument to\n" +"getrefcount()."); + +#define SYS_GETREFCOUNT_METHODDEF \ + {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, sys_getrefcount__doc__}, static PyObject * -sys_getrefcount(PyObject *self, PyObject *arg) +sys_getrefcount(PyModuleDef *module, PyObject *object) +/*[clinic end generated code: checksum=02644da9f4528a5099c07a308b7a23b10c076233]*/ { - return PyLong_FromSsize_t(arg->ob_refcnt); + return PyLong_FromSsize_t(object->ob_refcnt); } + #ifdef Py_REF_DEBUG + +/*[clinic input] +sys.gettotalrefcount +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_gettotalrefcount__doc__, +"gettotalrefcount()"); + +#define SYS_GETTOTALREFCOUNT_METHODDEF \ + {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS, sys_gettotalrefcount__doc__}, + static PyObject * -sys_gettotalrefcount(PyObject *self) +sys_gettotalrefcount_impl(PyModuleDef *module); + +static PyObject * +sys_gettotalrefcount(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_gettotalrefcount_impl(module); + + return return_value; +} + +static PyObject * +sys_gettotalrefcount_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=aae52dbae2fa2fae2a300aa0ff40586383abece0]*/ { return PyLong_FromSsize_t(_Py_GetRefTotal()); } #endif /* Py_REF_DEBUG */ -PyDoc_STRVAR(getrefcount_doc, -"getrefcount(object) -> integer\n\ -\n\ -Return the reference count of object. The count returned is generally\n\ -one higher than you might expect, because it includes the (temporary)\n\ -reference as an argument to getrefcount()." -); + +/*[clinic input] +sys.getallocatedblocks + +Return the number of memory blocks currently allocated, regardless of their size. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getallocatedblocks__doc__, +"getallocatedblocks()\n" +"Return the number of memory blocks currently allocated, regardless of their size."); + +#define SYS_GETALLOCATEDBLOCKS_METHODDEF \ + {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS, sys_getallocatedblocks__doc__}, static PyObject * -sys_getallocatedblocks(PyObject *self) +sys_getallocatedblocks_impl(PyModuleDef *module); + +static PyObject * +sys_getallocatedblocks(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getallocatedblocks_impl(module); + + return return_value; +} + +static PyObject * +sys_getallocatedblocks_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=1fd25fed4b6f37b7b3b34e873eb2d99a43efeb0c]*/ { return PyLong_FromSsize_t(_Py_GetAllocatedBlocks()); } -PyDoc_STRVAR(getallocatedblocks_doc, -"getallocatedblocks() -> integer\n\ -\n\ -Return the number of memory blocks currently allocated, regardless of their\n\ -size." -); #ifdef COUNT_ALLOCS + +/*[clinic input] +sys.getcounts +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_getcounts__doc__, +"getcounts()"); + +#define SYS_GETCOUNTS_METHODDEF \ + {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS, sys_getcounts__doc__}, + static PyObject * -sys_getcounts(PyObject *self) +sys_getcounts_impl(PyModuleDef *module); + +static PyObject * +sys_getcounts(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys_getcounts_impl(module); + + return return_value; +} + +static PyObject * +sys_getcounts_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=f2471715a0c89ec7adedf42f2afaed34fafce328]*/ { extern PyObject *get_counts(void); @@ -970,26 +1675,61 @@ sys_getcounts(PyObject *self) } #endif -PyDoc_STRVAR(getframe_doc, -"_getframe([depth]) -> frameobject\n\ -\n\ -Return a frame object from the call stack. If optional integer depth is\n\ -given, return the frame object that many calls below the top of the stack.\n\ -If that is deeper than the call stack, ValueError is raised. The default\n\ -for depth is zero, returning the frame at the top of the call stack.\n\ -\n\ -This function should be used for internal and specialized\n\ -purposes only." -); + +/*[clinic input] +sys._getframe + + depth: 'i' = -1 + / + +Return the top frame object from the call stack. + +If optional integer depth is positive, return the frame object that many +calls below the top of the stack. If that is deeper than the call stack, +ValueError is raised. The default for depth is zero, returning the frame +at the top of the call stack. + +This function should be used for internal and specialized purposes only. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys__getframe__doc__, +"_getframe(depth=-1)\n" +"Return the top frame object from the call stack.\n" +"\n" +"If optional integer depth is positive, return the frame object that many\n" +"calls below the top of the stack. If that is deeper than the call stack,\n" +"ValueError is raised. The default for depth is zero, returning the frame\n" +"at the top of the call stack.\n" +"\n" +"This function should be used for internal and specialized purposes only."); + +#define SYS__GETFRAME_METHODDEF \ + {"_getframe", (PyCFunction)sys__getframe, METH_VARARGS, sys__getframe__doc__}, static PyObject * -sys_getframe(PyObject *self, PyObject *args) +sys__getframe_impl(PyModuleDef *module, int depth); + +static PyObject * +sys__getframe(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int depth = -1; + + if (!PyArg_ParseTuple(args, + "|i:_getframe", + &depth)) + goto exit; + return_value = sys__getframe_impl(module, depth); + +exit: + return return_value; +} + +static PyObject * +sys__getframe_impl(PyModuleDef *module, int depth) +/*[clinic end generated code: checksum=bca42ebbeffde02de5df4478f13ce2265893d205]*/ { PyFrameObject *f = PyThreadState_GET()->frame; - int depth = -1; - - if (!PyArg_ParseTuple(args, "|i:_getframe", &depth)) - return NULL; while (depth > 0 && f != NULL) { f = f->f_back; @@ -1001,41 +1741,199 @@ sys_getframe(PyObject *self, PyObject *a return NULL; } Py_INCREF(f); - return (PyObject*)f; + return (PyObject *)f; } -PyDoc_STRVAR(current_frames_doc, -"_current_frames() -> dictionary\n\ -\n\ -Return a dictionary mapping each current thread T's thread id to T's\n\ -current stack frame.\n\ -\n\ -This function should be used for specialized purposes only." -); + +/*[clinic input] +sys._current_frames + +Return a dictionary mapping each current thread T's thread id to T's current stack frame. + +This function should be used for internal and specialized purposes only. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys__current_frames__doc__, +"_current_frames()\n" +"Return a dictionary mapping each current thread T\'s thread id to T\'s current stack frame.\n" +"\n" +"This function should be used for internal and specialized purposes only."); + +#define SYS__CURRENT_FRAMES_METHODDEF \ + {"_current_frames", (PyCFunction)sys__current_frames, METH_NOARGS, sys__current_frames__doc__}, static PyObject * -sys_current_frames(PyObject *self, PyObject *noargs) +sys__current_frames_impl(PyModuleDef *module); + +static PyObject * +sys__current_frames(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys__current_frames_impl(module); + + return return_value; +} + +static PyObject * +sys__current_frames_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=a13ad66ed50952ac562c47daada573758d6c1e3d]*/ { return _PyThread_CurrentFrames(); } -PyDoc_STRVAR(call_tracing_doc, -"call_tracing(func, args) -> object\n\ -\n\ -Call func(*args), while tracing is enabled. The tracing state is\n\ -saved, and restored afterwards. This is intended to be called from\n\ -a debugger from a checkpoint, to recursively debug some other code." -); + +/*[clinic input] +sys.call_tracing + + func: 'O' + args: object(subclass_of='&PyTuple_Type') + / + +Call func(*args), while tracing is enabled. + +The tracing state is saved, and restored afterwards. +This is intended to be called from a debugger from a checkpoint, +to recursively debug some other code. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys_call_tracing__doc__, +"call_tracing(func, args)\n" +"Call func(*args), while tracing is enabled.\n" +"\n" +"The tracing state is saved, and restored afterwards.\n" +"This is intended to be called from a debugger from a checkpoint,\n" +"to recursively debug some other code."); + +#define SYS_CALL_TRACING_METHODDEF \ + {"call_tracing", (PyCFunction)sys_call_tracing, METH_VARARGS, sys_call_tracing__doc__}, static PyObject * -sys_call_tracing(PyObject *self, PyObject *args) +sys_call_tracing_impl(PyModuleDef *module, PyObject *func, PyObject *args_value); + +static PyObject * +sys_call_tracing(PyModuleDef *module, PyObject *args) { - PyObject *func, *funcargs; - if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, &PyTuple_Type, &funcargs)) - return NULL; - return _PyEval_CallTracing(func, funcargs); + PyObject *return_value = NULL; + PyObject *func; + PyObject *args_value; + + if (!PyArg_ParseTuple(args, + "OO!:call_tracing", + &func, &PyTuple_Type, &args_value)) + goto exit; + return_value = sys_call_tracing_impl(module, func, args_value); + +exit: + return return_value; } +static PyObject * +sys_call_tracing_impl(PyModuleDef *module, PyObject *func, PyObject *args_value) +/*[clinic end generated code: checksum=c60115329f78c461dcf2e863a9dcdb39682e79a6]*/ +{ + return _PyEval_CallTracing(func, args_value); +} + + +#ifdef __cplusplus +extern "C" { +#endif + +/*[clinic input] +sys._debugmallocstats + +Print summary info to stderr about the state of pymalloc's structures. + +In Py_DEBUG mode, also perform some expensive internal consistency checks. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys__debugmallocstats__doc__, +"_debugmallocstats()\n" +"Print summary info to stderr about the state of pymalloc\'s structures.\n" +"\n" +"In Py_DEBUG mode, also perform some expensive internal consistency checks."); + +#define SYS__DEBUGMALLOCSTATS_METHODDEF \ + {"_debugmallocstats", (PyCFunction)sys__debugmallocstats, METH_NOARGS, sys__debugmallocstats__doc__}, + +static PyObject * +sys__debugmallocstats_impl(PyModuleDef *module); + +static PyObject * +sys__debugmallocstats(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys__debugmallocstats_impl(module); + + return return_value; +} + +static PyObject * +sys__debugmallocstats_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=6d8e6012034d63e22df22afea773a3b4d3f8f3bb]*/ +{ +#ifdef WITH_PYMALLOC + _PyObject_DebugMallocStats(stderr); + fputc('\n', stderr); +#endif + _PyObject_DebugTypeStats(stderr); + + Py_RETURN_NONE; +} + + +#ifdef Py_TRACE_REFS +/* Defined in objects.c because it uses static globals if that file */ +extern PyObject *_Py_GetObjects(PyObject *, PyObject *); +#endif + +#ifdef DYNAMIC_EXECUTION_PROFILE +/* Defined in ceval.c because it uses static globals if that file */ +extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); +#endif + +#ifdef __cplusplus +} +#endif + + +/*[clinic input] +sys._clear_type_cache + +Clear the internal type lookup cache. +[clinic start generated code]*/ + +PyDoc_STRVAR(sys__clear_type_cache__doc__, +"_clear_type_cache()\n" +"Clear the internal type lookup cache."); + +#define SYS__CLEAR_TYPE_CACHE_METHODDEF \ + {"_clear_type_cache", (PyCFunction)sys__clear_type_cache, METH_NOARGS, sys__clear_type_cache__doc__}, + +static PyObject * +sys__clear_type_cache_impl(PyModuleDef *module); + +static PyObject * +sys__clear_type_cache(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + + return_value = sys__clear_type_cache_impl(module); + + return return_value; +} + +static PyObject * +sys__clear_type_cache_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=7eeffc28102bd953bddb1861c744b331bffabfbc]*/ +{ + PyType_ClearCache(); + Py_RETURN_NONE; +} + + PyDoc_STRVAR(callstats_doc, "callstats() -> tuple of integers\n\ \n\ @@ -1059,131 +1957,65 @@ 9. All other calls\n\ 10. Number of stack pops performed by call_function()" ); -#ifdef __cplusplus -extern "C" { -#endif - -static PyObject * -sys_debugmallocstats(PyObject *self, PyObject *args) -{ -#ifdef WITH_PYMALLOC - _PyObject_DebugMallocStats(stderr); - fputc('\n', stderr); -#endif - _PyObject_DebugTypeStats(stderr); - - Py_RETURN_NONE; -} -PyDoc_STRVAR(debugmallocstats_doc, -"_debugmallocstats()\n\ -\n\ -Print summary info to stderr about the state of\n\ -pymalloc's structures.\n\ -\n\ -In Py_DEBUG mode, also perform some expensive internal consistency\n\ -checks.\n\ -"); - -#ifdef Py_TRACE_REFS -/* Defined in objects.c because it uses static globals if that file */ -extern PyObject *_Py_GetObjects(PyObject *, PyObject *); -#endif - -#ifdef DYNAMIC_EXECUTION_PROFILE -/* Defined in ceval.c because it uses static globals if that file */ -extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); -#endif - -#ifdef __cplusplus -} -#endif - -static PyObject * -sys_clear_type_cache(PyObject* self, PyObject* args) -{ - PyType_ClearCache(); - Py_RETURN_NONE; -} - -PyDoc_STRVAR(sys_clear_type_cache__doc__, -"_clear_type_cache() -> None\n\ -Clear the internal type lookup cache."); - static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, callstats_doc}, - {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS, - sys_clear_type_cache__doc__}, - {"_current_frames", sys_current_frames, METH_NOARGS, - current_frames_doc}, - {"displayhook", sys_displayhook, METH_O, displayhook_doc}, - {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, - {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, - {"exit", sys_exit, METH_VARARGS, exit_doc}, - {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, - METH_NOARGS, getdefaultencoding_doc}, + SYS__CLEAR_TYPE_CACHE_METHODDEF + SYS__CURRENT_FRAMES_METHODDEF + SYS_DISPLAYHOOK_METHODDEF + SYS_EXC_INFO_METHODDEF + SYS_EXCEPTHOOK_METHODDEF + SYS_EXIT_METHODDEF + SYS_GETDEFAULTENCODING_METHODDEF #ifdef HAVE_DLOPEN - {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, - getdlopenflags_doc}, + SYS_GETDLOPENFLAGS_METHODDEF #endif - {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS, - getallocatedblocks_doc}, + SYS_GETALLOCATEDBLOCKS_METHODDEF #ifdef COUNT_ALLOCS - {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, + SYS_GETCOUNTS_METHODDEF #endif #ifdef DYNAMIC_EXECUTION_PROFILE {"getdxp", _Py_GetDXProfile, METH_VARARGS}, #endif - {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding, - METH_NOARGS, getfilesystemencoding_doc}, + SYS_GETFILESYSTEMENCODING_METHODDEF #ifdef Py_TRACE_REFS {"getobjects", _Py_GetObjects, METH_VARARGS}, #endif #ifdef Py_REF_DEBUG - {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS}, + SYS_GETTOTALREFCOUNT_METHODDEF #endif - {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc}, - {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS, - getrecursionlimit_doc}, - {"getsizeof", (PyCFunction)sys_getsizeof, - METH_VARARGS | METH_KEYWORDS, getsizeof_doc}, - {"_getframe", sys_getframe, METH_VARARGS, getframe_doc}, + SYS_GETREFCOUNT_METHODDEF + SYS_GETRECURSIONLIMIT_METHODDEF + SYS_GETSIZEOF_METHODDEF + SYS__GETFRAME_METHODDEF #ifdef MS_WINDOWS - {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, - getwindowsversion_doc}, + SYS_GETWINDOWSVERSION_METHODDEF #endif /* MS_WINDOWS */ - {"intern", sys_intern, METH_VARARGS, intern_doc}, + SYS_INTERN_METHODDEF #ifdef USE_MALLOPT - {"mdebug", sys_mdebug, METH_VARARGS}, + SYS_MDEBUG_METHODDEF #endif - {"setcheckinterval", sys_setcheckinterval, METH_VARARGS, - setcheckinterval_doc}, - {"getcheckinterval", sys_getcheckinterval, METH_NOARGS, - getcheckinterval_doc}, + SYS_SETCHECKINTERVAL_METHODDEF + SYS_GETCHECKINTERVAL_METHODDEF #ifdef WITH_THREAD - {"setswitchinterval", sys_setswitchinterval, METH_VARARGS, - setswitchinterval_doc}, - {"getswitchinterval", sys_getswitchinterval, METH_NOARGS, - getswitchinterval_doc}, + SYS_SETSWITCHINTERVAL_METHODDEF + SYS_GETSWITCHINTERVAL_METHODDEF #endif #ifdef HAVE_DLOPEN - {"setdlopenflags", sys_setdlopenflags, METH_VARARGS, - setdlopenflags_doc}, + SYS_SETDLOPENFLAGS_METHODDEF #endif - {"setprofile", sys_setprofile, METH_O, setprofile_doc}, - {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc}, - {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS, - setrecursionlimit_doc}, + SYS_SETPROFILE_METHODDEF + SYS_GETPROFILE_METHODDEF + SYS_SETRECURSIONLIMIT_METHODDEF #ifdef WITH_TSC - {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc}, + SYS_SETTSCDUMP_METHODDEF #endif - {"settrace", sys_settrace, METH_O, settrace_doc}, - {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc}, - {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc}, - {"_debugmallocstats", sys_debugmallocstats, METH_NOARGS, - debugmallocstats_doc}, + SYS_SETTRACE_METHODDEF + SYS_GETTRACE_METHODDEF + SYS_CALL_TRACING_METHODDEF + SYS__DEBUGMALLOCSTATS_METHODDEF {NULL, NULL} /* sentinel */ };