code-google-com / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

Incorrect unicode conversion between python object and javascript object on FreeBSD #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I compiled PyV8 under freebsd, and got following error:

with JSContext() as c:
    c.locals.s = u"测试"
    print len(c.locals.s)    # this will print 1, instead of 2

    c.locals.s = u"1234"
    print len(c.locals.s)    # this will print 1, instead of 4

In fact assign an unicode to JSContext will always return its length as 1.

After dig into the code, I found this is caused because on my FreeBSD the
python unicode is defined as UCS4 - the wide unicode (on win32, it will be
UCS2) this caused a problem when converting python unicode to v8::String in
CPythonObject::Wrap() method.

I patched the method to check if python is using UCS4 or UCS2 to determine
how to convert python unicode to v8::String.

Attached is the patched Wrapper.cpp, line 458-470 is modified.

Original issue reported on code.google.com by nuphahu...@gmail.com on 30 Sep 2009 at 5:18

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for your contribute, please check out the changes after SVN r159

Original comment by flier...@gmail.com on 8 Oct 2009 at 4:29

GoogleCodeExporter commented 9 years ago
Issue 7 has been merged into this issue.

Original comment by flier...@gmail.com on 8 Oct 2009 at 4:30