From bc2f49454c330a83373e1f00c3de717dad4070ef Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 11 Nov 2016 01:43:56 +0100 Subject: Use PyThreadState_GET() in performance critical code It seems like _PyThreadState_UncheckedGet() is not inlined as expected, even when using gcc -O3. --- Python/sysmodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index e348b3873e..9247d4ed69 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1547,8 +1547,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 * -- cgit v1.2.1 From 5d858465b6ebdafa05f86309457848cc26913b6a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 20 Nov 2016 10:16:47 +0200 Subject: Added the const qualifier to char* variables that refer to readonly internal UTF-8 represenatation of Unicode objects. --- Python/sysmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 28561ace3b..db5a48fe57 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); @@ -2404,7 +2404,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); -- cgit v1.2.1 From 1078ad8ce638fcbe0084c63774f78679cc15b30a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 28 Nov 2016 11:59:04 +0100 Subject: Remove CALL_PROFILE special build Issue #28799: * Remove the PyEval_GetCallStats() function. * Deprecate the untested and undocumented sys.callstats() function. * Remove the CALL_PROFILE special build Use the sys.setprofile() function, cProfile or profile module to profile function calls. --- Python/sysmodule.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index db5a48fe57..79068304ab 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1287,6 +1287,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 @@ -1352,7 +1365,7 @@ Return True if Python is exiting."); 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__}, -- cgit v1.2.1 From 366f4ee4da4420842eac26b3fa00c2b01d4515a6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 1 Dec 2016 14:43:22 +0100 Subject: Replace PyObject_CallFunctionObjArgs() with fastcall * PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507. --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 79068304ab..2a3f36c6dd 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1098,7 +1098,7 @@ _PySys_GetSizeOf(PyObject *o) Py_TYPE(o)->tp_name); } else { - res = PyObject_CallFunctionObjArgs(method, NULL); + res = _PyObject_CallNoArg(method); Py_DECREF(method); } -- cgit v1.2.1 From e33e89d2c75b85e9a0fc35e8261567e8acd59c81 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 2 Dec 2016 01:13:46 +0100 Subject: Add sys.getandroidapilevel() Issue #28740: Add sys.getandroidapilevel(): return the build time API version of Android as an integer. Function only available on Android. --- Python/sysmodule.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 2a3f36c6dd..19a3850a59 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1363,6 +1363,20 @@ 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)sys_callstats, METH_NOARGS, @@ -1447,6 +1461,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 */ }; -- cgit v1.2.1 From 39ae5bedd90f9caf9a78efa82f4d11e838933b3a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 4 Dec 2016 22:59:09 +0100 Subject: Backed out changeset b9c9691c72c5 Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like _PyObject_CallArg1() uses more stack memory than PyObject_CallFunctionObjArgs(). --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 19a3850a59..98a66741f5 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1098,7 +1098,7 @@ _PySys_GetSizeOf(PyObject *o) Py_TYPE(o)->tp_name); } else { - res = _PyObject_CallNoArg(method); + res = PyObject_CallFunctionObjArgs(method, NULL); Py_DECREF(method); } -- cgit v1.2.1 From 40273ec4f37c65c13a09d0ac23b08c99ebe2f1a3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 5 Dec 2016 17:04:32 +0100 Subject: Issue #28858: Remove _PyObject_CallArg1() macro Replace _PyObject_CallArg1(func, arg) with PyObject_CallFunctionObjArgs(func, arg, NULL) Using the _PyObject_CallArg1() macro increases the usage of the C stack, which was unexpected and unwanted. PyObject_CallFunctionObjArgs() doesn't have this issue. --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 98a66741f5..416a02b546 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2325,7 +2325,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 { -- cgit v1.2.1 From a95a307d2cbb7fc1c778691f142e0c21c05fd5bc Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 6 Dec 2016 18:46:19 +0100 Subject: Use _PyObject_CallNoArg() Replace: PyObject_CallFunctionObjArgs(callable, NULL) with: _PyObject_CallNoArg(callable) --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 416a02b546..1537313b43 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1098,7 +1098,7 @@ _PySys_GetSizeOf(PyObject *o) Py_TYPE(o)->tp_name); } else { - res = PyObject_CallFunctionObjArgs(method, NULL); + res = _PyObject_CallNoArg(method); Py_DECREF(method); } -- cgit v1.2.1 From ff4988fe1c104125462faa6d68d1f2c957b00727 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 9 Dec 2016 00:36:19 +0100 Subject: Use _PyObject_CallMethodIdObjArgs() Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() when the format string only use the format 'O' for objects, like "(O)". _PyObject_CallMethodIdObjArgs() avoids the code to parse a format string and avoids the creation of a temporary tuple. --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1537313b43..9c4d9e6a1c 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -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) -- cgit v1.2.1