Hi,

:py3 vim.eval() doesn't handle multibyte characters properly
when 'encoding' is not utf-8 (e.g. cp932).

How to reproduce:

:set enc=cp932
:call setline(1, "\u82a0")  " Set Hiragana Letter A 'あ' (U+3042 in Unicode)
:py3 import vim
:py3 print(vim.eval('getline(1)'))  " Printing 'あ' is expected.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 0: 
invalid start byte

Attached patch fixes this problem.
Please check it.

Regards,
Ken Takata

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


# HG changeset patch
# Parent 78253a62f894866cc29a5d9a1ad88687f6464ba8
diff --git a/src/if_python3.c b/src/if_python3.c
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -86,7 +86,8 @@
 #ifndef PyString_Check
 # define PyString_Check(obj) PyUnicode_Check(obj)
 #endif
-#define PyString_FromString(repr) PyUnicode_FromString(repr)
+#define PyString_FromString(repr) \
+    PyUnicode_Decode(repr, STRLEN(repr), ENC_OPT, NULL)
 #define PyString_FromFormat PyUnicode_FromFormat
 #ifndef PyInt_Check
 # define PyInt_Check(obj) PyLong_Check(obj)

Raspunde prin e-mail lui