Skip to content

Commit

Permalink
patch 8.2.1883: compiler warnings when using Python
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brammool committed Oct 21, 2020
1 parent c58f545 commit 4ce5fe4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 50 deletions.
75 changes: 39 additions & 36 deletions src/if_py_both.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ static char *OutputAttrs[] = {
};

static PyObject *
OutputDir(PyObject *self)
OutputDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, OutputAttrs);
}
Expand Down Expand Up @@ -468,30 +468,33 @@ OutputWritelines(OutputObject *self, PyObject *seq)
}

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)

/***************/

Expand Down Expand Up @@ -1179,7 +1182,7 @@ map_finder_callback(char_u *path, void *_data)
}

static PyObject *
Vim_GetPaths(PyObject *self UNUSED)
Vim_GetPaths(PyObject *self UNUSED, PyObject *args UNUSED)
{
PyObject *ret;

Expand Down Expand Up @@ -1209,7 +1212,7 @@ FinderFindSpec(PyObject *self, PyObject *args)
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);
Expand Down Expand Up @@ -1344,7 +1347,7 @@ FinderFindModule(PyObject *self, PyObject *args)
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);
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -1643,7 +1646,7 @@ static char *DictionaryAttrs[] = {
};

static PyObject *
DictionaryDir(PyObject *self)
DictionaryDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, DictionaryAttrs);
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -2166,7 +2169,7 @@ DictionaryPop(DictionaryObject *self, PyObject *args)
}

static PyObject *
DictionaryPopItem(DictionaryObject *self)
DictionaryPopItem(DictionaryObject *self, PyObject *args UNUSED)
{
hashitem_T *hi;
PyObject *ret;
Expand Down Expand Up @@ -2229,7 +2232,7 @@ static struct PyMethodDef DictionaryMethods[] = {
{"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, ""},
Expand Down Expand Up @@ -2742,21 +2745,21 @@ ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj)
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))
{
Expand All @@ -2765,7 +2768,7 @@ ListAssItem(ListObject *self, PyObject *idx, PyObject *obj)
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
Expand Down Expand Up @@ -2858,7 +2861,7 @@ static char *ListAttrs[] = {
};

static PyObject *
ListDir(PyObject *self)
ListDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, ListAttrs);
}
Expand Down Expand Up @@ -3113,7 +3116,7 @@ static char *FunctionAttrs[] = {
};

static PyObject *
FunctionDir(PyObject *self)
FunctionDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, FunctionAttrs);
}
Expand All @@ -3128,20 +3131,20 @@ FunctionAttr(FunctionObject *self, char *name)
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]);
return NEW_LIST(list);
}
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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -3742,7 +3745,7 @@ static char *TabPageAttrs[] = {
};

static PyObject *
TabPageDir(PyObject *self)
TabPageDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, TabPageAttrs);
}
Expand Down Expand Up @@ -3968,7 +3971,7 @@ static char *WindowAttrs[] = {
};

static PyObject *
WindowDir(PyObject *self)
WindowDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, WindowAttrs);
}
Expand Down Expand Up @@ -5106,7 +5109,7 @@ static char *RangeAttrs[] = {
};

static PyObject *
RangeDir(PyObject *self)
RangeDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, RangeAttrs);
}
Expand Down Expand Up @@ -5223,7 +5226,7 @@ static char *BufferAttrs[] = {
};

static PyObject *
BufferDir(PyObject *self)
BufferDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, BufferAttrs);
}
Expand Down Expand Up @@ -5520,7 +5523,7 @@ static char *CurrentAttrs[] = {
};

static PyObject *
CurrentDir(PyObject *self)
CurrentDir(PyObject *self, PyObject *args UNUSED)
{
return ObjectDir(self, CurrentAttrs);
}
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/if_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
// -----------------------------------------------
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -1299,7 +1299,7 @@ RangeAssItem(PyObject *self, PyInt n, PyObject *val)
&((RangeObject *)(self))->end);
}

static PyInt
static int
RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
{
return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,
Expand Down
12 changes: 6 additions & 6 deletions src/if_python3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,16 +1252,16 @@ OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
#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
// --------------------------------------

#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
// -----------------------------------------------
Expand Down Expand Up @@ -1346,7 +1346,7 @@ BufferSubscript(PyObject *self, PyObject* idx)
}
}

static Py_ssize_t
static int
BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
{
if (PyLong_Check(idx))
Expand Down Expand Up @@ -1418,7 +1418,7 @@ RangeGetattro(PyObject *self, PyObject *nameobj)

////////////////

static Py_ssize_t
static int
RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val)
{
return RBAsItem(((RangeObject *)(self))->buf, n, val,
Expand Down Expand Up @@ -1461,7 +1461,7 @@ RangeSubscript(PyObject *self, PyObject* idx)
}
}

static Py_ssize_t
static int
RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
{
if (PyLong_Check(idx))
Expand Down
Loading

0 comments on commit 4ce5fe4

Please sign in to comment.