From 29d63ba175ff1ef1587c390b18ce61c8f1c150f3 Mon Sep 17 00:00:00 2001 From: Rami Ylimäki Date: Wed, 30 Mar 2011 16:47:30 +0300 Subject: xkb: Introduce helper function to handle similar reallocations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is preparation for a memory leak fix and doesn't contain any functional changes. Note that two variables are generally used for reallocation and clearing of arrays: geom->sz_elems (reallocation) and geom->num_elems (clearing). The interface of XkbGeomRealloc is deliberately kept simple and it only accepts geom->sz_elems as argument, because that is needed to determine whether the array needs to be resized. When the array is cleared, we just assume that either geom->sz_elems and geom->num_elems are synchronized to be equal or that unused elements are cleared whenever geom->num_elems is set to be less than geom->sz_elems without reallocation. Reviewed-by: Erkki Seppälä Signed-off-by: Rami Ylimäki Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- xkb/xkbgeom.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'xkb/xkbgeom.h') diff --git a/xkb/xkbgeom.h b/xkb/xkbgeom.h index fe4da3806..d10b956a6 100644 --- a/xkb/xkbgeom.h +++ b/xkb/xkbgeom.h @@ -311,6 +311,17 @@ typedef struct _XkbGeometrySizes { unsigned short num_key_aliases; } XkbGeometrySizesRec,*XkbGeometrySizesPtr; +/** + * Specifies which items should be cleared in an XKB geometry array + * when the array is reallocated. + */ +typedef enum +{ + XKB_GEOM_CLEAR_NONE, /* Don't clear any items, just reallocate. */ + XKB_GEOM_CLEAR_EXCESS, /* Clear new extra items after reallocation. */ + XKB_GEOM_CLEAR_ALL /* Clear all items after reallocation. */ +} XkbGeomClearance; + extern XkbPropertyPtr XkbAddGeomProperty( XkbGeometryPtr /* geom */, @@ -507,6 +518,15 @@ XkbFreeGeometry( Bool /* freeMap */ ); +extern Bool +XkbGeomRealloc( + void ** /* buffer */, + int /* szItems */, + int /* nrItems */, + int /* itemSize */, + XkbGeomClearance /* clearance */ +); + extern Status XkbAllocGeomProps( XkbGeometryPtr /* geom */, -- cgit v1.2.3