Mercurial > vim
comparison src/if_python3.c @ 4494:6d517f6e5f0b v7.3.995
updated for version 7.3.995
Problem: Python: Module initialization is duplicated.
Solution: Move to shared file. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 21 May 2013 19:11:01 +0200 |
parents | f74611bfb1b7 |
children | 47e6dec5ce3c |
comparison
equal
deleted
inserted
replaced
4493:36ea23677c9c | 4494:6d517f6e5f0b |
---|---|
698 | 698 |
699 /****************************************************** | 699 /****************************************************** |
700 * Internal function prototypes. | 700 * Internal function prototypes. |
701 */ | 701 */ |
702 | 702 |
703 static int PythonIO_Init(void); | |
704 static PyObject *Py3Init_vim(void); | 703 static PyObject *Py3Init_vim(void); |
705 | 704 |
706 /****************************************************** | 705 /****************************************************** |
707 * 1. Python interpreter main program. | 706 * 1. Python interpreter main program. |
708 */ | 707 */ |
778 PyEval_InitThreads(); | 777 PyEval_InitThreads(); |
779 #ifdef DYNAMIC_PYTHON3 | 778 #ifdef DYNAMIC_PYTHON3 |
780 get_py3_exceptions(); | 779 get_py3_exceptions(); |
781 #endif | 780 #endif |
782 | 781 |
783 if (PythonIO_Init()) | 782 if (PythonIO_Init_io()) |
784 goto fail; | 783 goto fail; |
785 | 784 |
786 globals = PyModule_GetDict(PyImport_AddModule("__main__")); | 785 globals = PyModule_GetDict(PyImport_AddModule("__main__")); |
787 | 786 |
788 /* Remove the element from sys.path that was added because of our | 787 /* Remove the element from sys.path that was added because of our |
809 return 0; | 808 return 0; |
810 | 809 |
811 fail: | 810 fail: |
812 /* We call PythonIO_Flush() here to print any Python errors. | 811 /* We call PythonIO_Flush() here to print any Python errors. |
813 * This is OK, as it is possible to call this function even | 812 * This is OK, as it is possible to call this function even |
814 * if PythonIO_Init() has not completed successfully (it will | 813 * if PythonIO_Init_io() has not completed successfully (it will |
815 * not do anything in this case). | 814 * not do anything in this case). |
816 */ | 815 */ |
817 PythonIO_Flush(); | 816 PythonIO_Flush(); |
818 return -1; | 817 return -1; |
819 } | 818 } |
1006 GET_ATTR_STRING(name, nameobj); | 1005 GET_ATTR_STRING(name, nameobj); |
1007 | 1006 |
1008 return OutputSetattr((OutputObject *)(self), name, val); | 1007 return OutputSetattr((OutputObject *)(self), name, val); |
1009 } | 1008 } |
1010 | 1009 |
1011 /***************/ | |
1012 | |
1013 static int | |
1014 PythonIO_Init(void) | |
1015 { | |
1016 PyType_Ready(&OutputType); | |
1017 return PythonIO_Init_io(); | |
1018 } | |
1019 | |
1020 /****************************************************** | 1010 /****************************************************** |
1021 * 3. Implementation of the Vim module for Python | 1011 * 3. Implementation of the Vim module for Python |
1022 */ | 1012 */ |
1023 | 1013 |
1024 /* Window type - Implementation functions | 1014 /* Window type - Implementation functions |
1536 TAB_PYTHON_REF(tab) = NULL; | 1526 TAB_PYTHON_REF(tab) = NULL; |
1537 } | 1527 } |
1538 } | 1528 } |
1539 #endif | 1529 #endif |
1540 | 1530 |
1541 static BufMapObject TheBufferMap = | |
1542 { | |
1543 PyObject_HEAD_INIT(&BufMapType) | |
1544 }; | |
1545 | |
1546 static WinListObject TheWindowList = | |
1547 { | |
1548 PyObject_HEAD_INIT(&WinListType) | |
1549 NULL | |
1550 }; | |
1551 | |
1552 static CurrentObject TheCurrent = | |
1553 { | |
1554 PyObject_HEAD_INIT(&CurrentType) | |
1555 }; | |
1556 | |
1557 static TabListObject TheTabPageList = | |
1558 { | |
1559 PyObject_HEAD_INIT(&TabListType) | |
1560 }; | |
1561 | |
1562 static PyObject * | 1531 static PyObject * |
1563 Py3Init_vim(void) | 1532 Py3Init_vim(void) |
1564 { | 1533 { |
1565 PyObject *mod; | 1534 PyObject *mod; |
1566 PyObject *tmp; | 1535 |
1567 /* The special value is removed from sys.path in Python3_Init(). */ | 1536 /* The special value is removed from sys.path in Python3_Init(). */ |
1568 static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL}; | 1537 static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL}; |
1569 | 1538 |
1570 PyType_Ready(&IterType); | 1539 if (init_types()) |
1571 PyType_Ready(&BufferType); | 1540 return NULL; |
1572 PyType_Ready(&RangeType); | |
1573 PyType_Ready(&WindowType); | |
1574 PyType_Ready(&TabPageType); | |
1575 PyType_Ready(&BufMapType); | |
1576 PyType_Ready(&WinListType); | |
1577 PyType_Ready(&TabListType); | |
1578 PyType_Ready(&CurrentType); | |
1579 PyType_Ready(&DictionaryType); | |
1580 PyType_Ready(&ListType); | |
1581 PyType_Ready(&FunctionType); | |
1582 PyType_Ready(&OptionsType); | |
1583 | 1541 |
1584 /* Set sys.argv[] to avoid a crash in warn(). */ | 1542 /* Set sys.argv[] to avoid a crash in warn(). */ |
1585 PySys_SetArgv(1, argv); | 1543 PySys_SetArgv(1, argv); |
1586 | 1544 |
1587 mod = PyModule_Create(&vimmodule); | 1545 mod = PyModule_Create(&vimmodule); |
1588 if (mod == NULL) | 1546 if (mod == NULL) |
1589 return NULL; | 1547 return NULL; |
1590 | 1548 |
1591 VimError = PyErr_NewException("vim.error", NULL, NULL); | 1549 if (populate_module(mod, PyModule_AddObject)) |
1592 | |
1593 Py_INCREF(VimError); | |
1594 PyModule_AddObject(mod, "error", VimError); | |
1595 Py_INCREF((PyObject *)(void *)&TheBufferMap); | |
1596 PyModule_AddObject(mod, "buffers", (PyObject *)(void *)&TheBufferMap); | |
1597 Py_INCREF((PyObject *)(void *)&TheCurrent); | |
1598 PyModule_AddObject(mod, "current", (PyObject *)(void *)&TheCurrent); | |
1599 Py_INCREF((PyObject *)(void *)&TheWindowList); | |
1600 PyModule_AddObject(mod, "windows", (PyObject *)(void *)&TheWindowList); | |
1601 Py_INCREF((PyObject *)(void *)&TheTabPageList); | |
1602 PyModule_AddObject(mod, "tabpages", (PyObject *)(void *)&TheTabPageList); | |
1603 | |
1604 PyModule_AddObject(mod, "vars", DictionaryNew(&globvardict)); | |
1605 PyModule_AddObject(mod, "vvars", DictionaryNew(&vimvardict)); | |
1606 PyModule_AddObject(mod, "options", | |
1607 OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL)); | |
1608 | |
1609 #define ADD_INT_CONSTANT(name, value) \ | |
1610 tmp = PyLong_FromLong(value); \ | |
1611 Py_INCREF(tmp); \ | |
1612 PyModule_AddObject(mod, name, tmp) | |
1613 | |
1614 ADD_INT_CONSTANT("VAR_LOCKED", VAR_LOCKED); | |
1615 ADD_INT_CONSTANT("VAR_FIXED", VAR_FIXED); | |
1616 ADD_INT_CONSTANT("VAR_SCOPE", VAR_SCOPE); | |
1617 ADD_INT_CONSTANT("VAR_DEF_SCOPE", VAR_DEF_SCOPE); | |
1618 | |
1619 if (PyErr_Occurred()) | |
1620 return NULL; | 1550 return NULL; |
1621 | 1551 |
1622 return mod; | 1552 return mod; |
1623 } | 1553 } |
1624 | 1554 |