Another refactoring: now moved most module initialization to if_py_both.h.

# HG changeset patch
# User ZyX <[email protected]>
# 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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


diff -cr vim.2a100913fd71/src/if_py_both.h vim.5c5d22791c61/src/if_py_both.h
*** vim.2a100913fd71/src/if_py_both.h	2013-05-19 14:53:20.161209066 +0400
--- vim.5c5d22791c61/src/if_py_both.h	2013-05-19 14:53:20.173208947 +0400
***************
*** 4181,4183 ****
--- 4181,4288 ----
      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 -cr vim.2a100913fd71/src/if_python3.c vim.5c5d22791c61/src/if_python3.c
*** vim.2a100913fd71/src/if_python3.c	2013-05-19 14:53:20.158209096 +0400
--- vim.5c5d22791c61/src/if_python3.c	2013-05-19 14:53:20.169208987 +0400
***************
*** 700,706 ****
   * Internal function prototypes.
   */
  
- static int PythonIO_Init(void);
  static PyObject *Py3Init_vim(void);
  
  /******************************************************
--- 700,705 ----
***************
*** 780,786 ****
  	get_py3_exceptions();
  #endif
  
! 	if (PythonIO_Init())
  	    goto fail;
  
  	globals = PyModule_GetDict(PyImport_AddModule("__main__"));
--- 779,785 ----
  	get_py3_exceptions();
  #endif
  
! 	if (PythonIO_Init_io())
  	    goto fail;
  
  	globals = PyModule_GetDict(PyImport_AddModule("__main__"));
***************
*** 811,817 ****
  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
       * not do anything in this case).
       */
      PythonIO_Flush();
--- 810,816 ----
  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_io() has not completed successfully (it will
       * not do anything in this case).
       */
      PythonIO_Flush();
***************
*** 1008,1022 ****
      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
   */
--- 1007,1012 ----
***************
*** 1538,1564 ****
  }
  #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)
  {
--- 1528,1533 ----
***************
*** 1567,1585 ****
      /* 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);
  
      /* Set sys.argv[] to avoid a crash in warn(). */
      PySys_SetArgv(1, argv);
--- 1536,1543 ----
      /* The special value is removed from sys.path in Python3_Init(). */
      static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL};
  
!     if (init_types())
! 	return NULL;
  
      /* Set sys.argv[] to avoid a crash in warn(). */
      PySys_SetArgv(1, argv);
***************
*** 1588,1622 ****
      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())
  	return NULL;
  
      return mod;
--- 1546,1552 ----
      if (mod == NULL)
  	return NULL;
  
!     if (populate_module(mod, PyModule_AddObject))
  	return NULL;
  
      return mod;
diff -cr vim.2a100913fd71/src/if_python.c vim.5c5d22791c61/src/if_python.c
*** vim.2a100913fd71/src/if_python.c	2013-05-19 14:53:20.165209026 +0400
--- vim.5c5d22791c61/src/if_python.c	2013-05-19 14:53:20.176208917 +0400
***************
*** 657,663 ****
   * Internal function prototypes.
   */
  
- static int PythonIO_Init(void);
  static int PythonMod_Init(void);
  
  
--- 657,662 ----
***************
*** 772,778 ****
  	get_exceptions();
  #endif
  
! 	if (PythonIO_Init())
  	    goto fail;
  
  	if (PythonMod_Init())
--- 771,777 ----
  	get_exceptions();
  #endif
  
! 	if (PythonIO_Init_io())
  	    goto fail;
  
  	if (PythonMod_Init())
***************
*** 806,812 ****
  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
       * not do anything in this case).
       */
      PythonIO_Flush();
--- 805,811 ----
  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_io() has not completed successfully (it will
       * not do anything in this case).
       */
      PythonIO_Flush();
***************
*** 993,1009 ****
      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
   */
--- 992,997 ----
***************
*** 1242,1267 ****
  }
  #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 int
  PythonMod_Init(void)
--- 1230,1243 ----
  }
  #endif
  
!     static int
! add_object(PyObject *dict, const char *name, PyObject *object)
  {
!     if (PyDict_SetItemString(dict, (char *) name, object))
! 	return -1;
!     Py_DECREF(object);
!     return 0;
! }
  
      static int
  PythonMod_Init(void)
***************
*** 1272,1288 ****
      /* 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);
  
      /* Set sys.argv[] to avoid a crash in warn(). */
      PySys_SetArgv(1, argv);
--- 1248,1255 ----
      /* The special value is removed from sys.path in Python_Init(). */
      static char *(argv[2]) = {"/must>not&exist/foo", NULL};
  
!     if (init_types())
! 	return -1;
  
      /* Set sys.argv[] to avoid a crash in warn(). */
      PySys_SetArgv(1, argv);
***************
*** 1290,1320 ****
      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;
  }
  
  /*************************************************************************
--- 1257,1263 ----
      mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL, PYTHON_API_VERSION);
      dict = PyModule_GetDict(mod);
  
!     return populate_module(dict, add_object);
  }
  
  /*************************************************************************

Raspunde prin e-mail lui