@@ -466,21 +466,20 @@ VimCheckInterrupt(void)
466466 */
467467
468468 static PyObject *
469- VimCommand (PyObject * self UNUSED , PyObject * args )
469+ VimCommand (PyObject * self UNUSED , PyObject * string )
470470{
471- char * cmd ;
472- PyObject * result ;
471+ char_u * cmd ;
472+ PyObject * result ;
473+ PyObject * todecref ;
473474
474- if (!PyArg_ParseTuple ( args , "s" , & cmd ))
475+ if (!( cmd = StringToChars ( string , & todecref ) ))
475476 return NULL ;
476477
477- PyErr_Clear ();
478-
479478 Py_BEGIN_ALLOW_THREADS
480479 Python_Lock_Vim ();
481480
482481 VimTryStart ();
483- do_cmdline_cmd (( char_u * ) cmd );
482+ do_cmdline_cmd (cmd );
484483 update_screen (VALID );
485484
486485 Python_Release_Vim ();
@@ -491,8 +490,8 @@ VimCommand(PyObject *self UNUSED, PyObject *args)
491490 else
492491 result = Py_None ;
493492
494-
495493 Py_XINCREF (result );
494+ Py_XDECREF (todecref );
496495 return result ;
497496}
498497
@@ -641,21 +640,28 @@ VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict)
641640 static PyObject *
642641VimEval (PyObject * self UNUSED , PyObject * args )
643642{
644- char * expr ;
643+ char_u * expr ;
645644 typval_T * our_tv ;
645+ PyObject * string ;
646+ PyObject * todecref ;
646647 PyObject * result ;
647- PyObject * lookup_dict ;
648+ PyObject * lookup_dict ;
649+
650+ if (!PyArg_ParseTuple (args , "O" , & string ))
651+ return NULL ;
648652
649- if (!PyArg_ParseTuple ( args , "s" , & expr ))
653+ if (!( expr = StringToChars ( string , & todecref ) ))
650654 return NULL ;
651655
652656 Py_BEGIN_ALLOW_THREADS
653657 Python_Lock_Vim ();
654658 VimTryStart ();
655- our_tv = eval_expr (( char_u * ) expr , NULL );
659+ our_tv = eval_expr (expr , NULL );
656660 Python_Release_Vim ();
657661 Py_END_ALLOW_THREADS
658662
663+ Py_XDECREF (todecref );
664+
659665 if (VimTryEnd ())
660666 return NULL ;
661667
@@ -688,22 +694,25 @@ VimEval(PyObject *self UNUSED, PyObject *args)
688694static PyObject * ConvertToPyObject (typval_T * );
689695
690696 static PyObject *
691- VimEvalPy (PyObject * self UNUSED , PyObject * args )
697+ VimEvalPy (PyObject * self UNUSED , PyObject * string )
692698{
693- char * expr ;
694699 typval_T * our_tv ;
695700 PyObject * result ;
701+ char_u * expr ;
702+ PyObject * todecref ;
696703
697- if (!PyArg_ParseTuple ( args , "s" , & expr ))
704+ if (!( expr = StringToChars ( string , & todecref ) ))
698705 return NULL ;
699706
700707 Py_BEGIN_ALLOW_THREADS
701708 Python_Lock_Vim ();
702709 VimTryStart ();
703- our_tv = eval_expr (( char_u * ) expr , NULL );
710+ our_tv = eval_expr (expr , NULL );
704711 Python_Release_Vim ();
705712 Py_END_ALLOW_THREADS
706713
714+ Py_XDECREF (todecref );
715+
707716 if (VimTryEnd ())
708717 return NULL ;
709718
@@ -724,20 +733,24 @@ VimEvalPy(PyObject *self UNUSED, PyObject *args)
724733}
725734
726735 static PyObject *
727- VimStrwidth (PyObject * self UNUSED , PyObject * args )
736+ VimStrwidth (PyObject * self UNUSED , PyObject * string )
728737{
729- char * expr ;
738+ char_u * str ;
739+ PyObject * todecref ;
740+ int result ;
730741
731- if (!PyArg_ParseTuple ( args , "s" , & expr ))
742+ if (!( str = StringToChars ( string , & todecref ) ))
732743 return NULL ;
733744
734- return PyLong_FromLong (
735745#ifdef FEAT_MBYTE
736- mb_string2cells (( char_u * ) expr , (int )STRLEN (expr ))
746+ result = mb_string2cells (str , (int )STRLEN (str ));
737747#else
738- STRLEN (expr )
748+ result = STRLEN (str );
739749#endif
740- );
750+
751+ Py_XDECREF (todecref );
752+
753+ return PyLong_FromLong (result );
741754}
742755
743756 static PyObject *
@@ -840,13 +853,11 @@ map_rtp_callback(char_u *path, void *_data)
840853}
841854
842855 static PyObject *
843- VimForeachRTP (PyObject * self UNUSED , PyObject * args )
856+ VimForeachRTP (PyObject * self UNUSED , PyObject * callable )
844857{
845858 map_rtp_data data ;
846859
847- if (!PyArg_ParseTuple (args , "O" , & data .callable ))
848- return NULL ;
849-
860+ data .callable = callable ;
850861 data .result = NULL ;
851862
852863 do_in_runtimepath (NULL , FALSE, & map_rtp_callback , & data );
@@ -1099,13 +1110,13 @@ VimPathHook(PyObject *self UNUSED, PyObject *args)
10991110
11001111static struct PyMethodDef VimMethods [] = {
11011112 /* name, function, calling, documentation */
1102- {"command" , VimCommand , METH_VARARGS , "Execute a Vim ex-mode command" },
1113+ {"command" , VimCommand , METH_O , "Execute a Vim ex-mode command" },
11031114 {"eval" , VimEval , METH_VARARGS , "Evaluate an expression using Vim evaluator" },
1104- {"bindeval" , VimEvalPy , METH_VARARGS , "Like eval(), but returns objects attached to vim ones" },
1105- {"strwidth" , VimStrwidth , METH_VARARGS , "Screen string width, counts <Tab> as having width 1" },
1115+ {"bindeval" , VimEvalPy , METH_O , "Like eval(), but returns objects attached to vim ones" },
1116+ {"strwidth" , VimStrwidth , METH_O , "Screen string width, counts <Tab> as having width 1" },
11061117 {"chdir" , (PyCFunction )VimChdir , METH_VARARGS |METH_KEYWORDS , "Change directory" },
11071118 {"fchdir" , (PyCFunction )VimFchdir , METH_VARARGS |METH_KEYWORDS , "Change directory" },
1108- {"foreach_rtp" , VimForeachRTP , METH_VARARGS , "Call given callable for each path in &rtp" },
1119+ {"foreach_rtp" , VimForeachRTP , METH_O , "Call given callable for each path in &rtp" },
11091120 {"find_module" , FinderFindModule , METH_VARARGS , "Internal use only, returns loader object for any input it receives" },
11101121 {"path_hook" , VimPathHook , METH_VARARGS , "Hook function to install in sys.path_hooks" },
11111122 {"_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)
17331744 {
17341745 PyObject * object ;
17351746
1736- if (!PyArg_Parse (args , "(O) " , & object ))
1747+ if (!PyArg_ParseTuple (args , "O " , & object ))
17371748 return NULL ;
17381749
17391750 if (PyObject_HasAttrString (object , "keys" ))
@@ -1877,13 +1888,8 @@ DictionaryPopItem(DictionaryObject *self)
18771888}
18781889
18791890 static PyObject *
1880- DictionaryHasKey (DictionaryObject * self , PyObject * args )
1891+ DictionaryHasKey (DictionaryObject * self , PyObject * keyObject )
18811892{
1882- PyObject * keyObject ;
1883-
1884- if (!PyArg_ParseTuple (args , "O" , & keyObject ))
1885- return NULL ;
1886-
18871893 return _DictionaryItem (self , keyObject , DICT_FLAG_RETURN_BOOL );
18881894}
18891895
@@ -1914,7 +1920,7 @@ static struct PyMethodDef DictionaryMethods[] = {
19141920 {"get" , (PyCFunction )DictionaryGet , METH_VARARGS , "" },
19151921 {"pop" , (PyCFunction )DictionaryPop , METH_VARARGS , "" },
19161922 {"popitem" , (PyCFunction )DictionaryPopItem , METH_NOARGS , "" },
1917- {"has_key" , (PyCFunction )DictionaryHasKey , METH_VARARGS , "" },
1923+ {"has_key" , (PyCFunction )DictionaryHasKey , METH_O , "" },
19181924 {"__dir__" , (PyCFunction )DictionaryDir , METH_NOARGS , "" },
19191925 { NULL , NULL , 0 , NULL }
19201926};
@@ -2434,11 +2440,13 @@ FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
24342440 return NULL ;
24352441 }
24362442
2437- if (!PyArg_ParseTuple (args , "s " , & name ))
2443+ if (!PyArg_ParseTuple (args , "et" , "ascii " , & name ))
24382444 return NULL ;
24392445
24402446 self = FunctionNew (subtype , name );
24412447
2448+ PyMem_Free (name );
2449+
24422450 return self ;
24432451}
24442452
@@ -4383,27 +4391,31 @@ BufferAppend(BufferObject *self, PyObject *args)
43834391}
43844392
43854393 static PyObject *
4386- BufferMark (BufferObject * self , PyObject * args )
4394+ BufferMark (BufferObject * self , PyObject * pmarkObject )
43874395{
43884396 pos_T * posp ;
4389- char * pmark ;
4390- char mark ;
4397+ char_u * pmark ;
4398+ char_u mark ;
43914399 buf_T * savebuf ;
4400+ PyObject * todecref ;
43924401
43934402 if (CheckBuffer (self ))
43944403 return NULL ;
43954404
4396- if (!PyArg_ParseTuple ( args , "s" , & pmark ))
4405+ if (!( pmark = StringToChars ( pmarkObject , & todecref ) ))
43974406 return NULL ;
43984407
4399- if (STRLEN ( pmark ) != 1 )
4408+ if (pmark [ 0 ] == '\0' || pmark [ 1 ] != '\0' )
44004409 {
44014410 PyErr_SetString (PyExc_ValueError ,
44024411 _ ("mark name must be a single character" ));
44034412 return NULL ;
44044413 }
44054414
44064415 mark = * pmark ;
4416+
4417+ Py_XDECREF (todecref );
4418+
44074419 VimTryStart ();
44084420 switch_buffer (& savebuf , self -> buf );
44094421 posp = getmark (mark , FALSE);
@@ -4461,7 +4473,7 @@ BufferRepr(BufferObject *self)
44614473static struct PyMethodDef BufferMethods [] = {
44624474 /* name, function, calling, documentation */
44634475 {"append" , (PyCFunction )BufferAppend , METH_VARARGS , "Append data to Vim buffer" },
4464- {"mark" , (PyCFunction )BufferMark , METH_VARARGS , "Return (row,col) representing position of named mark" },
4476+ {"mark" , (PyCFunction )BufferMark , METH_O , "Return (row,col) representing position of named mark" },
44654477 {"range" , (PyCFunction )BufferRange , METH_VARARGS , "Return a range object which represents the part of the given buffer between line numbers s and e" },
44664478 {"__dir__" , (PyCFunction )BufferDir , METH_NOARGS , "" },
44674479 { NULL , NULL , 0 , NULL }
0 commit comments