Mercurial > vim
comparison src/vim.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 | d4fa9db88d16 |
children | 7587d892c00c |
comparison
equal
deleted
inserted
replaced
20006:aee3c9266968 | 20007:aadd1cae2ff5 |
---|---|
1573 #define ALLOC_CLEAR_MULT(type, count) (type *)alloc_clear(sizeof(type) * (count)) | 1573 #define ALLOC_CLEAR_MULT(type, count) (type *)alloc_clear(sizeof(type) * (count)) |
1574 #define LALLOC_CLEAR_ONE(type) (type *)lalloc_clear(sizeof(type), FALSE) | 1574 #define LALLOC_CLEAR_ONE(type) (type *)lalloc_clear(sizeof(type), FALSE) |
1575 #define LALLOC_CLEAR_MULT(type, count) (type *)lalloc_clear(sizeof(type) * (count), FALSE) | 1575 #define LALLOC_CLEAR_MULT(type, count) (type *)lalloc_clear(sizeof(type) * (count), FALSE) |
1576 #define LALLOC_MULT(type, count) (type *)lalloc(sizeof(type) * (count), FALSE) | 1576 #define LALLOC_MULT(type, count) (type *)lalloc(sizeof(type) * (count), FALSE) |
1577 | 1577 |
1578 #ifdef HAVE_MEMSET | |
1579 # define vim_memset(ptr, c, size) memset((ptr), (c), (size)) | |
1580 #else | |
1581 void *vim_memset(void *, int, size_t); | |
1582 #endif | |
1583 #define CLEAR_FIELD(field) vim_memset(&(field), 0, sizeof(field)) | |
1584 #define CLEAR_POINTER(ptr) vim_memset((ptr), 0, sizeof(*(ptr))) | |
1585 | |
1578 /* | 1586 /* |
1579 * defines to avoid typecasts from (char_u *) to (char *) and back | 1587 * defines to avoid typecasts from (char_u *) to (char *) and back |
1580 * (vim_strchr() and vim_strrchr() are now in alloc.c) | 1588 * (vim_strchr() and vim_strrchr() are now in alloc.c) |
1581 */ | 1589 */ |
1582 #define STRLEN(s) strlen((char *)(s)) | 1590 #define STRLEN(s) strlen((char *)(s)) |
1705 * (this does not account for maximum name lengths and things like "../dir", | 1713 * (this does not account for maximum name lengths and things like "../dir", |
1706 * thus it is not 100% accurate!) | 1714 * thus it is not 100% accurate!) |
1707 */ | 1715 */ |
1708 #define fnamecmp(x, y) vim_fnamecmp((char_u *)(x), (char_u *)(y)) | 1716 #define fnamecmp(x, y) vim_fnamecmp((char_u *)(x), (char_u *)(y)) |
1709 #define fnamencmp(x, y, n) vim_fnamencmp((char_u *)(x), (char_u *)(y), (size_t)(n)) | 1717 #define fnamencmp(x, y, n) vim_fnamencmp((char_u *)(x), (char_u *)(y), (size_t)(n)) |
1710 | |
1711 #ifdef HAVE_MEMSET | |
1712 # define vim_memset(ptr, c, size) memset((ptr), (c), (size)) | |
1713 #else | |
1714 void *vim_memset(void *, int, size_t); | |
1715 #endif | |
1716 | 1718 |
1717 #if defined(UNIX) || defined(FEAT_GUI) || defined(VMS) \ | 1719 #if defined(UNIX) || defined(FEAT_GUI) || defined(VMS) \ |
1718 || defined(FEAT_CLIENTSERVER) | 1720 || defined(FEAT_CLIENTSERVER) |
1719 # define USE_INPUT_BUF | 1721 # define USE_INPUT_BUF |
1720 #endif | 1722 #endif |