comparison Python/bltinmodule.c @ 85417:df2fdd42b375

Close #11619: The parser and the import machinery do not encode Unicode filenames anymore on Windows.
author Victor Stinner <victor.stinner@gmail.com>
date Mon, 26 Aug 2013 22:28:21 +0200
parents a5d9e2f3f6c7
children 0872257752c2
comparison
equal deleted inserted replaced
85416:8fb3a6f9b0a4 85417:df2fdd42b375
577 577
578 static PyObject * 578 static PyObject *
579 builtin_compile(PyObject *self, PyObject *args, PyObject *kwds) 579 builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
580 { 580 {
581 char *str; 581 char *str;
582 PyObject *filename_obj; 582 PyObject *filename;
583 char *filename;
584 char *startstr; 583 char *startstr;
585 int mode = -1; 584 int mode = -1;
586 int dont_inherit = 0; 585 int dont_inherit = 0;
587 int supplied_flags = 0; 586 int supplied_flags = 0;
588 int optimize = -1; 587 int optimize = -1;
594 int start[] = {Py_file_input, Py_eval_input, Py_single_input}; 593 int start[] = {Py_file_input, Py_eval_input, Py_single_input};
595 PyObject *result; 594 PyObject *result;
596 595
597 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&s|iii:compile", kwlist, 596 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&s|iii:compile", kwlist,
598 &cmd, 597 &cmd,
599 PyUnicode_FSConverter, &filename_obj, 598 PyUnicode_FSDecoder, &filename,
600 &startstr, &supplied_flags, 599 &startstr, &supplied_flags,
601 &dont_inherit, &optimize)) 600 &dont_inherit, &optimize))
602 return NULL; 601 return NULL;
603 602
604 filename = PyBytes_AS_STRING(filename_obj);
605 cf.cf_flags = supplied_flags | PyCF_SOURCE_IS_UTF8; 603 cf.cf_flags = supplied_flags | PyCF_SOURCE_IS_UTF8;
606 604
607 if (supplied_flags & 605 if (supplied_flags &
608 ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | PyCF_ONLY_AST)) 606 ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | PyCF_ONLY_AST))
609 { 607 {
657 } 655 }
658 if (!PyAST_Validate(mod)) { 656 if (!PyAST_Validate(mod)) {
659 PyArena_Free(arena); 657 PyArena_Free(arena);
660 goto error; 658 goto error;
661 } 659 }
662 result = (PyObject*)PyAST_CompileEx(mod, filename, 660 result = (PyObject*)PyAST_CompileObject(mod, filename,
663 &cf, optimize, arena); 661 &cf, optimize, arena);
664 PyArena_Free(arena); 662 PyArena_Free(arena);
665 } 663 }
666 goto finally; 664 goto finally;
667 } 665 }
668 666
669 str = source_as_string(cmd, "compile", "string, bytes or AST", &cf); 667 str = source_as_string(cmd, "compile", "string, bytes or AST", &cf);
670 if (str == NULL) 668 if (str == NULL)
671 goto error; 669 goto error;
672 670
673 result = Py_CompileStringExFlags(str, filename, start[mode], &cf, optimize); 671 result = Py_CompileStringObject(str, filename, start[mode], &cf, optimize);
674 goto finally; 672 goto finally;
675 673
676 error: 674 error:
677 result = NULL; 675 result = NULL;
678 finally: 676 finally:
679 Py_DECREF(filename_obj); 677 Py_DECREF(filename);
680 return result; 678 return result;
681 } 679 }
682 680
683 PyDoc_STRVAR(compile_doc, 681 PyDoc_STRVAR(compile_doc,
684 "compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\ 682 "compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\