0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2020-10-21 21:01:59 +02:00
parent c58f5456e5
commit 4ce5fe4c87
4 changed files with 55 additions and 50 deletions

View File

@@ -324,7 +324,7 @@ static char *OutputAttrs[] = {
}; };
static PyObject * static PyObject *
OutputDir(PyObject *self) OutputDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, OutputAttrs); return ObjectDir(self, OutputAttrs);
} }
@@ -468,30 +468,33 @@ OutputWritelines(OutputObject *self, PyObject *seq)
} }
static PyObject * static PyObject *
AlwaysNone(PyObject *self UNUSED) AlwaysNone(PyObject *self UNUSED, PyObject *args UNUSED)
{ {
// do nothing // do nothing
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
#define ALWAYS_NONE AlwaysNone(NULL, NULL)
static PyObject * static PyObject *
AlwaysFalse(PyObject *self UNUSED) AlwaysFalse(PyObject *self UNUSED, PyObject *args UNUSED)
{ {
// do nothing // do nothing
PyObject *ret = Py_False; PyObject *ret = Py_False;
Py_INCREF(ret); Py_INCREF(ret);
return ret; return ret;
} }
#define ALWAYS_FALSE AlwaysFalse(NULL, NULL)
static PyObject * static PyObject *
AlwaysTrue(PyObject *self UNUSED) AlwaysTrue(PyObject *self UNUSED, PyObject *args UNUSED)
{ {
// do nothing // do nothing
PyObject *ret = Py_True; PyObject *ret = Py_True;
Py_INCREF(ret); Py_INCREF(ret);
return ret; return ret;
} }
#define ALWAYS_TRUE AlwaysTrue(NULL, NULL)
/***************/ /***************/
@@ -1179,7 +1182,7 @@ map_finder_callback(char_u *path, void *_data)
} }
static PyObject * static PyObject *
Vim_GetPaths(PyObject *self UNUSED) Vim_GetPaths(PyObject *self UNUSED, PyObject *args UNUSED)
{ {
PyObject *ret; PyObject *ret;
@@ -1209,7 +1212,7 @@ FinderFindSpec(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s|O", &fullname, &target)) if (!PyArg_ParseTuple(args, "s|O", &fullname, &target))
return NULL; return NULL;
if (!(paths = Vim_GetPaths(self))) if (!(paths = Vim_GetPaths(self, NULL)))
return NULL; return NULL;
spec = PyObject_CallFunction(py_find_spec, "sOO", fullname, paths, target); spec = PyObject_CallFunction(py_find_spec, "sOO", fullname, paths, target);
@@ -1344,7 +1347,7 @@ FinderFindModule(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s", &fullname)) if (!PyArg_ParseTuple(args, "s", &fullname))
return NULL; return NULL;
if (!(new_path = Vim_GetPaths(self))) if (!(new_path = Vim_GetPaths(self, NULL)))
return NULL; return NULL;
result = find_module(fullname, fullname, new_path); 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" }, {"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" },
{"bindeval", VimEvalPy, METH_O, "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_O, "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)(void *)VimChdir, METH_VARARGS|METH_KEYWORDS, "Change directory"},
{"fchdir", (PyCFunction)VimFchdir, 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"}, {"foreach_rtp", VimForeachRTP, METH_O, "Call given callable for each path in &rtp"},
#if PY_VERSION_HEX >= 0x030700f0 #if PY_VERSION_HEX >= 0x030700f0
{"find_spec", FinderFindSpec, METH_VARARGS, "Internal use only, returns spec object for any input it receives"}, {"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 * static PyObject *
DictionaryDir(PyObject *self) DictionaryDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, DictionaryAttrs); return ObjectDir(self, DictionaryAttrs);
} }
@@ -1850,11 +1853,11 @@ DictionaryIter(DictionaryObject *self)
dii->dii_todo = ht->ht_used; dii->dii_todo = ht->ht_used;
return IterNew(dii, return IterNew(dii,
(destructorfun) PyMem_Free, (nextfun) DictionaryIterNext, (destructorfun)(void *) PyMem_Free, (nextfun) DictionaryIterNext,
NULL, NULL, (PyObject *)self); NULL, NULL, (PyObject *)self);
} }
static PyInt static int
DictionaryAssItem( DictionaryAssItem(
DictionaryObject *self, PyObject *keyObject, PyObject *valObject) DictionaryObject *self, PyObject *keyObject, PyObject *valObject)
{ {
@@ -1970,7 +1973,7 @@ dict_key(hashitem_T *hi)
} }
static PyObject * static PyObject *
DictionaryListKeys(DictionaryObject *self) DictionaryListKeys(DictionaryObject *self, PyObject *args UNUSED)
{ {
return DictionaryListObjects(self, dict_key); return DictionaryListObjects(self, dict_key);
} }
@@ -1985,7 +1988,7 @@ dict_val(hashitem_T *hi)
} }
static PyObject * static PyObject *
DictionaryListValues(DictionaryObject *self) DictionaryListValues(DictionaryObject *self, PyObject *args UNUSED)
{ {
return DictionaryListObjects(self, dict_val); return DictionaryListObjects(self, dict_val);
} }
@@ -2015,7 +2018,7 @@ dict_item(hashitem_T *hi)
} }
static PyObject * static PyObject *
DictionaryListItems(DictionaryObject *self) DictionaryListItems(DictionaryObject *self, PyObject *args UNUSED)
{ {
return DictionaryListObjects(self, dict_item); return DictionaryListObjects(self, dict_item);
} }
@@ -2166,7 +2169,7 @@ DictionaryPop(DictionaryObject *self, PyObject *args)
} }
static PyObject * static PyObject *
DictionaryPopItem(DictionaryObject *self) DictionaryPopItem(DictionaryObject *self, PyObject *args UNUSED)
{ {
hashitem_T *hi; hashitem_T *hi;
PyObject *ret; PyObject *ret;
@@ -2229,7 +2232,7 @@ static struct PyMethodDef DictionaryMethods[] = {
{"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""}, {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
{"values", (PyCFunction)DictionaryListValues, METH_NOARGS, ""}, {"values", (PyCFunction)DictionaryListValues, METH_NOARGS, ""},
{"items", (PyCFunction)DictionaryListItems, 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, ""}, {"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, ""},
@@ -2742,21 +2745,21 @@ ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj)
return 0; return 0;
} }
static Py_ssize_t static int
ListAssItem(ListObject *self, PyObject *idx, PyObject *obj) ListAssItem(ListObject *self, PyObject *idx, PyObject *obj)
{ {
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
if (PyInt_Check(idx)) if (PyInt_Check(idx))
{ {
long _idx = PyInt_AsLong(idx); long _idx = PyInt_AsLong(idx);
return ListAssIndex(self, _idx, obj); return (int)ListAssIndex(self, _idx, obj);
} }
else else
#endif #endif
if (PyLong_Check(idx)) if (PyLong_Check(idx))
{ {
long _idx = PyLong_AsLong(idx); long _idx = PyLong_AsLong(idx);
return ListAssIndex(self, _idx, obj); return (int)ListAssIndex(self, _idx, obj);
} }
else if (PySlice_Check(idx)) else if (PySlice_Check(idx))
{ {
@@ -2765,7 +2768,7 @@ ListAssItem(ListObject *self, PyObject *idx, PyObject *obj)
if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self), if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self),
&start, &stop, &step, &slicelen) < 0) &start, &stop, &step, &slicelen) < 0)
return -1; return -1;
return ListAssSlice(self, start, step, slicelen, return (int)ListAssSlice(self, start, step, slicelen,
obj); obj);
} }
else else
@@ -2858,7 +2861,7 @@ static char *ListAttrs[] = {
}; };
static PyObject * static PyObject *
ListDir(PyObject *self) ListDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, ListAttrs); return ObjectDir(self, ListAttrs);
} }
@@ -3113,7 +3116,7 @@ static char *FunctionAttrs[] = {
}; };
static PyObject * static PyObject *
FunctionDir(PyObject *self) FunctionDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, FunctionAttrs); return ObjectDir(self, FunctionAttrs);
} }
@@ -3128,7 +3131,7 @@ FunctionAttr(FunctionObject *self, char *name)
else if (strcmp(name, "args") == 0) else if (strcmp(name, "args") == 0)
{ {
if (self->argv == NULL || (list = list_alloc()) == NULL) if (self->argv == NULL || (list = list_alloc()) == NULL)
return AlwaysNone(NULL); return ALWAYS_NONE;
for (i = 0; i < self->argc; ++i) for (i = 0; i < self->argc; ++i)
list_append_tv(list, &self->argv[i]); list_append_tv(list, &self->argv[i]);
@@ -3136,12 +3139,12 @@ FunctionAttr(FunctionObject *self, char *name)
} }
else if (strcmp(name, "self") == 0) else if (strcmp(name, "self") == 0)
return self->self == NULL return self->self == NULL
? AlwaysNone(NULL) ? ALWAYS_NONE
: NEW_DICTIONARY(self->self); : NEW_DICTIONARY(self->self);
else if (strcmp(name, "auto_rebind") == 0) else if (strcmp(name, "auto_rebind") == 0)
return self->auto_rebind return self->auto_rebind
? AlwaysTrue(NULL) ? ALWAYS_TRUE
: AlwaysFalse(NULL); : ALWAYS_FALSE;
else if (strcmp(name, "__members__") == 0) else if (strcmp(name, "__members__") == 0)
return ObjectDir(NULL, FunctionAttrs); return ObjectDir(NULL, FunctionAttrs);
return NULL; return NULL;
@@ -3497,7 +3500,7 @@ OptionsIter(OptionsObject *self)
oii->lastoption = NULL; oii->lastoption = NULL;
return IterNew(oii, return IterNew(oii,
(destructorfun) PyMem_Free, (nextfun) OptionsIterNext, (destructorfun)(void *) PyMem_Free, (nextfun) OptionsIterNext,
NULL, NULL, (PyObject *)self); NULL, NULL, (PyObject *)self);
} }
@@ -3742,7 +3745,7 @@ static char *TabPageAttrs[] = {
}; };
static PyObject * static PyObject *
TabPageDir(PyObject *self) TabPageDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, TabPageAttrs); return ObjectDir(self, TabPageAttrs);
} }
@@ -3968,7 +3971,7 @@ static char *WindowAttrs[] = {
}; };
static PyObject * static PyObject *
WindowDir(PyObject *self) WindowDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, WindowAttrs); return ObjectDir(self, WindowAttrs);
} }
@@ -5106,7 +5109,7 @@ static char *RangeAttrs[] = {
}; };
static PyObject * static PyObject *
RangeDir(PyObject *self) RangeDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, RangeAttrs); return ObjectDir(self, RangeAttrs);
} }
@@ -5223,7 +5226,7 @@ static char *BufferAttrs[] = {
}; };
static PyObject * static PyObject *
BufferDir(PyObject *self) BufferDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, BufferAttrs); return ObjectDir(self, BufferAttrs);
} }
@@ -5520,7 +5523,7 @@ static char *CurrentAttrs[] = {
}; };
static PyObject * static PyObject *
CurrentDir(PyObject *self) CurrentDir(PyObject *self, PyObject *args UNUSED)
{ {
return ObjectDir(self, CurrentAttrs); return ObjectDir(self, CurrentAttrs);
} }
@@ -6424,10 +6427,10 @@ ConvertToPyObject(typval_T *tv)
case VAR_SPECIAL: case VAR_SPECIAL:
switch (tv->vval.v_number) switch (tv->vval.v_number)
{ {
case VVAL_FALSE: return AlwaysFalse(NULL); case VVAL_FALSE: return ALWAYS_FALSE;
case VVAL_TRUE: return AlwaysTrue(NULL); case VVAL_TRUE: return ALWAYS_TRUE;
case VVAL_NONE: case VVAL_NONE:
case VVAL_NULL: return AlwaysNone(NULL); case VVAL_NULL: return ALWAYS_NONE;
} }
PyErr_SET_VIM(N_("internal error: invalid value type")); PyErr_SET_VIM(N_("internal error: invalid value type"));
return NULL; return NULL;

View File

@@ -1197,16 +1197,16 @@ OutputGetattr(PyObject *self, char *name)
#define BufferType_Check(obj) ((obj)->ob_type == &BufferType) #define BufferType_Check(obj) ((obj)->ob_type == &BufferType)
static PyInt BufferAssItem(PyObject *, PyInt, PyObject *); static int BufferAssItem(PyObject *, PyInt, PyObject *);
static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *); static int BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *);
// Line range type - Implementation functions // Line range type - Implementation functions
// -------------------------------------- // --------------------------------------
#define RangeType_Check(obj) ((obj)->ob_type == &RangeType) #define RangeType_Check(obj) ((obj)->ob_type == &RangeType)
static PyInt RangeAssItem(PyObject *, PyInt, PyObject *); static int RangeAssItem(PyObject *, PyInt, PyObject *);
static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *); static int RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *);
// Current objects type - Implementation functions // 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) BufferAssItem(PyObject *self, PyInt n, PyObject *val)
{ {
return RBAsItem((BufferObject *)(self), n, val, 1, -1, NULL); return RBAsItem((BufferObject *)(self), n, val, 1, -1, NULL);
} }
static PyInt static int
BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
{ {
return RBAsSlice((BufferObject *)(self), lo, hi, val, 1, -1, NULL); 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) RangeAssItem(PyObject *self, PyInt n, PyObject *val)
{ {
return RBAsItem(((RangeObject *)(self))->buf, n, val, return RBAsItem(((RangeObject *)(self))->buf, n, val,
@@ -1299,7 +1299,7 @@ RangeAssItem(PyObject *self, PyInt n, PyObject *val)
&((RangeObject *)(self))->end); &((RangeObject *)(self))->end);
} }
static PyInt static int
RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
{ {
return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val, return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,

View File

@@ -1252,7 +1252,7 @@ OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
#define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType) #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType)
static PyObject* BufferSubscript(PyObject *self, PyObject *idx); 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 // Line range type - Implementation functions
// -------------------------------------- // --------------------------------------
@@ -1260,8 +1260,8 @@ static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val
#define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType) #define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType)
static PyObject* RangeSubscript(PyObject *self, PyObject *idx); static PyObject* RangeSubscript(PyObject *self, PyObject *idx);
static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *); static int RangeAsItem(PyObject *, Py_ssize_t, PyObject *);
static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val); static int RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
// Current objects type - Implementation functions // Current objects type - Implementation functions
// ----------------------------------------------- // -----------------------------------------------
@@ -1346,7 +1346,7 @@ BufferSubscript(PyObject *self, PyObject* idx)
} }
} }
static Py_ssize_t static int
BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val) BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
{ {
if (PyLong_Check(idx)) if (PyLong_Check(idx))
@@ -1418,7 +1418,7 @@ RangeGetattro(PyObject *self, PyObject *nameobj)
//////////////// ////////////////
static Py_ssize_t static int
RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val) RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val)
{ {
return RBAsItem(((RangeObject *)(self))->buf, n, val, return RBAsItem(((RangeObject *)(self))->buf, n, val,
@@ -1461,7 +1461,7 @@ RangeSubscript(PyObject *self, PyObject* idx)
} }
} }
static Py_ssize_t static int
RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val) RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
{ {
if (PyLong_Check(idx)) if (PyLong_Check(idx))

View File

@@ -750,6 +750,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 */
/**/
1883,
/**/ /**/
1882, 1882,
/**/ /**/