xkb: Introduce helper function to handle similar reallocations.

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ä <erkki.seppala@vincit.fi>
Signed-off-by: Rami Ylimäki <rami.ylimaki@vincit.fi>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Rami Ylimäki 2011-03-30 16:47:30 +03:00 • committed by Peter Hutterer
commit 29d63ba175
3 changed files with 111 additions and 94 deletions

View file

@ -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 */,