diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/_warnings.c | 35 | ||||
-rw-r--r-- | Python/ast.c | 59 | ||||
-rw-r--r-- | Python/traceback.c | 2 |
3 files changed, 56 insertions, 40 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index d5c4ebe..956b3f5 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -382,9 +382,6 @@ warn_explicit(PyObject *category, PyObject *message, res = PyObject_CallFunctionObjArgs(show_fxn, message, category, filename, lineno_obj, - Py_None, - sourceline ? - sourceline: Py_None, NULL); Py_DECREF(show_fxn); Py_XDECREF(res); @@ -465,9 +462,9 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, /* Setup filename. */ *filename = PyDict_GetItemString(globals, "__file__"); if (*filename != NULL) { - Py_ssize_t len = PyUnicode_GetSize(*filename); + Py_ssize_t len = PyUnicode_GetSize(*filename); const char *file_str = PyUnicode_AsString(*filename); - if (file_str == NULL || (len < 0 && PyErr_Occurred())) + if (file_str == NULL || (len < 0 && PyErr_Occurred())) goto handle_error; /* if filename.lower().endswith((".pyc", ".pyo")): */ @@ -476,12 +473,13 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, tolower(file_str[len-3]) == 'p' && tolower(file_str[len-2]) == 'y' && (tolower(file_str[len-1]) == 'c' || - tolower(file_str[len-1]) == 'o')) { + tolower(file_str[len-1]) == 'o')) + { *filename = PyUnicode_FromStringAndSize(file_str, len-1); - if (*filename == NULL) - goto handle_error; - } - else + if (*filename == NULL) + goto handle_error; + } + else Py_INCREF(*filename); } else { @@ -489,14 +487,27 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, if (module_str && strcmp(module_str, "__main__") == 0) { PyObject *argv = PySys_GetObject("argv"); if (argv != NULL && PyList_Size(argv) > 0) { + int is_true; *filename = PyList_GetItem(argv, 0); Py_INCREF(*filename); + /* If sys.argv[0] is false, then use '__main__'. */ + is_true = PyObject_IsTrue(*filename); + if (is_true < 0) { + Py_DECREF(*filename); + goto handle_error; + } + else if (!is_true) { + Py_DECREF(*filename); + *filename = PyString_FromString("__main__"); + if (*filename == NULL) + goto handle_error; + } } else { /* embedded interpreters don't have sys.argv, see bug #839151 */ *filename = PyUnicode_FromString("__main__"); - if (*filename == NULL) - goto handle_error; + if (*filename == NULL) + goto handle_error; } } if (*filename == NULL) { diff --git a/Python/ast.c b/Python/ast.c index 6a9658a..1124a8b 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -34,7 +34,7 @@ static stmt_ty ast_for_classdef(struct compiling *, const node *, asdl_seq *); /* Note different signature for ast_for_call */ static expr_ty ast_for_call(struct compiling *, const node *, expr_ty); -static PyObject *parsenumber(const char *); +static PyObject *parsenumber(struct compiling *, const char *); static PyObject *parsestr(struct compiling *, const node *n, int *bytesmode); static PyObject *parsestrplus(struct compiling *, const node *n, int *bytesmode); @@ -379,7 +379,7 @@ forbidden_name(expr_ty e, const node *n) */ static int -set_context(expr_ty e, expr_context_ty ctx, const node *n) +set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n) { asdl_seq *s = NULL; /* If a particular expression type can't be used for assign / delete, @@ -405,7 +405,7 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n) break; case Starred_kind: e->v.Starred.ctx = ctx; - if (!set_context(e->v.Starred.value, ctx, n)) + if (!set_context(c, e->v.Starred.value, ctx, n)) return 0; break; case Name_kind: @@ -489,7 +489,7 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n) int i; for (i = 0; i < asdl_seq_LEN(s); i++) { - if (!set_context((expr_ty)asdl_seq_GET(s, i), ctx, n)) + if (!set_context(c, (expr_ty)asdl_seq_GET(s, i), ctx, n)) return 0; } } @@ -497,7 +497,7 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n) } static operator_ty -ast_for_augassign(const node *n) +ast_for_augassign(struct compiling *c, const node *n) { REQ(n, augassign); n = CHILD(n, 0); @@ -535,7 +535,7 @@ ast_for_augassign(const node *n) } static cmpop_ty -ast_for_comp_op(const node *n) +ast_for_comp_op(struct compiling *c, const node *n) { /* comp_op: '<'|'>'|'=='|'>='|'<='|'!='|'in'|'not' 'in'|'is' |'is' 'not' @@ -632,6 +632,12 @@ compiler_arg(struct compiling *c, const node *n) } return arg(name, annotation, c->c_arena); +#if 0 + result = Tuple(args, Store, LINENO(n), n->n_col_offset, c->c_arena); + if (!set_context(c, result, Store, n)) + return NULL; + return result; +#endif } /* returns -1 if failed to handle keyword only arguments @@ -1080,7 +1086,7 @@ ast_for_ifexpr(struct compiling *c, const node *n) */ static int -count_comp_fors(const node *n) +count_comp_fors(struct compiling *c, const node *n) { int n_fors = 0; @@ -1117,7 +1123,7 @@ count_comp_fors(const node *n) */ static int -count_comp_ifs(const node *n) +count_comp_ifs(struct compiling *c, const node *n) { int n_ifs = 0; @@ -1140,7 +1146,7 @@ ast_for_comprehension(struct compiling *c, const node *n) int i, n_fors; asdl_seq *comps; - n_fors = count_comp_fors(n); + n_fors = count_comp_fors(c, n); if (n_fors == -1) return NULL; @@ -1182,7 +1188,7 @@ ast_for_comprehension(struct compiling *c, const node *n) asdl_seq *ifs; n = CHILD(n, 4); - n_ifs = count_comp_ifs(n); + n_ifs = count_comp_ifs(c, n); if (n_ifs == -1) return NULL; @@ -1331,7 +1337,7 @@ ast_for_atom(struct compiling *c, const node *n) return Str(str, LINENO(n), n->n_col_offset, c->c_arena); } case NUMBER: { - PyObject *pynum = parsenumber(STR(ch)); + PyObject *pynum = parsenumber(c, STR(ch)); if (!pynum) return NULL; @@ -1822,7 +1828,7 @@ ast_for_expr(struct compiling *c, const node *n) for (i = 1; i < NCH(n); i += 2) { cmpop_ty newoperator; - newoperator = ast_for_comp_op(CHILD(n, i)); + newoperator = ast_for_comp_op(c, CHILD(n, i)); if (!newoperator) { return NULL; } @@ -2084,7 +2090,8 @@ ast_for_expr_stmt(struct compiling *c, const node *n) "assignment"); return NULL; } - set_context(expr1, Store, ch); + if(!set_context(c, expr1, Store, ch)) + return NULL; ch = CHILD(n, 2); if (TYPE(ch) == testlist) @@ -2094,7 +2101,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n) if (!expr2) return NULL; - newoperator = ast_for_augassign(CHILD(n, 1)); + newoperator = ast_for_augassign(c, CHILD(n, 1)); if (!newoperator) return NULL; @@ -2124,7 +2131,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n) if (!e) return NULL; - if (!set_context(e, Store, CHILD(n, i))) + if (!set_context(c, e, Store, CHILD(n, i))) return NULL; asdl_seq_SET(targets, i / 2, e); @@ -2157,7 +2164,7 @@ ast_for_exprlist(struct compiling *c, const node *n, expr_context_ty context) if (!e) return NULL; asdl_seq_SET(seq, i / 2, e); - if (context && !set_context(e, context, CHILD(n, i))) + if (context && !set_context(c, e, context, CHILD(n, i))) return NULL; } return seq; @@ -2928,7 +2935,7 @@ ast_for_with_stmt(struct compiling *c, const node *n) if (!optional_vars) { return NULL; } - if (!set_context(optional_vars, Store, n)) { + if (!set_context(c, optional_vars, Store, n)) { return NULL; } suite_index = 4; @@ -3057,13 +3064,13 @@ ast_for_stmt(struct compiling *c, const node *n) } static PyObject * -parsenumber(const char *s) +parsenumber(struct compiling *c, const char *s) { const char *end; long x; double dx; #ifndef WITHOUT_COMPLEX - Py_complex c; + Py_complex compl; int imflag; #endif @@ -3090,11 +3097,11 @@ parsenumber(const char *s) /* XXX Huge floats may silently fail */ #ifndef WITHOUT_COMPLEX if (imflag) { - c.real = 0.; + compl.real = 0.; PyFPE_START_PROTECT("atof", return 0) - c.imag = PyOS_ascii_atof(s); + compl.imag = PyOS_ascii_atof(s); PyFPE_END_PROTECT(c) - return PyComplex_FromCComplex(c); + return PyComplex_FromCComplex(compl); } else #endif @@ -3107,7 +3114,7 @@ parsenumber(const char *s) } static PyObject * -decode_utf8(const char **sPtr, const char *end, char* encoding) +decode_utf8(struct compiling *c, const char **sPtr, const char *end, char* encoding) { PyObject *u, *v; char *s, *t; @@ -3124,7 +3131,7 @@ decode_utf8(const char **sPtr, const char *end, char* encoding) } static PyObject * -decode_unicode(const char *s, size_t len, int rawmode, const char *encoding) +decode_unicode(struct compiling *c, const char *s, size_t len, int rawmode, const char *encoding) { PyObject *v, *u; char *buf; @@ -3156,7 +3163,7 @@ decode_unicode(const char *s, size_t len, int rawmode, const char *encoding) PyObject *w; char *r; Py_ssize_t rn, i; - w = decode_utf8(&s, end, "utf-16-be"); + w = decode_utf8(c, &s, end, "utf-16-be"); if (w == NULL) { Py_DECREF(u); return NULL; @@ -3232,7 +3239,7 @@ parsestr(struct compiling *c, const node *n, int *bytesmode) } } if (!*bytesmode && !rawmode) { - return decode_unicode(s, len, rawmode, c->c_encoding); + return decode_unicode(c, s, len, rawmode, c->c_encoding); } if (*bytesmode) { /* Disallow non-ascii characters (but not escapes) */ diff --git a/Python/traceback.c b/Python/traceback.c index e46e67d..bbc8e16 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -228,8 +228,6 @@ tb_displayline(PyObject *f, const char *filename, int lineno, const char *name) err = PyFile_WriteString(linebuf, f); if (err != 0) return err; - - err = PyFile_WriteString(" ", f); return Py_DisplaySourceLine(f, filename, lineno); } |