From: Neal Norwitz Date: Sat, 11 Aug 2007 21:31:25 +0000 (+0000) Subject: Fix problem when exec'ing a string with a coding X-Git-Tag: v3.0a1~441 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7f28fc46bc47465e3d36610940241a5ebadef02;p=python Fix problem when exec'ing a string with a coding --- diff --git a/Lib/test/test_coding.py b/Lib/test/test_coding.py index e83015e543..62cf55555b 100644 --- a/Lib/test/test_coding.py +++ b/Lib/test/test_coding.py @@ -21,6 +21,11 @@ class CodingTest(unittest.TestCase): fp.close() self.assertRaises(SyntaxError, compile, text, filename, 'exec') + def test_exec_valid_coding(self): + d = {} + exec('# coding: cp949\na = 5\n', d) + self.assertEqual(d['a'], 5) + def test_main(): test.test_support.run_unittest(CodingTest) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 00bb38ad19..284082d475 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -632,7 +632,7 @@ decode_str(const char *str, struct tok_state *tok) "unknown encoding: %s", tok->enc); return error_ret(tok); } - str = PyString_AsString(utf8); + str = PyBytes_AsString(utf8); } assert(tok->decoding_buffer == NULL); tok->decoding_buffer = utf8; /* CAUTION */