Mercurial > vim
comparison src/if_py_both.h @ 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 | 4281875776fb |
children | d8d9c591c50f |
comparison
equal
deleted
inserted
replaced
4318:f19b589e1e8d | 4319:b79f3c3a584c |
---|---|
540 | 540 |
541 /* | 541 /* |
542 * Buffer list object - Implementation | 542 * Buffer list object - Implementation |
543 */ | 543 */ |
544 | 544 |
545 typedef struct | |
546 { | |
547 PyObject_HEAD | |
548 } BufListObject; | |
549 | |
550 static PyTypeObject BufListType; | |
551 static PySequenceMethods WinListAsSeq; | |
552 | |
545 static PyInt | 553 static PyInt |
546 BufListLength(PyObject *self UNUSED) | 554 BufListLength(PyObject *self UNUSED) |
547 { | 555 { |
548 buf_T *b = firstbuf; | 556 buf_T *b = firstbuf; |
549 PyInt n = 0; | 557 PyInt n = 0; |
575 typedef struct | 583 typedef struct |
576 { | 584 { |
577 PyObject_HEAD | 585 PyObject_HEAD |
578 win_T *win; | 586 win_T *win; |
579 } WindowObject; | 587 } WindowObject; |
588 | |
589 static struct PyMethodDef WindowMethods[] = { | |
590 /* name, function, calling, documentation */ | |
591 { NULL, NULL, 0, NULL } | |
592 }; | |
580 | 593 |
581 static int ConvertFromPyObject(PyObject *, typval_T *); | 594 static int ConvertFromPyObject(PyObject *, typval_T *); |
582 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *); | 595 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *); |
583 | 596 |
584 typedef struct pylinkedlist_S { | 597 typedef struct pylinkedlist_S { |
640 PyObject_HEAD | 653 PyObject_HEAD |
641 dict_T *dict; | 654 dict_T *dict; |
642 pylinkedlist_T ref; | 655 pylinkedlist_T ref; |
643 } DictionaryObject; | 656 } DictionaryObject; |
644 | 657 |
658 static PyInt DictionaryAssItem(PyObject *, PyObject *, PyObject *); | |
659 static PyInt DictionaryLength(PyObject *); | |
660 static PyObject *DictionaryItem(PyObject *, PyObject *); | |
661 | |
662 static PyMappingMethods DictionaryAsMapping = { | |
663 (lenfunc) DictionaryLength, | |
664 (binaryfunc) DictionaryItem, | |
665 (objobjargproc) DictionaryAssItem, | |
666 }; | |
667 | |
645 static PyObject * | 668 static PyObject * |
646 DictionaryNew(dict_T *dict) | 669 DictionaryNew(dict_T *dict) |
647 { | 670 { |
648 DictionaryObject *self; | 671 DictionaryObject *self; |
649 | 672 |
654 ++dict->dv_refcount; | 677 ++dict->dv_refcount; |
655 | 678 |
656 pyll_add((PyObject *)(self), &self->ref, &lastdict); | 679 pyll_add((PyObject *)(self), &self->ref, &lastdict); |
657 | 680 |
658 return (PyObject *)(self); | 681 return (PyObject *)(self); |
682 } | |
683 | |
684 static void | |
685 DictionaryDestructor(PyObject *self) | |
686 { | |
687 DictionaryObject *this = ((DictionaryObject *) (self)); | |
688 | |
689 pyll_remove(&this->ref, &lastdict); | |
690 dict_unref(this->dict); | |
691 | |
692 DESTRUCTOR_FINISH(self); | |
659 } | 693 } |
660 | 694 |
661 static int | 695 static int |
662 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict) | 696 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict) |
663 { | 697 { |
802 } | 836 } |
803 Py_DECREF(list); | 837 Py_DECREF(list); |
804 return 0; | 838 return 0; |
805 } | 839 } |
806 | 840 |
807 static PyInt | 841 static int |
808 DictionarySetattr(DictionaryObject *self, char *name, PyObject *val) | 842 DictionarySetattr(PyObject *self, char *name, PyObject *val) |
809 { | 843 { |
844 DictionaryObject *this = (DictionaryObject *)(self); | |
845 | |
810 if (val == NULL) | 846 if (val == NULL) |
811 { | 847 { |
812 PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes")); | 848 PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes")); |
813 return -1; | 849 return -1; |
814 } | 850 } |
815 | 851 |
816 if (strcmp(name, "locked") == 0) | 852 if (strcmp(name, "locked") == 0) |
817 { | 853 { |
818 if (self->dict->dv_lock == VAR_FIXED) | 854 if (this->dict->dv_lock == VAR_FIXED) |
819 { | 855 { |
820 PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed dictionary")); | 856 PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed dictionary")); |
821 return -1; | 857 return -1; |
822 } | 858 } |
823 else | 859 else |
827 PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed")); | 863 PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed")); |
828 return -1; | 864 return -1; |
829 } | 865 } |
830 | 866 |
831 if (val == Py_True) | 867 if (val == Py_True) |
832 self->dict->dv_lock = VAR_LOCKED; | 868 this->dict->dv_lock = VAR_LOCKED; |
833 else | 869 else |
834 self->dict->dv_lock = 0; | 870 this->dict->dv_lock = 0; |
835 } | 871 } |
836 return 0; | 872 return 0; |
837 } | 873 } |
838 else | 874 else |
839 { | 875 { |
961 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""}, | 997 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""}, |
962 { NULL, NULL, 0, NULL } | 998 { NULL, NULL, 0, NULL } |
963 }; | 999 }; |
964 | 1000 |
965 static PyTypeObject ListType; | 1001 static PyTypeObject ListType; |
1002 static PySequenceMethods ListAsSeq; | |
1003 static PyMappingMethods ListAsMapping; | |
966 | 1004 |
967 typedef struct | 1005 typedef struct |
968 { | 1006 { |
969 PyObject_HEAD | 1007 PyObject_HEAD |
970 list_T *list; | 1008 list_T *list; |
983 ++list->lv_refcount; | 1021 ++list->lv_refcount; |
984 | 1022 |
985 pyll_add((PyObject *)(self), &self->ref, &lastlist); | 1023 pyll_add((PyObject *)(self), &self->ref, &lastlist); |
986 | 1024 |
987 return (PyObject *)(self); | 1025 return (PyObject *)(self); |
1026 } | |
1027 | |
1028 static void | |
1029 ListDestructor(PyObject *self) | |
1030 { | |
1031 ListObject *this = (ListObject *)(self); | |
1032 | |
1033 pyll_remove(&this->ref, &lastlist); | |
1034 list_unref(this->list); | |
1035 | |
1036 DESTRUCTOR_FINISH(self); | |
988 } | 1037 } |
989 | 1038 |
990 static int | 1039 static int |
991 list_py_concat(list_T *l, PyObject *obj, PyObject *lookupDict) | 1040 list_py_concat(list_T *l, PyObject *obj, PyObject *lookupDict) |
992 { | 1041 { |
1305 Py_INCREF(self); | 1354 Py_INCREF(self); |
1306 return self; | 1355 return self; |
1307 } | 1356 } |
1308 | 1357 |
1309 static int | 1358 static int |
1310 ListSetattr(ListObject *self, char *name, PyObject *val) | 1359 ListSetattr(PyObject *self, char *name, PyObject *val) |
1311 { | 1360 { |
1361 ListObject *this = (ListObject *)(self); | |
1362 | |
1312 if (val == NULL) | 1363 if (val == NULL) |
1313 { | 1364 { |
1314 PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes")); | 1365 PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes")); |
1315 return -1; | 1366 return -1; |
1316 } | 1367 } |
1317 | 1368 |
1318 if (strcmp(name, "locked") == 0) | 1369 if (strcmp(name, "locked") == 0) |
1319 { | 1370 { |
1320 if (self->list->lv_lock == VAR_FIXED) | 1371 if (this->list->lv_lock == VAR_FIXED) |
1321 { | 1372 { |
1322 PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed list")); | 1373 PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed list")); |
1323 return -1; | 1374 return -1; |
1324 } | 1375 } |
1325 else | 1376 else |
1329 PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed")); | 1380 PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed")); |
1330 return -1; | 1381 return -1; |
1331 } | 1382 } |
1332 | 1383 |
1333 if (val == Py_True) | 1384 if (val == Py_True) |
1334 self->list->lv_lock = VAR_LOCKED; | 1385 this->list->lv_lock = VAR_LOCKED; |
1335 else | 1386 else |
1336 self->list->lv_lock = 0; | 1387 this->list->lv_lock = 0; |
1337 } | 1388 } |
1338 return 0; | 1389 return 0; |
1339 } | 1390 } |
1340 else | 1391 else |
1341 { | 1392 { |
1372 return NULL; | 1423 return NULL; |
1373 } | 1424 } |
1374 STRCPY(self->name, name); | 1425 STRCPY(self->name, name); |
1375 func_ref(name); | 1426 func_ref(name); |
1376 return (PyObject *)(self); | 1427 return (PyObject *)(self); |
1428 } | |
1429 | |
1430 static void | |
1431 FunctionDestructor(PyObject *self) | |
1432 { | |
1433 FunctionObject *this = (FunctionObject *) (self); | |
1434 | |
1435 func_unref(this->name); | |
1436 PyMem_Del(this->name); | |
1437 | |
1438 DESTRUCTOR_FINISH(self); | |
1377 } | 1439 } |
1378 | 1440 |
1379 static PyObject * | 1441 static PyObject * |
1380 FunctionCall(PyObject *self, PyObject *argsObject, PyObject *kwargs) | 1442 FunctionCall(PyObject *self, PyObject *argsObject, PyObject *kwargs) |
1381 { | 1443 { |
1449 return 0; | 1511 return 0; |
1450 } | 1512 } |
1451 | 1513 |
1452 static int WindowSetattr(PyObject *, char *, PyObject *); | 1514 static int WindowSetattr(PyObject *, char *, PyObject *); |
1453 static PyObject *WindowRepr(PyObject *); | 1515 static PyObject *WindowRepr(PyObject *); |
1516 static PyTypeObject WindowType; | |
1517 | |
1518 static PyObject * | |
1519 WindowAttr(WindowObject *this, char *name) | |
1520 { | |
1521 if (strcmp(name, "buffer") == 0) | |
1522 return (PyObject *)BufferNew(this->win->w_buffer); | |
1523 else if (strcmp(name, "cursor") == 0) | |
1524 { | |
1525 pos_T *pos = &this->win->w_cursor; | |
1526 | |
1527 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col)); | |
1528 } | |
1529 else if (strcmp(name, "height") == 0) | |
1530 return Py_BuildValue("l", (long)(this->win->w_height)); | |
1531 #ifdef FEAT_VERTSPLIT | |
1532 else if (strcmp(name, "width") == 0) | |
1533 return Py_BuildValue("l", (long)(W_WIDTH(this->win))); | |
1534 #endif | |
1535 else if (strcmp(name,"__members__") == 0) | |
1536 return Py_BuildValue("[sss]", "buffer", "cursor", "height"); | |
1537 else | |
1538 return NULL; | |
1539 } | |
1540 | |
1541 static void | |
1542 WindowDestructor(PyObject *self) | |
1543 { | |
1544 WindowObject *this = (WindowObject *)(self); | |
1545 | |
1546 if (this->win && this->win != INVALID_WINDOW_VALUE) | |
1547 #if PY_MAJOR_VERSION >= 3 | |
1548 this->win->w_python3_ref = NULL; | |
1549 #else | |
1550 this->win->w_python_ref = NULL; | |
1551 #endif | |
1552 | |
1553 DESTRUCTOR_FINISH(self); | |
1554 } | |
1454 | 1555 |
1455 static int | 1556 static int |
1456 WindowSetattr(PyObject *self, char *name, PyObject *val) | 1557 WindowSetattr(PyObject *self, char *name, PyObject *val) |
1457 { | 1558 { |
1458 WindowObject *this = (WindowObject *)(self); | 1559 WindowObject *this = (WindowObject *)(self); |
1577 } | 1678 } |
1578 | 1679 |
1579 /* | 1680 /* |
1580 * Window list object - Implementation | 1681 * Window list object - Implementation |
1581 */ | 1682 */ |
1683 | |
1684 typedef struct | |
1685 { | |
1686 PyObject_HEAD | |
1687 } WinListObject; | |
1688 | |
1689 static PyTypeObject WinListType; | |
1690 static PySequenceMethods BufListAsSeq; | |
1691 | |
1582 static PyInt | 1692 static PyInt |
1583 WinListLength(PyObject *self UNUSED) | 1693 WinListLength(PyObject *self UNUSED) |
1584 { | 1694 { |
1585 win_T *w = firstwin; | 1695 win_T *w = firstwin; |
1586 PyInt n = 0; | 1696 PyInt n = 0; |
2308 | 2418 |
2309 Py_INCREF(Py_None); | 2419 Py_INCREF(Py_None); |
2310 return Py_None; | 2420 return Py_None; |
2311 } | 2421 } |
2312 | 2422 |
2313 | 2423 /* Range object - Definitions |
2314 /* Buffer object - Definitions | |
2315 */ | 2424 */ |
2425 | |
2426 static PyTypeObject RangeType; | |
2316 | 2427 |
2317 typedef struct | 2428 typedef struct |
2318 { | 2429 { |
2319 PyObject_HEAD | 2430 PyObject_HEAD |
2320 BufferObject *buf; | 2431 BufferObject *buf; |
2321 PyInt start; | 2432 PyInt start; |
2322 PyInt end; | 2433 PyInt end; |
2323 } RangeObject; | 2434 } RangeObject; |
2324 | 2435 |
2436 static void RangeDestructor(PyObject *); | |
2437 static PySequenceMethods RangeAsSeq; | |
2438 static PyMappingMethods RangeAsMapping; | |
2439 | |
2325 static PyObject * | 2440 static PyObject * |
2326 RangeNew(buf_T *buf, PyInt start, PyInt end) | 2441 RangeNew(buf_T *buf, PyInt start, PyInt end) |
2327 { | 2442 { |
2328 BufferObject *bufr; | 2443 BufferObject *bufr; |
2329 RangeObject *self; | 2444 RangeObject *self; |
2344 self->end = end; | 2459 self->end = end; |
2345 | 2460 |
2346 return (PyObject *)(self); | 2461 return (PyObject *)(self); |
2347 } | 2462 } |
2348 | 2463 |
2464 static void | |
2465 RangeDestructor(PyObject *self) | |
2466 { | |
2467 Py_DECREF(((RangeObject *)(self))->buf); | |
2468 DESTRUCTOR_FINISH(self); | |
2469 } | |
2470 | |
2471 static PyTypeObject BufferType; | |
2472 static PyObject *BufferRepr(PyObject *); | |
2473 static PySequenceMethods BufferAsSeq; | |
2474 static PyMappingMethods BufferAsMapping; | |
2475 | |
2476 static void | |
2477 BufferDestructor(PyObject *self) | |
2478 { | |
2479 BufferObject *this = (BufferObject *)(self); | |
2480 | |
2481 if (this->buf && this->buf != INVALID_BUFFER_VALUE) | |
2482 #if PY_MAJOR_VERSION >= 3 | |
2483 this->buf->b_python3_ref = NULL; | |
2484 #else | |
2485 this->buf->b_python_ref = NULL; | |
2486 #endif | |
2487 | |
2488 DESTRUCTOR_FINISH(self); | |
2489 } | |
2490 | |
2491 static PyObject * | |
2492 BufferAttr(BufferObject *this, char *name) | |
2493 { | |
2494 if (strcmp(name, "name") == 0) | |
2495 return Py_BuildValue("s", this->buf->b_ffname); | |
2496 else if (strcmp(name, "number") == 0) | |
2497 return Py_BuildValue(Py_ssize_t_fmt, this->buf->b_fnum); | |
2498 else if (strcmp(name,"__members__") == 0) | |
2499 return Py_BuildValue("[ss]", "name", "number"); | |
2500 else | |
2501 return NULL; | |
2502 } | |
2503 | |
2349 static PyObject * | 2504 static PyObject * |
2350 BufferAppend(PyObject *self, PyObject *args) | 2505 BufferAppend(PyObject *self, PyObject *args) |
2351 { | 2506 { |
2352 return RBAppend((BufferObject *)(self), args, 1, | 2507 return RBAppend((BufferObject *)(self), args, 1, |
2353 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count, | 2508 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count, |
2405 | 2560 |
2406 if (!PyArg_ParseTuple(args, "nn", &start, &end)) | 2561 if (!PyArg_ParseTuple(args, "nn", &start, &end)) |
2407 return NULL; | 2562 return NULL; |
2408 | 2563 |
2409 return RangeNew(((BufferObject *)(self))->buf, start, end); | 2564 return RangeNew(((BufferObject *)(self))->buf, start, end); |
2565 } | |
2566 | |
2567 static PyObject * | |
2568 BufferRepr(PyObject *self) | |
2569 { | |
2570 static char repr[100]; | |
2571 BufferObject *this = (BufferObject *)(self); | |
2572 | |
2573 if (this->buf == INVALID_BUFFER_VALUE) | |
2574 { | |
2575 vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self)); | |
2576 return PyString_FromString(repr); | |
2577 } | |
2578 else | |
2579 { | |
2580 char *name = (char *)this->buf->b_fname; | |
2581 PyInt len; | |
2582 | |
2583 if (name == NULL) | |
2584 name = ""; | |
2585 len = strlen(name); | |
2586 | |
2587 if (len > 35) | |
2588 name = name + (35 - len); | |
2589 | |
2590 vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name); | |
2591 | |
2592 return PyString_FromString(repr); | |
2593 } | |
2410 } | 2594 } |
2411 | 2595 |
2412 static struct PyMethodDef BufferMethods[] = { | 2596 static struct PyMethodDef BufferMethods[] = { |
2413 /* name, function, calling, documentation */ | 2597 /* name, function, calling, documentation */ |
2414 {"append", BufferAppend, 1, "Append data to Vim buffer" }, | 2598 {"append", BufferAppend, 1, "Append data to Vim buffer" }, |
2494 static struct PyMethodDef RangeMethods[] = { | 2678 static struct PyMethodDef RangeMethods[] = { |
2495 /* name, function, calling, documentation */ | 2679 /* name, function, calling, documentation */ |
2496 {"append", RangeAppend, 1, "Append data to the Vim range" }, | 2680 {"append", RangeAppend, 1, "Append data to the Vim range" }, |
2497 { NULL, NULL, 0, NULL } | 2681 { NULL, NULL, 0, NULL } |
2498 }; | 2682 }; |
2683 | |
2684 /* Current items object - Implementation | |
2685 */ | |
2686 | |
2687 static PyInt RangeStart; | |
2688 static PyInt RangeEnd; | |
2689 | |
2690 static PyObject * | |
2691 CurrentGetattr(PyObject *self UNUSED, char *name) | |
2692 { | |
2693 if (strcmp(name, "buffer") == 0) | |
2694 return (PyObject *)BufferNew(curbuf); | |
2695 else if (strcmp(name, "window") == 0) | |
2696 return (PyObject *)WindowNew(curwin); | |
2697 else if (strcmp(name, "line") == 0) | |
2698 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum); | |
2699 else if (strcmp(name, "range") == 0) | |
2700 return RangeNew(curbuf, RangeStart, RangeEnd); | |
2701 else if (strcmp(name,"__members__") == 0) | |
2702 return Py_BuildValue("[ssss]", "buffer", "window", "line", "range"); | |
2703 else | |
2704 { | |
2705 PyErr_SetString(PyExc_AttributeError, name); | |
2706 return NULL; | |
2707 } | |
2708 } | |
2709 | |
2710 static int | |
2711 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *value) | |
2712 { | |
2713 if (strcmp(name, "line") == 0) | |
2714 { | |
2715 if (SetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum, value, NULL) == FAIL) | |
2716 return -1; | |
2717 | |
2718 return 0; | |
2719 } | |
2720 else | |
2721 { | |
2722 PyErr_SetString(PyExc_AttributeError, name); | |
2723 return -1; | |
2724 } | |
2725 } | |
2499 | 2726 |
2500 static void | 2727 static void |
2501 set_ref_in_py(const int copyID) | 2728 set_ref_in_py(const int copyID) |
2502 { | 2729 { |
2503 pylinkedlist_T *cur; | 2730 pylinkedlist_T *cur; |
2768 default: | 2995 default: |
2769 PyErr_SetVim(_("internal error: invalid value type")); | 2996 PyErr_SetVim(_("internal error: invalid value type")); |
2770 return NULL; | 2997 return NULL; |
2771 } | 2998 } |
2772 } | 2999 } |
3000 | |
3001 typedef struct | |
3002 { | |
3003 PyObject_HEAD | |
3004 } CurrentObject; | |
3005 static PyTypeObject CurrentType; | |
3006 | |
3007 static void | |
3008 init_structs(void) | |
3009 { | |
3010 vim_memset(&OutputType, 0, sizeof(OutputType)); | |
3011 OutputType.tp_name = "vim.message"; | |
3012 OutputType.tp_basicsize = sizeof(OutputObject); | |
3013 OutputType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3014 OutputType.tp_doc = "vim message object"; | |
3015 OutputType.tp_methods = OutputMethods; | |
3016 #if PY_MAJOR_VERSION >= 3 | |
3017 OutputType.tp_getattro = OutputGetattro; | |
3018 OutputType.tp_setattro = OutputSetattro; | |
3019 OutputType.tp_alloc = call_PyType_GenericAlloc; | |
3020 OutputType.tp_new = call_PyType_GenericNew; | |
3021 OutputType.tp_free = call_PyObject_Free; | |
3022 #else | |
3023 OutputType.tp_getattr = OutputGetattr; | |
3024 OutputType.tp_setattr = OutputSetattr; | |
3025 #endif | |
3026 | |
3027 vim_memset(&BufferType, 0, sizeof(BufferType)); | |
3028 BufferType.tp_name = "vim.buffer"; | |
3029 BufferType.tp_basicsize = sizeof(BufferType); | |
3030 BufferType.tp_dealloc = BufferDestructor; | |
3031 BufferType.tp_repr = BufferRepr; | |
3032 BufferType.tp_as_sequence = &BufferAsSeq; | |
3033 BufferType.tp_as_mapping = &BufferAsMapping; | |
3034 BufferType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3035 BufferType.tp_doc = "vim buffer object"; | |
3036 BufferType.tp_methods = BufferMethods; | |
3037 #if PY_MAJOR_VERSION >= 3 | |
3038 BufferType.tp_getattro = BufferGetattro; | |
3039 BufferType.tp_alloc = call_PyType_GenericAlloc; | |
3040 BufferType.tp_new = call_PyType_GenericNew; | |
3041 BufferType.tp_free = call_PyObject_Free; | |
3042 #else | |
3043 BufferType.tp_getattr = BufferGetattr; | |
3044 #endif | |
3045 | |
3046 vim_memset(&WindowType, 0, sizeof(WindowType)); | |
3047 WindowType.tp_name = "vim.window"; | |
3048 WindowType.tp_basicsize = sizeof(WindowObject); | |
3049 WindowType.tp_dealloc = WindowDestructor; | |
3050 WindowType.tp_repr = WindowRepr; | |
3051 WindowType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3052 WindowType.tp_doc = "vim Window object"; | |
3053 WindowType.tp_methods = WindowMethods; | |
3054 #if PY_MAJOR_VERSION >= 3 | |
3055 WindowType.tp_getattro = WindowGetattro; | |
3056 WindowType.tp_setattro = WindowSetattro; | |
3057 WindowType.tp_alloc = call_PyType_GenericAlloc; | |
3058 WindowType.tp_new = call_PyType_GenericNew; | |
3059 WindowType.tp_free = call_PyObject_Free; | |
3060 #else | |
3061 WindowType.tp_getattr = WindowGetattr; | |
3062 WindowType.tp_setattr = WindowSetattr; | |
3063 #endif | |
3064 | |
3065 vim_memset(&BufListType, 0, sizeof(BufListType)); | |
3066 BufListType.tp_name = "vim.bufferlist"; | |
3067 BufListType.tp_basicsize = sizeof(BufListObject); | |
3068 BufListType.tp_as_sequence = &BufListAsSeq; | |
3069 BufListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3070 BufferType.tp_doc = "vim buffer list"; | |
3071 | |
3072 vim_memset(&WinListType, 0, sizeof(WinListType)); | |
3073 WinListType.tp_name = "vim.windowlist"; | |
3074 WinListType.tp_basicsize = sizeof(WinListType); | |
3075 WinListType.tp_as_sequence = &WinListAsSeq; | |
3076 WinListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3077 WinListType.tp_doc = "vim window list"; | |
3078 | |
3079 vim_memset(&RangeType, 0, sizeof(RangeType)); | |
3080 RangeType.tp_name = "vim.range"; | |
3081 RangeType.tp_basicsize = sizeof(RangeObject); | |
3082 RangeType.tp_dealloc = RangeDestructor; | |
3083 RangeType.tp_repr = RangeRepr; | |
3084 RangeType.tp_as_sequence = &RangeAsSeq; | |
3085 RangeType.tp_as_mapping = &RangeAsMapping; | |
3086 RangeType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3087 RangeType.tp_doc = "vim Range object"; | |
3088 RangeType.tp_methods = RangeMethods; | |
3089 #if PY_MAJOR_VERSION >= 3 | |
3090 RangeType.tp_getattro = RangeGetattro; | |
3091 RangeType.tp_alloc = call_PyType_GenericAlloc; | |
3092 RangeType.tp_new = call_PyType_GenericNew; | |
3093 RangeType.tp_free = call_PyObject_Free; | |
3094 #else | |
3095 RangeType.tp_getattr = RangeGetattr; | |
3096 #endif | |
3097 | |
3098 vim_memset(&CurrentType, 0, sizeof(CurrentType)); | |
3099 CurrentType.tp_name = "vim.currentdata"; | |
3100 CurrentType.tp_basicsize = sizeof(CurrentObject); | |
3101 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3102 CurrentType.tp_doc = "vim current object"; | |
3103 #if PY_MAJOR_VERSION >= 3 | |
3104 CurrentType.tp_getattro = CurrentGetattro; | |
3105 CurrentType.tp_setattro = CurrentSetattro; | |
3106 #else | |
3107 CurrentType.tp_getattr = CurrentGetattr; | |
3108 CurrentType.tp_setattr = CurrentSetattr; | |
3109 #endif | |
3110 | |
3111 vim_memset(&DictionaryType, 0, sizeof(DictionaryType)); | |
3112 DictionaryType.tp_name = "vim.dictionary"; | |
3113 DictionaryType.tp_basicsize = sizeof(DictionaryObject); | |
3114 DictionaryType.tp_dealloc = DictionaryDestructor; | |
3115 DictionaryType.tp_as_mapping = &DictionaryAsMapping; | |
3116 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3117 DictionaryType.tp_doc = "dictionary pushing modifications to vim structure"; | |
3118 DictionaryType.tp_methods = DictionaryMethods; | |
3119 #if PY_MAJOR_VERSION >= 3 | |
3120 DictionaryType.tp_getattro = DictionaryGetattro; | |
3121 DictionaryType.tp_setattro = DictionarySetattro; | |
3122 #else | |
3123 DictionaryType.tp_getattr = DictionaryGetattr; | |
3124 DictionaryType.tp_setattr = DictionarySetattr; | |
3125 #endif | |
3126 | |
3127 vim_memset(&ListType, 0, sizeof(ListType)); | |
3128 ListType.tp_name = "vim.list"; | |
3129 ListType.tp_dealloc = ListDestructor; | |
3130 ListType.tp_basicsize = sizeof(ListObject); | |
3131 ListType.tp_as_sequence = &ListAsSeq; | |
3132 ListType.tp_as_mapping = &ListAsMapping; | |
3133 ListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3134 ListType.tp_doc = "list pushing modifications to vim structure"; | |
3135 ListType.tp_methods = ListMethods; | |
3136 #if PY_MAJOR_VERSION >= 3 | |
3137 ListType.tp_getattro = ListGetattro; | |
3138 ListType.tp_setattro = ListSetattro; | |
3139 #else | |
3140 ListType.tp_getattr = ListGetattr; | |
3141 ListType.tp_setattr = ListSetattr; | |
3142 #endif | |
3143 | |
3144 vim_memset(&FunctionType, 0, sizeof(FunctionType)); | |
3145 FunctionType.tp_name = "vim.list"; | |
3146 FunctionType.tp_basicsize = sizeof(FunctionObject); | |
3147 FunctionType.tp_dealloc = FunctionDestructor; | |
3148 FunctionType.tp_call = FunctionCall; | |
3149 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT; | |
3150 FunctionType.tp_doc = "object that calls vim function"; | |
3151 FunctionType.tp_methods = FunctionMethods; | |
3152 #if PY_MAJOR_VERSION >= 3 | |
3153 FunctionType.tp_getattro = FunctionGetattro; | |
3154 #else | |
3155 FunctionType.tp_getattr = FunctionGetattr; | |
3156 #endif | |
3157 | |
3158 #if PY_MAJOR_VERSION >= 3 | |
3159 vim_memset(&vimmodule, 0, sizeof(vimmodule)); | |
3160 vimmodule.m_name = "vim"; | |
3161 vimmodule.m_doc = "Vim Python interface\n"; | |
3162 vimmodule.m_size = -1; | |
3163 vimmodule.m_methods = VimMethods; | |
3164 #endif | |
3165 } |