diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 4 | ||||
-rw-r--r-- | Python/ceval.c | 45 | ||||
-rw-r--r-- | Python/codecs.c | 23 | ||||
-rw-r--r-- | Python/compile.c | 2 | ||||
-rw-r--r-- | Python/errors.c | 16 | ||||
-rw-r--r-- | Python/getargs.c | 27 | ||||
-rw-r--r-- | Python/import.c | 2 | ||||
-rw-r--r-- | Python/importdl.c | 2 | ||||
-rw-r--r-- | Python/modsupport.c | 6 | ||||
-rw-r--r-- | Python/pylifecycle.c | 6 | ||||
-rw-r--r-- | Python/pythonrun.c | 6 | ||||
-rw-r--r-- | Python/structmember.c | 2 | ||||
-rw-r--r-- | Python/sysmodule.c | 7 |
13 files changed, 76 insertions, 72 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index a49cb9d..5c92545 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1893,7 +1893,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) char *s = NULL; PyObject *stdin_encoding = NULL, *stdin_errors = NULL; PyObject *stdout_encoding = NULL, *stdout_errors = NULL; - char *stdin_encoding_str, *stdin_errors_str; + const char *stdin_encoding_str, *stdin_errors_str; PyObject *result; size_t len; @@ -1914,7 +1914,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) Py_DECREF(tmp); if (prompt != NULL) { /* We have a prompt, encode it as stdout would */ - char *stdout_encoding_str, *stdout_errors_str; + const char *stdout_encoding_str, *stdout_errors_str; PyObject *stringpo; stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding); stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors); diff --git a/Python/ceval.c b/Python/ceval.c index ebf073a..b18fd91 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -718,7 +718,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) return tstate->interp->eval_frame(f, throwflag); } -PyObject * +PyObject* _Py_HOT_FUNCTION _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) { #ifdef DXPAIRS @@ -1424,6 +1424,12 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *right = POP(); PyObject *left = TOP(); PyObject *sum; + /* NOTE(haypo): Please don't try to micro-optimize int+int on + CPython using bytecode, it is simply worthless. + See http://bugs.python.org/issue21955 and + http://bugs.python.org/issue10044 for the discussion. In short, + no patch shown any impact on a realistic benchmark, only a minor + speedup on microbenchmarks. */ if (PyUnicode_CheckExact(left) && PyUnicode_CheckExact(right)) { sum = unicode_concatenate(left, right, f, next_instr); @@ -1538,7 +1544,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) TARGET(SET_ADD) { PyObject *v = POP(); - PyObject *set = stack_pointer[-oparg]; + PyObject *set = PEEK(oparg); int err; err = PySet_Add(set, v); Py_DECREF(v); @@ -2399,8 +2405,10 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) TARGET(DELETE_DEREF) { PyObject *cell = freevars[oparg]; - if (PyCell_GET(cell) != NULL) { - PyCell_Set(cell, NULL); + PyObject *oldobj = PyCell_GET(cell); + if (oldobj != NULL) { + PyCell_SET(cell, NULL); + Py_DECREF(oldobj); DISPATCH(); } format_exc_unbound(co, oparg); @@ -2797,7 +2805,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *map; int err; STACKADJ(-2); - map = stack_pointer[-oparg]; /* dict */ + map = PEEK(oparg); /* dict */ assert(PyDict_CheckExact(map)); err = PyDict_SetItem(map, key, value); /* map[key] = value */ Py_DECREF(value); @@ -4267,6 +4275,9 @@ do_raise(PyObject *exc, PyObject *cause) goto raise_error; } + assert(type != NULL); + assert(value != NULL); + if (cause) { PyObject *fixed_cause; if (PyExceptionClass_Check(cause)) { @@ -4293,8 +4304,8 @@ do_raise(PyObject *exc, PyObject *cause) PyErr_SetObject(type, value); /* PyErr_SetObject incref's its arguments */ - Py_XDECREF(value); - Py_XDECREF(type); + Py_DECREF(value); + Py_DECREF(type); return 0; raise_error: @@ -4763,7 +4774,7 @@ if (tstate->use_tracing && tstate->c_profilefunc) { \ x = call; \ } -static PyObject * +static PyObject* _Py_HOT_FUNCTION call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames) { PyObject **pfunc = (*pp_stack) - oparg - 1; @@ -4836,7 +4847,7 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames) done before evaluating the frame. */ -static PyObject* +static PyObject* _Py_HOT_FUNCTION _PyFunction_FastCall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs, PyObject *globals) { @@ -5342,8 +5353,10 @@ unicode_concatenate(PyObject *v, PyObject *w, PyObject **freevars = (f->f_localsplus + f->f_code->co_nlocals); PyObject *c = freevars[oparg]; - if (PyCell_GET(c) == v) - PyCell_Set(c, NULL); + if (PyCell_GET(c) == v) { + PyCell_SET(c, NULL); + Py_DECREF(v); + } break; } case STORE_NAME: @@ -5427,8 +5440,8 @@ _PyEval_RequestCodeExtraIndex(freefunc free) static void dtrace_function_entry(PyFrameObject *f) { - char* filename; - char* funcname; + const char *filename; + const char *funcname; int lineno; filename = PyUnicode_AsUTF8(f->f_code->co_filename); @@ -5441,8 +5454,8 @@ dtrace_function_entry(PyFrameObject *f) static void dtrace_function_return(PyFrameObject *f) { - char* filename; - char* funcname; + const char *filename; + const char *funcname; int lineno; filename = PyUnicode_AsUTF8(f->f_code->co_filename); @@ -5458,7 +5471,7 @@ maybe_dtrace_line(PyFrameObject *frame, int *instr_lb, int *instr_ub, int *instr_prev) { int line = frame->f_lineno; - char *co_filename, *co_name; + const char *co_filename, *co_name; /* If the last instruction executed isn't in the current instruction window, reset the window. diff --git a/Python/codecs.c b/Python/codecs.c index fe57d0d..bf152c2 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -867,17 +867,14 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc) Py_UCS4 c; if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeDecodeError)) { - unsigned char *p; + const unsigned char *p; if (PyUnicodeDecodeError_GetStart(exc, &start)) return NULL; if (PyUnicodeDecodeError_GetEnd(exc, &end)) return NULL; if (!(object = PyUnicodeDecodeError_GetObject(exc))) return NULL; - if (!(p = (unsigned char*)PyBytes_AsString(object))) { - Py_DECREF(object); - return NULL; - } + p = (const unsigned char*)PyBytes_AS_STRING(object); res = PyUnicode_New(4 * (end - start), 127); if (res == NULL) { Py_DECREF(object); @@ -1134,7 +1131,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc) PyObject *restuple; PyObject *object; PyObject *encode; - char *encoding; + const char *encoding; int code; int bytelength; Py_ssize_t i; @@ -1220,7 +1217,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc) return restuple; } else if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeDecodeError)) { - unsigned char *p; + const unsigned char *p; Py_UCS4 ch = 0; if (PyUnicodeDecodeError_GetStart(exc, &start)) return NULL; @@ -1228,10 +1225,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc) return NULL; if (!(object = PyUnicodeDecodeError_GetObject(exc))) return NULL; - if (!(p = (unsigned char*)PyBytes_AsString(object))) { - Py_DECREF(object); - return NULL; - } + p = (const unsigned char*)PyBytes_AS_STRING(object); if (!(encode = PyUnicodeDecodeError_GetEncoding(exc))) { Py_DECREF(object); return NULL; @@ -1338,7 +1332,7 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc) } else if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeDecodeError)) { PyObject *str; - unsigned char *p; + const unsigned char *p; Py_UCS2 ch[4]; /* decode up to 4 bad bytes. */ int consumed = 0; if (PyUnicodeDecodeError_GetStart(exc, &start)) @@ -1347,10 +1341,7 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc) return NULL; if (!(object = PyUnicodeDecodeError_GetObject(exc))) return NULL; - if (!(p = (unsigned char*)PyBytes_AsString(object))) { - Py_DECREF(object); - return NULL; - } + p = (const unsigned char*)PyBytes_AS_STRING(object); while (consumed < 4 && consumed < end-start) { /* Refuse to escape ASCII bytes. */ if (p[start+consumed] < 128) diff --git a/Python/compile.c b/Python/compile.c index a8d7fcd..46a40a3 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4039,7 +4039,7 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k) static int expr_constant(struct compiler *c, expr_ty e) { - char *id; + const char *id; switch (e->kind) { case Ellipsis_kind: return 1; diff --git a/Python/errors.c b/Python/errors.c index 7b25a22..01304d2 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -158,10 +158,10 @@ PyErr_SetString(PyObject *exception, const char *string) } -PyObject * +PyObject* _Py_HOT_FUNCTION PyErr_Occurred(void) { - PyThreadState *tstate = _PyThreadState_UncheckedGet(); + PyThreadState *tstate = PyThreadState_GET(); return tstate == NULL ? NULL : tstate->curexc_type; } @@ -582,9 +582,7 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename) PyObject * PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL); Py_XDECREF(name); return result; @@ -691,9 +689,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithUnicodeFilename( int ierr, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObjects(exc, ierr, name, @@ -729,9 +725,7 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( int ierr, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObjects( PyExc_OSError, ierr, name, NULL); diff --git a/Python/getargs.c b/Python/getargs.c index 616c6eb..c552d0f 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -74,7 +74,7 @@ static const char *converttuple(PyObject *, const char **, va_list *, int, int *, char *, size_t, int, freelist_t *); static const char *convertsimple(PyObject *, const char **, va_list *, int, char *, size_t, freelist_t *); -static Py_ssize_t convertbuffer(PyObject *, void **p, const char **); +static Py_ssize_t convertbuffer(PyObject *, const void **p, const char **); static int getbuffer(PyObject *, Py_buffer *, const char**); static int vgetargskeywords(PyObject *, PyObject *, @@ -625,7 +625,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, const char *format = *p_format; char c = *format++; - char *sarg; + const char *sarg; switch (c) { @@ -897,7 +897,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, } break; } - count = convertbuffer(arg, p, &buf); + count = convertbuffer(arg, (const void **)p, &buf); if (count < 0) return converterr(buf, arg, msgbuf, bufsize); if (*format == '#') { @@ -928,7 +928,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, if (sarg == NULL) return converterr(CONV_UNICODE, arg, msgbuf, bufsize); - PyBuffer_FillInfo(p, arg, sarg, len, 1, 0); + PyBuffer_FillInfo(p, arg, (void *)sarg, len, 1, 0); } else { /* any bytes-like object */ const char *buf; @@ -943,7 +943,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, format++; } else if (*format == '#') { /* a string or read-only bytes-like object */ /* "s#" or "z#" */ - void **p = (void **)va_arg(*p_va, char **); + const void **p = (const void **)va_arg(*p_va, const char **); FETCH_SIZE; if (c == 'z' && arg == Py_None) { @@ -970,7 +970,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, format++; } else { /* "s" or "z" */ - char **p = va_arg(*p_va, char **); + const char **p = va_arg(*p_va, const char **); Py_ssize_t len; sarg = NULL; @@ -1027,7 +1027,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, *p = PyUnicode_AsUnicodeAndSize(arg, &len); if (*p == NULL) RETURN_ERR_OCCURRED; - if (Py_UNICODE_strlen(*p) != (size_t)len) { + if (wcslen(*p) != (size_t)len) { PyErr_SetString(PyExc_ValueError, "embedded null character"); RETURN_ERR_OCCURRED; } @@ -1074,9 +1074,14 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, (PyBytes_Check(arg) || PyByteArray_Check(arg))) { s = arg; Py_INCREF(s); - if (PyObject_AsCharBuffer(s, &ptr, &size) < 0) - return converterr("(AsCharBuffer failed)", - arg, msgbuf, bufsize); + if (PyBytes_Check(arg)) { + size = PyBytes_GET_SIZE(s); + ptr = PyBytes_AS_STRING(s); + } + else { + size = PyByteArray_GET_SIZE(s); + ptr = PyByteArray_AS_STRING(s); + } } else if (PyUnicode_Check(arg)) { /* Encode object; use default error handling */ @@ -1300,7 +1305,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, } static Py_ssize_t -convertbuffer(PyObject *arg, void **p, const char **errmsg) +convertbuffer(PyObject *arg, const void **p, const char **errmsg) { PyBufferProcs *pb = Py_TYPE(arg)->tp_as_buffer; Py_ssize_t count; diff --git a/Python/import.c b/Python/import.c index cd865a5..6bcb1d7 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1035,7 +1035,7 @@ _imp_create_builtin(PyObject *module, PyObject *spec) { struct _inittab *p; PyObject *name; - char *namestr; + const char *namestr; PyObject *mod; name = PyObject_GetAttrString(spec, "name"); diff --git a/Python/importdl.c b/Python/importdl.c index f56fa94..d8656b9 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -94,7 +94,7 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) #endif PyObject *name_unicode = NULL, *name = NULL, *path = NULL, *m = NULL; const char *name_buf, *hook_prefix; - char *oldcontext; + const char *oldcontext; dl_funcptr exportfunc; PyModuleDef *def; PyObject *(*p0)(void); diff --git a/Python/modsupport.c b/Python/modsupport.c index aabee8f..06bdcab 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -9,7 +9,7 @@ typedef double va_double; static PyObject *va_build_value(const char *, va_list, int); /* Package context -- the full module name for package imports */ -char *_Py_PackageContext = NULL; +const char *_Py_PackageContext = NULL; /* Helper for mkvalue() to scan the length of a format */ @@ -286,8 +286,8 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) } else { if (n < 0) - n = Py_UNICODE_strlen(u); - v = PyUnicode_FromUnicode(u, n); + n = wcslen(u); + v = PyUnicode_FromWideChar(u, n); } return v; } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index a4f7f82..06030c3 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -193,7 +193,8 @@ add_flag(int flag, const char *envs) static char* get_codec_name(const char *encoding) { - char *name_utf8, *name_str; + const char *name_utf8; + char *name_str; PyObject *codec, *name = NULL; codec = _PyCodec_Lookup(encoding); @@ -1284,8 +1285,7 @@ initstdio(void) when import.c tries to write to stderr in verbose mode. */ encoding_attr = PyObject_GetAttrString(std, "encoding"); if (encoding_attr != NULL) { - const char * std_encoding; - std_encoding = PyUnicode_AsUTF8(encoding_attr); + const char *std_encoding = PyUnicode_AsUTF8(encoding_attr); if (std_encoding != NULL) { PyObject *codec_info = _PyCodec_Lookup(std_encoding); Py_XDECREF(codec_info); diff --git a/Python/pythonrun.c b/Python/pythonrun.c index c881f90..b862e2b 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -154,7 +154,7 @@ PyRun_InteractiveOneObject(FILE *fp, PyObject *filename, PyCompilerFlags *flags) PyObject *m, *d, *v, *w, *oenc = NULL, *mod_name; mod_ty mod; PyArena *arena; - char *ps1 = "", *ps2 = "", *enc = NULL; + const char *ps1 = "", *ps2 = "", *enc = NULL; int errcode = 0; _Py_IDENTIFIER(encoding); _Py_IDENTIFIER(__main__); @@ -511,8 +511,8 @@ PyErr_Print(void) static void print_error_text(PyObject *f, int offset, PyObject *text_obj) { - char *text; - char *nl; + const char *text; + const char *nl; text = PyUnicode_AsUTF8(text_obj); if (text == NULL) diff --git a/Python/structmember.c b/Python/structmember.c index be2737d..e653d02 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -249,7 +249,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) Py_XDECREF(oldv); break; case T_CHAR: { - char *string; + const char *string; Py_ssize_t len; string = PyUnicode_AsUTF8AndSize(v, &len); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 52034ff..db5a48f 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); @@ -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 * @@ -2403,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); |