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

Side by Side Diff: Python/_warnings.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Patch Set: Created 8 years, 9 months ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « Python/symtable.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "Python.h" 1 #include "Python.h"
2 #include "frameobject.h" 2 #include "frameobject.h"
3 3
4 #define MODULE_NAME "_warnings" 4 #define MODULE_NAME "_warnings"
5 5
6 PyDoc_STRVAR(warnings__doc__, 6 PyDoc_STRVAR(warnings__doc__,
7 MODULE_NAME " provides basic warning filtering support.\n" 7 MODULE_NAME " provides basic warning filtering support.\n"
8 "It is a helper module to speed up interpreter start-up."); 8 "It is a helper module to speed up interpreter start-up.");
9 9
10 /* Both 'filters' and 'onceregistry' can be set in warnings.py; 10 /* Both 'filters' and 'onceregistry' can be set in warnings.py;
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 691
692 /* Get the source line. */ 692 /* Get the source line. */
693 source_line = PyList_GetItem(source_list, lineno-1); 693 source_line = PyList_GetItem(source_list, lineno-1);
694 if (!source_line) { 694 if (!source_line) {
695 Py_DECREF(source_list); 695 Py_DECREF(source_list);
696 return NULL; 696 return NULL;
697 } 697 }
698 698
699 /* Handle the warning. */ 699 /* Handle the warning. */
700 returned = warn_explicit(category, message, filename, lineno, module, 700 returned = warn_explicit(category, message, filename, lineno, module,
701 registry, source_line); 701 registry, source_line);
702 Py_DECREF(source_list); 702 Py_DECREF(source_list);
703 return returned; 703 return returned;
704 } 704 }
705 705
706 standard_call: 706 standard_call:
707 return warn_explicit(category, message, filename, lineno, module, 707 return warn_explicit(category, message, filename, lineno, module,
708 registry, NULL); 708 registry, NULL);
709 } 709 }
710 710
711 711
712 /* Function to issue a warning message; may raise an exception. */ 712 /* Function to issue a warning message; may raise an exception. */
713 713
714 static int 714 static int
715 warn_unicode(PyObject *category, PyObject *message, 715 warn_unicode(PyObject *category, PyObject *message,
716 Py_ssize_t stack_level) 716 Py_ssize_t stack_level)
717 { 717 {
718 PyObject *res; 718 PyObject *res;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 769
770 #undef PyErr_Warn 770 #undef PyErr_Warn
771 771
772 PyAPI_FUNC(int) 772 PyAPI_FUNC(int)
773 PyErr_Warn(PyObject *category, char *text) 773 PyErr_Warn(PyObject *category, char *text)
774 { 774 {
775 return PyErr_WarnEx(category, text, 1); 775 return PyErr_WarnEx(category, text, 1);
776 } 776 }
777 777
778 /* Warning with explicit origin */ 778 /* Warning with explicit origin */
779 int
780 PyErr_WarnExplicitObject(PyObject *category, PyObject *message,
781 PyObject *filename, int lineno,
782 PyObject *module, PyObject *registry)
783 {
784 PyObject *res;
785 if (category == NULL)
786 category = PyExc_RuntimeWarning;
787 res = warn_explicit(category, message, filename, lineno,
788 module, registry, NULL);
789 if (res == NULL)
790 return -1;
791 Py_DECREF(res);
792 return 0;
793 }
794
779 int 795 int
780 PyErr_WarnExplicit(PyObject *category, const char *text, 796 PyErr_WarnExplicit(PyObject *category, const char *text,
781 const char *filename_str, int lineno, 797 const char *filename_str, int lineno,
782 const char *module_str, PyObject *registry) 798 const char *module_str, PyObject *registry)
783 { 799 {
784 PyObject *res;
785 PyObject *message = PyUnicode_FromString(text); 800 PyObject *message = PyUnicode_FromString(text);
786 PyObject *filename = PyUnicode_DecodeFSDefault(filename_str); 801 PyObject *filename = PyUnicode_DecodeFSDefault(filename_str);
787 PyObject *module = NULL; 802 PyObject *module = NULL;
788 int ret = -1; 803 int ret = -1;
789 804
790 if (message == NULL || filename == NULL) 805 if (message == NULL || filename == NULL)
791 goto exit; 806 goto exit;
792 if (module_str != NULL) { 807 if (module_str != NULL) {
793 module = PyUnicode_FromString(module_str); 808 module = PyUnicode_FromString(module_str);
794 if (module == NULL) 809 if (module == NULL)
795 goto exit; 810 goto exit;
796 } 811 }
797 812
798 if (category == NULL) 813 ret = PyErr_WarnExplicitObject(category, message, filename, lineno,
799 category = PyExc_RuntimeWarning; 814 module, registry);
800 res = warn_explicit(category, message, filename, lineno, module, registry,
801 NULL);
802 if (res == NULL)
803 goto exit;
804 Py_DECREF(res);
805 ret = 0;
806 815
807 exit: 816 exit:
808 Py_XDECREF(message); 817 Py_XDECREF(message);
809 Py_XDECREF(module); 818 Py_XDECREF(module);
810 Py_XDECREF(filename); 819 Py_XDECREF(filename);
811 return ret; 820 return ret;
812 } 821 }
813 822
814 823
815 PyDoc_STRVAR(warn_doc, 824 PyDoc_STRVAR(warn_doc,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 if (PyModule_AddObject(m, "_onceregistry", _once_registry) < 0) 973 if (PyModule_AddObject(m, "_onceregistry", _once_registry) < 0)
965 return NULL; 974 return NULL;
966 975
967 _default_action = PyUnicode_FromString("default"); 976 _default_action = PyUnicode_FromString("default");
968 if (_default_action == NULL) 977 if (_default_action == NULL)
969 return NULL; 978 return NULL;
970 if (PyModule_AddObject(m, "_defaultaction", _default_action) < 0) 979 if (PyModule_AddObject(m, "_defaultaction", _default_action) < 0)
971 return NULL; 980 return NULL;
972 return m; 981 return m;
973 } 982 }
OLDNEW
« no previous file with comments | « Python/symtable.c ('k') | no next file » | no next file with comments »

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