0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

updated for version 7.3.1227

Problem:    Inconsistent string conversion.
Solution:   Use 'encoding' instead of utf-8. Use METH_O in place of
            METH_VARARGS where appropriate. (ZyX)
This commit is contained in:
Bram Moolenaar
2013-06-23 13:00:44 +02:00
parent 6c85e7f3be
commit 389a1793f4
4 changed files with 72 additions and 58 deletions

View File

@@ -466,21 +466,20 @@ VimCheckInterrupt(void)
*/ */
static PyObject * static PyObject *
VimCommand(PyObject *self UNUSED, PyObject *args) VimCommand(PyObject *self UNUSED, PyObject *string)
{ {
char *cmd; char_u *cmd;
PyObject *result; PyObject *result;
PyObject *todecref;
if (!PyArg_ParseTuple(args, "s", &cmd)) if (!(cmd = StringToChars(string, &todecref)))
return NULL; return NULL;
PyErr_Clear();
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
Python_Lock_Vim(); Python_Lock_Vim();
VimTryStart(); VimTryStart();
do_cmdline_cmd((char_u *)cmd); do_cmdline_cmd(cmd);
update_screen(VALID); update_screen(VALID);
Python_Release_Vim(); Python_Release_Vim();
@@ -491,8 +490,8 @@ VimCommand(PyObject *self UNUSED, PyObject *args)
else else
result = Py_None; result = Py_None;
Py_XINCREF(result); Py_XINCREF(result);
Py_XDECREF(todecref);
return result; return result;
} }
@@ -641,21 +640,28 @@ VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict)
static PyObject * static PyObject *
VimEval(PyObject *self UNUSED, PyObject *args) VimEval(PyObject *self UNUSED, PyObject *args)
{ {
char *expr; char_u *expr;
typval_T *our_tv; typval_T *our_tv;
PyObject *string;
PyObject *todecref;
PyObject *result; PyObject *result;
PyObject *lookup_dict; PyObject *lookup_dict;
if (!PyArg_ParseTuple(args, "s", &expr)) if (!PyArg_ParseTuple(args, "O", &string))
return NULL;
if (!(expr = StringToChars(string, &todecref)))
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
Python_Lock_Vim(); Python_Lock_Vim();
VimTryStart(); VimTryStart();
our_tv = eval_expr((char_u *)expr, NULL); our_tv = eval_expr(expr, NULL);
Python_Release_Vim(); Python_Release_Vim();
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
Py_XDECREF(todecref);
if (VimTryEnd()) if (VimTryEnd())
return NULL; return NULL;
@@ -688,22 +694,25 @@ VimEval(PyObject *self UNUSED, PyObject *args)
static PyObject *ConvertToPyObject(typval_T *); static PyObject *ConvertToPyObject(typval_T *);
static PyObject * static PyObject *
VimEvalPy(PyObject *self UNUSED, PyObject *args) VimEvalPy(PyObject *self UNUSED, PyObject *string)
{ {
char *expr;
typval_T *our_tv; typval_T *our_tv;
PyObject *result; PyObject *result;
char_u *expr;
PyObject *todecref;
if (!PyArg_ParseTuple(args, "s", &expr)) if (!(expr = StringToChars(string, &todecref)))
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
Python_Lock_Vim(); Python_Lock_Vim();
VimTryStart(); VimTryStart();
our_tv = eval_expr((char_u *)expr, NULL); our_tv = eval_expr(expr, NULL);
Python_Release_Vim(); Python_Release_Vim();
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
Py_XDECREF(todecref);
if (VimTryEnd()) if (VimTryEnd())
return NULL; return NULL;
@@ -724,20 +733,24 @@ VimEvalPy(PyObject *self UNUSED, PyObject *args)
} }
static PyObject * static PyObject *
VimStrwidth(PyObject *self UNUSED, PyObject *args) VimStrwidth(PyObject *self UNUSED, PyObject *string)
{ {
char *expr; char_u *str;
PyObject *todecref;
int result;
if (!PyArg_ParseTuple(args, "s", &expr)) if (!(str = StringToChars(string, &todecref)))
return NULL; return NULL;
return PyLong_FromLong(
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
mb_string2cells((char_u *)expr, (int)STRLEN(expr)) result = mb_string2cells(str, (int)STRLEN(str));
#else #else
STRLEN(expr) result = STRLEN(str);
#endif #endif
);
Py_XDECREF(todecref);
return PyLong_FromLong(result);
} }
static PyObject * static PyObject *
@@ -840,13 +853,11 @@ map_rtp_callback(char_u *path, void *_data)
} }
static PyObject * static PyObject *
VimForeachRTP(PyObject *self UNUSED, PyObject *args) VimForeachRTP(PyObject *self UNUSED, PyObject *callable)
{ {
map_rtp_data data; map_rtp_data data;
if (!PyArg_ParseTuple(args, "O", &data.callable)) data.callable = callable;
return NULL;
data.result = NULL; data.result = NULL;
do_in_runtimepath(NULL, FALSE, &map_rtp_callback, &data); do_in_runtimepath(NULL, FALSE, &map_rtp_callback, &data);
@@ -1099,13 +1110,13 @@ VimPathHook(PyObject *self UNUSED, PyObject *args)
static struct PyMethodDef VimMethods[] = { static struct PyMethodDef VimMethods[] = {
/* name, function, calling, documentation */ /* name, function, calling, documentation */
{"command", VimCommand, METH_VARARGS, "Execute a Vim ex-mode command" }, {"command", VimCommand, METH_O, "Execute a Vim ex-mode command" },
{"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" }, {"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" },
{"bindeval", VimEvalPy, METH_VARARGS, "Like eval(), but returns objects attached to vim ones"}, {"bindeval", VimEvalPy, METH_O, "Like eval(), but returns objects attached to vim ones"},
{"strwidth", VimStrwidth, METH_VARARGS, "Screen string width, counts <Tab> as having width 1"}, {"strwidth", VimStrwidth, METH_O, "Screen string width, counts <Tab> as having width 1"},
{"chdir", (PyCFunction)VimChdir, METH_VARARGS|METH_KEYWORDS, "Change directory"}, {"chdir", (PyCFunction)VimChdir, METH_VARARGS|METH_KEYWORDS, "Change directory"},
{"fchdir", (PyCFunction)VimFchdir, METH_VARARGS|METH_KEYWORDS, "Change directory"}, {"fchdir", (PyCFunction)VimFchdir, METH_VARARGS|METH_KEYWORDS, "Change directory"},
{"foreach_rtp", VimForeachRTP, METH_VARARGS, "Call given callable for each path in &rtp"}, {"foreach_rtp", VimForeachRTP, METH_O, "Call given callable for each path in &rtp"},
{"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"}, {"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"},
{"path_hook", VimPathHook, METH_VARARGS, "Hook function to install in sys.path_hooks"}, {"path_hook", VimPathHook, METH_VARARGS, "Hook function to install in sys.path_hooks"},
{"_get_paths", (PyCFunction)Vim_GetPaths, METH_NOARGS, "Get &rtp-based additions to sys.path"}, {"_get_paths", (PyCFunction)Vim_GetPaths, METH_NOARGS, "Get &rtp-based additions to sys.path"},
@@ -1733,7 +1744,7 @@ DictionaryUpdate(DictionaryObject *self, PyObject *args, PyObject *kwargs)
{ {
PyObject *object; PyObject *object;
if (!PyArg_Parse(args, "(O)", &object)) if (!PyArg_ParseTuple(args, "O", &object))
return NULL; return NULL;
if (PyObject_HasAttrString(object, "keys")) if (PyObject_HasAttrString(object, "keys"))
@@ -1877,13 +1888,8 @@ DictionaryPopItem(DictionaryObject *self)
} }
static PyObject * static PyObject *
DictionaryHasKey(DictionaryObject *self, PyObject *args) DictionaryHasKey(DictionaryObject *self, PyObject *keyObject)
{ {
PyObject *keyObject;
if (!PyArg_ParseTuple(args, "O", &keyObject))
return NULL;
return _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL); return _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL);
} }
@@ -1914,7 +1920,7 @@ static struct PyMethodDef DictionaryMethods[] = {
{"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""}, {"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""},
{"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""}, {"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""},
{"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""}, {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""},
{"has_key", (PyCFunction)DictionaryHasKey, METH_VARARGS, ""}, {"has_key", (PyCFunction)DictionaryHasKey, METH_O, ""},
{"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""}, {"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""},
{ NULL, NULL, 0, NULL} { NULL, NULL, 0, NULL}
}; };
@@ -2434,11 +2440,13 @@ FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
return NULL; return NULL;
} }
if (!PyArg_ParseTuple(args, "s", &name)) if (!PyArg_ParseTuple(args, "et", "ascii", &name))
return NULL; return NULL;
self = FunctionNew(subtype, name); self = FunctionNew(subtype, name);
PyMem_Free(name);
return self; return self;
} }
@@ -4383,20 +4391,21 @@ BufferAppend(BufferObject *self, PyObject *args)
} }
static PyObject * static PyObject *
BufferMark(BufferObject *self, PyObject *args) BufferMark(BufferObject *self, PyObject *pmarkObject)
{ {
pos_T *posp; pos_T *posp;
char *pmark; char_u *pmark;
char mark; char_u mark;
buf_T *savebuf; buf_T *savebuf;
PyObject *todecref;
if (CheckBuffer(self)) if (CheckBuffer(self))
return NULL; return NULL;
if (!PyArg_ParseTuple(args, "s", &pmark)) if (!(pmark = StringToChars(pmarkObject, &todecref)))
return NULL; return NULL;
if (STRLEN(pmark) != 1) if (pmark[0] == '\0' || pmark[1] != '\0')
{ {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
_("mark name must be a single character")); _("mark name must be a single character"));
@@ -4404,6 +4413,9 @@ BufferMark(BufferObject *self, PyObject *args)
} }
mark = *pmark; mark = *pmark;
Py_XDECREF(todecref);
VimTryStart(); VimTryStart();
switch_buffer(&savebuf, self->buf); switch_buffer(&savebuf, self->buf);
posp = getmark(mark, FALSE); posp = getmark(mark, FALSE);
@@ -4461,7 +4473,7 @@ BufferRepr(BufferObject *self)
static struct PyMethodDef BufferMethods[] = { static struct PyMethodDef BufferMethods[] = {
/* name, function, calling, documentation */ /* name, function, calling, documentation */
{"append", (PyCFunction)BufferAppend, METH_VARARGS, "Append data to Vim buffer" }, {"append", (PyCFunction)BufferAppend, METH_VARARGS, "Append data to Vim buffer" },
{"mark", (PyCFunction)BufferMark, METH_VARARGS, "Return (row,col) representing position of named mark" }, {"mark", (PyCFunction)BufferMark, METH_O, "Return (row,col) representing position of named mark" },
{"range", (PyCFunction)BufferRange, METH_VARARGS, "Return a range object which represents the part of the given buffer between line numbers s and e" }, {"range", (PyCFunction)BufferRange, METH_VARARGS, "Return a range object which represents the part of the given buffer between line numbers s and e" },
{"__dir__", (PyCFunction)BufferDir, METH_NOARGS, ""}, {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, ""},
{ NULL, NULL, 0, NULL} { NULL, NULL, 0, NULL}

View File

@@ -446,14 +446,14 @@ sys.stdout.write(None):TypeError:('coercing to Unicode: need string or buffer, N
sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",) sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",)
sys.stdout.writelines([1]):TypeError:('coercing to Unicode: need string or buffer, int found',) sys.stdout.writelines([1]):TypeError:('coercing to Unicode: need string or buffer, int found',)
> VimCommand > VimCommand
vim.command(1):TypeError:('must be string, not int',) vim.command(1):TypeError:('object must be string',)
> VimToPython > VimToPython
> VimEval > VimEval
vim.eval(1):TypeError:('must be string, not int',) vim.eval(1):TypeError:('object must be string',)
> VimEvalPy > VimEvalPy
vim.bindeval(1):TypeError:('must be string, not int',) vim.bindeval(1):TypeError:('object must be string',)
> VimStrwidth > VimStrwidth
vim.strwidth(1):TypeError:('must be string, not int',) vim.strwidth(1):TypeError:('object must be string',)
> Dictionary > Dictionary
>> DictionaryConstructor >> DictionaryConstructor
vim.Dictionary("abc"):ValueError:('expected sequence element of size 2',) vim.Dictionary("abc"):ValueError:('expected sequence element of size 2',)
@@ -683,7 +683,7 @@ d.update((("a", FailingMappingKey()),)):NotImplementedError:()
>> DictionaryPopItem >> DictionaryPopItem
d.popitem(1, 2):TypeError:('popitem() takes no arguments (2 given)',) d.popitem(1, 2):TypeError:('popitem() takes no arguments (2 given)',)
>> DictionaryHasKey >> DictionaryHasKey
d.has_key():TypeError:('function takes exactly 1 argument (0 given)',) d.has_key():TypeError:('has_key() takes exactly one argument (0 given)',)
> List > List
>> ListConstructor >> ListConstructor
vim.List(1, 2):TypeError:('function takes at most 1 argument (2 given)',) vim.List(1, 2):TypeError:('function takes at most 1 argument (2 given)',)
@@ -1065,7 +1065,7 @@ vim.current.buffer.xxx:AttributeError:('xxx',)
vim.current.buffer.name = True:TypeError:('object must be string',) vim.current.buffer.name = True:TypeError:('object must be string',)
vim.current.buffer.xxx = True:AttributeError:('xxx',) vim.current.buffer.xxx = True:AttributeError:('xxx',)
>> BufferMark >> BufferMark
vim.current.buffer.mark(0):TypeError:('must be string, not int',) vim.current.buffer.mark(0):TypeError:('object must be string',)
vim.current.buffer.mark("abc"):ValueError:('mark name must be a single character',) vim.current.buffer.mark("abc"):ValueError:('mark name must be a single character',)
vim.current.buffer.mark("!"):error:('invalid mark name',) vim.current.buffer.mark("!"):error:('invalid mark name',)
>> BufferRange >> BufferRange

View File

@@ -439,14 +439,14 @@ sys.stdout.writelines(FailingIter()):(<class 'NotImplementedError'>, NotImplemen
sys.stdout.writelines(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError()) sys.stdout.writelines(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError())
<<< Finished <<< Finished
> VimCommand > VimCommand
vim.command(1):(<class 'TypeError'>, TypeError('must be str, not int',)) vim.command(1):(<class 'TypeError'>, TypeError('object must be string',))
> VimToPython > VimToPython
> VimEval > VimEval
vim.eval(1):(<class 'TypeError'>, TypeError('must be str, not int',)) vim.eval(1):(<class 'TypeError'>, TypeError('object must be string',))
> VimEvalPy > VimEvalPy
vim.bindeval(1):(<class 'TypeError'>, TypeError('must be str, not int',)) vim.bindeval(1):(<class 'TypeError'>, TypeError('object must be string',))
> VimStrwidth > VimStrwidth
vim.strwidth(1):(<class 'TypeError'>, TypeError('must be str, not int',)) vim.strwidth(1):(<class 'TypeError'>, TypeError('object must be string',))
> Dictionary > Dictionary
>> DictionaryConstructor >> DictionaryConstructor
vim.Dictionary("abc"):(<class 'ValueError'>, ValueError('expected sequence element of size 2',)) vim.Dictionary("abc"):(<class 'ValueError'>, ValueError('expected sequence element of size 2',))
@@ -680,7 +680,7 @@ d.update((("a", FailingMappingKey()),)):(<class 'NotImplementedError'>, NotImple
>> DictionaryPopItem >> DictionaryPopItem
d.popitem(1, 2):(<class 'TypeError'>, TypeError('popitem() takes no arguments (2 given)',)) d.popitem(1, 2):(<class 'TypeError'>, TypeError('popitem() takes no arguments (2 given)',))
>> DictionaryHasKey >> DictionaryHasKey
d.has_key():(<class 'TypeError'>, TypeError('function takes exactly 1 argument (0 given)',)) d.has_key():(<class 'TypeError'>, TypeError('has_key() takes exactly one argument (0 given)',))
> List > List
>> ListConstructor >> ListConstructor
vim.List(1, 2):(<class 'TypeError'>, TypeError('function takes at most 1 argument (2 given)',)) vim.List(1, 2):(<class 'TypeError'>, TypeError('function takes at most 1 argument (2 given)',))
@@ -1074,7 +1074,7 @@ vim.current.buffer.xxx:(<class 'AttributeError'>, AttributeError("'vim.buffer' o
vim.current.buffer.name = True:(<class 'TypeError'>, TypeError('object must be string',)) vim.current.buffer.name = True:(<class 'TypeError'>, TypeError('object must be string',))
vim.current.buffer.xxx = True:(<class 'AttributeError'>, AttributeError('xxx',)) vim.current.buffer.xxx = True:(<class 'AttributeError'>, AttributeError('xxx',))
>> BufferMark >> BufferMark
vim.current.buffer.mark(0):(<class 'TypeError'>, TypeError('must be str, not int',)) vim.current.buffer.mark(0):(<class 'TypeError'>, TypeError('object must be string',))
vim.current.buffer.mark("abc"):(<class 'ValueError'>, ValueError('mark name must be a single character',)) vim.current.buffer.mark("abc"):(<class 'ValueError'>, ValueError('mark name must be a single character',))
vim.current.buffer.mark("!"):(<class 'vim.error'>, error('invalid mark name',)) vim.current.buffer.mark("!"):(<class 'vim.error'>, error('invalid mark name',))
>> BufferRange >> BufferRange

View File

@@ -728,6 +728,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1227,
/**/ /**/
1226, 1226,
/**/ /**/