comparison src/if_py_both.h @ 20007:aadd1cae2ff5 v8.2.0559

patch 8.2.0559: clearing a struct is verbose Commit: https://github.com/vim/vim/commit/a80faa8930ed5a554beeb2727762538873135e83 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 12 19:37:17 2020 +0200 patch 8.2.0559: clearing a struct is verbose Problem: Clearing a struct is verbose. Solution: Define and use CLEAR_FIELD() and CLEAR_POINTER().
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 Apr 2020 19:45:05 +0200
parents 1f42c49c3d29
children 7e84afe0831e
comparison
equal deleted inserted replaced
20006:aee3c9266968 20007:aadd1cae2ff5
3198 } 3198 }
3199 } 3199 }
3200 3200
3201 if (self->argv || self->self) 3201 if (self->argv || self->self)
3202 { 3202 {
3203 vim_memset(&pt, 0, sizeof(partial_T)); 3203 CLEAR_FIELD(pt);
3204 set_partial(self, &pt, FALSE); 3204 set_partial(self, &pt, FALSE);
3205 pt_ptr = &pt; 3205 pt_ptr = &pt;
3206 } 3206 }
3207 3207
3208 Py_BEGIN_ALLOW_THREADS 3208 Py_BEGIN_ALLOW_THREADS
6418 static PyTypeObject CurrentType; 6418 static PyTypeObject CurrentType;
6419 6419
6420 static void 6420 static void
6421 init_structs(void) 6421 init_structs(void)
6422 { 6422 {
6423 vim_memset(&OutputType, 0, sizeof(OutputType)); 6423 CLEAR_FIELD(OutputType);
6424 OutputType.tp_name = "vim.message"; 6424 OutputType.tp_name = "vim.message";
6425 OutputType.tp_basicsize = sizeof(OutputObject); 6425 OutputType.tp_basicsize = sizeof(OutputObject);
6426 OutputType.tp_flags = Py_TPFLAGS_DEFAULT; 6426 OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
6427 OutputType.tp_doc = "vim message object"; 6427 OutputType.tp_doc = "vim message object";
6428 OutputType.tp_methods = OutputMethods; 6428 OutputType.tp_methods = OutputMethods;
6438 OutputType.tp_setattr = (setattrfunc)OutputSetattr; 6438 OutputType.tp_setattr = (setattrfunc)OutputSetattr;
6439 // Disabled, because this causes a crash in test86 6439 // Disabled, because this causes a crash in test86
6440 // OutputType.tp_base = &PyFile_Type; 6440 // OutputType.tp_base = &PyFile_Type;
6441 #endif 6441 #endif
6442 6442
6443 vim_memset(&IterType, 0, sizeof(IterType)); 6443 CLEAR_FIELD(IterType);
6444 IterType.tp_name = "vim.iter"; 6444 IterType.tp_name = "vim.iter";
6445 IterType.tp_basicsize = sizeof(IterObject); 6445 IterType.tp_basicsize = sizeof(IterObject);
6446 IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; 6446 IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
6447 IterType.tp_doc = "generic iterator object"; 6447 IterType.tp_doc = "generic iterator object";
6448 IterType.tp_iter = (getiterfunc)IterIter; 6448 IterType.tp_iter = (getiterfunc)IterIter;
6449 IterType.tp_iternext = (iternextfunc)IterNext; 6449 IterType.tp_iternext = (iternextfunc)IterNext;
6450 IterType.tp_dealloc = (destructor)IterDestructor; 6450 IterType.tp_dealloc = (destructor)IterDestructor;
6451 IterType.tp_traverse = (traverseproc)IterTraverse; 6451 IterType.tp_traverse = (traverseproc)IterTraverse;
6452 IterType.tp_clear = (inquiry)IterClear; 6452 IterType.tp_clear = (inquiry)IterClear;
6453 6453
6454 vim_memset(&BufferType, 0, sizeof(BufferType)); 6454 CLEAR_FIELD(BufferType);
6455 BufferType.tp_name = "vim.buffer"; 6455 BufferType.tp_name = "vim.buffer";
6456 BufferType.tp_basicsize = sizeof(BufferType); 6456 BufferType.tp_basicsize = sizeof(BufferType);
6457 BufferType.tp_dealloc = (destructor)BufferDestructor; 6457 BufferType.tp_dealloc = (destructor)BufferDestructor;
6458 BufferType.tp_repr = (reprfunc)BufferRepr; 6458 BufferType.tp_repr = (reprfunc)BufferRepr;
6459 BufferType.tp_as_sequence = &BufferAsSeq; 6459 BufferType.tp_as_sequence = &BufferAsSeq;
6470 #else 6470 #else
6471 BufferType.tp_getattr = (getattrfunc)BufferGetattr; 6471 BufferType.tp_getattr = (getattrfunc)BufferGetattr;
6472 BufferType.tp_setattr = (setattrfunc)BufferSetattr; 6472 BufferType.tp_setattr = (setattrfunc)BufferSetattr;
6473 #endif 6473 #endif
6474 6474
6475 vim_memset(&WindowType, 0, sizeof(WindowType)); 6475 CLEAR_FIELD(WindowType);
6476 WindowType.tp_name = "vim.window"; 6476 WindowType.tp_name = "vim.window";
6477 WindowType.tp_basicsize = sizeof(WindowObject); 6477 WindowType.tp_basicsize = sizeof(WindowObject);
6478 WindowType.tp_dealloc = (destructor)WindowDestructor; 6478 WindowType.tp_dealloc = (destructor)WindowDestructor;
6479 WindowType.tp_repr = (reprfunc)WindowRepr; 6479 WindowType.tp_repr = (reprfunc)WindowRepr;
6480 WindowType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; 6480 WindowType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
6491 #else 6491 #else
6492 WindowType.tp_getattr = (getattrfunc)WindowGetattr; 6492 WindowType.tp_getattr = (getattrfunc)WindowGetattr;
6493 WindowType.tp_setattr = (setattrfunc)WindowSetattr; 6493 WindowType.tp_setattr = (setattrfunc)WindowSetattr;
6494 #endif 6494 #endif
6495 6495
6496 vim_memset(&TabPageType, 0, sizeof(TabPageType)); 6496 CLEAR_FIELD(TabPageType);
6497 TabPageType.tp_name = "vim.tabpage"; 6497 TabPageType.tp_name = "vim.tabpage";
6498 TabPageType.tp_basicsize = sizeof(TabPageObject); 6498 TabPageType.tp_basicsize = sizeof(TabPageObject);
6499 TabPageType.tp_dealloc = (destructor)TabPageDestructor; 6499 TabPageType.tp_dealloc = (destructor)TabPageDestructor;
6500 TabPageType.tp_repr = (reprfunc)TabPageRepr; 6500 TabPageType.tp_repr = (reprfunc)TabPageRepr;
6501 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT; 6501 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT;
6508 TabPageType.tp_free = call_PyObject_Free; 6508 TabPageType.tp_free = call_PyObject_Free;
6509 #else 6509 #else
6510 TabPageType.tp_getattr = (getattrfunc)TabPageGetattr; 6510 TabPageType.tp_getattr = (getattrfunc)TabPageGetattr;
6511 #endif 6511 #endif
6512 6512
6513 vim_memset(&BufMapType, 0, sizeof(BufMapType)); 6513 CLEAR_FIELD(BufMapType);
6514 BufMapType.tp_name = "vim.bufferlist"; 6514 BufMapType.tp_name = "vim.bufferlist";
6515 BufMapType.tp_basicsize = sizeof(BufMapObject); 6515 BufMapType.tp_basicsize = sizeof(BufMapObject);
6516 BufMapType.tp_as_mapping = &BufMapAsMapping; 6516 BufMapType.tp_as_mapping = &BufMapAsMapping;
6517 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT; 6517 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT;
6518 BufMapType.tp_iter = BufMapIter; 6518 BufMapType.tp_iter = BufMapIter;
6519 BufferType.tp_doc = "vim buffer list"; 6519 BufferType.tp_doc = "vim buffer list";
6520 6520
6521 vim_memset(&WinListType, 0, sizeof(WinListType)); 6521 CLEAR_FIELD(WinListType);
6522 WinListType.tp_name = "vim.windowlist"; 6522 WinListType.tp_name = "vim.windowlist";
6523 WinListType.tp_basicsize = sizeof(WinListType); 6523 WinListType.tp_basicsize = sizeof(WinListType);
6524 WinListType.tp_as_sequence = &WinListAsSeq; 6524 WinListType.tp_as_sequence = &WinListAsSeq;
6525 WinListType.tp_flags = Py_TPFLAGS_DEFAULT; 6525 WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
6526 WinListType.tp_doc = "vim window list"; 6526 WinListType.tp_doc = "vim window list";
6527 WinListType.tp_dealloc = (destructor)WinListDestructor; 6527 WinListType.tp_dealloc = (destructor)WinListDestructor;
6528 6528
6529 vim_memset(&TabListType, 0, sizeof(TabListType)); 6529 CLEAR_FIELD(TabListType);
6530 TabListType.tp_name = "vim.tabpagelist"; 6530 TabListType.tp_name = "vim.tabpagelist";
6531 TabListType.tp_basicsize = sizeof(TabListType); 6531 TabListType.tp_basicsize = sizeof(TabListType);
6532 TabListType.tp_as_sequence = &TabListAsSeq; 6532 TabListType.tp_as_sequence = &TabListAsSeq;
6533 TabListType.tp_flags = Py_TPFLAGS_DEFAULT; 6533 TabListType.tp_flags = Py_TPFLAGS_DEFAULT;
6534 TabListType.tp_doc = "vim tab page list"; 6534 TabListType.tp_doc = "vim tab page list";
6535 6535
6536 vim_memset(&RangeType, 0, sizeof(RangeType)); 6536 CLEAR_FIELD(RangeType);
6537 RangeType.tp_name = "vim.range"; 6537 RangeType.tp_name = "vim.range";
6538 RangeType.tp_basicsize = sizeof(RangeObject); 6538 RangeType.tp_basicsize = sizeof(RangeObject);
6539 RangeType.tp_dealloc = (destructor)RangeDestructor; 6539 RangeType.tp_dealloc = (destructor)RangeDestructor;
6540 RangeType.tp_repr = (reprfunc)RangeRepr; 6540 RangeType.tp_repr = (reprfunc)RangeRepr;
6541 RangeType.tp_as_sequence = &RangeAsSeq; 6541 RangeType.tp_as_sequence = &RangeAsSeq;
6552 RangeType.tp_free = call_PyObject_Free; 6552 RangeType.tp_free = call_PyObject_Free;
6553 #else 6553 #else
6554 RangeType.tp_getattr = (getattrfunc)RangeGetattr; 6554 RangeType.tp_getattr = (getattrfunc)RangeGetattr;
6555 #endif 6555 #endif
6556 6556
6557 vim_memset(&CurrentType, 0, sizeof(CurrentType)); 6557 CLEAR_FIELD(CurrentType);
6558 CurrentType.tp_name = "vim.currentdata"; 6558 CurrentType.tp_name = "vim.currentdata";
6559 CurrentType.tp_basicsize = sizeof(CurrentObject); 6559 CurrentType.tp_basicsize = sizeof(CurrentObject);
6560 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT; 6560 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
6561 CurrentType.tp_doc = "vim current object"; 6561 CurrentType.tp_doc = "vim current object";
6562 CurrentType.tp_methods = CurrentMethods; 6562 CurrentType.tp_methods = CurrentMethods;
6566 #else 6566 #else
6567 CurrentType.tp_getattr = (getattrfunc)CurrentGetattr; 6567 CurrentType.tp_getattr = (getattrfunc)CurrentGetattr;
6568 CurrentType.tp_setattr = (setattrfunc)CurrentSetattr; 6568 CurrentType.tp_setattr = (setattrfunc)CurrentSetattr;
6569 #endif 6569 #endif
6570 6570
6571 vim_memset(&DictionaryType, 0, sizeof(DictionaryType)); 6571 CLEAR_FIELD(DictionaryType);
6572 DictionaryType.tp_name = "vim.dictionary"; 6572 DictionaryType.tp_name = "vim.dictionary";
6573 DictionaryType.tp_basicsize = sizeof(DictionaryObject); 6573 DictionaryType.tp_basicsize = sizeof(DictionaryObject);
6574 DictionaryType.tp_dealloc = (destructor)DictionaryDestructor; 6574 DictionaryType.tp_dealloc = (destructor)DictionaryDestructor;
6575 DictionaryType.tp_as_sequence = &DictionaryAsSeq; 6575 DictionaryType.tp_as_sequence = &DictionaryAsSeq;
6576 DictionaryType.tp_as_mapping = &DictionaryAsMapping; 6576 DictionaryType.tp_as_mapping = &DictionaryAsMapping;
6586 #else 6586 #else
6587 DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr; 6587 DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr;
6588 DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr; 6588 DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr;
6589 #endif 6589 #endif
6590 6590
6591 vim_memset(&ListType, 0, sizeof(ListType)); 6591 CLEAR_FIELD(ListType);
6592 ListType.tp_name = "vim.list"; 6592 ListType.tp_name = "vim.list";
6593 ListType.tp_dealloc = (destructor)ListDestructor; 6593 ListType.tp_dealloc = (destructor)ListDestructor;
6594 ListType.tp_basicsize = sizeof(ListObject); 6594 ListType.tp_basicsize = sizeof(ListObject);
6595 ListType.tp_as_sequence = &ListAsSeq; 6595 ListType.tp_as_sequence = &ListAsSeq;
6596 ListType.tp_as_mapping = &ListAsMapping; 6596 ListType.tp_as_mapping = &ListAsMapping;
6606 #else 6606 #else
6607 ListType.tp_getattr = (getattrfunc)ListGetattr; 6607 ListType.tp_getattr = (getattrfunc)ListGetattr;
6608 ListType.tp_setattr = (setattrfunc)ListSetattr; 6608 ListType.tp_setattr = (setattrfunc)ListSetattr;
6609 #endif 6609 #endif
6610 6610
6611 vim_memset(&FunctionType, 0, sizeof(FunctionType)); 6611 CLEAR_FIELD(FunctionType);
6612 FunctionType.tp_name = "vim.function"; 6612 FunctionType.tp_name = "vim.function";
6613 FunctionType.tp_basicsize = sizeof(FunctionObject); 6613 FunctionType.tp_basicsize = sizeof(FunctionObject);
6614 FunctionType.tp_dealloc = (destructor)FunctionDestructor; 6614 FunctionType.tp_dealloc = (destructor)FunctionDestructor;
6615 FunctionType.tp_call = (ternaryfunc)FunctionCall; 6615 FunctionType.tp_call = (ternaryfunc)FunctionCall;
6616 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; 6616 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
6623 FunctionType.tp_getattro = (getattrofunc)FunctionGetattro; 6623 FunctionType.tp_getattro = (getattrofunc)FunctionGetattro;
6624 #else 6624 #else
6625 FunctionType.tp_getattr = (getattrfunc)FunctionGetattr; 6625 FunctionType.tp_getattr = (getattrfunc)FunctionGetattr;
6626 #endif 6626 #endif
6627 6627
6628 vim_memset(&OptionsType, 0, sizeof(OptionsType)); 6628 CLEAR_FIELD(OptionsType);
6629 OptionsType.tp_name = "vim.options"; 6629 OptionsType.tp_name = "vim.options";
6630 OptionsType.tp_basicsize = sizeof(OptionsObject); 6630 OptionsType.tp_basicsize = sizeof(OptionsObject);
6631 OptionsType.tp_as_sequence = &OptionsAsSeq; 6631 OptionsType.tp_as_sequence = &OptionsAsSeq;
6632 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; 6632 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
6633 OptionsType.tp_doc = "object for manipulating options"; 6633 OptionsType.tp_doc = "object for manipulating options";
6636 OptionsType.tp_dealloc = (destructor)OptionsDestructor; 6636 OptionsType.tp_dealloc = (destructor)OptionsDestructor;
6637 OptionsType.tp_traverse = (traverseproc)OptionsTraverse; 6637 OptionsType.tp_traverse = (traverseproc)OptionsTraverse;
6638 OptionsType.tp_clear = (inquiry)OptionsClear; 6638 OptionsType.tp_clear = (inquiry)OptionsClear;
6639 6639
6640 #if PY_VERSION_HEX < 0x030700f0 6640 #if PY_VERSION_HEX < 0x030700f0
6641 vim_memset(&LoaderType, 0, sizeof(LoaderType)); 6641 CLEAR_FIELD(LoaderType);
6642 LoaderType.tp_name = "vim.Loader"; 6642 LoaderType.tp_name = "vim.Loader";
6643 LoaderType.tp_basicsize = sizeof(LoaderObject); 6643 LoaderType.tp_basicsize = sizeof(LoaderObject);
6644 LoaderType.tp_flags = Py_TPFLAGS_DEFAULT; 6644 LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
6645 LoaderType.tp_doc = "vim message object"; 6645 LoaderType.tp_doc = "vim message object";
6646 LoaderType.tp_methods = LoaderMethods; 6646 LoaderType.tp_methods = LoaderMethods;
6647 LoaderType.tp_dealloc = (destructor)LoaderDestructor; 6647 LoaderType.tp_dealloc = (destructor)LoaderDestructor;
6648 #endif 6648 #endif
6649 6649
6650 #if PY_MAJOR_VERSION >= 3 6650 #if PY_MAJOR_VERSION >= 3
6651 vim_memset(&vimmodule, 0, sizeof(vimmodule)); 6651 CLEAR_FIELD(vimmodule);
6652 vimmodule.m_name = "vim"; 6652 vimmodule.m_name = "vim";
6653 vimmodule.m_doc = "Vim Python interface\n"; 6653 vimmodule.m_doc = "Vim Python interface\n";
6654 vimmodule.m_size = -1; 6654 vimmodule.m_size = -1;
6655 vimmodule.m_methods = VimMethods; 6655 vimmodule.m_methods = VimMethods;
6656 #endif 6656 #endif