comparison src/if_python3.c @ 4319:b79f3c3a584c v7.3.909

updated for version 7.3.909 Problem: Duplicate Python code. Solution: Move more items to if_py_both.h. (ZyX) Also avoid compiler warnings for missing initializers.
author Bram Moolenaar <bram@vim.org>
date Wed, 24 Apr 2013 13:39:15 +0200
parents 9f3da1dea7c0
children f1eab4f77a6f
comparison
equal deleted inserted replaced
4318:f19b589e1e8d 4319:b79f3c3a584c
89 #define PyString_FromString(repr) PyUnicode_FromString(repr) 89 #define PyString_FromString(repr) PyUnicode_FromString(repr)
90 #define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len) 90 #define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)
91 #define PyInt_Check(obj) PyLong_Check(obj) 91 #define PyInt_Check(obj) PyLong_Check(obj)
92 #define PyInt_FromLong(i) PyLong_FromLong(i) 92 #define PyInt_FromLong(i) PyLong_FromLong(i)
93 #define PyInt_AsLong(obj) PyLong_AsLong(obj) 93 #define PyInt_AsLong(obj) PyLong_AsLong(obj)
94 #define Py_ssize_t_fmt "n"
94 95
95 #if defined(DYNAMIC_PYTHON3) || defined(PROTO) 96 #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
96 97
97 # ifndef WIN3264 98 # ifndef WIN3264
98 # include <dlfcn.h> 99 # include <dlfcn.h>
586 static PyObject *BufferNew (buf_T *); 587 static PyObject *BufferNew (buf_T *);
587 static PyObject *WindowNew(win_T *); 588 static PyObject *WindowNew(win_T *);
588 static PyObject *LineToString(const char *); 589 static PyObject *LineToString(const char *);
589 static PyObject *BufferDir(PyObject *, PyObject *); 590 static PyObject *BufferDir(PyObject *, PyObject *);
590 591
591 static PyTypeObject RangeType;
592
593 static int py3initialised = 0; 592 static int py3initialised = 0;
594 593
595 #define PYINITIALISED py3initialised 594 #define PYINITIALISED py3initialised
596 595
597 #define DICTKEY_DECL PyObject *bytes = NULL; 596 #define DICTKEY_DECL PyObject *bytes = NULL;
618 617
619 #define DICTKEY_UNREF \ 618 #define DICTKEY_UNREF \
620 if (bytes != NULL) \ 619 if (bytes != NULL) \
621 Py_XDECREF(bytes); 620 Py_XDECREF(bytes);
622 621
622 #define DESTRUCTOR_FINISH(self) Py_TYPE(self)->tp_free((PyObject*)self);
623
624 static void
625 call_PyObject_Free(void *p)
626 {
627 #ifdef Py_DEBUG
628 _PyObject_DebugFree(p);
629 #else
630 PyObject_Free(p);
631 #endif
632 }
633
634 static PyObject *
635 call_PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
636 {
637 return PyType_GenericNew(type,args,kwds);
638 }
639
640 static PyObject *
641 call_PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
642 {
643 return PyType_GenericAlloc(type,nitems);
644 }
645
646 static PyObject *OutputGetattro(PyObject *, PyObject *);
647 static int OutputSetattro(PyObject *, PyObject *, PyObject *);
648 static PyObject *BufferGetattro(PyObject *, PyObject *);
649 static PyObject *WindowGetattro(PyObject *, PyObject *);
650 static int WindowSetattro(PyObject *, PyObject *, PyObject *);
651 static PyObject *RangeGetattro(PyObject *, PyObject *);
652 static PyObject *CurrentGetattro(PyObject *, PyObject *);
653 static int CurrentSetattro(PyObject *, PyObject *, PyObject *);
654 static PyObject *DictionaryGetattro(PyObject *, PyObject *);
655 static int DictionarySetattro(PyObject *, PyObject *, PyObject *);
656 static PyObject *ListGetattro(PyObject *, PyObject *);
657 static int ListSetattro(PyObject *, PyObject *, PyObject *);
658 static PyObject *FunctionGetattro(PyObject *, PyObject *);
659
660 static struct PyModuleDef vimmodule;
661
623 /* 662 /*
624 * Include the code shared with if_python.c 663 * Include the code shared with if_python.c
625 */ 664 */
626 #include "if_py_both.h" 665 #include "if_py_both.h"
627 666
630 if (PyUnicode_Check(nameobj)) \ 669 if (PyUnicode_Check(nameobj)) \
631 name = _PyUnicode_AsString(nameobj) 670 name = _PyUnicode_AsString(nameobj)
632 671
633 #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0) 672 #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
634 673
635 static void
636 call_PyObject_Free(void *p)
637 {
638 #ifdef Py_DEBUG
639 _PyObject_DebugFree(p);
640 #else
641 PyObject_Free(p);
642 #endif
643 }
644
645 static PyObject *
646 call_PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
647 {
648 return PyType_GenericNew(type,args,kwds);
649 }
650
651 static PyObject *
652 call_PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
653 {
654 return PyType_GenericAlloc(type,nitems);
655 }
656
657 /****************************************************** 674 /******************************************************
658 * Internal function prototypes. 675 * Internal function prototypes.
659 */ 676 */
660
661 static Py_ssize_t RangeStart;
662 static Py_ssize_t RangeEnd;
663 677
664 static PyObject *globals; 678 static PyObject *globals;
665 679
666 static int PythonIO_Init(void); 680 static int PythonIO_Init(void);
667 static PyObject *Py3Init_vim(void); 681 static PyObject *Py3Init_vim(void);
1044 0, /* sq_contains */ 1058 0, /* sq_contains */
1045 0, /* sq_inplace_concat */ 1059 0, /* sq_inplace_concat */
1046 0, /* sq_inplace_repeat */ 1060 0, /* sq_inplace_repeat */
1047 }; 1061 };
1048 1062
1049 PyMappingMethods BufferAsMapping = { 1063 static PyMappingMethods BufferAsMapping = {
1050 /* mp_length */ (lenfunc)BufferLength, 1064 /* mp_length */ (lenfunc)BufferLength,
1051 /* mp_subscript */ (binaryfunc)BufferSubscript, 1065 /* mp_subscript */ (binaryfunc)BufferSubscript,
1052 /* mp_ass_subscript */ (objobjargproc)BufferAsSubscript, 1066 /* mp_ass_subscript */ (objobjargproc)BufferAsSubscript,
1053 }; 1067 };
1054 1068
1055 1069
1056 /* Buffer object - Definitions 1070 /* Buffer object - Definitions
1057 */ 1071 */
1058
1059 static PyTypeObject BufferType;
1060 1072
1061 static PyObject * 1073 static PyObject *
1062 BufferNew(buf_T *buf) 1074 BufferNew(buf_T *buf)
1063 { 1075 {
1064 /* We need to handle deletion of buffers underneath us. 1076 /* We need to handle deletion of buffers underneath us.
1092 } 1104 }
1093 1105
1094 return (PyObject *)(self); 1106 return (PyObject *)(self);
1095 } 1107 }
1096 1108
1097 static void
1098 BufferDestructor(PyObject *self)
1099 {
1100 BufferObject *this = (BufferObject *)(self);
1101
1102 if (this->buf && this->buf != INVALID_BUFFER_VALUE)
1103 this->buf->b_python3_ref = NULL;
1104
1105 Py_TYPE(self)->tp_free((PyObject*)self);
1106 }
1107
1108 static PyObject * 1109 static PyObject *
1109 BufferGetattro(PyObject *self, PyObject*nameobj) 1110 BufferGetattro(PyObject *self, PyObject*nameobj)
1110 { 1111 {
1111 BufferObject *this = (BufferObject *)(self); 1112 PyObject *r;
1112 1113
1113 GET_ATTR_STRING(name, nameobj); 1114 GET_ATTR_STRING(name, nameobj);
1114 1115
1115 if (CheckBuffer(this)) 1116 if (CheckBuffer((BufferObject *)(self)))
1116 return NULL; 1117 return NULL;
1117 1118
1118 if (strcmp(name, "name") == 0) 1119 r = BufferAttr((BufferObject *)(self), name);
1119 return Py_BuildValue("s", this->buf->b_ffname); 1120 if (r || PyErr_Occurred())
1120 else if (strcmp(name, "number") == 0) 1121 return r;
1121 return Py_BuildValue("n", this->buf->b_fnum);
1122 else 1122 else
1123 return PyObject_GenericGetAttr(self, nameobj); 1123 return PyObject_GenericGetAttr(self, nameobj);
1124 } 1124 }
1125 1125
1126 static PyObject * 1126 static PyObject *
1127 BufferDir(PyObject *self UNUSED, PyObject *args UNUSED) 1127 BufferDir(PyObject *self UNUSED, PyObject *args UNUSED)
1128 { 1128 {
1129 return Py_BuildValue("[sssss]", "name", "number", 1129 return Py_BuildValue("[sssss]", "name", "number",
1130 "append", "mark", "range"); 1130 "append", "mark", "range");
1131 }
1132
1133 static PyObject *
1134 BufferRepr(PyObject *self)
1135 {
1136 static char repr[100];
1137 BufferObject *this = (BufferObject *)(self);
1138
1139 if (this->buf == INVALID_BUFFER_VALUE)
1140 {
1141 vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self));
1142 return PyUnicode_FromString(repr);
1143 }
1144 else
1145 {
1146 char *name = (char *)this->buf->b_fname;
1147 Py_ssize_t len;
1148
1149 if (name == NULL)
1150 name = "";
1151 len = strlen(name);
1152
1153 if (len > 35)
1154 name = name + (35 - len);
1155
1156 vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name);
1157
1158 return PyUnicode_FromString(repr);
1159 }
1160 } 1131 }
1161 1132
1162 /******************/ 1133 /******************/
1163 1134
1164 static Py_ssize_t 1135 static Py_ssize_t
1253 0, /* sq_contains */ 1224 0, /* sq_contains */
1254 0, /* sq_inplace_concat */ 1225 0, /* sq_inplace_concat */
1255 0, /* sq_inplace_repeat */ 1226 0, /* sq_inplace_repeat */
1256 }; 1227 };
1257 1228
1258 PyMappingMethods RangeAsMapping = { 1229 static PyMappingMethods RangeAsMapping = {
1259 /* mp_length */ (lenfunc)RangeLength, 1230 /* mp_length */ (lenfunc)RangeLength,
1260 /* mp_subscript */ (binaryfunc)RangeSubscript, 1231 /* mp_subscript */ (binaryfunc)RangeSubscript,
1261 /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript, 1232 /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript,
1262 }; 1233 };
1263 1234
1264 /* Line range object - Implementation 1235 /* Line range object - Implementation
1265 */ 1236 */
1266
1267 static void
1268 RangeDestructor(PyObject *self)
1269 {
1270 Py_DECREF(((RangeObject *)(self))->buf);
1271 Py_TYPE(self)->tp_free((PyObject*)self);
1272 }
1273 1237
1274 static PyObject * 1238 static PyObject *
1275 RangeGetattro(PyObject *self, PyObject *nameobj) 1239 RangeGetattro(PyObject *self, PyObject *nameobj)
1276 { 1240 {
1277 GET_ATTR_STRING(name, nameobj); 1241 GET_ATTR_STRING(name, nameobj);
1356 PyErr_SetString(PyExc_IndexError, "Index must be int or slice"); 1320 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
1357 return -1; 1321 return -1;
1358 } 1322 }
1359 } 1323 }
1360 1324
1361
1362 /* Buffer list object - Definitions 1325 /* Buffer list object - Definitions
1363 */ 1326 */
1364
1365 typedef struct
1366 {
1367 PyObject_HEAD
1368 } BufListObject;
1369 1327
1370 static PySequenceMethods BufListAsSeq = { 1328 static PySequenceMethods BufListAsSeq = {
1371 (lenfunc) BufListLength, /* sq_length, len(x) */ 1329 (lenfunc) BufListLength, /* sq_length, len(x) */
1372 (binaryfunc) 0, /* sq_concat, x+y */ 1330 (binaryfunc) 0, /* sq_concat, x+y */
1373 (ssizeargfunc) 0, /* sq_repeat, x*n */ 1331 (ssizeargfunc) 0, /* sq_repeat, x*n */
1378 0, /* sq_contains */ 1336 0, /* sq_contains */
1379 0, /* sq_inplace_concat */ 1337 0, /* sq_inplace_concat */
1380 0, /* sq_inplace_repeat */ 1338 0, /* sq_inplace_repeat */
1381 }; 1339 };
1382 1340
1383 static PyTypeObject BufListType;
1384
1385 /* Window object - Definitions
1386 */
1387
1388 static struct PyMethodDef WindowMethods[] = {
1389 /* name, function, calling, documentation */
1390 { NULL, NULL, 0, NULL }
1391 };
1392
1393 static PyTypeObject WindowType;
1394
1395 /* Window object - Implementation 1341 /* Window object - Implementation
1396 */ 1342 */
1397 1343
1398 static PyObject * 1344 static PyObject *
1399 WindowNew(win_T *win) 1345 WindowNew(win_T *win)
1427 } 1373 }
1428 1374
1429 return (PyObject *)(self); 1375 return (PyObject *)(self);
1430 } 1376 }
1431 1377
1432 static void
1433 WindowDestructor(PyObject *self)
1434 {
1435 WindowObject *this = (WindowObject *)(self);
1436
1437 if (this->win && this->win != INVALID_WINDOW_VALUE)
1438 this->win->w_python3_ref = NULL;
1439
1440 Py_TYPE(self)->tp_free((PyObject*)self);
1441 }
1442
1443 static PyObject * 1378 static PyObject *
1444 WindowGetattro(PyObject *self, PyObject *nameobj) 1379 WindowGetattro(PyObject *self, PyObject *nameobj)
1445 { 1380 {
1446 WindowObject *this = (WindowObject *)(self); 1381 PyObject *r;
1447 1382
1448 GET_ATTR_STRING(name, nameobj); 1383 GET_ATTR_STRING(name, nameobj);
1449 1384
1450 if (CheckWindow(this)) 1385 if (CheckWindow((WindowObject *)(self)))
1451 return NULL; 1386 return NULL;
1452 1387
1453 if (strcmp(name, "buffer") == 0) 1388 r = WindowAttr((WindowObject *)(self), name);
1454 return (PyObject *)BufferNew(this->win->w_buffer); 1389 if (r || PyErr_Occurred())
1455 else if (strcmp(name, "cursor") == 0) 1390 return r;
1456 {
1457 pos_T *pos = &this->win->w_cursor;
1458
1459 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col));
1460 }
1461 else if (strcmp(name, "height") == 0)
1462 return Py_BuildValue("l", (long)(this->win->w_height));
1463 #ifdef FEAT_VERTSPLIT
1464 else if (strcmp(name, "width") == 0)
1465 return Py_BuildValue("l", (long)(W_WIDTH(this->win)));
1466 #endif
1467 else if (strcmp(name,"__members__") == 0)
1468 return Py_BuildValue("[sss]", "buffer", "cursor", "height");
1469 else 1391 else
1470 return PyObject_GenericGetAttr(self, nameobj); 1392 return PyObject_GenericGetAttr(self, nameobj);
1471 } 1393 }
1472 1394
1473 static int 1395 static int
1478 return WindowSetattr(self, name, val); 1400 return WindowSetattr(self, name, val);
1479 } 1401 }
1480 1402
1481 /* Window list object - Definitions 1403 /* Window list object - Definitions
1482 */ 1404 */
1483
1484 typedef struct
1485 {
1486 PyObject_HEAD
1487 }
1488 WinListObject;
1489 1405
1490 static PySequenceMethods WinListAsSeq = { 1406 static PySequenceMethods WinListAsSeq = {
1491 (lenfunc) WinListLength, /* sq_length, len(x) */ 1407 (lenfunc) WinListLength, /* sq_length, len(x) */
1492 (binaryfunc) 0, /* sq_concat, x+y */ 1408 (binaryfunc) 0, /* sq_concat, x+y */
1493 (ssizeargfunc) 0, /* sq_repeat, x*n */ 1409 (ssizeargfunc) 0, /* sq_repeat, x*n */
1498 0, /* sq_contains */ 1414 0, /* sq_contains */
1499 0, /* sq_inplace_concat */ 1415 0, /* sq_inplace_concat */
1500 0, /* sq_inplace_repeat */ 1416 0, /* sq_inplace_repeat */
1501 }; 1417 };
1502 1418
1503 static PyTypeObject WinListType;
1504
1505 /* Current items object - Definitions
1506 */
1507
1508 typedef struct
1509 {
1510 PyObject_HEAD
1511 } CurrentObject;
1512
1513 static PyTypeObject CurrentType;
1514
1515 /* Current items object - Implementation 1419 /* Current items object - Implementation
1516 */ 1420 */
1517 static PyObject * 1421 static PyObject *
1518 CurrentGetattro(PyObject *self UNUSED, PyObject *nameobj) 1422 CurrentGetattro(PyObject *self, PyObject *nameobj)
1519 { 1423 {
1520 GET_ATTR_STRING(name, nameobj); 1424 GET_ATTR_STRING(name, nameobj);
1521 1425 return CurrentGetattr(self, name);
1522 if (strcmp(name, "buffer") == 0)
1523 return (PyObject *)BufferNew(curbuf);
1524 else if (strcmp(name, "window") == 0)
1525 return (PyObject *)WindowNew(curwin);
1526 else if (strcmp(name, "line") == 0)
1527 return GetBufferLine(curbuf, (Py_ssize_t)curwin->w_cursor.lnum);
1528 else if (strcmp(name, "range") == 0)
1529 return RangeNew(curbuf, RangeStart, RangeEnd);
1530 else if (strcmp(name,"__members__") == 0)
1531 return Py_BuildValue("[ssss]", "buffer", "window", "line", "range");
1532 else
1533 {
1534 PyErr_SetString(PyExc_AttributeError, name);
1535 return NULL;
1536 }
1537 } 1426 }
1538 1427
1539 static int 1428 static int
1540 CurrentSetattro(PyObject *self UNUSED, PyObject *nameobj, PyObject *value) 1429 CurrentSetattro(PyObject *self, PyObject *nameobj, PyObject *value)
1541 { 1430 {
1542 char *name = ""; 1431 GET_ATTR_STRING(name, nameobj);
1543 if (PyUnicode_Check(nameobj)) 1432 return CurrentSetattr(self, name, value);
1544 name = _PyUnicode_AsString(nameobj);
1545
1546 if (strcmp(name, "line") == 0)
1547 {
1548 if (SetBufferLine(curbuf, (Py_ssize_t)curwin->w_cursor.lnum, value, NULL) == FAIL)
1549 return -1;
1550
1551 return 0;
1552 }
1553 else
1554 {
1555 PyErr_SetString(PyExc_AttributeError, name);
1556 return -1;
1557 }
1558 } 1433 }
1559 1434
1560 /* Dictionary object - Definitions 1435 /* Dictionary object - Definitions
1561 */ 1436 */
1562 1437
1563 static PyInt DictionaryLength(PyObject *); 1438 static PyInt DictionaryLength(PyObject *);
1564
1565 static PyMappingMethods DictionaryAsMapping = {
1566 /* mp_length */ (lenfunc) DictionaryLength,
1567 /* mp_subscript */ (binaryfunc) DictionaryItem,
1568 /* mp_ass_subscript */ (objobjargproc) DictionaryAssItem,
1569 };
1570 1439
1571 static PyObject * 1440 static PyObject *
1572 DictionaryGetattro(PyObject *self, PyObject *nameobj) 1441 DictionaryGetattro(PyObject *self, PyObject *nameobj)
1573 { 1442 {
1574 DictionaryObject *this = ((DictionaryObject *) (self)); 1443 DictionaryObject *this = ((DictionaryObject *) (self));
1585 1454
1586 static int 1455 static int
1587 DictionarySetattro(PyObject *self, PyObject *nameobj, PyObject *val) 1456 DictionarySetattro(PyObject *self, PyObject *nameobj, PyObject *val)
1588 { 1457 {
1589 GET_ATTR_STRING(name, nameobj); 1458 GET_ATTR_STRING(name, nameobj);
1590 return DictionarySetattr((DictionaryObject *) self, name, val); 1459 return DictionarySetattr(self, name, val);
1591 }
1592
1593 static PyTypeObject DictionaryType;
1594
1595 static void
1596 DictionaryDestructor(PyObject *self)
1597 {
1598 DictionaryObject *this = (DictionaryObject *)(self);
1599
1600 pyll_remove(&this->ref, &lastdict);
1601 dict_unref(this->dict);
1602
1603 Py_TYPE(self)->tp_free((PyObject*)self);
1604 } 1460 }
1605 1461
1606 /* List object - Definitions 1462 /* List object - Definitions
1607 */ 1463 */
1608 1464
1629 /* mp_length */ (lenfunc) ListLength, 1485 /* mp_length */ (lenfunc) ListLength,
1630 /* mp_subscript */ (binaryfunc) ListSubscript, 1486 /* mp_subscript */ (binaryfunc) ListSubscript,
1631 /* mp_ass_subscript */ (objobjargproc) ListAsSubscript, 1487 /* mp_ass_subscript */ (objobjargproc) ListAsSubscript,
1632 }; 1488 };
1633 1489
1634 static PyTypeObject ListType;
1635
1636 static PyObject * 1490 static PyObject *
1637 ListSubscript(PyObject *self, PyObject* idxObject) 1491 ListSubscript(PyObject *self, PyObject* idxObject)
1638 { 1492 {
1639 if (PyLong_Check(idxObject)) 1493 if (PyLong_Check(idxObject))
1640 { 1494 {
1694 1548
1695 static int 1549 static int
1696 ListSetattro(PyObject *self, PyObject *nameobj, PyObject *val) 1550 ListSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
1697 { 1551 {
1698 GET_ATTR_STRING(name, nameobj); 1552 GET_ATTR_STRING(name, nameobj);
1699 return ListSetattr((ListObject *) self, name, val); 1553 return ListSetattr(self, name, val);
1700 }
1701
1702 static void
1703 ListDestructor(PyObject *self)
1704 {
1705 ListObject *this = (ListObject *)(self);
1706
1707 pyll_remove(&this->ref, &lastlist);
1708 list_unref(this->list);
1709
1710 Py_TYPE(self)->tp_free((PyObject*)self);
1711 } 1554 }
1712 1555
1713 /* Function object - Definitions 1556 /* Function object - Definitions
1714 */ 1557 */
1715
1716 static void
1717 FunctionDestructor(PyObject *self)
1718 {
1719 FunctionObject *this = (FunctionObject *) (self);
1720
1721 func_unref(this->name);
1722 PyMem_Del(this->name);
1723
1724 Py_TYPE(self)->tp_free((PyObject*)self);
1725 }
1726 1558
1727 static PyObject * 1559 static PyObject *
1728 FunctionGetattro(PyObject *self, PyObject *nameobj) 1560 FunctionGetattro(PyObject *self, PyObject *nameobj)
1729 { 1561 {
1730 FunctionObject *this = (FunctionObject *)(self); 1562 FunctionObject *this = (FunctionObject *)(self);
1776 1608
1777 static CurrentObject TheCurrent = 1609 static CurrentObject TheCurrent =
1778 { 1610 {
1779 PyObject_HEAD_INIT(&CurrentType) 1611 PyObject_HEAD_INIT(&CurrentType)
1780 }; 1612 };
1781
1782 PyDoc_STRVAR(vim_module_doc,"vim python interface\n");
1783
1784 static struct PyModuleDef vimmodule;
1785 1613
1786 static PyObject * 1614 static PyObject *
1787 Py3Init_vim(void) 1615 Py3Init_vim(void)
1788 { 1616 {
1789 PyObject *mod; 1617 PyObject *mod;
1896 void 1724 void
1897 set_ref_in_python3 (int copyID) 1725 set_ref_in_python3 (int copyID)
1898 { 1726 {
1899 set_ref_in_py(copyID); 1727 set_ref_in_py(copyID);
1900 } 1728 }
1901
1902 static void
1903 init_structs(void)
1904 {
1905 vim_memset(&OutputType, 0, sizeof(OutputType));
1906 OutputType.tp_name = "vim.message";
1907 OutputType.tp_basicsize = sizeof(OutputObject);
1908 OutputType.tp_getattro = OutputGetattro;
1909 OutputType.tp_setattro = OutputSetattro;
1910 OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
1911 OutputType.tp_doc = "vim message object";
1912 OutputType.tp_methods = OutputMethods;
1913 OutputType.tp_alloc = call_PyType_GenericAlloc;
1914 OutputType.tp_new = call_PyType_GenericNew;
1915 OutputType.tp_free = call_PyObject_Free;
1916
1917 vim_memset(&BufferType, 0, sizeof(BufferType));
1918 BufferType.tp_name = "vim.buffer";
1919 BufferType.tp_basicsize = sizeof(BufferType);
1920 BufferType.tp_dealloc = BufferDestructor;
1921 BufferType.tp_repr = BufferRepr;
1922 BufferType.tp_as_sequence = &BufferAsSeq;
1923 BufferType.tp_as_mapping = &BufferAsMapping;
1924 BufferType.tp_getattro = BufferGetattro;
1925 BufferType.tp_flags = Py_TPFLAGS_DEFAULT;
1926 BufferType.tp_doc = "vim buffer object";
1927 BufferType.tp_methods = BufferMethods;
1928 BufferType.tp_alloc = call_PyType_GenericAlloc;
1929 BufferType.tp_new = call_PyType_GenericNew;
1930 BufferType.tp_free = call_PyObject_Free;
1931
1932 vim_memset(&WindowType, 0, sizeof(WindowType));
1933 WindowType.tp_name = "vim.window";
1934 WindowType.tp_basicsize = sizeof(WindowObject);
1935 WindowType.tp_dealloc = WindowDestructor;
1936 WindowType.tp_repr = WindowRepr;
1937 WindowType.tp_getattro = WindowGetattro;
1938 WindowType.tp_setattro = WindowSetattro;
1939 WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
1940 WindowType.tp_doc = "vim Window object";
1941 WindowType.tp_methods = WindowMethods;
1942 WindowType.tp_alloc = call_PyType_GenericAlloc;
1943 WindowType.tp_new = call_PyType_GenericNew;
1944 WindowType.tp_free = call_PyObject_Free;
1945
1946 vim_memset(&BufListType, 0, sizeof(BufListType));
1947 BufListType.tp_name = "vim.bufferlist";
1948 BufListType.tp_basicsize = sizeof(BufListObject);
1949 BufListType.tp_as_sequence = &BufListAsSeq;
1950 BufListType.tp_flags = Py_TPFLAGS_DEFAULT;
1951 BufferType.tp_doc = "vim buffer list";
1952
1953 vim_memset(&WinListType, 0, sizeof(WinListType));
1954 WinListType.tp_name = "vim.windowlist";
1955 WinListType.tp_basicsize = sizeof(WinListType);
1956 WinListType.tp_as_sequence = &WinListAsSeq;
1957 WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
1958 WinListType.tp_doc = "vim window list";
1959
1960 vim_memset(&RangeType, 0, sizeof(RangeType));
1961 RangeType.tp_name = "vim.range";
1962 RangeType.tp_basicsize = sizeof(RangeObject);
1963 RangeType.tp_dealloc = RangeDestructor;
1964 RangeType.tp_repr = RangeRepr;
1965 RangeType.tp_as_sequence = &RangeAsSeq;
1966 RangeType.tp_as_mapping = &RangeAsMapping;
1967 RangeType.tp_getattro = RangeGetattro;
1968 RangeType.tp_flags = Py_TPFLAGS_DEFAULT;
1969 RangeType.tp_doc = "vim Range object";
1970 RangeType.tp_methods = RangeMethods;
1971 RangeType.tp_alloc = call_PyType_GenericAlloc;
1972 RangeType.tp_new = call_PyType_GenericNew;
1973 RangeType.tp_free = call_PyObject_Free;
1974
1975 vim_memset(&CurrentType, 0, sizeof(CurrentType));
1976 CurrentType.tp_name = "vim.currentdata";
1977 CurrentType.tp_basicsize = sizeof(CurrentObject);
1978 CurrentType.tp_getattro = CurrentGetattro;
1979 CurrentType.tp_setattro = CurrentSetattro;
1980 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
1981 CurrentType.tp_doc = "vim current object";
1982
1983 vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
1984 DictionaryType.tp_name = "vim.dictionary";
1985 DictionaryType.tp_basicsize = sizeof(DictionaryObject);
1986 DictionaryType.tp_getattro = DictionaryGetattro;
1987 DictionaryType.tp_setattro = DictionarySetattro;
1988 DictionaryType.tp_dealloc = DictionaryDestructor;
1989 DictionaryType.tp_as_mapping = &DictionaryAsMapping;
1990 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT;
1991 DictionaryType.tp_doc = "dictionary pushing modifications to vim structure";
1992 DictionaryType.tp_methods = DictionaryMethods;
1993
1994 vim_memset(&ListType, 0, sizeof(ListType));
1995 ListType.tp_name = "vim.list";
1996 ListType.tp_dealloc = ListDestructor;
1997 ListType.tp_basicsize = sizeof(ListObject);
1998 ListType.tp_getattro = ListGetattro;
1999 ListType.tp_setattro = ListSetattro;
2000 ListType.tp_as_sequence = &ListAsSeq;
2001 ListType.tp_as_mapping = &ListAsMapping;
2002 ListType.tp_flags = Py_TPFLAGS_DEFAULT;
2003 ListType.tp_doc = "list pushing modifications to vim structure";
2004 ListType.tp_methods = ListMethods;
2005
2006 vim_memset(&FunctionType, 0, sizeof(FunctionType));
2007 FunctionType.tp_name = "vim.list";
2008 FunctionType.tp_basicsize = sizeof(FunctionObject);
2009 FunctionType.tp_getattro = FunctionGetattro;
2010 FunctionType.tp_dealloc = FunctionDestructor;
2011 FunctionType.tp_call = FunctionCall;
2012 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT;
2013 FunctionType.tp_doc = "object that calls vim function";
2014 FunctionType.tp_methods = FunctionMethods;
2015
2016 vim_memset(&vimmodule, 0, sizeof(vimmodule));
2017 vimmodule.m_name = "vim";
2018 vimmodule.m_doc = vim_module_doc;
2019 vimmodule.m_size = -1;
2020 vimmodule.m_methods = VimMethods;
2021 }