summaryrefslogtreecommitdiffstats
path: root/Parser/tokenizer.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-03-17 20:43:42 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-03-17 20:43:42 (GMT)
commit259314622750c72de2ef377e77a0b70b8d8b2fb5 (patch)
tree089ad865c7be59bf68fd72e0d5c18c12d831e345 /Parser/tokenizer.c
parentddaa7064ee81c48adc4fdea327892c29179f7845 (diff)
downloadcpython-259314622750c72de2ef377e77a0b70b8d8b2fb5.zip
cpython-259314622750c72de2ef377e77a0b70b8d8b2fb5.tar.gz
cpython-259314622750c72de2ef377e77a0b70b8d8b2fb5.tar.bz2
Bug #2301: Don't try decoding the source code into the original
encoding for syntax errors.
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c64
1 files changed, 0 insertions, 64 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 2833e53..0b8341a 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -1579,70 +1579,6 @@ PyTokenizer_Get(struct tok_state *tok, char **p_start, char **p_end)
return result;
}
-/* This function is only called from parsetok. However, it cannot live
- there, as it must be empty for PGEN, and we can check for PGEN only
- in this file. */
-
-#ifdef PGEN
-char*
-PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int* offset)
-{
- return NULL;
-}
-#else
-static PyObject *
-dec_utf8(const char *enc, const char *text, size_t len) {
- PyObject *ret = NULL;
- PyObject *unicode_text = PyUnicode_DecodeUTF8(text, len, "replace");
- if (unicode_text) {
- ret = PyUnicode_AsEncodedString(unicode_text, enc, "replace");
- Py_DECREF(unicode_text);
- }
- if (!ret) {
- PyErr_Clear();
- }
- else {
- assert(PyString_Check(ret));
- }
- return ret;
-}
-
-char *
-PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int *offset)
-{
- char *text = NULL;
- if (tok->encoding) {
- /* convert source to original encondig */
- PyObject *lineobj = dec_utf8(tok->encoding, tok->buf, len);
- if (lineobj != NULL) {
- int linelen = PyString_GET_SIZE(lineobj);
- const char *line = PyString_AS_STRING(lineobj);
- text = PyObject_MALLOC(linelen + 1);
- if (text != NULL && line != NULL) {
- if (linelen)
- strncpy(text, line, linelen);
- text[linelen] = '\0';
- }
- Py_DECREF(lineobj);
-
- /* adjust error offset */
- if (*offset > 1) {
- PyObject *offsetobj = dec_utf8(tok->encoding,
- tok->buf,
- *offset-1);
- if (offsetobj) {
- *offset = 1 + Py_SIZE(offsetobj);
- Py_DECREF(offsetobj);
- }
- }
-
- }
- }
- return text;
-
-}
-#endif
-
/* Get -*- encoding -*- from a Python file.
PyTokenizer_FindEncoding returns NULL when it can't find the encoding in