@@ -544,20 +544,30 @@ VimTryStart(void)
544544VimTryEnd (void )
545545{
546546 -- trylevel ;
547+ /* Without this it stops processing all subsequent VimL commands and
548+ * generates strange error messages if I e.g. try calling Test() in a cycle */
549+ did_emsg = FALSE;
550+ /* Keyboard interrupt should be preferred over anything else */
547551 if (got_int )
548552 {
553+ did_throw = got_int = FALSE;
549554 PyErr_SetNone (PyExc_KeyboardInterrupt );
550- return 1 ;
555+ return - 1 ;
551556 }
552557 else if (!did_throw )
553- return 0 ;
558+ return (PyErr_Occurred () ? -1 : 0 );
559+ /* Python exception is preferred over vim one; unlikely to occur though */
554560 else if (PyErr_Occurred ())
555- return 1 ;
561+ {
562+ did_throw = FALSE;
563+ return -1 ;
564+ }
565+ /* Finally transform VimL exception to python one */
556566 else
557567 {
558568 PyErr_SetVim ((char * ) current_exception -> value );
559569 discard_current_exception ();
560- return 1 ;
570+ return - 1 ;
561571 }
562572}
563573
@@ -2649,7 +2659,14 @@ FunctionCall(FunctionObject *self, PyObject *argsObject, PyObject *kwargs)
26492659 static PyObject *
26502660FunctionRepr (FunctionObject * self )
26512661{
2652- return PyString_FromFormat ("<vim.Function '%s'>" , self -> name );
2662+ #ifdef Py_TRACE_REFS
2663+ /* For unknown reason self->name may be NULL after calling
2664+ * Finalize */
2665+ return PyString_FromFormat ("<vim.Function '%s'>" ,
2666+ (self -> name == NULL ? "<NULL>" : (char * ) self -> name ));
2667+ #else
2668+ return PyString_FromFormat ("<vim.Function '%s'>" , (char * ) self -> name );
2669+ #endif
26532670}
26542671
26552672static struct PyMethodDef FunctionMethods [] = {
@@ -3534,6 +3551,7 @@ StringToLine(PyObject *obj)
35343551 else
35353552 {
35363553 PyErr_SET_VIM ("string cannot contain newlines" );
3554+ Py_XDECREF (bytes );
35373555 return NULL ;
35383556 }
35393557 }
@@ -3545,6 +3563,7 @@ StringToLine(PyObject *obj)
35453563 if (save == NULL )
35463564 {
35473565 PyErr_NoMemory ();
3566+ Py_XDECREF (bytes );
35483567 return NULL ;
35493568 }
35503569
@@ -4551,6 +4570,7 @@ BufferMark(BufferObject *self, PyObject *pmarkObject)
45514570 {
45524571 PyErr_SET_STRING (PyExc_ValueError ,
45534572 "mark name must be a single character" );
4573+ Py_XDECREF (todecref );
45544574 return NULL ;
45554575 }
45564576
@@ -5298,6 +5318,9 @@ convert_dl(PyObject *obj, typval_T *tv,
52985318 tv -> v_type = VAR_UNKNOWN ;
52995319 return -1 ;
53005320 }
5321+
5322+ Py_DECREF (capsule );
5323+
53015324 if (py_to_tv (obj , tv , lookup_dict ) == -1 )
53025325 {
53035326 tv -> v_type = VAR_UNKNOWN ;
@@ -5378,13 +5401,13 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
53785401 tv -> vval .v_dict = (((DictionaryObject * )(obj ))-> dict );
53795402 ++ tv -> vval .v_dict -> dv_refcount ;
53805403 }
5381- else if (obj -> ob_type == & ListType )
5404+ else if (PyType_IsSubtype ( obj -> ob_type , & ListType ) )
53825405 {
53835406 tv -> v_type = VAR_LIST ;
53845407 tv -> vval .v_list = (((ListObject * )(obj ))-> list );
53855408 ++ tv -> vval .v_list -> lv_refcount ;
53865409 }
5387- else if (obj -> ob_type == & FunctionType )
5410+ else if (PyType_IsSubtype ( obj -> ob_type , & FunctionType ) )
53885411 {
53895412 if (set_string_copy (((FunctionObject * ) (obj ))-> name , tv ) == -1 )
53905413 return -1 ;
0 commit comments