diff options
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 76 |
1 files changed, 49 insertions, 27 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 52034ff7fb..81520ea84f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -108,7 +108,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) { PyObject *stdout_encoding = NULL; PyObject *encoded, *escaped_str, *repr_str, *buffer, *result; - char *stdout_encoding_str; + const char *stdout_encoding_str; int ret; stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding); @@ -130,7 +130,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) buffer = _PyObject_GetAttrId(outf, &PyId_buffer); if (buffer) { - result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded); + result = _PyObject_CallMethodIdObjArgs(buffer, &PyId_write, encoded, NULL); Py_DECREF(buffer); Py_DECREF(encoded); if (result == NULL) @@ -179,8 +179,7 @@ sys_displayhook(PyObject *self, PyObject *o) /* After printing, also assign to '_' */ /* Before, set '_' to None to avoid recursion */ if (o == Py_None) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0) return NULL; @@ -211,8 +210,7 @@ sys_displayhook(PyObject *self, PyObject *o) return NULL; if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(displayhook_doc, @@ -228,8 +226,7 @@ sys_excepthook(PyObject* self, PyObject* args) if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb)) return NULL; PyErr_Display(exc, value, tb); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(excepthook_doc, @@ -461,8 +458,7 @@ sys_settrace(PyObject *self, PyObject *args) PyEval_SetTrace(NULL, NULL); else PyEval_SetTrace(trace_trampoline, args); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(settrace_doc, @@ -500,8 +496,7 @@ sys_setprofile(PyObject *self, PyObject *args) PyEval_SetProfile(NULL, NULL); else PyEval_SetProfile(profile_trampoline, args); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(setprofile_doc, @@ -542,8 +537,7 @@ sys_setcheckinterval(PyObject *self, PyObject *args) return NULL; if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_check_interval)) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(setcheckinterval_doc, @@ -581,8 +575,7 @@ sys_setswitchinterval(PyObject *self, PyObject *args) return NULL; } _PyEval_SetSwitchInterval((unsigned long) (1e6 * d)); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(setswitchinterval_doc, @@ -644,8 +637,7 @@ sys_setrecursionlimit(PyObject *self, PyObject *args) } Py_SetRecursionLimit(new_limit); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1032,8 +1024,7 @@ sys_setdlopenflags(PyObject *self, PyObject *args) if (!tstate) return NULL; tstate->interp->dlopenflags = new_val; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(setdlopenflags_doc, @@ -1074,8 +1065,7 @@ sys_mdebug(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "i:mdebug", &flag)) return NULL; mallopt(M_DEBUG, flag); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #endif /* USE_MALLOPT */ @@ -1098,7 +1088,7 @@ _PySys_GetSizeOf(PyObject *o) Py_TYPE(o)->tp_name); } else { - res = PyObject_CallFunctionObjArgs(method, NULL); + res = _PyObject_CallNoArg(method); Py_DECREF(method); } @@ -1287,6 +1277,19 @@ a 11-tuple where the entries in the tuple are counts of:\n\ 10. Number of stack pops performed by call_function()" ); +static PyObject * +sys_callstats(PyObject *self) +{ + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "sys.callstats() has been deprecated in Python 3.7 " + "and will be removed in the future", 1) < 0) { + return NULL; + } + + Py_RETURN_NONE; +} + + #ifdef __cplusplus extern "C" { #endif @@ -1350,9 +1353,23 @@ PyDoc_STRVAR(is_finalizing_doc, Return True if Python is exiting."); +#ifdef ANDROID_API_LEVEL +PyDoc_STRVAR(getandroidapilevel_doc, +"getandroidapilevel()\n\ +\n\ +Return the build time API version of Android as an integer."); + +static PyObject * +sys_getandroidapilevel(PyObject *self) +{ + return PyLong_FromLong(ANDROID_API_LEVEL); +} +#endif /* ANDROID_API_LEVEL */ + + static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ - {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, + {"callstats", (PyCFunction)sys_callstats, METH_NOARGS, callstats_doc}, {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS, sys_clear_type_cache__doc__}, @@ -1434,6 +1451,10 @@ static PyMethodDef sys_methods[] = { METH_VARARGS | METH_KEYWORDS, set_asyncgen_hooks_doc}, {"get_asyncgen_hooks", sys_get_asyncgen_hooks, METH_NOARGS, get_asyncgen_hooks_doc}, +#ifdef ANDROID_API_LEVEL + {"getandroidapilevel", (PyCFunction)sys_getandroidapilevel, METH_NOARGS, + getandroidapilevel_doc}, +#endif {NULL, NULL} /* sentinel */ }; @@ -1547,8 +1568,9 @@ error: Py_XDECREF(name); Py_XDECREF(value); /* No return value, therefore clear error state if possible */ - if (_PyThreadState_UncheckedGet()) + if (_PyThreadState_UncheckedGet()) { PyErr_Clear(); + } } PyObject * @@ -2293,7 +2315,7 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) if (writer == NULL) goto error; - result = _PyObject_CallArg1(writer, unicode); + result = PyObject_CallFunctionObjArgs(writer, unicode, NULL); if (result == NULL) { goto error; } else { @@ -2403,7 +2425,7 @@ sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va) { PyObject *file, *message; PyObject *error_type, *error_value, *error_traceback; - char *utf8; + const char *utf8; PyErr_Fetch(&error_type, &error_value, &error_traceback); file = _PySys_GetObjectId(key); |