1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Python 3: vim.error is a 'str' instead of an 'Exception' object,
12 so 'except' or 'raise' it causes a 'SystemError' exception.
13 Buffer objects do not support slice assignment.
14 When exchanging text between Vim and Python, multibyte texts become
15 gabage or cause Unicode Expceptions, etc.
16 'py3file' tries to read in the file as Unicode, sometimes causes
17 UnicodeDecodeException
18 Solution: Fix the problems. (lilydjwg)
19 Files: src/if_py_both.h, src/if_python.c, src/if_python3.c
22 *** ../mercurial/vim73/src/if_py_both.h 2011-03-22 15:47:18.000000000 +0100
23 --- src/if_py_both.h 2011-06-18 23:54:25.000000000 +0200
26 OutputWrite(PyObject *self, PyObject *args)
30 int error = ((OutputObject *)(self))->error;
32 ! if (!PyArg_ParseTuple(args, "s#", &str, &len))
35 Py_BEGIN_ALLOW_THREADS
37 OutputWrite(PyObject *self, PyObject *args)
41 int error = ((OutputObject *)(self))->error;
43 ! if (!PyArg_ParseTuple(args, "es#", p_enc, &str, &len))
46 Py_BEGIN_ALLOW_THREADS
50 writer((writefn)(error ? emsg : msg), (char_u *)str, len);
59 for (i = 0; i < n; ++i)
61 PyObject *line = PyList_GetItem(list, i);
65 ! if (!PyArg_Parse(line, "s#", &str, &len)) {
66 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
70 for (i = 0; i < n; ++i)
72 PyObject *line = PyList_GetItem(list, i);
76 ! if (!PyArg_Parse(line, "es#", p_enc, &str, &len)) {
77 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
83 writer((writefn)(error ? emsg : msg), (char_u *)str, len);
105 ! str = PyString_AsString(obj);
106 ! len = PyString_Size(obj);
109 * Error checking: String must not contain newlines, as we
114 ! bytes = PyString_AsBytes(obj); /* for Python 2 this does nothing */
115 ! str = PyString_AsString(bytes);
116 ! len = PyString_Size(bytes);
119 * Error checking: String must not contain newlines, as we
126 + PyString_FreeBytes(bytes); /* Python 2 does nothing here */
132 invalidate_botline();
135 ! /* Replace a line in the specified buffer. The line number is
136 * in Vim format (1-based). The replacement line is given as
137 * a Python string object. The object is checked for validity
138 * and correct format. Errors are returned as a value of FAIL.
140 invalidate_botline();
144 ! * Replace a line in the specified buffer. The line number is
145 * in Vim format (1-based). The replacement line is given as
146 * a Python string object. The object is checked for validity
147 * and correct format. Errors are returned as a value of FAIL.
154 + /* Replace a range of lines in the specified buffer. The line numbers are in
155 + * Vim format (1-based). The range is from lo up to, but not including, hi.
156 + * The replacement lines are given as a Python list of string objects. The
157 + * list is checked for validity and correct format. Errors are returned as a
158 + * value of FAIL. The return value is OK on success.
159 + * If OK is returned and len_change is not NULL, *len_change
160 + * is set to the change in the buffer length.
163 + SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, PyInt *len_change)
165 + /* First of all, we check the thpe of the supplied Python object.
166 + * There are three cases:
167 + * 1. NULL, or None - this is a deletion.
168 + * 2. A list - this is a replacement.
169 + * 3. Anything else - this is an error.
171 + if (list == Py_None || list == NULL)
174 + PyInt n = (int)(hi - lo);
175 + buf_T *savebuf = curbuf;
180 + if (u_savedel((linenr_T)lo, (long)n) == FAIL)
181 + PyErr_SetVim(_("cannot save undo information"));
184 + for (i = 0; i < n; ++i)
186 + if (ml_delete((linenr_T)lo, FALSE) == FAIL)
188 + PyErr_SetVim(_("cannot delete line"));
192 + if (buf == curwin->w_buffer)
193 + py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
194 + deleted_lines_mark((linenr_T)lo, (long)i);
199 + if (PyErr_Occurred() || VimErrorCheck())
207 + else if (PyList_Check(list))
210 + PyInt new_len = PyList_Size(list);
211 + PyInt old_len = hi - lo;
212 + PyInt extra = 0; /* lines added to text, can be negative */
216 + if (new_len == 0) /* avoid allocating zero bytes */
220 + array = (char **)alloc((unsigned)(new_len * sizeof(char *)));
228 + for (i = 0; i < new_len; ++i)
230 + PyObject *line = PyList_GetItem(list, i);
232 + array[i] = StringToLine(line);
233 + if (array[i] == NULL)
236 + vim_free(array[--i]);
247 + if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
248 + PyErr_SetVim(_("cannot save undo information"));
250 + /* If the size of the range is reducing (ie, new_len < old_len) we
251 + * need to delete some old_len. We do this at the start, by
252 + * repeatedly deleting line "lo".
254 + if (!PyErr_Occurred())
256 + for (i = 0; i < old_len - new_len; ++i)
257 + if (ml_delete((linenr_T)lo, FALSE) == FAIL)
259 + PyErr_SetVim(_("cannot delete line"));
265 + /* For as long as possible, replace the existing old_len with the
266 + * new old_len. This is a more efficient operation, as it requires
267 + * less memory allocation and freeing.
269 + if (!PyErr_Occurred())
271 + for (i = 0; i < old_len && i < new_len; ++i)
272 + if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE)
275 + PyErr_SetVim(_("cannot replace line"));
282 + /* Now we may need to insert the remaining new old_len. If we do, we
283 + * must free the strings as we finish with them (we can't pass the
284 + * responsibility to vim in this case).
286 + if (!PyErr_Occurred())
288 + while (i < new_len)
290 + if (ml_append((linenr_T)(lo + i - 1),
291 + (char_u *)array[i], 0, FALSE) == FAIL)
293 + PyErr_SetVim(_("cannot insert line"));
296 + vim_free(array[i]);
302 + /* Free any left-over old_len, as a result of an error */
303 + while (i < new_len)
305 + vim_free(array[i]);
309 + /* Free the array of old_len. All of its contents have now
310 + * been dealt with (either freed, or the responsibility passed
315 + /* Adjust marks. Invalidate any which lie in the
316 + * changed range, and move any in the remainder of the buffer.
318 + mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
319 + (long)MAXLNUM, (long)extra);
320 + changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
322 + if (buf == curwin->w_buffer)
323 + py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
327 + if (PyErr_Occurred() || VimErrorCheck())
331 + *len_change = new_len - old_len;
337 + PyErr_BadArgument();
342 /* Insert a number of lines into the specified buffer after the specifed line.
343 * The line number is in Vim format (1-based). The lines to be inserted are
350 + *new_end = end + len_change;
356 + RBAsSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, PyInt start, PyInt end, PyInt *new_end)
361 + /* Self must be a valid buffer */
362 + if (CheckBuffer(self))
365 + /* Sort out the slice range */
366 + size = end - start + 1;
370 + else if (lo > size)
376 + else if (hi > size)
379 + if (SetBufferLineList(self->buf, lo + start, hi + start,
380 + val, &len_change) == FAIL)
384 *new_end = end + len_change;
387 *** ../mercurial/vim73/src/if_python.c 2011-03-26 18:32:00.000000000 +0100
388 --- src/if_python.c 2011-06-19 00:02:15.000000000 +0200
393 static void init_structs(void);
395 + /* No-op conversion functions, use with care! */
396 + #define PyString_AsBytes(obj) (obj)
397 + #define PyString_FreeBytes(obj)
399 #if !defined(FEAT_PYTHON) && defined(PROTO)
400 /* Use this to be able to generate prototypes without python being used. */
401 # define PyObject Py_ssize_t
406 # define PyArg_Parse dll_PyArg_Parse
407 # define PyArg_ParseTuple dll_PyArg_ParseTuple
408 + # define PyMem_Free dll_PyMem_Free
409 # define PyDict_SetItemString dll_PyDict_SetItemString
410 # define PyErr_BadArgument dll_PyErr_BadArgument
411 # define PyErr_Clear dll_PyErr_Clear
416 static int(*dll_PyArg_Parse)(PyObject *, char *, ...);
417 static int(*dll_PyArg_ParseTuple)(PyObject *, char *, ...);
418 + static int(*dll_PyMem_Free)(void *);
419 static int(*dll_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
420 static int(*dll_PyErr_BadArgument)(void);
421 static void(*dll_PyErr_Clear)(void);
426 {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse},
427 {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple},
428 + {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free},
429 {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString},
430 {"PyErr_BadArgument", (PYTHON_PROC*)&dll_PyErr_BadArgument},
431 {"PyErr_Clear", (PYTHON_PROC*)&dll_PyErr_Clear},
434 static PyObject *CurrentGetattr(PyObject *, char *);
435 static int CurrentSetattr(PyObject *, char *, PyObject *);
437 - /* Common routines for buffers and line ranges
438 - * -------------------------------------------
442 - RBAssSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, PyInt start, PyInt end, PyInt *new_end)
447 - /* Self must be a valid buffer */
448 - if (CheckBuffer(self))
451 - /* Sort out the slice range */
452 - size = end - start + 1;
456 - else if (lo > size)
462 - else if (hi > size)
465 - if (SetBufferLineList(self->buf, lo + start, hi + start,
466 - val, &len_change) == FAIL)
470 - *new_end = end + len_change;
475 static PySequenceMethods BufferAsSeq = {
476 (PyInquiry) BufferLength, /* sq_length, len(x) */
477 (binaryfunc) 0, /* BufferConcat, */ /* sq_concat, x+y */
482 BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
484 ! return RBAssSlice((BufferObject *)(self), lo, hi, val, 1,
485 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
490 BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
492 ! return RBAsSlice((BufferObject *)(self), lo, hi, val, 1,
493 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
499 RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
501 ! return RBAssSlice(((RangeObject *)(self))->buf, lo, hi, val,
502 ((RangeObject *)(self))->start,
503 ((RangeObject *)(self))->end,
504 &((RangeObject *)(self))->end);
507 RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
509 ! return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,
510 ((RangeObject *)(self))->start,
511 ((RangeObject *)(self))->end,
512 &((RangeObject *)(self))->end);
515 * 4. Utility functions for handling the interface between Vim and Python.
518 - /* Replace a range of lines in the specified buffer. The line numbers are in
519 - * Vim format (1-based). The range is from lo up to, but not including, hi.
520 - * The replacement lines are given as a Python list of string objects. The
521 - * list is checked for validity and correct format. Errors are returned as a
522 - * value of FAIL. The return value is OK on success.
523 - * If OK is returned and len_change is not NULL, *len_change
524 - * is set to the change in the buffer length.
527 - SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, PyInt *len_change)
529 - /* First of all, we check the thpe of the supplied Python object.
530 - * There are three cases:
531 - * 1. NULL, or None - this is a deletion.
532 - * 2. A list - this is a replacement.
533 - * 3. Anything else - this is an error.
535 - if (list == Py_None || list == NULL)
538 - PyInt n = (int)(hi - lo);
539 - buf_T *savebuf = curbuf;
544 - if (u_savedel((linenr_T)lo, (long)n) == FAIL)
545 - PyErr_SetVim(_("cannot save undo information"));
548 - for (i = 0; i < n; ++i)
550 - if (ml_delete((linenr_T)lo, FALSE) == FAIL)
552 - PyErr_SetVim(_("cannot delete line"));
556 - if (buf == curwin->w_buffer)
557 - py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
558 - deleted_lines_mark((linenr_T)lo, (long)i);
563 - if (PyErr_Occurred() || VimErrorCheck())
571 - else if (PyList_Check(list))
574 - PyInt new_len = PyList_Size(list);
575 - PyInt old_len = hi - lo;
576 - PyInt extra = 0; /* lines added to text, can be negative */
580 - if (new_len == 0) /* avoid allocating zero bytes */
584 - array = (char **)alloc((unsigned)(new_len * sizeof(char *)));
592 - for (i = 0; i < new_len; ++i)
594 - PyObject *line = PyList_GetItem(list, i);
596 - array[i] = StringToLine(line);
597 - if (array[i] == NULL)
600 - vim_free(array[--i]);
611 - if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
612 - PyErr_SetVim(_("cannot save undo information"));
614 - /* If the size of the range is reducing (ie, new_len < old_len) we
615 - * need to delete some old_len. We do this at the start, by
616 - * repeatedly deleting line "lo".
618 - if (!PyErr_Occurred())
620 - for (i = 0; i < old_len - new_len; ++i)
621 - if (ml_delete((linenr_T)lo, FALSE) == FAIL)
623 - PyErr_SetVim(_("cannot delete line"));
629 - /* For as long as possible, replace the existing old_len with the
630 - * new old_len. This is a more efficient operation, as it requires
631 - * less memory allocation and freeing.
633 - if (!PyErr_Occurred())
635 - for (i = 0; i < old_len && i < new_len; ++i)
636 - if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE)
639 - PyErr_SetVim(_("cannot replace line"));
646 - /* Now we may need to insert the remaining new old_len. If we do, we
647 - * must free the strings as we finish with them (we can't pass the
648 - * responsibility to vim in this case).
650 - if (!PyErr_Occurred())
652 - while (i < new_len)
654 - if (ml_append((linenr_T)(lo + i - 1),
655 - (char_u *)array[i], 0, FALSE) == FAIL)
657 - PyErr_SetVim(_("cannot insert line"));
660 - vim_free(array[i]);
666 - /* Free any left-over old_len, as a result of an error */
667 - while (i < new_len)
669 - vim_free(array[i]);
673 - /* Free the array of old_len. All of its contents have now
674 - * been dealt with (either freed, or the responsibility passed
679 - /* Adjust marks. Invalidate any which lie in the
680 - * changed range, and move any in the remainder of the buffer.
682 - mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
683 - (long)MAXLNUM, (long)extra);
684 - changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
686 - if (buf == curwin->w_buffer)
687 - py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
691 - if (PyErr_Occurred() || VimErrorCheck())
695 - *len_change = new_len - old_len;
701 - PyErr_BadArgument();
706 /* Convert a Vim line into a Python string.
707 * All internal newlines are replaced by null characters.
710 *** ../mercurial/vim73/src/if_python3.c 2011-06-12 21:37:06.000000000 +0200
711 --- src/if_python3.c 2011-06-19 00:10:42.000000000 +0200
715 #define PyInt Py_ssize_t
716 #define PyString_Check(obj) PyUnicode_Check(obj)
717 ! #define PyString_AsString(obj) _PyUnicode_AsString(obj)
718 ! #define PyString_Size(obj) PyUnicode_GET_SIZE(obj)
719 #define PyString_FromString(repr) PyUnicode_FromString(repr)
721 #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
724 #define PyInt Py_ssize_t
725 #define PyString_Check(obj) PyUnicode_Check(obj)
726 ! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)p_enc, NULL);
727 ! #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
728 ! #define PyString_AsString(obj) PyBytes_AsString(obj)
729 ! #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
730 #define PyString_FromString(repr) PyUnicode_FromString(repr)
732 #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
736 # define PyArg_Parse py3_PyArg_Parse
737 # undef PyArg_ParseTuple
738 # define PyArg_ParseTuple py3_PyArg_ParseTuple
739 + # define PyMem_Free py3_PyMem_Free
740 # define PyDict_SetItemString py3_PyDict_SetItemString
741 # define PyErr_BadArgument py3_PyErr_BadArgument
742 # define PyErr_Clear py3_PyErr_Clear
746 # define PyModule_AddObject py3_PyModule_AddObject
747 # define PyImport_AppendInittab py3_PyImport_AppendInittab
748 # define _PyUnicode_AsString py3__PyUnicode_AsString
749 + # undef PyUnicode_AsEncodedString
750 + # define PyUnicode_AsEncodedString py3_PyUnicode_AsEncodedString
751 + # undef PyBytes_AsString
752 + # define PyBytes_AsString py3_PyBytes_AsString
753 # define PyObject_GenericGetAttr py3_PyObject_GenericGetAttr
754 # define PySlice_Type (*py3_PySlice_Type)
755 + # define PyErr_NewException py3_PyErr_NewException
757 # define _Py_NegativeRefcount py3__Py_NegativeRefcount
758 # define _Py_RefTotal (*py3__Py_RefTotal)
761 # define PyModule_Create2 py3_PyModule_Create2
762 # undef PyUnicode_FromString
763 # define PyUnicode_FromString py3_PyUnicode_FromString
764 ! # undef PyUnicode_FromStringAndSize
765 ! # define PyUnicode_FromStringAndSize py3_PyUnicode_FromStringAndSize
770 # define PyModule_Create2 py3_PyModule_Create2
771 # undef PyUnicode_FromString
772 # define PyUnicode_FromString py3_PyUnicode_FromString
773 ! # undef PyUnicode_Decode
774 ! # define PyUnicode_Decode py3_PyUnicode_Decode
780 static int (*py3_PyType_Ready)(PyTypeObject *type);
781 static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
782 static PyObject* (*py3_PyUnicode_FromString)(const char *u);
783 ! static PyObject* (*py3_PyUnicode_FromStringAndSize)(const char *u, Py_ssize_t size);
784 static long (*py3_PyLong_AsLong)(PyObject *);
785 static void (*py3_PyErr_SetNone)(PyObject *);
786 static void (*py3_PyEval_InitThreads)(void);
788 static int (*py3_PyType_Ready)(PyTypeObject *type);
789 static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
790 static PyObject* (*py3_PyUnicode_FromString)(const char *u);
791 ! static PyObject* (*py3_PyUnicode_Decode)(const char *u, Py_ssize_t size,
792 ! const char *encoding, const char *errors);
793 static long (*py3_PyLong_AsLong)(PyObject *);
794 static void (*py3_PyErr_SetNone)(PyObject *);
795 static void (*py3_PyEval_InitThreads)(void);
799 static PyThreadState*(*py3_PyEval_SaveThread)(void);
800 static int (*py3_PyArg_Parse)(PyObject *, char *, ...);
801 static int (*py3_PyArg_ParseTuple)(PyObject *, char *, ...);
802 + static int (*py3_PyMem_Free)(void *);
803 static int (*py3_Py_IsInitialized)(void);
804 static void (*py3_PyErr_Clear)(void);
805 static PyObject*(*py3__PyObject_Init)(PyObject *, PyTypeObject *);
809 static int (*py3_PyModule_AddObject)(PyObject *m, const char *name, PyObject *o);
810 static int (*py3_PyImport_AppendInittab)(const char *name, PyObject* (*initfunc)(void));
811 static char* (*py3__PyUnicode_AsString)(PyObject *unicode);
812 + static PyObject* (*py3_PyUnicode_AsEncodedString)(PyObject *unicode, const char* encoding, const char* errors);
813 + static char* (*py3_PyBytes_AsString)(PyObject *bytes);
814 static PyObject* (*py3_PyObject_GenericGetAttr)(PyObject *obj, PyObject *name);
815 static PyObject* (*py3_PyModule_Create2)(struct PyModuleDef* module, int module_api_version);
816 static PyObject* (*py3_PyType_GenericAlloc)(PyTypeObject *type, Py_ssize_t nitems);
817 static PyObject* (*py3_PyType_GenericNew)(PyTypeObject *type, PyObject *args, PyObject *kwds);
818 static PyTypeObject* py3_PySlice_Type;
819 + static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict);
821 static void (*py3__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op);
822 static Py_ssize_t* py3__Py_RefTotal;
826 {"Py_SetPythonHome", (PYTHON_PROC*)&py3_Py_SetPythonHome},
827 {"Py_Initialize", (PYTHON_PROC*)&py3_Py_Initialize},
828 {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
829 + {"PyMem_Free", (PYTHON_PROC*)&py3_PyMem_Free},
830 {"PyList_New", (PYTHON_PROC*)&py3_PyList_New},
831 {"PyGILState_Ensure", (PYTHON_PROC*)&py3_PyGILState_Ensure},
832 {"PyGILState_Release", (PYTHON_PROC*)&py3_PyGILState_Release},
835 {"PyEval_RestoreThread", (PYTHON_PROC*)&py3_PyEval_RestoreThread},
836 {"PyEval_SaveThread", (PYTHON_PROC*)&py3_PyEval_SaveThread},
837 {"PyArg_Parse", (PYTHON_PROC*)&py3_PyArg_Parse},
838 - {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
839 {"Py_IsInitialized", (PYTHON_PROC*)&py3_Py_IsInitialized},
840 {"_Py_NoneStruct", (PYTHON_PROC*)&py3__Py_NoneStruct},
841 {"PyErr_Clear", (PYTHON_PROC*)&py3_PyErr_Clear},
846 {"PyModule_AddObject", (PYTHON_PROC*)&py3_PyModule_AddObject},
847 {"PyImport_AppendInittab", (PYTHON_PROC*)&py3_PyImport_AppendInittab},
848 {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString},
849 + {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString},
850 {"PyObject_GenericGetAttr", (PYTHON_PROC*)&py3_PyObject_GenericGetAttr},
851 {"PyModule_Create2", (PYTHON_PROC*)&py3_PyModule_Create2},
852 {"PyType_GenericAlloc", (PYTHON_PROC*)&py3_PyType_GenericAlloc},
853 {"PyType_GenericNew", (PYTHON_PROC*)&py3_PyType_GenericNew},
854 {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type},
855 + {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException},
857 {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount},
858 {"_Py_RefTotal", (PYTHON_PROC*)&py3__Py_RefTotal},
861 py3_runtime_link_init(char *libname, int verbose)
864 ! void *ucs_from_string, *ucs_from_string_and_size;
866 # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON)
867 /* Can't have Python and Python3 loaded at the same time.
869 py3_runtime_link_init(char *libname, int verbose)
872 ! void *ucs_from_string, *ucs_decode, *ucs_as_encoded_string;
874 # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON)
875 /* Can't have Python and Python3 loaded at the same time.
878 /* Load unicode functions separately as only the ucs2 or the ucs4 functions
879 * will be present in the library. */
880 ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString");
881 ! ucs_from_string_and_size = symbol_from_dll(hinstPy3,
882 ! "PyUnicodeUCS2_FromStringAndSize");
883 ! if (!ucs_from_string || !ucs_from_string_and_size)
885 ucs_from_string = symbol_from_dll(hinstPy3,
886 "PyUnicodeUCS4_FromString");
887 ! ucs_from_string_and_size = symbol_from_dll(hinstPy3,
888 ! "PyUnicodeUCS4_FromStringAndSize");
890 ! if (ucs_from_string && ucs_from_string_and_size)
892 py3_PyUnicode_FromString = ucs_from_string;
893 ! py3_PyUnicode_FromStringAndSize = ucs_from_string_and_size;
898 /* Load unicode functions separately as only the ucs2 or the ucs4 functions
899 * will be present in the library. */
900 ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString");
901 ! ucs_decode = symbol_from_dll(hinstPy3,
902 ! "PyUnicodeUCS2_Decode");
903 ! ucs_as_encoded_string = symbol_from_dll(hinstPy3,
904 ! "PyUnicodeUCS2_AsEncodedString");
905 ! if (!ucs_from_string || !ucs_decode || !ucs_as_encoded_string)
907 ucs_from_string = symbol_from_dll(hinstPy3,
908 "PyUnicodeUCS4_FromString");
909 ! ucs_decode = symbol_from_dll(hinstPy3,
910 ! "PyUnicodeUCS4_Decode");
911 ! ucs_as_encoded_string = symbol_from_dll(hinstPy3,
912 ! "PyUnicodeUCS4_AsEncodedString");
914 ! if (ucs_from_string && ucs_decode && ucs_as_encoded_string)
916 py3_PyUnicode_FromString = ucs_from_string;
917 ! py3_PyUnicode_Decode = ucs_decode;
918 ! py3_PyUnicode_AsEncodedString = ucs_as_encoded_string;
924 /* Remove the element from sys.path that was added because of our
925 * argv[0] value in Py3Init_vim(). Previously we used an empty
926 * string, but dependinding on the OS we then get an empty entry or
927 ! * the current directory in sys.path. */
928 ! PyRun_SimpleString("import sys; sys.path = list(filter(lambda x: x != '/must>not&exist', sys.path))");
930 // lock is created and acquired in PyEval_InitThreads() and thread
931 // state is created in Py_Initialize()
933 /* Remove the element from sys.path that was added because of our
934 * argv[0] value in Py3Init_vim(). Previously we used an empty
935 * string, but dependinding on the OS we then get an empty entry or
936 ! * the current directory in sys.path.
937 ! * Only after vim has been imported, the element does exist in
940 ! PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))");
942 // lock is created and acquired in PyEval_InitThreads() and thread
943 // state is created in Py_Initialize()
947 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
951 + PyObject *cmdbytes;
953 #if defined(MACOS) && !defined(MACOS_X_UNIX)
958 pygilstate = PyGILState_Ensure();
960 ! PyRun_SimpleString((char *)(cmd));
962 PyGILState_Release(pygilstate);
966 pygilstate = PyGILState_Ensure();
968 ! /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
969 ! * SyntaxError (unicode error). */
970 ! cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)p_enc, NULL);
971 ! cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", NULL);
972 ! Py_XDECREF(cmdstr);
973 ! PyRun_SimpleString(PyBytes_AsString(cmdbytes));
974 ! Py_XDECREF(cmdbytes);
976 PyGILState_Release(pygilstate);
980 * different options under Windows, meaning that stdio pointers aren't
981 * compatible between the two. Yuk.
983 ! * construct: exec(compile(open('a_filename').read(), 'a_filename', 'exec'))
985 * We need to escape any backslashes or single quotes in the file name, so that
986 * Python won't mangle the file name.
988 * different options under Windows, meaning that stdio pointers aren't
989 * compatible between the two. Yuk.
991 ! * construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec'))
993 ! * Using bytes so that Python can detect the source encoding as it normally
994 ! * does. The doc does not say "compile" accept bytes, though.
996 * We need to escape any backslashes or single quotes in the file name, so that
997 * Python won't mangle the file name.
1003 ! strcpy(p,"').read(),'");
1012 ! strcpy(p,"','rb').read(),'");
1020 static Py_ssize_t BufferLength(PyObject *);
1021 static PyObject *BufferItem(PyObject *, Py_ssize_t);
1022 - static Py_ssize_t BufferAsItem(PyObject *, Py_ssize_t, PyObject *);
1023 static PyObject* BufferSubscript(PyObject *self, PyObject* idx);
1026 /* Line range type - Implementation functions
1029 static Py_ssize_t BufferLength(PyObject *);
1030 static PyObject *BufferItem(PyObject *, Py_ssize_t);
1031 static PyObject* BufferSubscript(PyObject *self, PyObject* idx);
1032 + static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val);
1035 /* Line range type - Implementation functions
1038 (ssizeargfunc) 0, /* sq_repeat, x*n */
1039 (ssizeargfunc) BufferItem, /* sq_item, x[i] */
1040 0, /* was_sq_slice, x[i:j] */
1041 ! (ssizeobjargproc) BufferAsItem, /* sq_ass_item, x[i]=v */
1042 0, /* sq_ass_slice, x[i:j]=v */
1043 0, /* sq_contains */
1044 0, /* sq_inplace_concat */
1046 (ssizeargfunc) 0, /* sq_repeat, x*n */
1047 (ssizeargfunc) BufferItem, /* sq_item, x[i] */
1048 0, /* was_sq_slice, x[i:j] */
1049 ! 0, /* sq_ass_item, x[i]=v */
1050 0, /* sq_ass_slice, x[i:j]=v */
1051 0, /* sq_contains */
1052 0, /* sq_inplace_concat */
1055 PyMappingMethods BufferAsMapping = {
1056 /* mp_length */ (lenfunc)BufferLength,
1057 /* mp_subscript */ (binaryfunc)BufferSubscript,
1058 ! /* mp_ass_subscript */ (objobjargproc)0,
1063 PyMappingMethods BufferAsMapping = {
1064 /* mp_length */ (lenfunc)BufferLength,
1065 /* mp_subscript */ (binaryfunc)BufferSubscript,
1066 ! /* mp_ass_subscript */ (objobjargproc)BufferAsSubscript,
1074 if (this->buf && this->buf != INVALID_BUFFER_VALUE)
1075 this->buf->b_python3_ref = NULL;
1077 + Py_TYPE(self)->tp_free((PyObject*)self);
1083 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count);
1087 - BufferAsItem(PyObject *self, Py_ssize_t n, PyObject *val)
1089 - return RBAsItem((BufferObject *)(self), n, val, 1,
1090 - (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
1096 BufferSubscript(PyObject *self, PyObject* idx)
1101 &step, &slicelen) < 0) {
1104 ! return BufferSlice(self,start,stop+1);
1106 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
1111 static PySequenceMethods RangeAsSeq = {
1112 (lenfunc) RangeLength, /* sq_length, len(x) */
1113 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
1115 &step, &slicelen) < 0) {
1118 ! return BufferSlice(self,start,stop);
1120 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
1126 + BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
1128 + if (PyLong_Check(idx)) {
1129 + long n = PyLong_AsLong(idx);
1130 + return RBAsItem((BufferObject *)(self), n, val, 1,
1131 + (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
1133 + } else if (PySlice_Check(idx)) {
1134 + Py_ssize_t start, stop, step, slicelen;
1136 + if (PySlice_GetIndicesEx((PySliceObject *)idx,
1137 + (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
1139 + &step, &slicelen) < 0) {
1142 + return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
1143 + (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
1146 + PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
1151 static PySequenceMethods RangeAsSeq = {
1152 (lenfunc) RangeLength, /* sq_length, len(x) */
1153 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
1157 RangeDestructor(PyObject *self)
1159 Py_DECREF(((RangeObject *)(self))->buf);
1160 + Py_TYPE(self)->tp_free((PyObject*)self);
1168 if (this->win && this->win != INVALID_WINDOW_VALUE)
1169 this->win->w_python3_ref = NULL;
1171 + Py_TYPE(self)->tp_free((PyObject*)self);
1177 PySys_SetArgv(1, argv);
1179 mod = PyModule_Create(&vimmodule);
1181 ! VimError = Py_BuildValue("s", "vim.error");
1183 PyModule_AddObject(mod, "error", VimError);
1184 Py_INCREF((PyObject *)(void *)&TheBufferList);
1186 PySys_SetArgv(1, argv);
1188 mod = PyModule_Create(&vimmodule);
1192 ! VimError = PyErr_NewException("vim.error", NULL, NULL);
1193 ! Py_INCREF(VimError);
1195 PyModule_AddObject(mod, "error", VimError);
1196 Py_INCREF((PyObject *)(void *)&TheBufferList);
1202 ! result = PyUnicode_FromStringAndSize(tmp, len);
1210 ! result = PyUnicode_Decode(tmp, len, (char *)p_enc, NULL);
1214 *** ../vim-7.3.219/src/version.c 2011-06-13 02:03:55.000000000 +0200
1215 --- src/version.c 2011-06-19 00:25:38.000000000 +0200
1219 { /* Add new patch number below this line */
1225 I'm in shape. Round IS a shape.
1227 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
1228 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
1229 \\\ an exciting new programming language -- http://www.Zimbu.org ///
1230 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///