[PATCH 3/3] Build required portions of registry.c automatically

Keith Packard keithp at keithp.com
Wed Sep 10 16:00:02 PDT 2014


Instead of making the inclusion of the registry code a global
conditional, split the registry into two pieces; the bits required by
the X-Resource extension (the resource names) and the bits required by
the XCSECURITY extension (the protocol names). Build each set of code
if the related extension is being built.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 configure.ac       |  6 ------
 dix/extension.c    |  2 ++
 dix/registry.c     | 52 +++++++++++++++++++++++++++++++++++++++-------------
 dix/resource.c     |  2 ++
 include/registry.h | 31 +++++++------------------------
 5 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/configure.ac b/configure.ac
index cba7d24..ce76baa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -587,7 +587,6 @@ AC_ARG_WITH(khronos-spec-dir, AS_HELP_STRING([--with-khronos-spec-dir=PATH], [Pa
 				[KHRONOS_SPEC_DIR=auto])
 
 dnl Extensions.
-AC_ARG_ENABLE(registry,       AS_HELP_STRING([--disable-registry], [Build string registry module (default: enabled)]), [XREGISTRY=$enableval], [XREGISTRY=yes])
 AC_ARG_ENABLE(composite,      AS_HELP_STRING([--disable-composite], [Build Composite extension (default: enabled)]), [COMPOSITE=$enableval], [COMPOSITE=yes])
 AC_ARG_ENABLE(mitshm,         AS_HELP_STRING([--disable-mitshm], [Build SHM extension (default: auto)]), [MITSHM=$enableval], [MITSHM=auto])
 AC_ARG_ENABLE(xres,           AS_HELP_STRING([--disable-xres], [Build XRes extension (default: enabled)]), [RES=$enableval], [RES=yes])
@@ -1038,11 +1037,6 @@ if test "x$XVMC" = xyes; then
 	AC_DEFINE(XvMCExtension, 1, [Build XvMC extension])
 fi
 
-AM_CONDITIONAL(XREGISTRY, [test "x$XREGISTRY" = xyes])
-if test "x$XREGISTRY" = xyes; then
-	AC_DEFINE(XREGISTRY, 1, [Build registry module])
-fi
-
 AM_CONDITIONAL(COMPOSITE, [test "x$COMPOSITE" = xyes])
 if test "x$COMPOSITE" = xyes; then
 	AC_DEFINE(COMPOSITE, 1, [Support Composite Extension])
diff --git a/dix/extension.c b/dix/extension.c
index ede4bf5..6fbaa0e 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -139,7 +139,9 @@ AddExtension(const char *name, int NumEvents, int NumErrors,
         ext->errorLast = 0;
     }
 
+#ifdef XCSECURITY
     RegisterExtensionNames(ext);
+#endif
     return ext;
 }
 
diff --git a/dix/registry.c b/dix/registry.c
index 8b76d56..7355990 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -21,8 +21,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <dix-config.h>
 #endif
 
-#ifdef XREGISTRY
-
 #include <stdlib.h>
 #include <string.h>
 #include <X11/X.h>
@@ -31,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "registry.h"
 
 #define BASE_SIZE 16
+
+#ifdef XCSECURITY
 #define CORE "X11"
 #define FILENAME SERVER_MISC_CONFIG_PATH "/protocol.txt"
 
@@ -42,9 +42,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 static FILE *fh;
 
 static char ***requests, **events, **errors;
+static unsigned nmajor, *nminor, nevent, nerror;
+#endif
+
+#ifdef RES
 static const char **resources;
-static unsigned nmajor, *nminor, nevent, nerror, nresource;
+static unsigned nresource;
+#endif
 
+#if defined(RES) || defined(XCSECURITY)
 /*
  * File parsing routines
  */
@@ -72,7 +78,9 @@ double_size(void *p, unsigned n, unsigned size)
     memset(*ptr + s, 0, f - s);
     return TRUE;
 }
+#endif
 
+#ifdef XCSECURITY
 static void
 RegisterRequestName(unsigned major, unsigned minor, char *name)
 {
@@ -196,7 +204,9 @@ RegisterExtensionNames(ExtensionEntry * extEntry)
         free(lineobj);
     }
 }
+#endif /* XCSECURITY */
 
+#ifdef RES
 /*
  * Registration functions
  */
@@ -214,11 +224,14 @@ RegisterResourceName(RESTYPE resource, const char *name)
 
     resources[resource] = name;
 }
+#endif /* RES */
 
 /*
  * Lookup functions
  */
 
+#ifdef XCSECURITY
+
 const char *
 LookupRequestName(int major, int minor)
 {
@@ -269,7 +282,9 @@ LookupErrorName(int error)
 
     return errors[error] ? errors[error] : XREGISTRY_UNKNOWN;
 }
+#endif /* XCSECURITY */
 
+#ifdef RES
 const char *
 LookupResourceName(RESTYPE resource)
 {
@@ -279,10 +294,12 @@ LookupResourceName(RESTYPE resource)
 
     return resources[resource] ? resources[resource] : XREGISTRY_UNKNOWN;
 }
+#endif /* RES */
 
 void
 dixFreeRegistry(void)
 {
+#ifdef XCSECURITY
     /* Free all memory */
     while (nmajor--) {
         while (nminor[nmajor])
@@ -299,25 +316,30 @@ dixFreeRegistry(void)
     while (nerror--)
         free(errors[nerror]);
     free(errors);
-
-    free(resources);
-
     requests = NULL;
     nminor = NULL;
     events = NULL;
     errors = NULL;
-    resources = NULL;
+    nmajor = nevent = nerror = 0;
+#endif
+
+#ifdef RES
+    free(resources);
 
-    nmajor = nevent = nerror = nresource = 0;
+    resources = NULL;
+    nresource = 0;
+#endif
 }
 
 void
 dixCloseRegistry(void)
 {
+#ifdef XCSECURITY
     if (fh) {
 	fclose(fh);
         fh = NULL;
     }
+#endif
 }
 
 /*
@@ -326,16 +348,24 @@ dixCloseRegistry(void)
 void
 dixResetRegistry(void)
 {
+#ifdef XCSECURITY
     ExtensionEntry extEntry = { .name = CORE };
+#endif
 
     dixFreeRegistry();
 
+#ifdef XCSECURITY
     /* Open the protocol file */
     fh = fopen(FILENAME, "r");
     if (!fh)
         LogMessage(X_WARNING,
                    "Failed to open protocol names file " FILENAME "\n");
 
+    /* Add the core protocol */
+    RegisterExtensionNames(&extEntry);
+#endif
+
+#ifdef RES
     /* Add built-in resources */
     RegisterResourceName(RT_NONE, "NONE");
     RegisterResourceName(RT_WINDOW, "WINDOW");
@@ -347,9 +377,5 @@ dixResetRegistry(void)
     RegisterResourceName(RT_CMAPENTRY, "COLORMAP ENTRY");
     RegisterResourceName(RT_OTHERCLIENT, "OTHER CLIENT");
     RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
-
-    /* Add the core protocol */
-    RegisterExtensionNames(&extEntry);
+#endif
 }
-
-#endif                          /* XREGISTRY */
diff --git a/dix/resource.c b/dix/resource.c
index 623d862..f0f5307 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -524,8 +524,10 @@ CreateNewResourceType(DeleteType deleteFunc, const char *name)
     resourceTypes[next].findSubResFunc = DefaultFindSubRes;
     resourceTypes[next].errorValue = BadValue;
 
+#if RES
     /* Called even if name is NULL, to remove any previous entry */
     RegisterResourceName(next, name);
+#endif
 
     return next;
 }
diff --git a/include/registry.h b/include/registry.h
index 4e54bf6..244cef5 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -17,18 +17,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 #define XREGISTRY_UNKNOWN "<unknown>"
 
-#ifdef XREGISTRY
-
 #include "resource.h"
 #include "extnsionst.h"
 
 /* Internal string registry - for auditing, debugging, security, etc. */
 
-/*
- * Registration functions.  The name string is not copied, so it must
- * not be a stack variable.
- */
+#ifdef RES
+/* Functions used by the X-Resource extension */
 extern _X_EXPORT void RegisterResourceName(RESTYPE type, const char *name);
+extern _X_EXPORT const char *LookupResourceName(RESTYPE rtype);
+#endif
+
+#ifdef XCSECURITY
 extern _X_EXPORT void RegisterExtensionNames(ExtensionEntry * ext);
 
 /*
@@ -38,7 +38,7 @@ extern _X_EXPORT const char *LookupMajorName(int major);
 extern _X_EXPORT const char *LookupRequestName(int major, int minor);
 extern _X_EXPORT const char *LookupEventName(int event);
 extern _X_EXPORT const char *LookupErrorName(int error);
-extern _X_EXPORT const char *LookupResourceName(RESTYPE rtype);
+#endif
 
 /*
  * Setup and teardown
@@ -47,21 +47,4 @@ extern _X_EXPORT void dixResetRegistry(void);
 extern _X_EXPORT void dixFreeRegistry(void);
 extern _X_EXPORT void dixCloseRegistry(void);
 
-#else                           /* XREGISTRY */
-
-/* Define calls away when the registry is not being built. */
-
-#define RegisterResourceName(a, b) { ; }
-#define RegisterExtensionNames(a) { ; }
-
-#define LookupMajorName(a) XREGISTRY_UNKNOWN
-#define LookupRequestName(a, b) XREGISTRY_UNKNOWN
-#define LookupEventName(a) XREGISTRY_UNKNOWN
-#define LookupErrorName(a) XREGISTRY_UNKNOWN
-#define LookupResourceName(a) XREGISTRY_UNKNOWN
-
-#define dixResetRegistry() { ; }
-#define dixFreeRegistry() { ; }
-
-#endif                          /* XREGISTRY */
 #endif                          /* DIX_REGISTRY_H */
-- 
2.0.1



More information about the xorg-devel mailing list