[PATCH 05/25] constify strings in resource name registry

Alan Coopersmith alan.coopersmith at oracle.com
Sun Dec 11 10:16:18 PST 2011


LookupResourceName already returned a const char *, so just needed
to change the variable we're storing the list in to be a const char **
and then add const to the name argument to RegisterResourceName
(which just stores name in the array) and CreateNewResourceType
(which just passes name to RegisterResourceName).

Clears a bunch of gcc warnings of the form:
registry.c:319:5: warning: passing argument 2 of 'RegisterResourceName' discards qualifiers from pointer target type
registry.c:200:1: note: expected 'char *' but argument is of type 'const char *'

and from all the extensions:
damageext.c: In function 'DamageExtensionInit':
damageext.c:490:5: warning: passing argument 2 of 'CreateNewResourceType' discards qualifiers from pointer target type
../include/resource.h:159:26: note: expected 'char *' but argument is of type 'const char *'

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 dix/registry.c     |    5 +++--
 dix/resource.c     |    2 +-
 include/registry.h |    2 +-
 include/resource.h |    2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/dix/registry.c b/dix/registry.c
index fc35dbb..5ab25ad 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -41,7 +41,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 static FILE *fh;
 
-static char ***requests, **events, **errors, **resources;
+static char ***requests, **events, **errors;
+static const char **resources;
 static unsigned nmajor, *nminor, nevent, nerror, nresource;
 
 /*
@@ -197,7 +198,7 @@ RegisterExtensionNames(ExtensionEntry *extEntry)
  */
 
 void
-RegisterResourceName(RESTYPE resource, char *name)
+RegisterResourceName(RESTYPE resource, const char *name)
 {
     resource &= TypeMask;
 
diff --git a/dix/resource.c b/dix/resource.c
index eb9f049..be8a8f8 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -242,7 +242,7 @@ CallResourceStateCallback(ResourceState state, ResourceRec *res)
 }
 
 RESTYPE
-CreateNewResourceType(DeleteType deleteFunc, char *name)
+CreateNewResourceType(DeleteType deleteFunc, const char *name)
 {
     RESTYPE next = lastResourceType + 1;
     struct ResourceType *types;
diff --git a/include/registry.h b/include/registry.h
index 325f765..44f7925 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -28,7 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * Registration functions.  The name string is not copied, so it must
  * not be a stack variable.
  */
-extern _X_EXPORT void RegisterResourceName(RESTYPE type, char *name);
+extern _X_EXPORT void RegisterResourceName(RESTYPE type, const char *name);
 extern _X_EXPORT void RegisterExtensionNames(ExtensionEntry *ext);
 
 /*
diff --git a/include/resource.h b/include/resource.h
index 772b7b8..5da2819 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -157,7 +157,7 @@ typedef Bool (*FindComplexResType)(
     pointer /*cdata*/);
 
 extern _X_EXPORT RESTYPE CreateNewResourceType(
-    DeleteType /*deleteFunc*/, char * /*name*/);
+    DeleteType /*deleteFunc*/, const char * /*name*/);
 
 extern _X_EXPORT void SetResourceTypeErrorValue(
     RESTYPE /*type*/, int /*errorValue*/);
-- 
1.7.3.2



More information about the xorg-devel mailing list