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

Delta Between Two Patch Sets: Python/ast.c

Issue 28128: Improve the warning message for invalid escape sequences
Left Patch Set: Created 3 years, 1 month ago
Right Patch Set: Created 3 years, 1 month 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Objects/unicodeobject.c ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file includes functions to transform a concrete syntax tree (CST) to 2 * This file includes functions to transform a concrete syntax tree (CST) to
3 * an abstract syntax tree (AST). The main function is PyAST_FromNode(). 3 * an abstract syntax tree (AST). The main function is PyAST_FromNode().
4 * 4 *
5 */ 5 */
6 #include "Python.h" 6 #include "Python.h"
7 #include "Python-ast.h" 7 #include "Python-ast.h"
8 #include "node.h" 8 #include "node.h"
9 #include "ast.h" 9 #include "ast.h"
10 #include "token.h" 10 #include "token.h"
(...skipping 4099 matching lines...) Expand 10 before | Expand all | Expand 10 after
4110 /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */ 4110 /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */
4111 while (s < end && (*s & 0x80)) s++; 4111 while (s < end && (*s & 0x80)) s++;
4112 *sPtr = s; 4112 *sPtr = s;
4113 return PyUnicode_DecodeUTF8(t, s - t, NULL); 4113 return PyUnicode_DecodeUTF8(t, s - t, NULL);
4114 } 4114 }
4115 4115
4116 static int 4116 static int
4117 warn_invalid_escape_sequence(struct compiling *c, const node *n, 4117 warn_invalid_escape_sequence(struct compiling *c, const node *n,
4118 char first_invalid_escape_char) 4118 char first_invalid_escape_char)
4119 { 4119 {
4120 int res;
4121 PyObject *msg = PyUnicode_FromFormat("invalid escape sequence \\%c", 4120 PyObject *msg = PyUnicode_FromFormat("invalid escape sequence \\%c",
4122 first_invalid_escape_char); 4121 first_invalid_escape_char);
4123 if (msg == NULL) { 4122 if (msg == NULL) {
4124 return -1; 4123 return -1;
4125 } 4124 }
4126 res = PyErr_WarnExplicitObject(PyExc_DeprecationWarning, msg, 4125 if (PyErr_WarnExplicitObject(PyExc_DeprecationWarning, msg,
4127 c->c_filename, LINENO(n), 4126 c->c_filename, LINENO(n),
4128 NULL, NULL); 4127 NULL, NULL) < 0 &&
4128 PyErr_ExceptionMatches(PyExc_DeprecationWarning))
4129 {
4130 const char *s = PyUnicode_AsUTF8(msg);
4131 if (s != NULL) {
4132 ast_error(c, n, s);
4133 }
4134 Py_DECREF(msg);
4135 return -1;
4136 }
4129 Py_DECREF(msg); 4137 Py_DECREF(msg);
4130 return res; 4138 return 0;
4131 } 4139 }
4132 4140
4133 static PyObject * 4141 static PyObject *
4134 decode_unicode_with_escapes(struct compiling *c, const node *n, const char *s, 4142 decode_unicode_with_escapes(struct compiling *c, const node *n, const char *s,
4135 size_t len) 4143 size_t len)
4136 { 4144 {
4137 PyObject *v, *u; 4145 PyObject *v, *u;
4138 char *buf; 4146 char *buf;
4139 char *p; 4147 char *p;
4140 const char *end; 4148 const char *end;
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
5186 /* We're not a bytes string, bytes_str should never have been set. */ 5194 /* We're not a bytes string, bytes_str should never have been set. */
5187 assert(bytes_str == NULL); 5195 assert(bytes_str == NULL);
5188 5196
5189 return FstringParser_Finish(&state, c, n); 5197 return FstringParser_Finish(&state, c, n);
5190 5198
5191 error: 5199 error:
5192 Py_XDECREF(bytes_str); 5200 Py_XDECREF(bytes_str);
5193 FstringParser_Dealloc(&state); 5201 FstringParser_Dealloc(&state);
5194 return NULL; 5202 return NULL;
5195 } 5203 }
LEFTRIGHT

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