mirror of https://github.com/python/cpython
Fix SF Bug 564931: compile() traceback must include filename.
This commit is contained in:
parent
4254cbd29c
commit
6b17abf6c0
|
@ -32,6 +32,10 @@ extern DL_IMPORT(node *) PyParser_ParseFileFlags(FILE *, char *, grammar *,
|
|||
int, char *, char *,
|
||||
perrdetail *, int);
|
||||
|
||||
extern DL_IMPORT(node *) PyParser_ParseStringFlagsFilename(char *,
|
||||
char *,
|
||||
grammar *, int,
|
||||
perrdetail *, int);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ DL_IMPORT(int) PyRun_InteractiveLoopFlags(FILE *, char *, PyCompilerFlags *);
|
|||
DL_IMPORT(struct _node *) PyParser_SimpleParseString(char *, int);
|
||||
DL_IMPORT(struct _node *) PyParser_SimpleParseFile(FILE *, char *, int);
|
||||
DL_IMPORT(struct _node *) PyParser_SimpleParseStringFlags(char *, int, int);
|
||||
DL_IMPORT(struct _node *) PyParser_SimpleParseStringFlagsFilename(char *,
|
||||
char *,
|
||||
int,
|
||||
int);
|
||||
DL_IMPORT(struct _node *) PyParser_SimpleParseFileFlags(FILE *, char *,
|
||||
int, int);
|
||||
|
||||
|
|
|
@ -22,6 +22,15 @@ try:
|
|||
except SyntaxError:
|
||||
pass
|
||||
|
||||
if verbose:
|
||||
print "compiling string with syntax error"
|
||||
|
||||
try:
|
||||
compile("1+*3", "filename", "exec")
|
||||
except SyntaxError, detail:
|
||||
if not detail.filename == "filename":
|
||||
raise TestFailed, "expected 'filename', got %r" % detail.filename
|
||||
|
||||
try:
|
||||
exec 'def f(a = 0, a = 1): pass'
|
||||
raise TestFailed, "duplicate keyword arguments"
|
||||
|
|
|
@ -26,10 +26,19 @@ PyParser_ParseString(char *s, grammar *g, int start, perrdetail *err_ret)
|
|||
node *
|
||||
PyParser_ParseStringFlags(char *s, grammar *g, int start,
|
||||
perrdetail *err_ret, int flags)
|
||||
{
|
||||
return PyParser_ParseStringFlagsFilename(s, NULL,
|
||||
g, start, err_ret, 0);
|
||||
}
|
||||
|
||||
node *
|
||||
PyParser_ParseStringFlagsFilename(char *s, char *filename,
|
||||
grammar *g, int start,
|
||||
perrdetail *err_ret, int flags)
|
||||
{
|
||||
struct tok_state *tok;
|
||||
|
||||
initerr(err_ret, NULL);
|
||||
initerr(err_ret, filename);
|
||||
|
||||
if ((tok = PyTokenizer_FromString(s)) == NULL) {
|
||||
err_ret->error = E_NOMEM;
|
||||
|
@ -37,7 +46,7 @@ PyParser_ParseStringFlags(char *s, grammar *g, int start,
|
|||
}
|
||||
|
||||
if (Py_TabcheckFlag || Py_VerboseFlag) {
|
||||
tok->filename = "<string>";
|
||||
tok->filename = filename ? filename : "<string>";
|
||||
tok->altwarning = (tok->filename != NULL);
|
||||
if (Py_TabcheckFlag >= 2)
|
||||
tok->alterror++;
|
||||
|
|
|
@ -1134,7 +1134,9 @@ Py_CompileStringFlags(char *str, char *filename, int start,
|
|||
{
|
||||
node *n;
|
||||
PyCodeObject *co;
|
||||
n = PyParser_SimpleParseStringFlags(str, start, PARSER_FLAGS(flags));
|
||||
|
||||
n = PyParser_SimpleParseStringFlagsFilename(str, filename, start,
|
||||
PARSER_FLAGS(flags));
|
||||
if (n == NULL)
|
||||
return NULL;
|
||||
co = PyNode_CompileFlags(n, filename, flags);
|
||||
|
@ -1147,7 +1149,8 @@ Py_SymtableString(char *str, char *filename, int start)
|
|||
{
|
||||
node *n;
|
||||
struct symtable *st;
|
||||
n = PyParser_SimpleParseString(str, start);
|
||||
n = PyParser_SimpleParseStringFlagsFilename(str, filename,
|
||||
start, 0);
|
||||
if (n == NULL)
|
||||
return NULL;
|
||||
st = PyNode_CompileSymtable(n, filename);
|
||||
|
@ -1195,6 +1198,28 @@ PyParser_SimpleParseString(char *str, int start)
|
|||
return PyParser_SimpleParseStringFlags(str, start, 0);
|
||||
}
|
||||
|
||||
node *
|
||||
PyParser_SimpleParseStringFlagsFilename(char *str, char *filename,
|
||||
int start, int flags)
|
||||
{
|
||||
node *n;
|
||||
perrdetail err;
|
||||
|
||||
n = PyParser_ParseStringFlagsFilename(str, filename,
|
||||
&_PyParser_Grammar,
|
||||
start, &err, flags);
|
||||
if (n == NULL)
|
||||
err_input(&err);
|
||||
return n;
|
||||
}
|
||||
|
||||
node *
|
||||
PyParser_SimpleParseStringFilename(char *str, char *filename, int start)
|
||||
{
|
||||
return PyParser_SimpleParseStringFlagsFilename(str, filename,
|
||||
start, 0);
|
||||
}
|
||||
|
||||
/* Set the error appropriate to the given input error code (see errcode.h) */
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue