Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(160948)

Unified Diff: Parser/parsetok.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Modules/symtablemodule.c ('k') | Python/ast.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Parser/parsetok.c Mon Aug 26 14:05:19 2013 +0200
+++ b/Parser/parsetok.c Mon Aug 26 16:10:52 2013 +0200
@@ -13,7 +13,7 @@
/* Forward */
static node *parsetok(struct tok_state *, grammar *, int, perrdetail *, int *);
-static int initerr(perrdetail *err_ret, const char* filename);
+static int initerr(perrdetail *err_ret, PyObject * filename);
/* Parse input coming from a string. Return error code, print some errors. */
node *
@@ -41,9 +41,9 @@ PyParser_ParseStringFlagsFilename(const
}
node *
-PyParser_ParseStringFlagsFilenameEx(const char *s, const char *filename,
- grammar *g, int start,
- perrdetail *err_ret, int *flags)
+PyParser_ParseStringObject(const char *s, PyObject *filename,
+ grammar *g, int start,
+ perrdetail *err_ret, int *flags)
{
struct tok_state *tok;
int exec_input = start == file_input;
@@ -67,6 +67,30 @@ PyParser_ParseStringFlagsFilenameEx(cons
return parsetok(tok, g, start, err_ret, flags);
}
+node *
+PyParser_ParseStringFlagsFilenameEx(const char *s, const char *filename_str,
+ grammar *g, int start,
+ perrdetail *err_ret, int *flags)
+{
+ PyObject *filename;
+ node *n;
+ filename = NULL;
+#ifndef PGEN
+ if (filename_str != NULL) {
+ filename = PyUnicode_DecodeFSDefault(filename_str);
+ if (filename == NULL) {
+ err_ret->error = E_ERROR;
+ return NULL;
+ }
+ }
+#endif
+ n = PyParser_ParseStringObject(s, filename, g, start, err_ret, flags);
+#ifndef PGEN
+ Py_XDECREF(filename);
+#endif
+ return n;
+}
+
/* Parse input coming from a file. Return error code, print some errors. */
node *
@@ -88,9 +112,10 @@ PyParser_ParseFileFlags(FILE *fp, const
}
node *
-PyParser_ParseFileFlagsEx(FILE *fp, const char *filename,
- const char *enc, grammar *g, int start,
- char *ps1, char *ps2, perrdetail *err_ret, int *flags)
+PyParser_ParseFileObject(FILE *fp, PyObject *filename,
+ const char *enc, grammar *g, int start,
+ char *ps1, char *ps2, perrdetail *err_ret,
+ int *flags)
{
struct tok_state *tok;
@@ -108,6 +133,32 @@ PyParser_ParseFileFlagsEx(FILE *fp, cons
return parsetok(tok, g, start, err_ret, flags);
}
+node *
+PyParser_ParseFileFlagsEx(FILE *fp, const char *filename,
+ const char *enc, grammar *g, int start,
+ char *ps1, char *ps2, perrdetail *err_ret, int *flags)
+{
+ node *n;
+ PyObject *fileobj;
+#ifndef PGEN
+ if (filename != NULL) {
+ fileobj = PyUnicode_DecodeFSDefault(filename);
+ if (fileobj == NULL) {
+ err_ret->error = E_ERROR;
+ return NULL;
+ }
+ }
+ else
+#endif
+ fileobj = NULL;
+ n = PyParser_ParseFileObject(fp, fileobj, enc, g,
+ start, ps1, ps2, err_ret, flags);
+#ifndef PGEN
+ Py_XDECREF(fileobj);
+#endif
+ return n;
+}
+
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
#if 0
static char with_msg[] =
@@ -306,7 +357,7 @@ done:
}
static int
-initerr(perrdetail *err_ret, const char *filename)
+initerr(perrdetail *err_ret, PyObject *filename)
{
err_ret->error = E_OK;
err_ret->lineno = 0;
@@ -315,13 +366,16 @@ initerr(perrdetail *err_ret, const char
err_ret->token = -1;
err_ret->expected = -1;
#ifndef PGEN
- if (filename)
- err_ret->filename = PyUnicode_DecodeFSDefault(filename);
- else
+ if (filename) {
+ Py_INCREF(filename);
+ err_ret->filename = filename;
+ }
+ else {
err_ret->filename = PyUnicode_FromString("<string>");
- if (err_ret->filename == NULL) {
- err_ret->error = E_ERROR;
- return -1;
+ if (err_ret->filename == NULL) {
+ err_ret->error = E_ERROR;
+ return -1;
+ }
}
#endif
return 0;
« no previous file with comments | « Modules/symtablemodule.c ('k') | Python/ast.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+