xserver: Branch 'master' - 2 commits
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Feb 29 10:16:28 UTC 2024
os/alloc.c | 60 ++++++++++++++++++++++++++++++
os/meson.build | 2 +
os/string.c | 73 +++++++++++++++++++++++++++++++++++++
os/utils.c | 112 ---------------------------------------------------------
4 files changed, 135 insertions(+), 112 deletions(-)
New commits:
commit 22a67f7818c8e7abc6448d6b32efb5806ab259f3
Author: Enrico Weigelt, metux IT consult <info at metux.net>
Date: Tue Feb 27 18:01:17 2024 +0100
os: move string functions to separate source file
Unclutter the huge utils.c a bit, by moving out string functions to
their own source file.
Signed-off-by: Enrico Weigelt, metux IT consult <info at metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1336>
diff --git a/os/meson.build b/os/meson.build
index 00375d17c..67c7140ed 100644
--- a/os/meson.build
+++ b/os/meson.build
@@ -12,6 +12,7 @@ srcs_os = [
'oscolor.c',
'osinit.c',
'ospoll.c',
+ 'string.c',
'utils.c',
'xdmauth.c',
'xsha1.c',
diff --git a/os/string.c b/os/string.c
new file mode 100644
index 000000000..f0e34e40b
--- /dev/null
+++ b/os/string.c
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: MIT OR X11
+ *
+ * Copyright © 1987, 1998 The Open Group
+ * Copyright © 2024 Enrico Weigelt, metux IT consult <info at metux.net>
+ */
+#include <dix-config.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "os.h"
+
+char *
+Xstrdup(const char *s)
+{
+ if (s == NULL)
+ return NULL;
+ return strdup(s);
+}
+
+char *
+XNFstrdup(const char *s)
+{
+ char *ret;
+
+ if (s == NULL)
+ return NULL;
+
+ ret = strdup(s);
+ if (!ret)
+ FatalError("XNFstrdup: Out of memory");
+ return ret;
+}
+
+/*
+ * Tokenize a string into a NULL terminated array of strings. Always returns
+ * an allocated array unless an error occurs.
+ */
+char **
+xstrtokenize(const char *str, const char *separators)
+{
+ char **list, **nlist;
+ char *tok, *tmp;
+ unsigned num = 0, n;
+
+ if (!str)
+ return NULL;
+ list = calloc(1, sizeof(*list));
+ if (!list)
+ return NULL;
+ tmp = strdup(str);
+ if (!tmp)
+ goto error;
+ for (tok = strtok(tmp, separators); tok; tok = strtok(NULL, separators)) {
+ nlist = reallocarray(list, num + 2, sizeof(*list));
+ if (!nlist)
+ goto error;
+ list = nlist;
+ list[num] = strdup(tok);
+ if (!list[num])
+ goto error;
+ list[++num] = NULL;
+ }
+ free(tmp);
+ return list;
+
+ error:
+ free(tmp);
+ for (n = 0; n < num; n++)
+ free(list[n]);
+ free(list);
+ return NULL;
+}
diff --git a/os/utils.c b/os/utils.c
index 467fc3b91..ba8ebf97a 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1131,28 +1131,6 @@ set_font_authorizations(char **authorizations, int *authlen, void *client)
#endif /* TCPCONN */
}
-char *
-Xstrdup(const char *s)
-{
- if (s == NULL)
- return NULL;
- return strdup(s);
-}
-
-char *
-XNFstrdup(const char *s)
-{
- char *ret;
-
- if (s == NULL)
- return NULL;
-
- ret = strdup(s);
- if (!ret)
- FatalError("XNFstrdup: Out of memory");
- return ret;
-}
-
void
SmartScheduleStopTimer(void)
{
@@ -1916,46 +1894,6 @@ CheckUserAuthorization(void)
#endif
}
-/*
- * Tokenize a string into a NULL terminated array of strings. Always returns
- * an allocated array unless an error occurs.
- */
-char **
-xstrtokenize(const char *str, const char *separators)
-{
- char **list, **nlist;
- char *tok, *tmp;
- unsigned num = 0, n;
-
- if (!str)
- return NULL;
- list = calloc(1, sizeof(*list));
- if (!list)
- return NULL;
- tmp = strdup(str);
- if (!tmp)
- goto error;
- for (tok = strtok(tmp, separators); tok; tok = strtok(NULL, separators)) {
- nlist = reallocarray(list, num + 2, sizeof(*list));
- if (!nlist)
- goto error;
- list = nlist;
- list[num] = strdup(tok);
- if (!list[num])
- goto error;
- list[++num] = NULL;
- }
- free(tmp);
- return list;
-
- error:
- free(tmp);
- for (n = 0; n < num; n++)
- free(list[n]);
- free(list);
- return NULL;
-}
-
/* Format a signed number into a string in a signal safe manner. The string
* should be at least 21 characters in order to handle all int64_t values.
*/
commit 3e9ac852bc8ddb10459790b37c4c7a2145a6a80b
Author: Enrico Weigelt, metux IT consult <info at metux.net>
Date: Tue Feb 27 17:48:08 2024 +0100
os: move alloc functions to separate source file
Reduce the massive os/utils.c a little bit by moving out the alloc
functions to their own source file.
Signed-off-by: Enrico Weigelt, metux IT consult <info at metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1336>
diff --git a/os/alloc.c b/os/alloc.c
new file mode 100644
index 000000000..d808b0fe8
--- /dev/null
+++ b/os/alloc.c
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: MIT OR X11
+ *
+ * Copyright © 1987, 1998 The Open Group
+ * Copyright © 2024 Enrico Weigelt, metux IT consult <info at metux.net>
+ */
+#include <dix-config.h>
+
+#include <stdlib.h>
+
+#include "os.h"
+
+void *
+XNFalloc(unsigned long amount)
+{
+ void *ptr = malloc(amount);
+
+ if (!ptr)
+ FatalError("Out of memory");
+ return ptr;
+}
+
+/* The original XNFcalloc was used with the xnfcalloc macro which multiplied
+ * the arguments at the call site without allowing calloc to check for overflow.
+ * XNFcallocarray was added to fix that without breaking ABI.
+ */
+void *
+XNFcalloc(unsigned long amount)
+{
+ return XNFcallocarray(1, amount);
+}
+
+void *
+XNFcallocarray(size_t nmemb, size_t size)
+{
+ void *ret = calloc(nmemb, size);
+
+ if (!ret)
+ FatalError("XNFcalloc: Out of memory");
+ return ret;
+}
+
+void *
+XNFrealloc(void *ptr, unsigned long amount)
+{
+ void *ret = realloc(ptr, amount);
+
+ if (!ret)
+ FatalError("XNFrealloc: Out of memory");
+ return ret;
+}
+
+void *
+XNFreallocarray(void *ptr, size_t nmemb, size_t size)
+{
+ void *ret = reallocarray(ptr, nmemb, size);
+
+ if (!ret)
+ FatalError("XNFreallocarray: Out of memory");
+ return ret;
+}
diff --git a/os/meson.build b/os/meson.build
index a6cf8a444..00375d17c 100644
--- a/os/meson.build
+++ b/os/meson.build
@@ -1,6 +1,7 @@
srcs_os = [
'WaitFor.c',
'access.c',
+ 'alloc.c',
'auth.c',
'backtrace.c',
'client.c',
diff --git a/os/utils.c b/os/utils.c
index 8287a66f5..467fc3b91 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1131,56 +1131,6 @@ set_font_authorizations(char **authorizations, int *authlen, void *client)
#endif /* TCPCONN */
}
-void *
-XNFalloc(unsigned long amount)
-{
- void *ptr = malloc(amount);
-
- if (!ptr)
- FatalError("Out of memory");
- return ptr;
-}
-
-/* The original XNFcalloc was used with the xnfcalloc macro which multiplied
- * the arguments at the call site without allowing calloc to check for overflow.
- * XNFcallocarray was added to fix that without breaking ABI.
- */
-void *
-XNFcalloc(unsigned long amount)
-{
- return XNFcallocarray(1, amount);
-}
-
-void *
-XNFcallocarray(size_t nmemb, size_t size)
-{
- void *ret = calloc(nmemb, size);
-
- if (!ret)
- FatalError("XNFcalloc: Out of memory");
- return ret;
-}
-
-void *
-XNFrealloc(void *ptr, unsigned long amount)
-{
- void *ret = realloc(ptr, amount);
-
- if (!ret)
- FatalError("XNFrealloc: Out of memory");
- return ret;
-}
-
-void *
-XNFreallocarray(void *ptr, size_t nmemb, size_t size)
-{
- void *ret = reallocarray(ptr, nmemb, size);
-
- if (!ret)
- FatalError("XNFreallocarray: Out of memory");
- return ret;
-}
-
char *
Xstrdup(const char *s)
{
More information about the xorg-commit
mailing list