diff options
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 8d7e05a..be8e164 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -20,6 +20,7 @@ Data members: #include "pythread.h" #include "osdefs.h" +#include <locale.h> #ifdef MS_WINDOWS #define WIN32_LEAN_AND_MEAN @@ -33,7 +34,6 @@ extern const char *PyWin_DLLVersionString; #endif #ifdef HAVE_LANGINFO_H -#include <locale.h> #include <langinfo.h> #endif @@ -346,8 +346,10 @@ static PyObject *whatstrings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; static int trace_init(void) { - static char *whatnames[7] = {"call", "exception", "line", "return", - "c_call", "c_exception", "c_return"}; + static const char * const whatnames[7] = { + "call", "exception", "line", "return", + "c_call", "c_exception", "c_return" + }; PyObject *name; int i; for (i = 0; i < 7; ++i) { @@ -366,34 +368,25 @@ static PyObject * call_trampoline(PyObject* callback, PyFrameObject *frame, int what, PyObject *arg) { - PyObject *args; - PyObject *whatstr; PyObject *result; + PyObject *stack[3]; - args = PyTuple_New(3); - if (args == NULL) - return NULL; - if (PyFrame_FastToLocalsWithError(frame) < 0) + if (PyFrame_FastToLocalsWithError(frame) < 0) { return NULL; + } - Py_INCREF(frame); - whatstr = whatstrings[what]; - Py_INCREF(whatstr); - if (arg == NULL) - arg = Py_None; - Py_INCREF(arg); - PyTuple_SET_ITEM(args, 0, (PyObject *)frame); - PyTuple_SET_ITEM(args, 1, whatstr); - PyTuple_SET_ITEM(args, 2, arg); + stack[0] = (PyObject *)frame; + stack[1] = whatstrings[what]; + stack[2] = (arg != NULL) ? arg : Py_None; /* call the Python-level function */ - result = PyEval_CallObject(callback, args); + result = _PyObject_FastCall(callback, stack, 3, NULL); + PyFrame_LocalsToFast(frame, 1); - if (result == NULL) + if (result == NULL) { PyTraceBack_Here(frame); + } - /* cleanup */ - Py_DECREF(args); return result; } @@ -434,10 +427,7 @@ trace_trampoline(PyObject *self, PyFrameObject *frame, return -1; } if (result != Py_None) { - PyObject *temp = frame->f_trace; - frame->f_trace = NULL; - Py_XDECREF(temp); - frame->f_trace = result; + Py_XSETREF(frame->f_trace, result); } else { Py_DECREF(result); @@ -1152,8 +1142,10 @@ static PyObject * sys_debugmallocstats(PyObject *self, PyObject *args) { #ifdef WITH_PYMALLOC - _PyObject_DebugMallocStats(stderr); - fputc('\n', stderr); + if (_PyMem_PymallocEnabled()) { + _PyObject_DebugMallocStats(stderr); + fputc('\n', stderr); + } #endif _PyObject_DebugTypeStats(stderr); @@ -1643,15 +1635,11 @@ make_version_info(void) /* sys.implementation values */ #define NAME "cpython" const char *_PySys_ImplName = NAME; -#define QUOTE(arg) #arg -#define STRIFY(name) QUOTE(name) -#define MAJOR STRIFY(PY_MAJOR_VERSION) -#define MINOR STRIFY(PY_MINOR_VERSION) +#define MAJOR Py_STRINGIFY(PY_MAJOR_VERSION) +#define MINOR Py_STRINGIFY(PY_MINOR_VERSION) #define TAG NAME "-" MAJOR MINOR const char *_PySys_ImplCacheTag = TAG; #undef NAME -#undef QUOTE -#undef STRIFY #undef MAJOR #undef MINOR #undef TAG @@ -1696,6 +1684,16 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; +#ifdef MULTIARCH + value = PyUnicode_FromString(MULTIARCH); + if (value == NULL) + goto error; + res = PyDict_SetItemString(impl_info, "_multiarch", value); + Py_DECREF(value); + if (res < 0) + goto error; +#endif + /* dict ready */ ns = _PyNamespace_New(impl_info); @@ -2114,7 +2112,7 @@ PySys_SetArgv(int argc, wchar_t **argv) static int sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) { - PyObject *writer = NULL, *args = NULL, *result = NULL; + PyObject *writer = NULL, *result = NULL; int err; if (file == NULL) @@ -2124,11 +2122,7 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) if (writer == NULL) goto error; - args = PyTuple_Pack(1, unicode); - if (args == NULL) - goto error; - - result = PyEval_CallObject(writer, args); + result = _PyObject_FastCall(writer, &unicode, 1, NULL); if (result == NULL) { goto error; } else { @@ -2140,7 +2134,6 @@ error: err = -1; finally: Py_XDECREF(writer); - Py_XDECREF(args); Py_XDECREF(result); return err; } |