[PATCH] Constify atom name strings
Changes MakeAtom to take a const char * and NameForAtom to return them, since many callers pass pointers to constant strings stored in read-only ELF sections. Updates in-tree callers as necessary to clear const mismatch warnings introduced by this change. Signed-off-by: Alan Coopersmith alan.coopersm...@sun.com --- dix/atom.c | 15 --- dix/dispatch.c |2 +- hw/dmx/dmxfont.c |4 ++-- hw/kdrive/ephyr/ephyrvideo.c |2 +- hw/xnest/Font.c |4 ++-- include/dix.h|4 ++-- include/xkbsrv.h |2 +- xfixes/cursor.c |4 ++-- xkb/xkb.c|2 +- xkb/xkbfmisc.c |2 +- xkb/xkbtext.c| 18 +++--- xkb/xkmread.c|2 +- 12 files changed, 33 insertions(+), 28 deletions(-) diff --git a/dix/atom.c b/dix/atom.c index ab9ee80..f5bf8ad 100644 --- a/dix/atom.c +++ b/dix/atom.c @@ -64,7 +64,7 @@ typedef struct _Node { struct _Node *left, *right; Atom a; unsigned int fingerPrint; -char *string; +const char *string; } NodeRec, *NodePtr; static Atom lastAtom = None; @@ -75,7 +75,7 @@ static NodePtr *nodeTable; void FreeAtom(NodePtr patom); Atom -MakeAtom(char *string, unsigned len, Bool makeit) +MakeAtom(const char *string, unsigned len, Bool makeit) { NodePtr * np; unsigned i; @@ -118,13 +118,14 @@ MakeAtom(char *string, unsigned len, Bool makeit) } else { - nd-string = xalloc(len + 1); - if (!nd-string) { + char *newstring = xalloc(len + 1); + if (!newstring) { xfree(nd); return BAD_RESOURCE; } - strncpy(nd-string, string, (int)len); - nd-string[len] = 0; + strncpy(newstring, string, (int)len); + newstring[len] = 0; + nd-string = newstring; } if ((lastAtom + 1) = tableLength) { NodePtr *table; @@ -157,7 +158,7 @@ ValidAtom(Atom atom) return (atom != None) (atom = lastAtom); } -char * +const char * NameForAtom(Atom atom) { NodePtr node; diff --git a/dix/dispatch.c b/dix/dispatch.c index 5cde80b..b06f4aa 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -901,7 +901,7 @@ ProcInternAtom(ClientPtr client) int ProcGetAtomName(ClientPtr client) { -char *str; +const char *str; xGetAtomNameReply reply; int len; REQUEST(xResourceReq); diff --git a/hw/dmx/dmxfont.c b/hw/dmx/dmxfont.c index b70f7d2..c33aee7 100644 --- a/hw/dmx/dmxfont.c +++ b/hw/dmx/dmxfont.c @@ -253,7 +253,7 @@ Bool dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont) { DMXScreenInfo *dmxScreen = dmxScreens[pScreen-myNum]; dmxFontPrivPtr pFontPriv = FontGetPrivate(pFont, dmxFontPrivateIndex); -char *name; +const char *name; char **oldFontPath = NULL; int nOldPaths; Atomname_atom, value_atom; @@ -415,7 +415,7 @@ Bool dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont) } if (!value_atom) return FALSE; -name = (char *)NameForAtom(value_atom); +name = NameForAtom(value_atom); if (!name) return FALSE; pFontPriv-font[pScreen-myNum] = diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c index c4eb066..5058ebe 100644 --- a/hw/kdrive/ephyr/ephyrvideo.c +++ b/hw/kdrive/ephyr/ephyrvideo.c @@ -236,7 +236,7 @@ DoSimpleClip (BoxPtr a_dst_box, static Bool ephyrLocalAtomToHost (int a_local_atom, int *a_host_atom) { -char *atom_name=NULL; +const char *atom_name=NULL; int host_atom=None ; EPHYR_RETURN_VAL_IF_FAIL (a_host_atom, FALSE) ; diff --git a/hw/xnest/Font.c b/hw/xnest/Font.c index 26faf16..7b388f0 100644 --- a/hw/xnest/Font.c +++ b/hw/xnest/Font.c @@ -40,7 +40,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont) int nprops; FontPropPtr props; int i; - char *name; + const char *name; FontSetPrivate(pFont, xnestFontPrivateIndex, NULL); @@ -58,7 +58,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont) if (!value_atom) return False; - name = (char *)NameForAtom(value_atom); + name = NameForAtom(value_atom); if (!name) return False; diff --git a/include/dix.h b/include/dix.h index b210846..658dd29 100644 --- a/include/dix.h +++ b/include/dix.h @@ -280,14 +280,14 @@ extern _X_EXPORT Bool ClientIsAsleep( /* atom.c */ extern _X_EXPORT Atom MakeAtom( -char * /*string*/, +const char * /*string*/, unsigned /*len*/, Bool /*makeit*/); extern _X_EXPORT Bool ValidAtom( Atom /*atom*/); -extern _X_EXPORT char *NameForAtom( +extern _X_EXPORT const char *NameForAtom( Atom /*atom*/); extern _X_EXPORT void AtomError(void); diff --git a/include/xkbsrv.h b/include/xkbsrv.h index 8f6a767..4497220 100644 --- a/include/xkbsrv.h +++ b/include/xkbsrv.h @@ -880,7 +880,7 @@ extern _X_EXPORT
Re: [PATCH] Constify atom name strings
On Mon, Feb 02, 2009 at 07:30:47PM -0800, Alan Coopersmith wrote: Changes MakeAtom to take a const char * and NameForAtom to return them, since many callers pass pointers to constant strings stored in read-only ELF sections. Updates in-tree callers as necessary to clear const mismatch warnings introduced by this change. Signed-off-by: Alan Coopersmith alan.coopersm...@sun.com --- dix/atom.c | 15 --- dix/dispatch.c |2 +- hw/dmx/dmxfont.c |4 ++-- hw/kdrive/ephyr/ephyrvideo.c |2 +- hw/xnest/Font.c |4 ++-- include/dix.h|4 ++-- include/xkbsrv.h |2 +- xfixes/cursor.c |4 ++-- xkb/xkb.c|2 +- xkb/xkbfmisc.c |2 +- xkb/xkbtext.c| 18 +++--- xkb/xkmread.c|2 +- 12 files changed, 33 insertions(+), 28 deletions(-) diff --git a/dix/atom.c b/dix/atom.c index ab9ee80..f5bf8ad 100644 --- a/dix/atom.c +++ b/dix/atom.c @@ -64,7 +64,7 @@ typedef struct _Node { struct _Node *left, *right; Atom a; unsigned int fingerPrint; -char *string; +const char *string; } NodeRec, *NodePtr; static Atom lastAtom = None; @@ -75,7 +75,7 @@ static NodePtr *nodeTable; void FreeAtom(NodePtr patom); Atom -MakeAtom(char *string, unsigned len, Bool makeit) +MakeAtom(const char *string, unsigned len, Bool makeit) { NodePtr * np; unsigned i; @@ -118,13 +118,14 @@ MakeAtom(char *string, unsigned len, Bool makeit) } else { - nd-string = xalloc(len + 1); - if (!nd-string) { + char *newstring = xalloc(len + 1); + if (!newstring) { xfree(nd); return BAD_RESOURCE; } - strncpy(nd-string, string, (int)len); - nd-string[len] = 0; + strncpy(newstring, string, (int)len); + newstring[len] = 0; + nd-string = newstring; } if ((lastAtom + 1) = tableLength) { NodePtr *table; @@ -157,7 +158,7 @@ ValidAtom(Atom atom) return (atom != None) (atom = lastAtom); } -char * +const char * NameForAtom(Atom atom) { NodePtr node; diff --git a/dix/dispatch.c b/dix/dispatch.c index 5cde80b..b06f4aa 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -901,7 +901,7 @@ ProcInternAtom(ClientPtr client) int ProcGetAtomName(ClientPtr client) { -char *str; +const char *str; xGetAtomNameReply reply; int len; REQUEST(xResourceReq); diff --git a/hw/dmx/dmxfont.c b/hw/dmx/dmxfont.c index b70f7d2..c33aee7 100644 --- a/hw/dmx/dmxfont.c +++ b/hw/dmx/dmxfont.c @@ -253,7 +253,7 @@ Bool dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont) { DMXScreenInfo *dmxScreen = dmxScreens[pScreen-myNum]; dmxFontPrivPtr pFontPriv = FontGetPrivate(pFont, dmxFontPrivateIndex); -char *name; +const char *name; char **oldFontPath = NULL; int nOldPaths; Atomname_atom, value_atom; @@ -415,7 +415,7 @@ Bool dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont) } if (!value_atom) return FALSE; -name = (char *)NameForAtom(value_atom); +name = NameForAtom(value_atom); if (!name) return FALSE; pFontPriv-font[pScreen-myNum] = diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c index c4eb066..5058ebe 100644 --- a/hw/kdrive/ephyr/ephyrvideo.c +++ b/hw/kdrive/ephyr/ephyrvideo.c @@ -236,7 +236,7 @@ DoSimpleClip (BoxPtr a_dst_box, static Bool ephyrLocalAtomToHost (int a_local_atom, int *a_host_atom) { -char *atom_name=NULL; +const char *atom_name=NULL; int host_atom=None ; EPHYR_RETURN_VAL_IF_FAIL (a_host_atom, FALSE) ; diff --git a/hw/xnest/Font.c b/hw/xnest/Font.c index 26faf16..7b388f0 100644 --- a/hw/xnest/Font.c +++ b/hw/xnest/Font.c @@ -40,7 +40,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont) int nprops; FontPropPtr props; int i; - char *name; + const char *name; FontSetPrivate(pFont, xnestFontPrivateIndex, NULL); @@ -58,7 +58,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont) if (!value_atom) return False; - name = (char *)NameForAtom(value_atom); + name = NameForAtom(value_atom); if (!name) return False; diff --git a/include/dix.h b/include/dix.h index b210846..658dd29 100644 --- a/include/dix.h +++ b/include/dix.h @@ -280,14 +280,14 @@ extern _X_EXPORT Bool ClientIsAsleep( /* atom.c */ extern _X_EXPORT Atom MakeAtom( -char * /*string*/, +const char * /*string*/, unsigned /*len*/, Bool /*makeit*/); extern _X_EXPORT Bool ValidAtom( Atom /*atom*/); -extern _X_EXPORT char *NameForAtom( +extern _X_EXPORT const char *NameForAtom( Atom /*atom*/); extern