mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 02:21:51 +00:00
unittest: Add dict_items function
This commit is contained in:
@@ -6445,7 +6445,7 @@ void dict_free(dict_T *d) {
|
||||
*/
|
||||
dictitem_T *dictitem_alloc(char_u *key) FUNC_ATTR_NONNULL_RET
|
||||
{
|
||||
dictitem_T *di = xmalloc(sizeof(dictitem_T) + STRLEN(key));
|
||||
dictitem_T *di = xmalloc(offsetof(dictitem_T, di_key) + STRLEN(key) + 1);
|
||||
#ifndef __clang_analyzer__
|
||||
STRCPY(di->di_key, key);
|
||||
#endif
|
||||
|
||||
@@ -409,10 +409,6 @@ EXTERN struct caller_scope {
|
||||
} provider_caller_scope;
|
||||
EXTERN int provider_call_nesting INIT(= 0);
|
||||
|
||||
/* Magic number used for hashitem "hi_key" value indicating a deleted item.
|
||||
* Only the address is used. */
|
||||
EXTERN char_u hash_removed;
|
||||
|
||||
|
||||
EXTERN int t_colors INIT(= 256); // int value of T_CCO
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
# include "hashtab.c.generated.h"
|
||||
#endif
|
||||
|
||||
char hash_removed;
|
||||
|
||||
/// Initialize an empty hash table.
|
||||
void hash_init(hashtab_T *ht)
|
||||
{
|
||||
@@ -380,3 +382,13 @@ hash_T hash_hash(char_u *key)
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/// Function to get HI_KEY_REMOVED value
|
||||
///
|
||||
/// Used for testing because luajit ffi does not allow getting addresses of
|
||||
/// globals.
|
||||
const char_u *_hash_key_removed(void)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
return HI_KEY_REMOVED;
|
||||
}
|
||||
|
||||
@@ -5,14 +5,19 @@
|
||||
|
||||
#include "nvim/types.h"
|
||||
|
||||
/// Magic number used for hashitem "hi_key" value indicating a deleted item
|
||||
///
|
||||
/// Only the address is used.
|
||||
extern char hash_removed;
|
||||
|
||||
/// Type for hash number (hash calculation result).
|
||||
typedef size_t hash_T;
|
||||
|
||||
/// The address of "hash_removed" is used as a magic number
|
||||
/// for hi_key to indicate a removed item.
|
||||
#define HI_KEY_REMOVED &hash_removed
|
||||
#define HI_KEY_REMOVED ((char_u *)&hash_removed)
|
||||
#define HASHITEM_EMPTY(hi) ((hi)->hi_key == NULL \
|
||||
|| (hi)->hi_key == &hash_removed)
|
||||
|| (hi)->hi_key == (char_u *)&hash_removed)
|
||||
|
||||
/// A hastable item.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user