[PATCH] fix broken Python3 support

49 views
Skip to first unread message

lilydjwg

unread,
Feb 24, 2011, 9:27:57 AM2/24/11
to vim_dev
Hi there,

I made a patch to fix some bugs related to Vim's Python3 support. The
bugs I found are:

* vim.error is a `str` instead of an `Exception` object, so `except` or
`raise` it causes a `SystemError` exception
* buffer objects do not support slice assignment
* when exchange text between Vim and Python, multibyte texts become
gabage or cause Unicode Expceptions, etc
* `py3file` tries to read in the file as Unicode, sometimes causes
UnicodeDecodeException

The patch works on my Ubuntu Linux 32bit and Windows XP SP3 and should
apply to any Vim 7.3+ version.

--
Best regards,
lilydjwg

Linux Vim Python 我的博客
http://lilydjwg.is-programmer.com/

lilydjwg

unread,
Feb 24, 2011, 9:32:03 AM2/24/11
to vim_dev
Sorry, I forgot the attachment.
vim73py3fix.patch

Bram Moolenaar

unread,
Feb 25, 2011, 8:43:22 AM2/25/11
to lilydjwg, vim_dev

Lilydjwg wrote:

> I made a patch to fix some bugs related to Vim's Python3 support. The
> bugs I found are:
>
> * vim.error is a `str` instead of an `Exception` object, so `except` or
> `raise` it causes a `SystemError` exception
> * buffer objects do not support slice assignment
> * when exchange text between Vim and Python, multibyte texts become
> gabage or cause Unicode Expceptions, etc
> * `py3file` tries to read in the file as Unicode, sometimes causes
> UnicodeDecodeException
>
> The patch works on my Ubuntu Linux 32bit and Windows XP SP3 and should
> apply to any Vim 7.3+ version.

Sounds good.

Can a few people try this out?

--
Apologies for taking up the bandwidth with the apology. Anything else I
can apologise for ...... er no can't think of anything, sorry about that.
Andy Hunt (Member of British Olympic Apology Squad)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Bram Moolenaar

unread,
Jun 12, 2011, 9:54:04 PM6/12/11
to lilydjwg, vim_dev

lilydjwg wrote:

> I made a patch to fix some bugs related to Vim's Python3 support. The
> bugs I found are:
>
> * vim.error is a `str` instead of an `Exception` object, so `except` or
> `raise` it causes a `SystemError` exception
> * buffer objects do not support slice assignment
> * when exchange text between Vim and Python, multibyte texts become
> gabage or cause Unicode Expceptions, etc
> * `py3file` tries to read in the file as Unicode, sometimes causes
> UnicodeDecodeException
>
> The patch works on my Ubuntu Linux 32bit and Windows XP SP3 and should
> apply to any Vim 7.3+ version.

I have included the patch, but on my Ubuntu system I get this error:

E448: Could not load library function PyUnicode_UCSX_*

when doing something simple as ":py3 print('hello')"

Can you fix that?

--
If Microsoft would build a car...
... Occasionally your car would die on the freeway for no
reason. You would have to pull over to the side of the road,
close all of the car windows, shut it off, restart it, and
reopen the windows before you could continue. For some reason
you would simply accept this.

lilydjwg

unread,
Jun 13, 2011, 2:27:07 AM6/13/11
to Bram Moolenaar, vim_dev
On Mon, Jun 13, 2011 at 03:54:04AM +0200, Bram Moolenaar wrote:
> I have included the patch, but on my Ubuntu system I get this error:
>
> E448: Could not load library function PyUnicode_UCSX_*
>
> when doing something simple as ":py3 print('hello')"
>
> Can you fix that?
>

Yes, just a typo preventing Python symbols from loading.

Later a user found that there was heavy memory leakage, and I tried hard
to fix them. It was partly introduced by my code, and I believe partly
had been there before. Attached patch should fix this too.

--
Best regards,
lilydjwg

vim73py3fix.patch

Bram Moolenaar

unread,
Jun 14, 2011, 12:06:51 AM6/14/11
to lilydjwg, vim_dev

lilydjwg wronte:

Thanks for the update. I'll check it out later.

I have this remark in the todo list, I suppose this patch is fixing it:

Python3 interface doesn't handle utf-8 correctly? (Nov 2010, lilydjwg)

--
hundred-and-one symptoms of being an internet addict:
179. You wonder why your household garbage can doesn't have an
"empty recycle bin" button.

lilydjwg

unread,
Jun 15, 2011, 5:24:09 AM6/15/11
to Bram Moolenaar, vim_dev
On Tue, Jun 14, 2011 at 06:06:51AM +0200, Bram Moolenaar wrote:
> Thanks for the update. I'll check it out later.
>
> I have this remark in the todo list, I suppose this patch is fixing it:
>
> Python3 interface doesn't handle utf-8 correctly? (Nov 2010, lilydjwg)
>

Yes.

--
Best regards,
lilydjwg

Linux Vim Python 我的博客
http://bit.ly/lilydjwg or http://goo.gl/y4Gsy

Reply all
Reply to author
Forward
0 new messages