changeset 22669:3ceb24835183 v8.2.1883

patch 8.2.1883: compiler warnings when using Python Commit: https://github.com/vim/vim/commit/4ce5fe4c87820c7d22964d6e91d7b07e96640e6f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Oct 21 21:01:59 2020 +0200 patch 8.2.1883: compiler warnings when using Python Problem: Compiler warnings when using Python. Solution: Adjust PyCFunction to also have the second argument. Use "int" return type for some functions. Insert "(void *)" to get rid of the remaining warnings.
author Bram Moolenaar <Bram@vim.org>
date Wed, 21 Oct 2020 21:15:03 +0200
parents 7c0ebc6eb7ae
children 1ec5fdb8244e
files src/if_py_both.h src/if_python.c src/if_python3.c src/version.c
diffstat 4 files changed, 55 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -324,7 +324,7 @@ static char *OutputAttrs[] = {
 };
 
     static PyObject *
-OutputDir(PyObject *self)
+OutputDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, OutputAttrs);
 }
@@ -468,30 +468,33 @@ OutputWritelines(OutputObject *self, PyO
 }
 
     static PyObject *
-AlwaysNone(PyObject *self UNUSED)
+AlwaysNone(PyObject *self UNUSED, PyObject *args UNUSED)
 {
     // do nothing
     Py_INCREF(Py_None);
     return Py_None;
 }
+#define ALWAYS_NONE AlwaysNone(NULL, NULL)
 
     static PyObject *
-AlwaysFalse(PyObject *self UNUSED)
+AlwaysFalse(PyObject *self UNUSED, PyObject *args UNUSED)
 {
     // do nothing
     PyObject	*ret = Py_False;
     Py_INCREF(ret);
     return ret;
 }
+#define ALWAYS_FALSE AlwaysFalse(NULL, NULL)
 
     static PyObject *
-AlwaysTrue(PyObject *self UNUSED)
+AlwaysTrue(PyObject *self UNUSED, PyObject *args UNUSED)
 {
     // do nothing
     PyObject	*ret = Py_True;
     Py_INCREF(ret);
     return ret;
 }
+#define ALWAYS_TRUE AlwaysTrue(NULL, NULL)
 
 /***************/
 
@@ -1179,7 +1182,7 @@ map_finder_callback(char_u *path, void *
 }
 
     static PyObject *
-Vim_GetPaths(PyObject *self UNUSED)
+Vim_GetPaths(PyObject *self UNUSED, PyObject *args UNUSED)
 {
     PyObject	*ret;
 
@@ -1209,7 +1212,7 @@ FinderFindSpec(PyObject *self, PyObject 
     if (!PyArg_ParseTuple(args, "s|O", &fullname, &target))
 	return NULL;
 
-    if (!(paths = Vim_GetPaths(self)))
+    if (!(paths = Vim_GetPaths(self, NULL)))
 	return NULL;
 
     spec = PyObject_CallFunction(py_find_spec, "sOO", fullname, paths, target);
@@ -1344,7 +1347,7 @@ FinderFindModule(PyObject *self, PyObjec
     if (!PyArg_ParseTuple(args, "s", &fullname))
 	return NULL;
 
-    if (!(new_path = Vim_GetPaths(self)))
+    if (!(new_path = Vim_GetPaths(self, NULL)))
 	return NULL;
 
     result = find_module(fullname, fullname, new_path);
@@ -1408,8 +1411,8 @@ static struct PyMethodDef VimMethods[] =
     {"eval",	    VimEval,			METH_VARARGS,			"Evaluate an expression using Vim evaluator" },
     {"bindeval",    VimEvalPy,			METH_O,				"Like eval(), but returns objects attached to Vim ones"},
     {"strwidth",    VimStrwidth,		METH_O,				"Screen string width, counts <Tab> as having width 1"},
-    {"chdir",	    (PyCFunction)VimChdir,	METH_VARARGS|METH_KEYWORDS,	"Change directory"},
-    {"fchdir",	    (PyCFunction)VimFchdir,	METH_VARARGS|METH_KEYWORDS,	"Change directory"},
+    {"chdir",	    (PyCFunction)(void *)VimChdir,	METH_VARARGS|METH_KEYWORDS,	"Change directory"},
+    {"fchdir",	    (PyCFunction)(void *)VimFchdir,	METH_VARARGS|METH_KEYWORDS,	"Change directory"},
     {"foreach_rtp", VimForeachRTP,		METH_O,				"Call given callable for each path in &rtp"},
 #if PY_VERSION_HEX >= 0x030700f0
     {"find_spec",   FinderFindSpec,		METH_VARARGS,			"Internal use only, returns spec object for any input it receives"},
@@ -1643,7 +1646,7 @@ static char *DictionaryAttrs[] = {
 };
 
     static PyObject *
-DictionaryDir(PyObject *self)
+DictionaryDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, DictionaryAttrs);
 }
@@ -1850,11 +1853,11 @@ DictionaryIter(DictionaryObject *self)
     dii->dii_todo = ht->ht_used;
 
     return IterNew(dii,
-	    (destructorfun) PyMem_Free, (nextfun) DictionaryIterNext,
+	    (destructorfun)(void *) PyMem_Free, (nextfun) DictionaryIterNext,
 	    NULL, NULL, (PyObject *)self);
 }
 
-    static PyInt
+    static int
 DictionaryAssItem(
 	DictionaryObject *self, PyObject *keyObject, PyObject *valObject)
 {
@@ -1970,7 +1973,7 @@ dict_key(hashitem_T *hi)
 }
 
     static PyObject *
-DictionaryListKeys(DictionaryObject *self)
+DictionaryListKeys(DictionaryObject *self, PyObject *args UNUSED)
 {
     return DictionaryListObjects(self, dict_key);
 }
@@ -1985,7 +1988,7 @@ dict_val(hashitem_T *hi)
 }
 
     static PyObject *
-DictionaryListValues(DictionaryObject *self)
+DictionaryListValues(DictionaryObject *self, PyObject *args UNUSED)
 {
     return DictionaryListObjects(self, dict_val);
 }
@@ -2015,7 +2018,7 @@ dict_item(hashitem_T *hi)
 }
 
     static PyObject *
-DictionaryListItems(DictionaryObject *self)
+DictionaryListItems(DictionaryObject *self, PyObject *args UNUSED)
 {
     return DictionaryListObjects(self, dict_item);
 }
@@ -2166,7 +2169,7 @@ DictionaryPop(DictionaryObject *self, Py
 }
 
     static PyObject *
-DictionaryPopItem(DictionaryObject *self)
+DictionaryPopItem(DictionaryObject *self, PyObject *args UNUSED)
 {
     hashitem_T	*hi;
     PyObject	*ret;
@@ -2229,7 +2232,7 @@ static struct PyMethodDef DictionaryMeth
     {"keys",	(PyCFunction)DictionaryListKeys,	METH_NOARGS,	""},
     {"values",	(PyCFunction)DictionaryListValues,	METH_NOARGS,	""},
     {"items",	(PyCFunction)DictionaryListItems,	METH_NOARGS,	""},
-    {"update",	(PyCFunction)DictionaryUpdate,		METH_VARARGS|METH_KEYWORDS, ""},
+    {"update",	(PyCFunction)(void *)DictionaryUpdate,		METH_VARARGS|METH_KEYWORDS, ""},
     {"get",	(PyCFunction)DictionaryGet,		METH_VARARGS,	""},
     {"pop",	(PyCFunction)DictionaryPop,		METH_VARARGS,	""},
     {"popitem",	(PyCFunction)DictionaryPopItem,		METH_NOARGS,	""},
@@ -2742,21 +2745,21 @@ ListAssIndex(ListObject *self, Py_ssize_
     return 0;
 }
 
-    static Py_ssize_t
+    static int
 ListAssItem(ListObject *self, PyObject *idx, PyObject *obj)
 {
 #if PY_MAJOR_VERSION < 3
     if (PyInt_Check(idx))
     {
 	long _idx = PyInt_AsLong(idx);
-	return ListAssIndex(self, _idx, obj);
+	return (int)ListAssIndex(self, _idx, obj);
     }
     else
 #endif
     if (PyLong_Check(idx))
     {
 	long _idx = PyLong_AsLong(idx);
-	return ListAssIndex(self, _idx, obj);
+	return (int)ListAssIndex(self, _idx, obj);
     }
     else if (PySlice_Check(idx))
     {
@@ -2765,7 +2768,7 @@ ListAssItem(ListObject *self, PyObject *
 	if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self),
 				 &start, &stop, &step, &slicelen) < 0)
 	    return -1;
-	return ListAssSlice(self, start, step, slicelen,
+	return (int)ListAssSlice(self, start, step, slicelen,
 		obj);
     }
     else
@@ -2858,7 +2861,7 @@ static char *ListAttrs[] = {
 };
 
     static PyObject *
-ListDir(PyObject *self)
+ListDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, ListAttrs);
 }
@@ -3113,7 +3116,7 @@ static char *FunctionAttrs[] = {
 };
 
     static PyObject *
-FunctionDir(PyObject *self)
+FunctionDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, FunctionAttrs);
 }
@@ -3128,7 +3131,7 @@ FunctionAttr(FunctionObject *self, char 
     else if (strcmp(name, "args") == 0)
     {
 	if (self->argv == NULL || (list = list_alloc()) == NULL)
-	    return AlwaysNone(NULL);
+	    return ALWAYS_NONE;
 
 	for (i = 0; i < self->argc; ++i)
 	    list_append_tv(list, &self->argv[i]);
@@ -3136,12 +3139,12 @@ FunctionAttr(FunctionObject *self, char 
     }
     else if (strcmp(name, "self") == 0)
 	return self->self == NULL
-	    ? AlwaysNone(NULL)
+	    ? ALWAYS_NONE
 	    : NEW_DICTIONARY(self->self);
     else if (strcmp(name, "auto_rebind") == 0)
 	return self->auto_rebind
-	    ? AlwaysTrue(NULL)
-	    : AlwaysFalse(NULL);
+	    ? ALWAYS_TRUE
+	    : ALWAYS_FALSE;
     else if (strcmp(name, "__members__") == 0)
 	return ObjectDir(NULL, FunctionAttrs);
     return NULL;
@@ -3497,7 +3500,7 @@ OptionsIter(OptionsObject *self)
     oii->lastoption = NULL;
 
     return IterNew(oii,
-	    (destructorfun) PyMem_Free, (nextfun) OptionsIterNext,
+	    (destructorfun)(void *) PyMem_Free, (nextfun) OptionsIterNext,
 	    NULL, NULL, (PyObject *)self);
 }
 
@@ -3742,7 +3745,7 @@ static char *TabPageAttrs[] = {
 };
 
     static PyObject *
-TabPageDir(PyObject *self)
+TabPageDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, TabPageAttrs);
 }
@@ -3968,7 +3971,7 @@ static char *WindowAttrs[] = {
 };
 
     static PyObject *
-WindowDir(PyObject *self)
+WindowDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, WindowAttrs);
 }
@@ -5106,7 +5109,7 @@ static char *RangeAttrs[] = {
 };
 
     static PyObject *
-RangeDir(PyObject *self)
+RangeDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, RangeAttrs);
 }
@@ -5223,7 +5226,7 @@ static char *BufferAttrs[] = {
 };
 
     static PyObject *
-BufferDir(PyObject *self)
+BufferDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, BufferAttrs);
 }
@@ -5520,7 +5523,7 @@ static char *CurrentAttrs[] = {
 };
 
     static PyObject *
-CurrentDir(PyObject *self)
+CurrentDir(PyObject *self, PyObject *args UNUSED)
 {
     return ObjectDir(self, CurrentAttrs);
 }
@@ -6424,10 +6427,10 @@ ConvertToPyObject(typval_T *tv)
 	case VAR_SPECIAL:
 	    switch (tv->vval.v_number)
 	    {
-		case VVAL_FALSE: return AlwaysFalse(NULL);
-		case VVAL_TRUE:  return AlwaysTrue(NULL);
+		case VVAL_FALSE: return ALWAYS_FALSE;
+		case VVAL_TRUE:  return ALWAYS_TRUE;
 		case VVAL_NONE:
-		case VVAL_NULL:  return AlwaysNone(NULL);
+		case VVAL_NULL:  return ALWAYS_NONE;
 	    }
 	    PyErr_SET_VIM(N_("internal error: invalid value type"));
 	    return NULL;
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -1197,16 +1197,16 @@ OutputGetattr(PyObject *self, char *name
 
 #define BufferType_Check(obj) ((obj)->ob_type == &BufferType)
 
-static PyInt BufferAssItem(PyObject *, PyInt, PyObject *);
-static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *);
+static int BufferAssItem(PyObject *, PyInt, PyObject *);
+static int BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *);
 
 // Line range type - Implementation functions
 // --------------------------------------
 
 #define RangeType_Check(obj) ((obj)->ob_type == &RangeType)
 
-static PyInt RangeAssItem(PyObject *, PyInt, PyObject *);
-static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *);
+static int RangeAssItem(PyObject *, PyInt, PyObject *);
+static int RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *);
 
 // Current objects type - Implementation functions
 // -----------------------------------------------
@@ -1246,13 +1246,13 @@ BufferGetattr(PyObject *self, char *name
 
 //////////////////
 
-    static PyInt
+    static int
 BufferAssItem(PyObject *self, PyInt n, PyObject *val)
 {
     return RBAsItem((BufferObject *)(self), n, val, 1, -1, NULL);
 }
 
-    static PyInt
+    static int
 BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
 {
     return RBAsSlice((BufferObject *)(self), lo, hi, val, 1, -1, NULL);
@@ -1290,7 +1290,7 @@ RangeGetattr(PyObject *self, char *name)
 
 ////////////////
 
-    static PyInt
+    static int
 RangeAssItem(PyObject *self, PyInt n, PyObject *val)
 {
     return RBAsItem(((RangeObject *)(self))->buf, n, val,
@@ -1299,7 +1299,7 @@ RangeAssItem(PyObject *self, PyInt n, Py
 		     &((RangeObject *)(self))->end);
 }
 
-    static PyInt
+    static int
 RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
 {
     return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -1252,7 +1252,7 @@ OutputSetattro(PyObject *self, PyObject 
 #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType)
 
 static PyObject* BufferSubscript(PyObject *self, PyObject *idx);
-static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
+static int BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
 
 // Line range type - Implementation functions
 // --------------------------------------
@@ -1260,8 +1260,8 @@ static Py_ssize_t BufferAsSubscript(PyOb
 #define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType)
 
 static PyObject* RangeSubscript(PyObject *self, PyObject *idx);
-static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *);
-static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
+static int RangeAsItem(PyObject *, Py_ssize_t, PyObject *);
+static int RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
 
 // Current objects type - Implementation functions
 // -----------------------------------------------
@@ -1346,7 +1346,7 @@ BufferSubscript(PyObject *self, PyObject
     }
 }
 
-    static Py_ssize_t
+    static int
 BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
 {
     if (PyLong_Check(idx))
@@ -1418,7 +1418,7 @@ RangeGetattro(PyObject *self, PyObject *
 
 ////////////////
 
-    static Py_ssize_t
+    static int
 RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val)
 {
     return RBAsItem(((RangeObject *)(self))->buf, n, val,
@@ -1461,7 +1461,7 @@ RangeSubscript(PyObject *self, PyObject*
     }
 }
 
-    static Py_ssize_t
+    static int
 RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
 {
     if (PyLong_Check(idx))
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1883,
+/**/
     1882,
 /**/
     1881,