Loading ...
Sorry, an error occurred while loading the content.

[PATCH] Refactoring: less type casts and less magic variables

Expand Messages
  • ZyX
    # HG changeset patch # User ZyX # Date 1368866112 -14400 # Branch python-extended-2 # Node ID 97bbb36fe75d0842ada71d0e62eca7ca411072a6 # Parent
    Message 1 of 7 , May 18, 2013
    • 0 Attachment
      # HG changeset patch
      # User ZyX <kp-pav@...>
      # Date 1368866112 -14400
      # Branch python-extended-2
      # Node ID 97bbb36fe75d0842ada71d0e62eca7ca411072a6
      # Parent a682902e547d02c97e816ec52a34e257582662d7
      Refactoring: replace a big bunch of type casts with proper argument types

      Implies type casts when initializing structures.

      diff -r a682902e547d -r 97bbb36fe75d src/if_py_both.h
      --- a/src/if_py_both.h Sat May 18 01:47:01 2013 +0400
      +++ b/src/if_py_both.h Sat May 18 12:35:12 2013 +0400
      @@ -76,7 +76,7 @@
      } OutputObject;

      static int
      -OutputSetattr(PyObject *self, char *name, PyObject *val)
      +OutputSetattr(OutputObject *self, char *name, PyObject *val)
      {
      if (val == NULL)
      {
      @@ -93,7 +93,7 @@
      return -1;
      }

      - ((OutputObject *)(self))->softspace = PyInt_AsLong(val);
      + self->softspace = PyInt_AsLong(val);
      return 0;
      }

      @@ -152,11 +152,11 @@
      }

      static PyObject *
      -OutputWrite(PyObject *self, PyObject *args)
      +OutputWrite(OutputObject *self, PyObject *args)
      {
      Py_ssize_t len = 0;
      char *str = NULL;
      - int error = ((OutputObject *)(self))->error;
      + int error = self->error;

      if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len))
      return NULL;
      @@ -173,12 +173,12 @@
      }

      static PyObject *
      -OutputWritelines(PyObject *self, PyObject *args)
      +OutputWritelines(OutputObject *self, PyObject *args)
      {
      PyInt n;
      PyInt i;
      PyObject *list;
      - int error = ((OutputObject *)(self))->error;
      + int error = self->error;

      if (!PyArg_ParseTuple(args, "O", &list))
      return NULL;
      @@ -230,11 +230,11 @@
      /***************/

      static struct PyMethodDef OutputMethods[] = {
      - /* name, function, calling, documentation */
      - {"write", OutputWrite, 1, ""},
      - {"writelines", OutputWritelines, 1, ""},
      - {"flush", OutputFlush, 1, ""},
      - { NULL, NULL, 0, NULL}
      + /* name, function, calling, doc */
      + {"write", (PyCFunction)OutputWrite, 1, ""},
      + {"writelines", (PyCFunction)OutputWritelines, 1, ""},
      + {"flush", (PyCFunction)OutputFlush, 1, ""},
      + { NULL, NULL, 0, NULL}
      };

      static OutputObject Output =
      @@ -583,22 +583,18 @@
      }

      static void
      -IterDestructor(PyObject *self)
      +IterDestructor(IterObject *self)
      {
      - IterObject *this = (IterObject *)(self);
      -
      - this->destruct(this->cur);
      + self->destruct(self->cur);

      DESTRUCTOR_FINISH(self);
      }

      static int
      -IterTraverse(PyObject *self, visitproc visit, void *arg)
      +IterTraverse(IterObject *self, visitproc visit, void *arg)
      {
      - IterObject *this = (IterObject *)(self);
      -
      - if (this->traverse != NULL)
      - return this->traverse(this->cur, visit, arg);
      + if (self->traverse != NULL)
      + return self->traverse(self->cur, visit, arg);
      else
      return 0;
      }
      @@ -609,22 +605,18 @@
      #endif

      static int
      -IterClear(PyObject *self)
      +IterClear(IterObject *self)
      {
      - IterObject *this = (IterObject *)(self);
      -
      - if (this->clear != NULL)
      - return this->clear(&this->cur);
      + if (self->clear != NULL)
      + return self->clear(&self->cur);
      else
      return 0;
      }

      static PyObject *
      -IterNext(PyObject *self)
      +IterNext(IterObject *self)
      {
      - IterObject *this = (IterObject *)(self);
      -
      - return this->next(&this->cur);
      + return self->next(&self->cur);
      }

      static PyObject *
      @@ -711,21 +703,17 @@
      }

      static void
      -DictionaryDestructor(PyObject *self)
      +DictionaryDestructor(DictionaryObject *self)
      {
      - DictionaryObject *this = ((DictionaryObject *) (self));
      -
      - pyll_remove(&this->ref, &lastdict);
      - dict_unref(this->dict);
      + pyll_remove(&self->ref, &lastdict);
      + dict_unref(self->dict);

      DESTRUCTOR_FINISH(self);
      }

      static int
      -DictionarySetattr(PyObject *self, char *name, PyObject *val)
      +DictionarySetattr(DictionaryObject *self, char *name, PyObject *val)
      {
      - DictionaryObject *this = (DictionaryObject *)(self);
      -
      if (val == NULL)
      {
      PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes"));
      @@ -734,7 +722,7 @@

      if (strcmp(name, "locked") == 0)
      {
      - if (this->dict->dv_lock == VAR_FIXED)
      + if (self->dict->dv_lock == VAR_FIXED)
      {
      PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed dictionary"));
      return -1;
      @@ -745,9 +733,9 @@
      if (istrue == -1)
      return -1;
      else if (istrue)
      - this->dict->dv_lock = VAR_LOCKED;
      + self->dict->dv_lock = VAR_LOCKED;
      else
      - this->dict->dv_lock = 0;
      + self->dict->dv_lock = 0;
      }
      return 0;
      }
      @@ -759,13 +747,13 @@
      }

      static PyInt
      -DictionaryLength(PyObject *self)
      +DictionaryLength(DictionaryObject *self)
      {
      - return ((PyInt) ((((DictionaryObject *)(self))->dict->dv_hashtab.ht_used)));
      + return ((PyInt) (self->dict->dv_hashtab.ht_used));
      }

      static PyObject *
      -DictionaryItem(PyObject *self, PyObject *keyObject)
      +DictionaryItem(DictionaryObject *self, PyObject *keyObject)
      {
      char_u *key;
      dictitem_T *di;
      @@ -773,7 +761,7 @@

      DICTKEY_GET_NOTEMPTY(NULL)

      - di = dict_find(((DictionaryObject *) (self))->dict, key, -1);
      + di = dict_find(self->dict, key, -1);

      DICTKEY_UNREF

      @@ -787,11 +775,11 @@
      }

      static PyInt
      -DictionaryAssItem(PyObject *self, PyObject *keyObject, PyObject *valObject)
      +DictionaryAssItem(DictionaryObject *self, PyObject *keyObject, PyObject *valObject)
      {
      char_u *key;
      typval_T tv;
      - dict_T *d = ((DictionaryObject *)(self))->dict;
      + dict_T *d = self->dict;
      dictitem_T *di;
      DICTKEY_DECL

      @@ -852,9 +840,9 @@
      }

      static PyObject *
      -DictionaryListKeys(PyObject *self UNUSED)
      +DictionaryListKeys(DictionaryObject *self)
      {
      - dict_T *dict = ((DictionaryObject *)(self))->dict;
      + dict_T *dict = self->dict;
      long_u todo = dict->dv_hashtab.ht_used;
      Py_ssize_t i = 0;
      PyObject *r;
      @@ -912,12 +900,10 @@
      }

      static void
      -ListDestructor(PyObject *self)
      +ListDestructor(ListObject *self)
      {
      - ListObject *this = (ListObject *)(self);
      -
      - pyll_remove(&this->ref, &lastlist);
      - list_unref(this->list);
      + pyll_remove(&self->ref, &lastlist);
      + list_unref(self->list);

      DESTRUCTOR_FINISH(self);
      }
      @@ -952,22 +938,22 @@
      }

      static PyInt
      -ListLength(PyObject *self)
      +ListLength(ListObject *self)
      {
      - return ((PyInt) (((ListObject *) (self))->list->lv_len));
      + return ((PyInt) (self->list->lv_len));
      }

      static PyObject *
      -ListItem(PyObject *self, Py_ssize_t index)
      +ListItem(ListObject *self, Py_ssize_t index)
      {
      listitem_T *li;

      - if (index>=ListLength(self))
      + if (index >= ListLength(self))
      {
      PyErr_SetString(PyExc_IndexError, _("list index out of range"));
      return NULL;
      }
      - li = list_find(((ListObject *) (self))->list, (long) index);
      + li = list_find(self->list, (long) index);
      if (li == NULL)
      {
      PyErr_SetVim(_("internal error: failed to get vim list item"));
      @@ -991,7 +977,7 @@
      last = size;

      static PyObject *
      -ListSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last)
      +ListSlice(ListObject *self, Py_ssize_t first, Py_ssize_t last)
      {
      PyInt i;
      PyInt size = ListLength(self);
      @@ -1058,10 +1044,10 @@
      }

      static PyObject *
      -ListIter(PyObject *self)
      +ListIter(ListObject *self)
      {
      listiterinfo_T *lii;
      - list_T *l = ((ListObject *) (self))->list;
      + list_T *l = self->list;

      if (!(lii = PyMem_New(listiterinfo_T, 1)))
      {
      @@ -1079,10 +1065,10 @@
      }

      static int
      -ListAssItem(PyObject *self, Py_ssize_t index, PyObject *obj)
      +ListAssItem(ListObject *self, Py_ssize_t index, PyObject *obj)
      {
      typval_T tv;
      - list_T *l = ((ListObject *) (self))->list;
      + list_T *l = self->list;
      listitem_T *li;
      Py_ssize_t length = ListLength(self);

      @@ -1127,7 +1113,7 @@
      }

      static int
      -ListAssSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *obj)
      +ListAssSlice(ListObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *obj)
      {
      PyInt size = ListLength(self);
      Py_ssize_t i;
      @@ -1136,7 +1122,7 @@
      listitem_T *li;
      listitem_T *next;
      typval_T v;
      - list_T *l = ((ListObject *) (self))->list;
      + list_T *l = self->list;

      if (l->lv_lock)
      {
      @@ -1196,9 +1182,9 @@
      }

      static PyObject *
      -ListConcatInPlace(PyObject *self, PyObject *obj)
      +ListConcatInPlace(ListObject *self, PyObject *obj)
      {
      - list_T *l = ((ListObject *) (self))->list;
      + list_T *l = self->list;
      PyObject *lookup_dict;

      if (l->lv_lock)
      @@ -1222,14 +1208,12 @@
      Py_DECREF(lookup_dict);

      Py_INCREF(self);
      - return self;
      + return (PyObject *)(self);
      }

      static int
      -ListSetattr(PyObject *self, char *name, PyObject *val)
      +ListSetattr(ListObject *self, char *name, PyObject *val)
      {
      - ListObject *this = (ListObject *)(self);
      -
      if (val == NULL)
      {
      PyErr_SetString(PyExc_AttributeError,
      @@ -1239,7 +1223,7 @@

      if (strcmp(name, "locked") == 0)
      {
      - if (this->list->lv_lock == VAR_FIXED)
      + if (self->list->lv_lock == VAR_FIXED)
      {
      PyErr_SetString(PyExc_TypeError, _("cannot modify fixed list"));
      return -1;
      @@ -1250,9 +1234,9 @@
      if (istrue == -1)
      return -1;
      else if (istrue)
      - this->list->lv_lock = VAR_LOCKED;
      + self->list->lv_lock = VAR_LOCKED;
      else
      - this->list->lv_lock = 0;
      + self->list->lv_lock = 0;
      }
      return 0;
      }
      @@ -1296,21 +1280,18 @@
      }

      static void
      -FunctionDestructor(PyObject *self)
      +FunctionDestructor(FunctionObject *self)
      {
      - FunctionObject *this = (FunctionObject *) (self);
      -
      - func_unref(this->name);
      - PyMem_Free(this->name);
      + func_unref(self->name);
      + PyMem_Free(self->name);

      DESTRUCTOR_FINISH(self);
      }

      static PyObject *
      -FunctionCall(PyObject *self, PyObject *argsObject, PyObject *kwargs)
      +FunctionCall(FunctionObject *self, PyObject *argsObject, PyObject *kwargs)
      {
      - FunctionObject *this = (FunctionObject *)(self);
      - char_u *name = this->name;
      + char_u *name = self->name;
      typval_T args;
      typval_T selfdicttv;
      typval_T rettv;
      @@ -1415,29 +1396,29 @@
      }

      static void
      -OptionsDestructor(PyObject *self)
      +OptionsDestructor(OptionsObject *self)
      {
      - if (((OptionsObject *)(self))->fromObj)
      - Py_DECREF(((OptionsObject *)(self))->fromObj);
      + if (self->fromObj)
      + Py_DECREF(self->fromObj);
      DESTRUCTOR_FINISH(self);
      }

      static int
      -OptionsTraverse(PyObject *self, visitproc visit, void *arg)
      +OptionsTraverse(OptionsObject *self, visitproc visit, void *arg)
      {
      - Py_VISIT(((OptionsObject *)(self))->fromObj);
      + Py_VISIT(self->fromObj);
      return 0;
      }

      static int
      -OptionsClear(PyObject *self)
      +OptionsClear(OptionsObject *self)
      {
      - Py_CLEAR(((OptionsObject *)(self))->fromObj);
      + Py_CLEAR(self->fromObj);
      return 0;
      }

      static PyObject *
      -OptionsItem(OptionsObject *this, PyObject *keyObject)
      +OptionsItem(OptionsObject *self, PyObject *keyObject)
      {
      char_u *key;
      int flags;
      @@ -1445,13 +1426,13 @@
      char_u *stringval;
      DICTKEY_DECL

      - if (this->Check(this->from))
      + if (self->Check(self->from))
      return NULL;

      DICTKEY_GET_NOTEMPTY(NULL)

      flags = get_option_value_strict(key, &numval, &stringval,
      - this->opt_type, this->from);
      + self->opt_type, self->from);

      DICTKEY_UNREF

      @@ -1532,7 +1513,7 @@
      }

      static int
      -OptionsAssItem(OptionsObject *this, PyObject *keyObject, PyObject *valObject)
      +OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
      {
      char_u *key;
      int flags;
      @@ -1540,13 +1521,13 @@
      int r = 0;
      DICTKEY_DECL

      - if (this->Check(this->from))
      + if (self->Check(self->from))
      return -1;

      DICTKEY_GET_NOTEMPTY(-1)

      flags = get_option_value_strict(key, NULL, NULL,
      - this->opt_type, this->from);
      + self->opt_type, self->from);

      DICTKEY_UNREF

      @@ -1558,7 +1539,7 @@

      if (valObject == NULL)
      {
      - if (this->opt_type == SREQ_GLOBAL)
      + if (self->opt_type == SREQ_GLOBAL)
      {
      PyErr_SetString(PyExc_ValueError,
      _("unable to unset global option"));
      @@ -1572,12 +1553,12 @@
      }
      else
      {
      - unset_global_local_option(key, this->from);
      + unset_global_local_option(key, self->from);
      return 0;
      }
      }

      - opt_flags = (this->opt_type ? OPT_LOCAL : OPT_GLOBAL);
      + opt_flags = (self->opt_type ? OPT_LOCAL : OPT_GLOBAL);

      if (flags & SOPT_BOOL)
      {
      @@ -1585,7 +1566,7 @@
      if (istrue == -1)
      return -1;
      r = set_option_value_for(key, istrue, NULL,
      - opt_flags, this->opt_type, this->from);
      + opt_flags, self->opt_type, self->from);
      }
      else if (flags & SOPT_NUM)
      {
      @@ -1605,7 +1586,7 @@
      }

      r = set_option_value_for(key, val, NULL, opt_flags,
      - this->opt_type, this->from);
      + self->opt_type, self->from);
      }
      else
      {
      @@ -1643,7 +1624,7 @@
      }

      r = set_option_value_for(key, 0, val, opt_flags,
      - this->opt_type, this->from);
      + self->opt_type, self->from);
      vim_free(val);
      }

      @@ -1670,9 +1651,9 @@
      static PyTypeObject TabPageType;

      static int
      -CheckTabPage(TabPageObject *this)
      +CheckTabPage(TabPageObject *self)
      {
      - if (this->tab == INVALID_TABPAGE_VALUE)
      + if (self->tab == INVALID_TABPAGE_VALUE)
      {
      PyErr_SetVim(_("attempt to refer to deleted tab page"));
      return -1;
      @@ -1704,51 +1685,48 @@
      }

      static void
      -TabPageDestructor(PyObject *self)
      +TabPageDestructor(TabPageObject *self)
      {
      - TabPageObject *this = (TabPageObject *)(self);
      -
      - if (this->tab && this->tab != INVALID_TABPAGE_VALUE)
      - TAB_PYTHON_REF(this->tab) = NULL;
      + if (self->tab && self->tab != INVALID_TABPAGE_VALUE)
      + TAB_PYTHON_REF(self->tab) = NULL;

      DESTRUCTOR_FINISH(self);
      }

      static PyObject *
      -TabPageAttr(TabPageObject *this, char *name)
      +TabPageAttr(TabPageObject *self, char *name)
      {
      if (strcmp(name, "windows") == 0)
      - return WinListNew(this);
      + return WinListNew(self);
      else if (strcmp(name, "number") == 0)
      - return PyLong_FromLong((long) get_tab_number(this->tab));
      + return PyLong_FromLong((long) get_tab_number(self->tab));
      else if (strcmp(name, "vars") == 0)
      - return DictionaryNew(this->tab->tp_vars);
      + return DictionaryNew(self->tab->tp_vars);
      else if (strcmp(name, "window") == 0)
      {
      /* For current tab window.c does not bother to set or update tp_curwin
      */
      - if (this->tab == curtab)
      + if (self->tab == curtab)
      return WindowNew(curwin, curtab);
      else
      - return WindowNew(this->tab->tp_curwin, this->tab);
      + return WindowNew(self->tab->tp_curwin, self->tab);
      }
      return NULL;
      }

      static PyObject *
      -TabPageRepr(PyObject *self)
      +TabPageRepr(TabPageObject *self)
      {
      static char repr[100];
      - TabPageObject *this = (TabPageObject *)(self);
      -
      - if (this->tab == INVALID_TABPAGE_VALUE)
      +
      + if (self->tab == INVALID_TABPAGE_VALUE)
      {
      vim_snprintf(repr, 100, _("<tabpage object (deleted) at %p>"), (self));
      return PyString_FromString(repr);
      }
      else
      {
      - int t = get_tab_number(this->tab);
      + int t = get_tab_number(self->tab);

      if (t == 0)
      vim_snprintf(repr, 100, _("<tabpage object (unknown) at %p>"),
      @@ -1818,9 +1796,9 @@
      static PyTypeObject WindowType;

      static int
      -CheckWindow(WindowObject *this)
      +CheckWindow(WindowObject *self)
      {
      - if (this->win == INVALID_WINDOW_VALUE)
      + if (self->win == INVALID_WINDOW_VALUE)
      {
      PyErr_SetVim(_("attempt to refer to deleted window"));
      return -1;
      @@ -1869,14 +1847,12 @@
      }

      static void
      -WindowDestructor(PyObject *self)
      +WindowDestructor(WindowObject *self)
      {
      - WindowObject *this = (WindowObject *)(self);
      -
      - if (this->win && this->win != INVALID_WINDOW_VALUE)
      - WIN_PYTHON_REF(this->win) = NULL;
      -
      - Py_DECREF(((PyObject *)(this->tabObject)));
      + if (self->win && self->win != INVALID_WINDOW_VALUE)
      + WIN_PYTHON_REF(self->win) = NULL;
      +
      + Py_DECREF(((PyObject *)(self->tabObject)));

      DESTRUCTOR_FINISH(self);
      }
      @@ -1899,58 +1875,58 @@
      return firstwin;
      }
      static int
      -WindowTraverse(PyObject *self, visitproc visit, void *arg)
      +WindowTraverse(WindowObject *self, visitproc visit, void *arg)
      {
      - Py_VISIT(((PyObject *)(((WindowObject *)(self))->tabObject)));
      + Py_VISIT(((PyObject *)(self->tabObject)));
      return 0;
      }

      static int
      -WindowClear(PyObject *self)
      +WindowClear(WindowObject *self)
      {
      - Py_CLEAR((((WindowObject *)(self))->tabObject));
      + Py_CLEAR(self->tabObject);
      return 0;
      }

      static PyObject *
      -WindowAttr(WindowObject *this, char *name)
      +WindowAttr(WindowObject *self, char *name)
      {
      if (strcmp(name, "buffer") == 0)
      - return (PyObject *)BufferNew(this->win->w_buffer);
      + return (PyObject *)BufferNew(self->win->w_buffer);
      else if (strcmp(name, "cursor") == 0)
      {
      - pos_T *pos = &this->win->w_cursor;
      + pos_T *pos = &self->win->w_cursor;

      return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col));
      }
      else if (strcmp(name, "height") == 0)
      - return PyLong_FromLong((long)(this->win->w_height));
      + return PyLong_FromLong((long)(self->win->w_height));
      #ifdef FEAT_WINDOWS
      else if (strcmp(name, "row") == 0)
      - return PyLong_FromLong((long)(this->win->w_winrow));
      + return PyLong_FromLong((long)(self->win->w_winrow));
      #endif
      #ifdef FEAT_VERTSPLIT
      else if (strcmp(name, "width") == 0)
      - return PyLong_FromLong((long)(W_WIDTH(this->win)));
      + return PyLong_FromLong((long)(W_WIDTH(self->win)));
      else if (strcmp(name, "col") == 0)
      - return PyLong_FromLong((long)(W_WINCOL(this->win)));
      + return PyLong_FromLong((long)(W_WINCOL(self->win)));
      #endif
      else if (strcmp(name, "vars") == 0)
      - return DictionaryNew(this->win->w_vars);
      + return DictionaryNew(self->win->w_vars);
      else if (strcmp(name, "options") == 0)
      - return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
      - (PyObject *) this);
      + return OptionsNew(SREQ_WIN, self->win, (checkfun) CheckWindow,
      + (PyObject *) self);
      else if (strcmp(name, "number") == 0)
      {
      - if (CheckTabPage(this->tabObject))
      + if (CheckTabPage(self->tabObject))
      return NULL;
      return PyLong_FromLong((long)
      - get_win_number(this->win, get_firstwin(this->tabObject)));
      + get_win_number(self->win, get_firstwin(self->tabObject)));
      }
      else if (strcmp(name, "tabpage") == 0)
      {
      - Py_INCREF(this->tabObject);
      - return (PyObject *)(this->tabObject);
      + Py_INCREF(self->tabObject);
      + return (PyObject *)(self->tabObject);
      }
      else if (strcmp(name,"__members__") == 0)
      return Py_BuildValue("[sssssssss]", "buffer", "cursor", "height",
      @@ -1960,11 +1936,9 @@
      }

      static int
      -WindowSetattr(PyObject *self, char *name, PyObject *val)
      +WindowSetattr(WindowObject *self, char *name, PyObject *val)
      {
      - WindowObject *this = (WindowObject *)(self);
      -
      - if (CheckWindow(this))
      + if (CheckWindow(self))
      return -1;

      if (strcmp(name, "buffer") == 0)
      @@ -1980,7 +1954,7 @@
      if (!PyArg_Parse(val, "(ll)", &lnum, &col))
      return -1;

      - if (lnum <= 0 || lnum > this->win->w_buffer->b_ml.ml_line_count)
      + if (lnum <= 0 || lnum > self->win->w_buffer->b_ml.ml_line_count)
      {
      PyErr_SetVim(_("cursor position outside buffer"));
      return -1;
      @@ -1990,13 +1964,13 @@
      if (VimErrorCheck())
      return -1;

      - this->win->w_cursor.lnum = lnum;
      - this->win->w_cursor.col = col;
      + self->win->w_cursor.lnum = lnum;
      + self->win->w_cursor.col = col;
      #ifdef FEAT_VIRTUALEDIT
      - this->win->w_cursor.coladd = 0;
      + self->win->w_cursor.coladd = 0;
      #endif
      /* When column is out of range silently correct it. */
      - check_cursor_col_win(this->win);
      + check_cursor_col_win(self->win);

      update_screen(VALID);
      return 0;
      @@ -2013,7 +1987,7 @@
      need_mouse_correct = TRUE;
      #endif
      savewin = curwin;
      - curwin = this->win;
      + curwin = self->win;
      win_setheight(height);
      curwin = savewin;

      @@ -2036,7 +2010,7 @@
      need_mouse_correct = TRUE;
      #endif
      savewin = curwin;
      - curwin = this->win;
      + curwin = self->win;
      win_setwidth(width);
      curwin = savewin;

      @@ -2055,19 +2029,18 @@
      }

      static PyObject *
      -WindowRepr(PyObject *self)
      +WindowRepr(WindowObject *self)
      {
      static char repr[100];
      - WindowObject *this = (WindowObject *)(self);
      -
      - if (this->win == INVALID_WINDOW_VALUE)
      +
      + if (self->win == INVALID_WINDOW_VALUE)
      {
      vim_snprintf(repr, 100, _("<window object (deleted) at %p>"), (self));
      return PyString_FromString(repr);
      }
      else
      {
      - int w = get_win_number(this->win, firstwin);
      + int w = get_win_number(self->win, firstwin);

      if (w == 0)
      vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
      @@ -2110,9 +2083,9 @@
      }

      static void
      -WinListDestructor(PyObject *self)
      +WinListDestructor(WinListObject *self)
      {
      - TabPageObject *tabObject = ((WinListObject *)(self))->tabObject;
      + TabPageObject *tabObject = self->tabObject;

      if (tabObject)
      Py_DECREF((PyObject *)(tabObject));
      @@ -2121,12 +2094,12 @@
      }

      static PyInt
      -WinListLength(PyObject *self)
      +WinListLength(WinListObject *self)
      {
      win_T *w;
      PyInt n = 0;

      - if (!(w = get_firstwin(((WinListObject *)(self))->tabObject)))
      + if (!(w = get_firstwin(self->tabObject)))
      return -1;

      while (w != NULL)
      @@ -2139,17 +2112,16 @@
      }

      static PyObject *
      -WinListItem(PyObject *self, PyInt n)
      +WinListItem(WinListObject *self, PyInt n)
      {
      - WinListObject *this = ((WinListObject *)(self));
      win_T *w;

      - if (!(w = get_firstwin(this->tabObject)))
      + if (!(w = get_firstwin(self->tabObject)))
      return NULL;

      for (; w != NULL; w = W_NEXT(w), --n)
      if (n == 0)
      - return WindowNew(w, this->tabObject? this->tabObject->tab: curtab);
      + return WindowNew(w, self->tabObject? self->tabObject->tab: curtab);

      PyErr_SetString(PyExc_IndexError, _("no such window"));
      return NULL;
      @@ -2721,9 +2693,9 @@
      } BufferObject;

      static int
      -CheckBuffer(BufferObject *this)
      +CheckBuffer(BufferObject *self)
      {
      - if (this->buf == INVALID_BUFFER_VALUE)
      + if (self->buf == INVALID_BUFFER_VALUE)
      {
      PyErr_SetVim(_("attempt to refer to deleted buffer"));
      return -1;
      @@ -2922,54 +2894,46 @@
      }

      static void
      -RangeDestructor(PyObject *self)
      +RangeDestructor(RangeObject *self)
      {
      - Py_DECREF(((RangeObject *)(self))->buf);
      + Py_DECREF(self->buf);
      DESTRUCTOR_FINISH(self);
      }

      static PyInt
      -RangeLength(PyObject *self)
      +RangeLength(RangeObject *self)
      {
      /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
      - if (CheckBuffer(((RangeObject *)(self))->buf))
      + if (CheckBuffer(self->buf))
      return -1; /* ??? */

      - return (((RangeObject *)(self))->end - ((RangeObject *)(self))->start + 1);
      + return (self->end - self->start + 1);
      }

      static PyObject *
      -RangeItem(PyObject *self, PyInt n)
      +RangeItem(RangeObject *self, PyInt n)
      {
      - return RBItem(((RangeObject *)(self))->buf, n,
      - ((RangeObject *)(self))->start,
      - ((RangeObject *)(self))->end);
      + return RBItem(self->buf, n, self->start, self->end);
      }

      static PyObject *
      -RangeSlice(PyObject *self, PyInt lo, PyInt hi)
      +RangeSlice(RangeObject *self, PyInt lo, PyInt hi)
      {
      - return RBSlice(((RangeObject *)(self))->buf, lo, hi,
      - ((RangeObject *)(self))->start,
      - ((RangeObject *)(self))->end);
      + return RBSlice(self->buf, lo, hi, self->start, self->end);
      }

      static PyObject *
      -RangeAppend(PyObject *self, PyObject *args)
      +RangeAppend(RangeObject *self, PyObject *args)
      {
      - return RBAppend(((RangeObject *)(self))->buf, args,
      - ((RangeObject *)(self))->start,
      - ((RangeObject *)(self))->end,
      - &((RangeObject *)(self))->end);
      + return RBAppend(self->buf, args, self->start, self->end, &self->end);
      }

      static PyObject *
      -RangeRepr(PyObject *self)
      +RangeRepr(RangeObject *self)
      {
      static char repr[100];
      - RangeObject *this = (RangeObject *)(self);
      -
      - if (this->buf->buf == INVALID_BUFFER_VALUE)
      +
      + if (self->buf->buf == INVALID_BUFFER_VALUE)
      {
      vim_snprintf(repr, 100, "<range object (for deleted buffer) at %p>",
      (self));
      @@ -2977,7 +2941,7 @@
      }
      else
      {
      - char *name = (char *)this->buf->buf->b_fname;
      + char *name = (char *)self->buf->buf->b_fname;
      int len;

      if (name == NULL)
      @@ -2989,16 +2953,16 @@

      vim_snprintf(repr, 100, "<range %s%s (%d:%d)>",
      len > 45 ? "..." : "", name,
      - this->start, this->end);
      + self->start, self->end);

      return PyString_FromString(repr);
      }
      }

      static struct PyMethodDef RangeMethods[] = {
      - /* name, function, calling, documentation */
      - {"append", RangeAppend, 1, "Append data to the Vim range" },
      - { NULL, NULL, 0, NULL }
      + /* name, function, calling, documentation */
      + {"append", (PyCFunction)RangeAppend, 1, "Append data to the Vim range" },
      + { NULL, NULL, 0, NULL }
      };

      static PyTypeObject BufferType;
      @@ -3045,50 +3009,48 @@
      }

      static void
      -BufferDestructor(PyObject *self)
      +BufferDestructor(BufferObject *self)
      {
      - BufferObject *this = (BufferObject *)(self);
      -
      - if (this->buf && this->buf != INVALID_BUFFER_VALUE)
      - BUF_PYTHON_REF(this->buf) = NULL;
      + if (self->buf && self->buf != INVALID_BUFFER_VALUE)
      + BUF_PYTHON_REF(self->buf) = NULL;

      DESTRUCTOR_FINISH(self);
      }

      static PyInt
      -BufferLength(PyObject *self)
      +BufferLength(BufferObject *self)
      {
      /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
      - if (CheckBuffer((BufferObject *)(self)))
      + if (CheckBuffer(self))
      return -1; /* ??? */

      - return (PyInt)(((BufferObject *)(self))->buf->b_ml.ml_line_count);
      + return (PyInt)(self->buf->b_ml.ml_line_count);
      }

      static PyObject *
      -BufferItem(PyObject *self, PyInt n)
      +BufferItem(BufferObject *self, PyInt n)
      {
      - return RBItem((BufferObject *)(self), n, 1, -1);
      + return RBItem(self, n, 1, -1);
      }

      static PyObject *
      -BufferSlice(PyObject *self, PyInt lo, PyInt hi)
      +BufferSlice(BufferObject *self, PyInt lo, PyInt hi)
      {
      - return RBSlice((BufferObject *)(self), lo, hi, 1, -1);
      + return RBSlice(self, lo, hi, 1, -1);
      }

      static PyObject *
      -BufferAttr(BufferObject *this, char *name)
      +BufferAttr(BufferObject *self, char *name)
      {
      if (strcmp(name, "name") == 0)
      - return Py_BuildValue("s", this->buf->b_ffname);
      + return Py_BuildValue("s", self->buf->b_ffname);
      else if (strcmp(name, "number") == 0)
      - return Py_BuildValue(Py_ssize_t_fmt, this->buf->b_fnum);
      + return Py_BuildValue(Py_ssize_t_fmt, self->buf->b_fnum);
      else if (strcmp(name, "vars") == 0)
      - return DictionaryNew(this->buf->b_vars);
      + return DictionaryNew(self->buf->b_vars);
      else if (strcmp(name, "options") == 0)
      - return OptionsNew(SREQ_BUF, this->buf, (checkfun) CheckBuffer,
      - (PyObject *) this);
      + return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
      + (PyObject *) self);
      else if (strcmp(name,"__members__") == 0)
      return Py_BuildValue("[ssss]", "name", "number", "vars", "options");
      else
      @@ -3096,27 +3058,27 @@
      }

      static PyObject *
      -BufferAppend(PyObject *self, PyObject *args)
      +BufferAppend(BufferObject *self, PyObject *args)
      {
      - return RBAppend((BufferObject *)(self), args, 1, -1, NULL);
      + return RBAppend(self, args, 1, -1, NULL);
      }

      static PyObject *
      -BufferMark(PyObject *self, PyObject *args)
      +BufferMark(BufferObject *self, PyObject *args)
      {
      pos_T *posp;
      char *pmark;
      char mark;
      buf_T *savebuf;

      - if (CheckBuffer((BufferObject *)(self)))
      + if (CheckBuffer(self))
      return NULL;

      if (!PyArg_ParseTuple(args, "s", &pmark))
      return NULL;
      mark = *pmark;

      - switch_buffer(&savebuf, ((BufferObject *)(self))->buf);
      + switch_buffer(&savebuf, self->buf);
      posp = getmark(mark, FALSE);
      restore_buffer(savebuf);

      @@ -3141,34 +3103,33 @@
      }

      static PyObject *
      -BufferRange(PyObject *self, PyObject *args)
      +BufferRange(BufferObject *self, PyObject *args)
      {
      PyInt start;
      PyInt end;

      - if (CheckBuffer((BufferObject *)(self)))
      + if (CheckBuffer(self))
      return NULL;

      if (!PyArg_ParseTuple(args, "nn", &start, &end))
      return NULL;

      - return RangeNew(((BufferObject *)(self))->buf, start, end);
      + return RangeNew(self->buf, start, end);
      }

      static PyObject *
      -BufferRepr(PyObject *self)
      +BufferRepr(BufferObject *self)
      {
      static char repr[100];
      - BufferObject *this = (BufferObject *)(self);
      -
      - if (this->buf == INVALID_BUFFER_VALUE)
      +
      + if (self->buf == INVALID_BUFFER_VALUE)
      {
      vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self));
      return PyString_FromString(repr);
      }
      else
      {
      - char *name = (char *)this->buf->b_fname;
      + char *name = (char *)self->buf->b_fname;
      PyInt len;

      if (name == NULL)
      @@ -3185,14 +3146,14 @@
      }

      static struct PyMethodDef BufferMethods[] = {
      - /* name, function, calling, documentation */
      - {"append", BufferAppend, 1, "Append data to Vim buffer" },
      - {"mark", BufferMark, 1, "Return (row,col) representing position of named mark" },
      - {"range", BufferRange, 1, "Return a range object which represents the part of the given buffer between line numbers s and e" },
      + /* name, function, calling, documentation */
      + {"append", (PyCFunction)BufferAppend, 1, "Append data to Vim buffer" },
      + {"mark", (PyCFunction)BufferMark, 1, "Return (row,col) representing position of named mark" },
      + {"range", (PyCFunction)BufferRange, 1, "Return a range object which represents the part of the given buffer between line numbers s and e" },
      #if PY_VERSION_HEX >= 0x03000000
      - {"__dir__", BufferDir, 4, "List its attributes" },
      + {"__dir__", (PyCFunction)BufferDir, 4, "List its attributes" },
      #endif
      - { NULL, NULL, 0, NULL }
      + { NULL, NULL, 0, NULL }
      };

      /*
      @@ -4021,14 +3982,14 @@
      OutputType.tp_doc = "vim message object";
      OutputType.tp_methods = OutputMethods;
      #if PY_MAJOR_VERSION >= 3
      - OutputType.tp_getattro = OutputGetattro;
      - OutputType.tp_setattro = OutputSetattro;
      + OutputType.tp_getattro = (getattrofunc)OutputGetattro;
      + OutputType.tp_setattro = (setattrofunc)OutputSetattro;
      OutputType.tp_alloc = call_PyType_GenericAlloc;
      OutputType.tp_new = call_PyType_GenericNew;
      OutputType.tp_free = call_PyObject_Free;
      #else
      - OutputType.tp_getattr = OutputGetattr;
      - OutputType.tp_setattr = OutputSetattr;
      + OutputType.tp_getattr = (getattrfunc)OutputGetattr;
      + OutputType.tp_setattr = (setattrfunc)OutputSetattr;
      #endif

      vim_memset(&IterType, 0, sizeof(IterType));
      @@ -4036,67 +3997,67 @@
      IterType.tp_basicsize = sizeof(IterObject);
      IterType.tp_flags = Py_TPFLAGS_DEFAULT;
      IterType.tp_doc = "generic iterator object";
      - IterType.tp_iter = IterIter;
      - IterType.tp_iternext = IterNext;
      - IterType.tp_dealloc = IterDestructor;
      - IterType.tp_traverse = IterTraverse;
      - IterType.tp_clear = IterClear;
      + IterType.tp_iter = (getiterfunc)IterIter;
      + IterType.tp_iternext = (iternextfunc)IterNext;
      + IterType.tp_dealloc = (destructor)IterDestructor;
      + IterType.tp_traverse = (traverseproc)IterTraverse;
      + IterType.tp_clear = (inquiry)IterClear;

      vim_memset(&BufferType, 0, sizeof(BufferType));
      BufferType.tp_name = "vim.buffer";
      BufferType.tp_basicsize = sizeof(BufferType);
      - BufferType.tp_dealloc = BufferDestructor;
      - BufferType.tp_repr = BufferRepr;
      + BufferType.tp_dealloc = (destructor)BufferDestructor;
      + BufferType.tp_repr = (reprfunc)BufferRepr;
      BufferType.tp_as_sequence = &BufferAsSeq;
      BufferType.tp_as_mapping = &BufferAsMapping;
      BufferType.tp_flags = Py_TPFLAGS_DEFAULT;
      BufferType.tp_doc = "vim buffer object";
      BufferType.tp_methods = BufferMethods;
      #if PY_MAJOR_VERSION >= 3
      - BufferType.tp_getattro = BufferGetattro;
      + BufferType.tp_getattro = (getattrofunc)BufferGetattro;
      BufferType.tp_alloc = call_PyType_GenericAlloc;
      BufferType.tp_new = call_PyType_GenericNew;
      BufferType.tp_free = call_PyObject_Free;
      #else
      - BufferType.tp_getattr = BufferGetattr;
      + BufferType.tp_getattr = (getattrfunc)BufferGetattr;
      #endif

      vim_memset(&WindowType, 0, sizeof(WindowType));
      WindowType.tp_name = "vim.window";
      WindowType.tp_basicsize = sizeof(WindowObject);
      - WindowType.tp_dealloc = WindowDestructor;
      - WindowType.tp_repr = WindowRepr;
      + WindowType.tp_dealloc = (destructor)WindowDestructor;
      + WindowType.tp_repr = (reprfunc)WindowRepr;
      WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
      WindowType.tp_doc = "vim Window object";
      WindowType.tp_methods = WindowMethods;
      - WindowType.tp_traverse = WindowTraverse;
      - WindowType.tp_clear = WindowClear;
      + WindowType.tp_traverse = (traverseproc)WindowTraverse;
      + WindowType.tp_clear = (inquiry)WindowClear;
      #if PY_MAJOR_VERSION >= 3
      - WindowType.tp_getattro = WindowGetattro;
      - WindowType.tp_setattro = WindowSetattro;
      + WindowType.tp_getattro = (getattrofunc)WindowGetattro;
      + WindowType.tp_setattro = (setattrofunc)WindowSetattro;
      WindowType.tp_alloc = call_PyType_GenericAlloc;
      WindowType.tp_new = call_PyType_GenericNew;
      WindowType.tp_free = call_PyObject_Free;
      #else
      - WindowType.tp_getattr = WindowGetattr;
      - WindowType.tp_setattr = WindowSetattr;
      + WindowType.tp_getattr = (getattrfunc)WindowGetattr;
      + WindowType.tp_setattr = (setattrfunc)WindowSetattr;
      #endif

      vim_memset(&TabPageType, 0, sizeof(TabPageType));
      TabPageType.tp_name = "vim.tabpage";
      TabPageType.tp_basicsize = sizeof(TabPageObject);
      - TabPageType.tp_dealloc = TabPageDestructor;
      - TabPageType.tp_repr = TabPageRepr;
      + TabPageType.tp_dealloc = (destructor)TabPageDestructor;
      + TabPageType.tp_repr = (reprfunc)TabPageRepr;
      TabPageType.tp_flags = Py_TPFLAGS_DEFAULT;
      TabPageType.tp_doc = "vim tab page object";
      TabPageType.tp_methods = TabPageMethods;
      #if PY_MAJOR_VERSION >= 3
      - TabPageType.tp_getattro = TabPageGetattro;
      + TabPageType.tp_getattro = (getattrofunc)TabPageGetattro;
      TabPageType.tp_alloc = call_PyType_GenericAlloc;
      TabPageType.tp_new = call_PyType_GenericNew;
      TabPageType.tp_free = call_PyObject_Free;
      #else
      - TabPageType.tp_getattr = TabPageGetattr;
      + TabPageType.tp_getattr = (getattrfunc)TabPageGetattr;
      #endif

      vim_memset(&BufMapType, 0, sizeof(BufMapType));
      @@ -4113,7 +4074,7 @@
      WinListType.tp_as_sequence = &WinListAsSeq;
      WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
      WinListType.tp_doc = "vim window list";
      - WinListType.tp_dealloc = WinListDestructor;
      + WinListType.tp_dealloc = (destructor)WinListDestructor;

      vim_memset(&TabListType, 0, sizeof(TabListType));
      TabListType.tp_name = "vim.tabpagelist";
      @@ -4125,20 +4086,20 @@
      vim_memset(&RangeType, 0, sizeof(RangeType));
      RangeType.tp_name = "vim.range";
      RangeType.tp_basicsize = sizeof(RangeObject);
      - RangeType.tp_dealloc = RangeDestructor;
      - RangeType.tp_repr = RangeRepr;
      + RangeType.tp_dealloc = (destructor)RangeDestructor;
      + RangeType.tp_repr = (reprfunc)RangeRepr;
      RangeType.tp_as_sequence = &RangeAsSeq;
      RangeType.tp_as_mapping = &RangeAsMapping;
      RangeType.tp_flags = Py_TPFLAGS_DEFAULT;
      RangeType.tp_doc = "vim Range object";
      RangeType.tp_methods = RangeMethods;
      #if PY_MAJOR_VERSION >= 3
      - RangeType.tp_getattro = RangeGetattro;
      + RangeType.tp_getattro = (getattrofunc)RangeGetattro;
      RangeType.tp_alloc = call_PyType_GenericAlloc;
      RangeType.tp_new = call_PyType_GenericNew;
      RangeType.tp_free = call_PyObject_Free;
      #else
      - RangeType.tp_getattr = RangeGetattr;
      + RangeType.tp_getattr = (getattrfunc)RangeGetattr;
      #endif

      vim_memset(&CurrentType, 0, sizeof(CurrentType));
      @@ -4147,59 +4108,59 @@
      CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
      CurrentType.tp_doc = "vim current object";
      #if PY_MAJOR_VERSION >= 3
      - CurrentType.tp_getattro = CurrentGetattro;
      - CurrentType.tp_setattro = CurrentSetattro;
      + CurrentType.tp_getattro = (getattrofunc)CurrentGetattro;
      + CurrentType.tp_setattro = (setattrofunc)CurrentSetattro;
      #else
      - CurrentType.tp_getattr = CurrentGetattr;
      - CurrentType.tp_setattr = CurrentSetattr;
      + CurrentType.tp_getattr = (getattrfunc)CurrentGetattr;
      + CurrentType.tp_setattr = (setattrfunc)CurrentSetattr;
      #endif

      vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
      DictionaryType.tp_name = "vim.dictionary";
      DictionaryType.tp_basicsize = sizeof(DictionaryObject);
      - DictionaryType.tp_dealloc = DictionaryDestructor;
      + DictionaryType.tp_dealloc = (destructor)DictionaryDestructor;
      DictionaryType.tp_as_mapping = &DictionaryAsMapping;
      DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT;
      DictionaryType.tp_doc = "dictionary pushing modifications to vim structure";
      DictionaryType.tp_methods = DictionaryMethods;
      #if PY_MAJOR_VERSION >= 3
      - DictionaryType.tp_getattro = DictionaryGetattro;
      - DictionaryType.tp_setattro = DictionarySetattro;
      + DictionaryType.tp_getattro = (getattrofunc)DictionaryGetattro;
      + DictionaryType.tp_setattro = (setattrofunc)DictionarySetattro;
      #else
      - DictionaryType.tp_getattr = DictionaryGetattr;
      - DictionaryType.tp_setattr = DictionarySetattr;
      + DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr;
      + DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr;
      #endif

      vim_memset(&ListType, 0, sizeof(ListType));
      ListType.tp_name = "vim.list";
      - ListType.tp_dealloc = ListDestructor;
      + ListType.tp_dealloc = (destructor)ListDestructor;
      ListType.tp_basicsize = sizeof(ListObject);
      ListType.tp_as_sequence = &ListAsSeq;
      ListType.tp_as_mapping = &ListAsMapping;
      ListType.tp_flags = Py_TPFLAGS_DEFAULT;
      ListType.tp_doc = "list pushing modifications to vim structure";
      ListType.tp_methods = ListMethods;
      - ListType.tp_iter = ListIter;
      + ListType.tp_iter = (getiterfunc)ListIter;
      #if PY_MAJOR_VERSION >= 3
      - ListType.tp_getattro = ListGetattro;
      - ListType.tp_setattro = ListSetattro;
      + ListType.tp_getattro = (getattrofunc)ListGetattro;
      + ListType.tp_setattro = (setattrofunc)ListSetattro;
      #else
      - ListType.tp_getattr = ListGetattr;
      - ListType.tp_setattr = ListSetattr;
      + ListType.tp_getattr = (getattrfunc)ListGetattr;
      + ListType.tp_setattr = (setattrfunc)ListSetattr;
      #endif

      vim_memset(&FunctionType, 0, sizeof(FunctionType));
      FunctionType.tp_name = "vim.function";
      FunctionType.tp_basicsize = sizeof(FunctionObject);
      - FunctionType.tp_dealloc = FunctionDestructor;
      - FunctionType.tp_call = FunctionCall;
      + FunctionType.tp_dealloc = (destructor)FunctionDestructor;
      + FunctionType.tp_call = (ternaryfunc)FunctionCall;
      FunctionType.tp_flags = Py_TPFLAGS_DEFAULT;
      FunctionType.tp_doc = "object that calls vim function";
      FunctionType.tp_methods = FunctionMethods;
      #if PY_MAJOR_VERSION >= 3
      - FunctionType.tp_getattro = FunctionGetattro;
      + FunctionType.tp_getattro = (getattrofunc)FunctionGetattro;
      #else
      - FunctionType.tp_getattr = FunctionGetattr;
      + FunctionType.tp_getattr = (getattrfunc)FunctionGetattr;
      #endif

      vim_memset(&OptionsType, 0, sizeof(OptionsType));
      @@ -4208,9 +4169,9 @@
      OptionsType.tp_flags = Py_TPFLAGS_DEFAULT;
      OptionsType.tp_doc = "object for manipulating options";
      OptionsType.tp_as_mapping = &OptionsAsMapping;
      - OptionsType.tp_dealloc = OptionsDestructor;
      - OptionsType.tp_traverse = OptionsTraverse;
      - OptionsType.tp_clear = OptionsClear;
      + OptionsType.tp_dealloc = (destructor)OptionsDestructor;
      + OptionsType.tp_traverse = (traverseproc)OptionsTraverse;
      + OptionsType.tp_clear = (inquiry)OptionsClear;

      #if PY_MAJOR_VERSION >= 3
      vim_memset(&vimmodule, 0, sizeof(vimmodule));
      diff -r a682902e547d -r 97bbb36fe75d src/if_python.c
      --- a/src/if_python.c Sat May 18 01:47:01 2013 +0400
      +++ b/src/if_python.c Sat May 18 12:35:12 2013 +0400
      @@ -56,8 +56,6 @@
      # define PY_SSIZE_T_CLEAN
      #endif

      -static void init_structs(void);
      -
      #define PyBytes_FromString PyString_FromString
      #define PyBytes_Check PyString_Check

      @@ -659,16 +657,9 @@
      * Internal function prototypes.
      */

      -static void PythonIO_Flush(void);
      static int PythonIO_Init(void);
      static int PythonMod_Init(void);

      -/* Utility functions for the vim/python interface
      - * ----------------------------------------------
      - */
      -
      -static int SetBufferLineList(buf_T *, PyInt, PyInt, PyObject *, PyInt *);
      -

      /******************************************************
      * 1. Python interpreter main program.
      @@ -1017,9 +1008,6 @@
      * 3. Implementation of the Vim module for Python
      */

      -static PyObject *ConvertToPyObject(typval_T *);
      -static int ConvertFromPyObject(PyObject *, typval_T *);
      -
      /* Window type - Implementation functions
      * --------------------------------------
      */
      diff -r a682902e547d -r 97bbb36fe75d src/if_python3.c
      --- a/src/if_python3.c Sat May 18 01:47:01 2013 +0400
      +++ b/src/if_python3.c Sat May 18 12:35:12 2013 +0400
      @@ -68,8 +68,6 @@
      # define PY_SSIZE_T_CLEAN
      #endif

      -static void init_structs(void);
      -
      /* The "surrogateescape" error handler is new in Python 3.1 */
      #if PY_VERSION_HEX >= 0x030100f0
      # define CODEC_ERROR_HANDLER "surrogateescape"
      @@ -610,8 +608,6 @@
      }
      #endif /* DYNAMIC_PYTHON3 */

      -static PyObject *BufferDir(PyObject *, PyObject *);
      -
      static int py3initialised = 0;

      #define PYINITIALISED py3initialised
      @@ -670,6 +666,7 @@
      return PyType_GenericAlloc(type,nitems);
      }

      +static PyObject *BufferDir(PyObject *, PyObject *);
      static PyObject *OutputGetattro(PyObject *, PyObject *);
      static int OutputSetattro(PyObject *, PyObject *, PyObject *);
      static PyObject *BufferGetattro(PyObject *, PyObject *);
      @@ -1008,7 +1005,7 @@
      {
      GET_ATTR_STRING(name, nameobj);

      - return OutputSetattr(self, name, val);
      + return OutputSetattr((OutputObject *)(self), name, val);
      }

      /***************/
      @@ -1036,12 +1033,9 @@

      #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType)

      -static Py_ssize_t BufferLength(PyObject *);
      -static PyObject *BufferItem(PyObject *, Py_ssize_t);
      static PyObject* BufferSubscript(PyObject *self, PyObject *idx);
      static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val);

      -
      /* Line range type - Implementation functions
      * --------------------------------------
      */
      @@ -1111,7 +1105,7 @@
      if (PyLong_Check(idx))
      {
      long _idx = PyLong_AsLong(idx);
      - return BufferItem(self,_idx);
      + return BufferItem((BufferObject *)(self), _idx);
      } else if (PySlice_Check(idx))
      {
      Py_ssize_t start, stop, step, slicelen;
      @@ -1126,7 +1120,7 @@
      {
      return NULL;
      }
      - return BufferSlice(self, start, stop);
      + return BufferSlice((BufferObject *)(self), start, stop);
      }
      else
      {
      @@ -1230,7 +1224,7 @@
      if (PyLong_Check(idx))
      {
      long _idx = PyLong_AsLong(idx);
      - return RangeItem(self,_idx);
      + return RangeItem((RangeObject *)(self), _idx);
      } else if (PySlice_Check(idx))
      {
      Py_ssize_t start, stop, step, slicelen;
      @@ -1242,7 +1236,7 @@
      {
      return NULL;
      }
      - return RangeSlice(self, start, stop);
      + return RangeSlice((RangeObject *)(self), start, stop);
      }
      else
      {
      @@ -1323,7 +1317,7 @@
      {
      GET_ATTR_STRING(name, nameobj);

      - return WindowSetattr(self, name, val);
      + return WindowSetattr((WindowObject *)(self), name, val);
      }

      /* Tab page list object - Definitions
      @@ -1377,8 +1371,6 @@
      /* Dictionary object - Definitions
      */

      -static PyInt DictionaryLength(PyObject *);
      -
      static PyObject *
      DictionaryGetattro(PyObject *self, PyObject *nameobj)
      {
      @@ -1398,15 +1390,12 @@
      DictionarySetattro(PyObject *self, PyObject *nameobj, PyObject *val)
      {
      GET_ATTR_STRING(name, nameobj);
      - return DictionarySetattr(self, name, val);
      + return DictionarySetattr((DictionaryObject *)(self), name, val);
      }

      /* List object - Definitions
      */

      -static PyInt ListLength(PyObject *);
      -static PyObject *ListItem(PyObject *, Py_ssize_t);
      -
      static PySequenceMethods ListAsSeq = {
      (lenfunc) ListLength, /* sq_length, len(x) */
      (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
      @@ -1430,21 +1419,21 @@
      };

      static PyObject *
      -ListSubscript(PyObject *self, PyObject* idxObject)
      +ListSubscript(PyObject *self, PyObject* idx)
      {
      - if (PyLong_Check(idxObject))
      + if (PyLong_Check(idx))
      {
      - long idx = PyLong_AsLong(idxObject);
      - return ListItem(self, idx);
      + long _idx = PyLong_AsLong(idx);
      + return ListItem((ListObject *)(self), _idx);
      }
      - else if (PySlice_Check(idxObject))
      + else if (PySlice_Check(idx))
      {
      Py_ssize_t start, stop, step, slicelen;

      - if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
      - &step, &slicelen) < 0)
      + if (PySlice_GetIndicesEx(idx, ListLength((ListObject *)(self)),
      + &start, &stop, &step, &slicelen) < 0)
      return NULL;
      - return ListSlice(self, start, stop);
      + return ListSlice((ListObject *)(self), start, stop);
      }
      else
      {
      @@ -1454,21 +1443,21 @@
      }

      static Py_ssize_t
      -ListAsSubscript(PyObject *self, PyObject *idxObject, PyObject *obj)
      +ListAsSubscript(PyObject *self, PyObject *idx, PyObject *obj)
      {
      - if (PyLong_Check(idxObject))
      + if (PyLong_Check(idx))
      {
      - long idx = PyLong_AsLong(idxObject);
      - return ListAssItem(self, idx, obj);
      + long _idx = PyLong_AsLong(idx);
      + return ListAssItem((ListObject *)(self), _idx, obj);
      }
      - else if (PySlice_Check(idxObject))
      + else if (PySlice_Check(idx))
      {
      Py_ssize_t start, stop, step, slicelen;

      - if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
      - &step, &slicelen) < 0)
      + if (PySlice_GetIndicesEx(idx, ListLength((ListObject *)(self)),
      + &start, &stop, &step, &slicelen) < 0)
      return -1;
      - return ListAssSlice(self, start, stop, obj);
      + return ListAssSlice((ListObject *)(self), start, stop, obj);
      }
      else
      {
      @@ -1492,7 +1481,7 @@
      ListSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
      {
      GET_ATTR_STRING(name, nameobj);
      - return ListSetattr(self, name, val);
      + return ListSetattr((ListObject *)(self), name, val);
      }

      /* Function object - Definitions
      # HG changeset patch
      # User ZyX <kp-pav@...>
      # Date 1368885495 -14400
      # Branch python-extended-2
      # Node ID 2a100913fd7195b95cead858e84dcffe138ac765
      # Parent 97bbb36fe75d0842ada71d0e62eca7ca411072a6
      Refactoring: get rid of magic constants

      ml_flags should not use raw numbers as arguments, there are standard descriptive
      macros.

      diff -r 97bbb36fe75d -r 2a100913fd71 src/if_py_both.h
      --- a/src/if_py_both.h Sat May 18 12:35:12 2013 +0400
      +++ b/src/if_py_both.h Sat May 18 17:58:15 2013 +0400
      @@ -220,7 +220,7 @@
      }

      static PyObject *
      -OutputFlush(PyObject *self UNUSED, PyObject *args UNUSED)
      +OutputFlush(PyObject *self UNUSED)
      {
      /* do nothing */
      Py_INCREF(Py_None);
      @@ -230,11 +230,11 @@
      /***************/

      static struct PyMethodDef OutputMethods[] = {
      - /* name, function, calling, doc */
      - {"write", (PyCFunction)OutputWrite, 1, ""},
      - {"writelines", (PyCFunction)OutputWritelines, 1, ""},
      - {"flush", (PyCFunction)OutputFlush, 1, ""},
      - { NULL, NULL, 0, NULL}
      + /* name, function, calling, doc */
      + {"write", (PyCFunction)OutputWrite, METH_VARARGS, ""},
      + {"writelines", (PyCFunction)OutputWritelines, METH_VARARGS, ""},
      + {"flush", (PyCFunction)OutputFlush, METH_NOARGS, ""},
      + { NULL, NULL, 0, NULL}
      };

      static OutputObject Output =
      @@ -533,12 +533,12 @@
      */

      static struct PyMethodDef VimMethods[] = {
      - /* name, function, calling, documentation */
      - {"command", VimCommand, 1, "Execute a Vim ex-mode command" },
      - {"eval", VimEval, 1, "Evaluate an expression using Vim evaluator" },
      - {"bindeval", VimEvalPy, 1, "Like eval(), but returns objects attached to vim ones"},
      - {"strwidth", VimStrwidth, 1, "Screen string width, counts <Tab> as having width 1"},
      - { NULL, NULL, 0, NULL }
      + /* name, function, calling, documentation */
      + {"command", VimCommand, METH_VARARGS, "Execute a Vim ex-mode command" },
      + {"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" },
      + {"bindeval", VimEvalPy, METH_VARARGS, "Like eval(), but returns objects attached to vim ones"},
      + {"strwidth", VimStrwidth, METH_VARARGS, "Screen string width, counts <Tab> as having width 1"},
      + { NULL, NULL, 0, NULL }
      };

      /*
      @@ -868,8 +868,8 @@
      };

      static struct PyMethodDef DictionaryMethods[] = {
      - {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
      - { NULL, NULL, 0, NULL }
      + {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
      + { NULL, NULL, 0, NULL }
      };

      static PyTypeObject ListType;
      @@ -1248,8 +1248,8 @@
      }

      static struct PyMethodDef ListMethods[] = {
      - {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
      - { NULL, NULL, 0, NULL }
      + {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
      + { NULL, NULL, 0, NULL }
      };

      typedef struct
      @@ -1349,8 +1349,8 @@
      }

      static struct PyMethodDef FunctionMethods[] = {
      - {"__call__", (PyCFunction)FunctionCall, METH_VARARGS|METH_KEYWORDS, ""},
      - { NULL, NULL, 0, NULL }
      + {"__call__", (PyCFunction)FunctionCall, METH_VARARGS|METH_KEYWORDS, ""},
      + { NULL, NULL, 0, NULL}
      };

      /*
      @@ -2960,9 +2960,9 @@
      }

      static struct PyMethodDef RangeMethods[] = {
      - /* name, function, calling, documentation */
      - {"append", (PyCFunction)RangeAppend, 1, "Append data to the Vim range" },
      - { NULL, NULL, 0, NULL }
      + /* name, function, calling, documentation */
      + {"append", (PyCFunction)RangeAppend, METH_VARARGS, "Append data to the Vim range" },
      + { NULL, NULL, 0, NULL }
      };

      static PyTypeObject BufferType;
      @@ -3146,14 +3146,14 @@
      }

      static struct PyMethodDef BufferMethods[] = {
      - /* name, function, calling, documentation */
      - {"append", (PyCFunction)BufferAppend, 1, "Append data to Vim buffer" },
      - {"mark", (PyCFunction)BufferMark, 1, "Return (row,col) representing position of named mark" },
      - {"range", (PyCFunction)BufferRange, 1, "Return a range object which represents the part of the given buffer between line numbers s and e" },
      + /* name, function, calling, documentation */
      + {"append", (PyCFunction)BufferAppend, METH_VARARGS, "Append data to Vim buffer" },
      + {"mark", (PyCFunction)BufferMark, METH_VARARGS, "Return (row,col) representing position of named mark" },
      + {"range", (PyCFunction)BufferRange, METH_VARARGS, "Return a range object which represents the part of the given buffer between line numbers s and e" },
      #if PY_VERSION_HEX >= 0x03000000
      - {"__dir__", (PyCFunction)BufferDir, 4, "List its attributes" },
      + {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, "List buffer attributes" },
      #endif
      - { NULL, NULL, 0, NULL }
      + { NULL, NULL, 0, NULL }
      };

      /*
      diff -r 97bbb36fe75d -r 2a100913fd71 src/if_python3.c
      --- a/src/if_python3.c Sat May 18 12:35:12 2013 +0400
      +++ b/src/if_python3.c Sat May 18 17:58:15 2013 +0400
      @@ -666,7 +666,7 @@
      return PyType_GenericAlloc(type,nitems);
      }

      -static PyObject *BufferDir(PyObject *, PyObject *);
      +static PyObject *BufferDir(PyObject *);
      static PyObject *OutputGetattro(PyObject *, PyObject *);
      static int OutputSetattro(PyObject *, PyObject *, PyObject *);
      static PyObject *BufferGetattro(PyObject *, PyObject *);
      @@ -1091,7 +1091,7 @@
      }

      static PyObject *
      -BufferDir(PyObject *self UNUSED, PyObject *args UNUSED)
      +BufferDir(PyObject *self UNUSED)
      {
      return Py_BuildValue("[sssss]", "name", "number",
      "append", "mark", "range");

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Bram Moolenaar
      ... I like it. -- BEDEVERE: Look! It s the old man from scene 24 - what s he Doing here? ARTHUR: He is the keeper of the Bridge. He asks each traveler five
      Message 2 of 7 , May 18, 2013
      • 0 Attachment
        ZyX wrote:

        > # HG changeset patch
        > # User ZyX <kp-pav@...>
        > # Date 1368866112 -14400
        > # Branch python-extended-2
        > # Node ID 97bbb36fe75d0842ada71d0e62eca7ca411072a6
        > # Parent a682902e547d02c97e816ec52a34e257582662d7
        > Refactoring: replace a big bunch of type casts with proper argument types
        >
        > Implies type casts when initializing structures.

        I like it.


        --
        BEDEVERE: Look! It's the old man from scene 24 - what's he Doing here?
        ARTHUR: He is the keeper of the Bridge. He asks each traveler five
        questions ...
        GALAHAD: Three questions.
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ an exciting new programming language -- http://www.Zimbu.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • ZyX
        ... I meant “magic numbers”. -- -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying
        Message 3 of 7 , May 18, 2013
        • 0 Attachment
          > [PATCH] Refactoring: less type casts and less magic variables

          I meant “magic numbers”.

          --
          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • ZyX
          Another refactoring: now moved most module initialization to if_py_both.h. # HG changeset patch # User ZyX # Date 1368960476 -14400 # Branch
          Message 4 of 7 , May 19, 2013
          • 0 Attachment
            Another refactoring: now moved most module initialization to if_py_both.h.

            # HG changeset patch
            # User ZyX <kp-pav@...>
            # Date 1368960476 -14400
            # Branch python-extended-2
            # Node ID 5c5d22791c61dc77a3685fe3b5e86c377330ea79
            # Parent 2a100913fd7195b95cead858e84dcffe138ac765
            Refactoring: move PyType_Ready calls and vim module population to if_py_both.h

            diff -r 2a100913fd71 -r 5c5d22791c61 src/if_py_both.h
            --- a/src/if_py_both.h Sat May 18 17:58:15 2013 +0400
            +++ b/src/if_py_both.h Sun May 19 14:47:56 2013 +0400
            @@ -4181,3 +4181,108 @@
            vimmodule.m_methods = VimMethods;
            #endif
            }
            +
            +#define PYTYPE_READY(type) \
            + if (PyType_Ready(&type)) \
            + return -1;
            +
            + static int
            +init_types()
            +{
            + PYTYPE_READY(IterType);
            + PYTYPE_READY(BufferType);
            + PYTYPE_READY(RangeType);
            + PYTYPE_READY(WindowType);
            + PYTYPE_READY(TabPageType);
            + PYTYPE_READY(BufMapType);
            + PYTYPE_READY(WinListType);
            + PYTYPE_READY(TabListType);
            + PYTYPE_READY(CurrentType);
            + PYTYPE_READY(DictionaryType);
            + PYTYPE_READY(ListType);
            + PYTYPE_READY(FunctionType);
            + PYTYPE_READY(OptionsType);
            + PYTYPE_READY(OutputType);
            + return 0;
            +}
            +
            +static BufMapObject TheBufferMap =
            +{
            + PyObject_HEAD_INIT(&BufMapType)
            +};
            +
            +static WinListObject TheWindowList =
            +{
            + PyObject_HEAD_INIT(&WinListType)
            + NULL
            +};
            +
            +static CurrentObject TheCurrent =
            +{
            + PyObject_HEAD_INIT(&CurrentType)
            +};
            +
            +static TabListObject TheTabPageList =
            +{
            + PyObject_HEAD_INIT(&TabListType)
            +};
            +
            +static struct numeric_constant {
            + char *name;
            + int value;
            +} numeric_constants[] = {
            + {"VAR_LOCKED", VAR_LOCKED},
            + {"VAR_FIXED", VAR_FIXED},
            + {"VAR_SCOPE", VAR_SCOPE},
            + {"VAR_DEF_SCOPE", VAR_DEF_SCOPE},
            +};
            +
            +static struct object_constant {
            + char *name;
            + PyObject *value;
            +} object_constants[] = {
            + {"buffers", (PyObject *)(void *)&TheBufferMap},
            + {"windows", (PyObject *)(void *)&TheWindowList},
            + {"tabpages", (PyObject *)(void *)&TheTabPageList},
            + {"current", (PyObject *)(void *)&TheCurrent},
            +};
            +
            +typedef int (*object_adder)(PyObject *, const char *, PyObject *);
            +
            +#define ADD_OBJECT(m, name, obj) \
            + if (add_object(m, name, obj)) \
            + return -1;
            +
            + static int
            +populate_module(PyObject *m, object_adder add_object)
            +{
            + int i;
            +
            + for (i = 0; i < sizeof(numeric_constants) / sizeof(struct numeric_constant);
            + ++i)
            + {
            + PyObject *value;
            + if (!(value = PyInt_FromLong(numeric_constants[i].value)))
            + return -1;
            + ADD_OBJECT(m, numeric_constants[i].name, value);
            + }
            +
            + for (i = 0; i < sizeof(object_constants) / sizeof(struct object_constant);
            + ++i)
            + {
            + PyObject *value;
            +
            + value = object_constants[i].value;
            + Py_INCREF(value);
            + ADD_OBJECT(m, object_constants[i].name, value);
            + }
            +
            + if (!(VimError = PyErr_NewException("vim.error", NULL, NULL)))
            + return -1;
            + ADD_OBJECT(m, "error", VimError);
            +
            + ADD_OBJECT(m, "vars", DictionaryNew(&globvardict));
            + ADD_OBJECT(m, "vvars", DictionaryNew(&vimvardict));
            + ADD_OBJECT(m, "options", OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
            + return 0;
            +}
            diff -r 2a100913fd71 -r 5c5d22791c61 src/if_python.c
            --- a/src/if_python.c Sat May 18 17:58:15 2013 +0400
            +++ b/src/if_python.c Sun May 19 14:47:56 2013 +0400
            @@ -657,7 +657,6 @@
            * Internal function prototypes.
            */

            -static int PythonIO_Init(void);
            static int PythonMod_Init(void);


            @@ -772,7 +771,7 @@
            get_exceptions();
            #endif

            - if (PythonIO_Init())
            + if (PythonIO_Init_io())
            goto fail;

            if (PythonMod_Init())
            @@ -806,7 +805,7 @@
            fail:
            /* We call PythonIO_Flush() here to print any Python errors.
            * This is OK, as it is possible to call this function even
            - * if PythonIO_Init() has not completed successfully (it will
            + * if PythonIO_Init_io() has not completed successfully (it will
            * not do anything in this case).
            */
            PythonIO_Flush();
            @@ -993,17 +992,6 @@
            return Py_FindMethod(OutputMethods, self, name);
            }

            -/***************/
            -
            - static int
            -PythonIO_Init(void)
            -{
            - /* Fixups... */
            - PyType_Ready(&OutputType);
            -
            - return PythonIO_Init_io();
            -}
            -
            /******************************************************
            * 3. Implementation of the Vim module for Python
            */
            @@ -1242,26 +1230,14 @@
            }
            #endif

            -static BufMapObject TheBufferMap =
            + static int
            +add_object(PyObject *dict, const char *name, PyObject *object)
            {
            - PyObject_HEAD_INIT(&BufMapType)
            -};
            -
            -static WinListObject TheWindowList =
            -{
            - PyObject_HEAD_INIT(&WinListType)
            - NULL
            -};
            -
            -static CurrentObject TheCurrent =
            -{
            - PyObject_HEAD_INIT(&CurrentType)
            -};
            -
            -static TabListObject TheTabPageList =
            -{
            - PyObject_HEAD_INIT(&TabListType)
            -};
            + if (PyDict_SetItemString(dict, (char *) name, object))
            + return -1;
            + Py_DECREF(object);
            + return 0;
            +}

            static int
            PythonMod_Init(void)
            @@ -1272,17 +1248,8 @@
            /* The special value is removed from sys.path in Python_Init(). */
            static char *(argv[2]) = {"/must>not&exist/foo", NULL};

            - /* Fixups... */
            - PyType_Ready(&IterType);
            - PyType_Ready(&BufferType);
            - PyType_Ready(&RangeType);
            - PyType_Ready(&WindowType);
            - PyType_Ready(&TabPageType);
            - PyType_Ready(&BufMapType);
            - PyType_Ready(&WinListType);
            - PyType_Ready(&TabListType);
            - PyType_Ready(&CurrentType);
            - PyType_Ready(&OptionsType);
            + if (init_types())
            + return -1;

            /* Set sys.argv[] to avoid a crash in warn(). */
            PySys_SetArgv(1, argv);
            @@ -1290,31 +1257,7 @@
            mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL, PYTHON_API_VERSION);
            dict = PyModule_GetDict(mod);

            - VimError = PyErr_NewException("vim.error", NULL, NULL);
            -
            - PyDict_SetItemString(dict, "error", VimError);
            - PyDict_SetItemString(dict, "buffers", (PyObject *)(void *)&TheBufferMap);
            - PyDict_SetItemString(dict, "current", (PyObject *)(void *)&TheCurrent);
            - PyDict_SetItemString(dict, "windows", (PyObject *)(void *)&TheWindowList);
            - PyDict_SetItemString(dict, "tabpages", (PyObject *)(void *)&TheTabPageList);
            - tmp = DictionaryNew(&globvardict);
            - PyDict_SetItemString(dict, "vars", tmp);
            - Py_DECREF(tmp);
            - tmp = DictionaryNew(&vimvardict);
            - PyDict_SetItemString(dict, "vvars", tmp);
            - Py_DECREF(tmp);
            - tmp = OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL);
            - PyDict_SetItemString(dict, "options", tmp);
            - Py_DECREF(tmp);
            - PyDict_SetItemString(dict, "VAR_LOCKED", PyInt_FromLong(VAR_LOCKED));
            - PyDict_SetItemString(dict, "VAR_FIXED", PyInt_FromLong(VAR_FIXED));
            - PyDict_SetItemString(dict, "VAR_SCOPE", PyInt_FromLong(VAR_SCOPE));
            - PyDict_SetItemString(dict, "VAR_DEF_SCOPE", PyInt_FromLong(VAR_DEF_SCOPE));
            -
            - if (PyErr_Occurred())
            - return -1;
            -
            - return 0;
            + return populate_module(dict, add_object);
            }

            /*************************************************************************
            diff -r 2a100913fd71 -r 5c5d22791c61 src/if_python3.c
            --- a/src/if_python3.c Sat May 18 17:58:15 2013 +0400
            +++ b/src/if_python3.c Sun May 19 14:47:56 2013 +0400
            @@ -700,7 +700,6 @@
            * Internal function prototypes.
            */

            -static int PythonIO_Init(void);
            static PyObject *Py3Init_vim(void);

            /******************************************************
            @@ -780,7 +779,7 @@
            get_py3_exceptions();
            #endif

            - if (PythonIO_Init())
            + if (PythonIO_Init_io())
            goto fail;

            globals = PyModule_GetDict(PyImport_AddModule("__main__"));
            @@ -811,7 +810,7 @@
            fail:
            /* We call PythonIO_Flush() here to print any Python errors.
            * This is OK, as it is possible to call this function even
            - * if PythonIO_Init() has not completed successfully (it will
            + * if PythonIO_Init_io() has not completed successfully (it will
            * not do anything in this case).
            */
            PythonIO_Flush();
            @@ -1008,15 +1007,6 @@
            return OutputSetattr((OutputObject *)(self), name, val);
            }

            -/***************/
            -
            - static int
            -PythonIO_Init(void)
            -{
            - PyType_Ready(&OutputType);
            - return PythonIO_Init_io();
            -}
            -
            /******************************************************
            * 3. Implementation of the Vim module for Python
            */
            @@ -1538,27 +1528,6 @@
            }
            #endif

            -static BufMapObject TheBufferMap =
            -{
            - PyObject_HEAD_INIT(&BufMapType)
            -};
            -
            -static WinListObject TheWindowList =
            -{
            - PyObject_HEAD_INIT(&WinListType)
            - NULL
            -};
            -
            -static CurrentObject TheCurrent =
            -{
            - PyObject_HEAD_INIT(&CurrentType)
            -};
            -
            -static TabListObject TheTabPageList =
            -{
            - PyObject_HEAD_INIT(&TabListType)
            -};
            -
            static PyObject *
            Py3Init_vim(void)
            {
            @@ -1567,19 +1536,8 @@
            /* The special value is removed from sys.path in Python3_Init(). */
            static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL};

            - PyType_Ready(&IterType);
            - PyType_Ready(&BufferType);
            - PyType_Ready(&RangeType);
            - PyType_Ready(&WindowType);
            - PyType_Ready(&TabPageType);
            - PyType_Ready(&BufMapType);
            - PyType_Ready(&WinListType);
            - PyType_Ready(&TabListType);
            - PyType_Ready(&CurrentType);
            - PyType_Ready(&DictionaryType);
            - PyType_Ready(&ListType);
            - PyType_Ready(&FunctionType);
            - PyType_Ready(&OptionsType);
            + if (init_types())
            + return NULL;

            /* Set sys.argv[] to avoid a crash in warn(). */
            PySys_SetArgv(1, argv);
            @@ -1588,35 +1546,7 @@
            if (mod == NULL)
            return NULL;

            - VimError = PyErr_NewException("vim.error", NULL, NULL);
            -
            - Py_INCREF(VimError);
            - PyModule_AddObject(mod, "error", VimError);
            - Py_INCREF((PyObject *)(void *)&TheBufferMap);
            - PyModule_AddObject(mod, "buffers", (PyObject *)(void *)&TheBufferMap);
            - Py_INCREF((PyObject *)(void *)&TheCurrent);
            - PyModule_AddObject(mod, "current", (PyObject *)(void *)&TheCurrent);
            - Py_INCREF((PyObject *)(void *)&TheWindowList);
            - PyModule_AddObject(mod, "windows", (PyObject *)(void *)&TheWindowList);
            - Py_INCREF((PyObject *)(void *)&TheTabPageList);
            - PyModule_AddObject(mod, "tabpages", (PyObject *)(void *)&TheTabPageList);
            -
            - PyModule_AddObject(mod, "vars", DictionaryNew(&globvardict));
            - PyModule_AddObject(mod, "vvars", DictionaryNew(&vimvardict));
            - PyModule_AddObject(mod, "options",
            - OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
            -
            -#define ADD_INT_CONSTANT(name, value) \
            - tmp = PyLong_FromLong(value); \
            - Py_INCREF(tmp); \
            - PyModule_AddObject(mod, name, tmp)
            -
            - ADD_INT_CONSTANT("VAR_LOCKED", VAR_LOCKED);
            - ADD_INT_CONSTANT("VAR_FIXED", VAR_FIXED);
            - ADD_INT_CONSTANT("VAR_SCOPE", VAR_SCOPE);
            - ADD_INT_CONSTANT("VAR_DEF_SCOPE", VAR_DEF_SCOPE);
            -
            - if (PyErr_Occurred())
            + if (populate_module(mod, PyModule_AddObject))
            return NULL;

            return mod;

            --
            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • ZyX
            Forgot this. Attached patch contains both this and previous change # HG changeset patch # User ZyX # Date 1368961186 -14400 # Branch
            Message 5 of 7 , May 19, 2013
            • 0 Attachment
              Forgot this. Attached patch contains both this and previous change
              # HG changeset patch
              # User ZyX <kp-pav@...>
              # Date 1368961186 -14400
              # Branch python-extended-2
              # Node ID eea6cccdddc53335661cc56d592f1f412adcf0df
              # Parent 5c5d22791c61dc77a3685fe3b5e86c377330ea79
              Also check *New output for errors

              diff -r 5c5d22791c61 -r eea6cccdddc5 src/if_py_both.h
              --- a/src/if_py_both.h Sun May 19 14:47:56 2013 +0400
              +++ b/src/if_py_both.h Sun May 19 14:59:46 2013 +0400
              @@ -4253,6 +4253,14 @@
              if (add_object(m, name, obj)) \
              return -1;

              +#define ADD_CHECKED_OBJECT(m, name, obj) \
              + { \
              + PyObject *value = obj; \
              + if (!value) \
              + return -1; \
              + ADD_OBJECT(m, name, value); \
              + }
              +
              static int
              populate_module(PyObject *m, object_adder add_object)
              {
              @@ -4260,12 +4268,8 @@

              for (i = 0; i < sizeof(numeric_constants) / sizeof(struct numeric_constant);
              ++i)
              - {
              - PyObject *value;
              - if (!(value = PyInt_FromLong(numeric_constants[i].value)))
              - return -1;
              - ADD_OBJECT(m, numeric_constants[i].name, value);
              - }
              + ADD_CHECKED_OBJECT(m, numeric_constants[i].name,
              + PyInt_FromLong(numeric_constants[i].value));

              for (i = 0; i < sizeof(object_constants) / sizeof(struct object_constant);
              ++i)
              @@ -4281,8 +4285,9 @@
              return -1;
              ADD_OBJECT(m, "error", VimError);

              - ADD_OBJECT(m, "vars", DictionaryNew(&globvardict));
              - ADD_OBJECT(m, "vvars", DictionaryNew(&vimvardict));
              - ADD_OBJECT(m, "options", OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
              + ADD_CHECKED_OBJECT(m, "vars", DictionaryNew(&globvardict));
              + ADD_CHECKED_OBJECT(m, "vvars", DictionaryNew(&vimvardict));
              + ADD_CHECKED_OBJECT(m, "options",
              + OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
              return 0;
              }

              --
              --
              You received this message from the "vim_dev" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_dev" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Bram Moolenaar
              ... Where does this go in the list of patches? Before 0/? or after 5/?? -- Any sufficiently advanced technology is indistinguishable from magic. Arthur C.
              Message 6 of 7 , May 19, 2013
              • 0 Attachment
                ZyX wrote:

                > Forgot this. Attached patch contains both this and previous change
                > # HG changeset patch
                > # User ZyX <kp-pav@...>
                > # Date 1368961186 -14400
                > # Branch python-extended-2
                > # Node ID eea6cccdddc53335661cc56d592f1f412adcf0df
                > # Parent 5c5d22791c61dc77a3685fe3b5e86c377330ea79
                > Also check *New output for errors

                Where does this go in the list of patches? Before 0/? or after 5/??


                --
                Any sufficiently advanced technology is indistinguishable from magic.
                Arthur C. Clarke
                Any sufficiently advanced bug is indistinguishable from a feature.
                Rich Kulawiec

                /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                \\\ an exciting new programming language -- http://www.Zimbu.org ///
                \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

                --
                --
                You received this message from the "vim_dev" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_dev" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • ZyX
                ... Nowhere: it is already part of (4/?). This list contains *all* unapplied patches. -- -- You received this message from the vim_dev maillist. Do not
                Message 7 of 7 , May 19, 2013
                • 0 Attachment
                  > Where does this go in the list of patches? Before 0/? or after 5/??

                  Nowhere: it is already part of (4/?). This list contains *all* unapplied patches.

                  --
                  --
                  You received this message from the "vim_dev" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_dev" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                Your message has been successfully submitted and would be delivered to recipients shortly.