From 5d41cec800dc6100b8181b95a08f7803dac6eeb9 Mon Sep 17 00:00:00 2001 From: "Chris Hall (GMCH)" Date: Tue, 24 Nov 2009 19:54:30 +0000 Subject: Upgrade lib/vector.c & .h This upgrade maintains the existing vector operations, but changes the underlying mechanisms. It then adds a number of new functions, extending the operations on vectors. The "struct vector" is redefined, which affects only some code in lib/command.c -- which pokes around inside what should be treated as a private data structure. Pro tem this is supported by a macro. The constant VECTOR_MIN_SIZE has been removed -- if there is a minimum size that should be enforced by the vector code. New functions include: vector_insert_item -- insert item, moving existing items vector_move_item -- move item from place to place in vector vector_delete_item -- delete item and close up gap vector_reverse -- reverse order of vector vector_push_item -- simple push vector_pop_item -- simple pop vector_insert -- insert 1 or more NULL items, moving existing items vector_delete -- delete 1 or more items and close up gap vector_bsearch -- perform binary search on vector vector_sort -- qsort vector vector_copy_here -- make copy of body of vector vector_move_here -- move body of vector vector_copy_append -- append copy of vector to end of another vector_move_append -- move body of vector to the end of another vector_copy_extract -- copy part of one vector to another vector_move_extract -- move part of one vector to another vector_copy_splice -- copy part of one vector to replace part of another, taking a copy of the replaced part vector_move_splice -- move part of one vector to replace part of another, taking a copy of the replaced part vector_copy_replace -- copy part of one vector to replace part of another vector_move_replace -- move part of one vector to replace part of another vector_discard -- discard body of vector vector_chop -- discard any unused memory in body of vector vector_decant -- decant vector to new body Other files affected: command.c: -- removal of VECTOR_MIN_SIZE -- use of vector_sort() -- use of VECTOR_INDEX to poke around inside vector (removing this is TODO) memtypes.c & memory.c -- updating names and comments for vectors vty.c -- removal of VECTOR_MIN_SIZE memory.h -- added SIZE(t,n) macro -- (sizeof(t) * (n)) --- lib/memory.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/memory.h') diff --git a/lib/memory.h b/lib/memory.h index 42eb5cae..037efef2 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -32,7 +32,7 @@ struct mlist { struct memory_list *list; const char *name; }; - + #include "lib/memtypes.h" extern struct mlist mlists[]; @@ -60,6 +60,8 @@ extern struct mlist mlists[]; #define XSTRDUP(mtype, str) zstrdup ((mtype), (str)) #endif /* MEMORY_LOG */ +#define SIZE(t,n) (sizeof(t) * (n)) + /* Prototypes of memory function. */ extern void *zmalloc (int type, size_t size); extern void *zcalloc (int type, size_t size); @@ -69,7 +71,7 @@ extern char *zstrdup (int type, const char *str); extern void *mtype_zmalloc (const char *file, int line, int type, size_t size); -extern void *mtype_zcalloc (const char *file, int line, int type, +extern void *mtype_zcalloc (const char *file, int line, int type, size_t num, size_t size); extern void *mtype_zrealloc (const char *file, int line, int type, void *ptr, -- cgit v1.2.3