]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Remove scratchbuf implementation
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 12 Nov 2024 20:31:36 +0000 (14:31 -0600)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Sun, 17 Nov 2024 21:35:14 +0000 (15:35 -0600)
All its unique features have been ported to strbuf and users converted.
Nuke it.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
Makefile.am
meson.build
shared/scratchbuf.c [deleted file]
shared/scratchbuf.h [deleted file]
testsuite/.gitignore
testsuite/meson.build
testsuite/test-scratchbuf.c [deleted file]

index a7eb1b200a904f876be0fc2ba5ddba3e967a6563..e8ff63183d698775109c05b900444f3c9e25b95e 100644 (file)
@@ -62,8 +62,6 @@ shared_libshared_la_SOURCES = \
        shared/hash.h \
        shared/macro.h \
        shared/missing.h \
-       shared/scratchbuf.c \
-       shared/scratchbuf.h \
        shared/strbuf.c \
        shared/strbuf.h \
        shared/util.c \
@@ -295,7 +293,6 @@ TESTSUITE = \
        testsuite/test-modinfo \
        testsuite/test-modprobe \
        testsuite/test-new-module \
-       testsuite/test-scratchbuf \
        testsuite/test-strbuf \
        testsuite/test-testsuite \
        testsuite/test-util \
@@ -314,9 +311,6 @@ testsuite_test_hash_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 testsuite_test_array_LDADD = $(TESTSUITE_LDADD)
 testsuite_test_array_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 
-testsuite_test_scratchbuf_LDADD = $(TESTSUITE_LDADD)
-testsuite_test_scratchbuf_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
-
 testsuite_test_strbuf_LDADD = $(TESTSUITE_LDADD)
 testsuite_test_strbuf_CPPFLAGS = $(TESTSUITE_CPPFLAGS)
 
index 905342c29d661f17cec895817aa2fdace10c7659..3631dd2af6e575fdf772e710843974d01f8d7d4a 100644 (file)
@@ -343,8 +343,6 @@ libshared = static_library(
     'shared/hash.h',
     'shared/macro.h',
     'shared/missing.h',
-    'shared/scratchbuf.c',
-    'shared/scratchbuf.h',
     'shared/strbuf.c',
     'shared/strbuf.h',
     'shared/util.c',
diff --git a/shared/scratchbuf.c b/shared/scratchbuf.c
deleted file mode 100644 (file)
index 5c51e4b..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// SPDX-License-Identifier: LGPL-2.1-or-later
-/*
- * Copyright (C) 2016  Intel Corporation. All rights reserved.
- */
-#include "scratchbuf.h"
-
-#include <errno.h>
-#include <string.h>
-
-void scratchbuf_init(struct scratchbuf *buf, char *stackbuf, size_t size)
-{
-       buf->bytes = stackbuf;
-       buf->size = size;
-       buf->need_free = false;
-}
-
-int scratchbuf_alloc(struct scratchbuf *buf, size_t size)
-{
-       char *tmp;
-
-       if (size <= buf->size)
-               return 0;
-
-       if (buf->need_free) {
-               tmp = realloc(buf->bytes, size);
-               if (tmp == NULL)
-                       return -ENOMEM;
-       } else {
-               tmp = malloc(size);
-               if (tmp == NULL)
-                       return -ENOMEM;
-               memcpy(tmp, buf->bytes, buf->size);
-       }
-
-       buf->size = size;
-       buf->bytes = tmp;
-       buf->need_free = true;
-
-       return 0;
-}
-
-void scratchbuf_release(struct scratchbuf *buf)
-{
-       if (buf->need_free)
-               free(buf->bytes);
-}
diff --git a/shared/scratchbuf.h b/shared/scratchbuf.h
deleted file mode 100644 (file)
index 7ba8437..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#pragma once
-
-#include <stdbool.h>
-#include <stdlib.h>
-
-#include <shared/macro.h>
-
-/*
- * Buffer abstract data type
- */
-struct scratchbuf {
-       char *bytes;
-       size_t size;
-       bool need_free;
-};
-
-void scratchbuf_init(struct scratchbuf *buf, char *stackbuf, size_t size);
-int scratchbuf_alloc(struct scratchbuf *buf, size_t sz);
-void scratchbuf_release(struct scratchbuf *buf);
-
-/* Return a C string */
-static inline char *scratchbuf_str(struct scratchbuf *buf)
-{
-       return buf->bytes;
-}
-
-#define SCRATCHBUF_INITIALIZER(buf_)                          \
-       {                                                     \
-               .bytes = buf_,                                \
-               .size = sizeof(buf_) + _array_size_chk(buf_), \
-               .need_free = false,                           \
-       }
index ce51cc20610f36de7c38270c35cd8dc7bee6beb6..f0289d473224a1fb77814280e117e96960970e76 100644 (file)
@@ -2,7 +2,6 @@
 *.la
 *.so
 /.dirstamp
-/test-scratchbuf
 /test-strbuf
 /test-array
 /test-util
@@ -21,8 +20,6 @@
 /test-weakdep
 /rootfs
 /stamp-rootfs
-/test-scratchbuf.log
-/test-scratchbuf.trs
 /test-strbuf.log
 /test-strbuf.trs
 /test-array.log
index fdfa6eb121389c8e6551ca11bd3379546ccf17c3..1f49f69895da27c19adca65158c3d058f4022e5e 100644 (file)
@@ -91,7 +91,6 @@ _testsuite = [
   'test-modinfo',
   'test-modprobe',
   'test-new-module',
-  'test-scratchbuf',
   'test-strbuf',
   'test-testsuite',
   'test-util',
diff --git a/testsuite/test-scratchbuf.c b/testsuite/test-scratchbuf.c
deleted file mode 100644 (file)
index b5fdd7f..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-// SPDX-License-Identifier: LGPL-2.1-or-later
-/*
- * Copyright (C)  2016 Intel Corporation. All rights reserved.
- */
-
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <shared/scratchbuf.h>
-
-#include "testsuite.h"
-
-static int test_scratchbuf_onlystack(const struct test *t)
-{
-       struct scratchbuf sbuf;
-       const char *smallstr = "xyz";
-       char buf[3 + 2];
-       char buf2[3 + 1];
-
-       scratchbuf_init(&sbuf, buf, sizeof(buf));
-       assert_return(scratchbuf_alloc(&sbuf, strlen(smallstr) + 1) == 0, EXIT_FAILURE);
-       assert_return(sbuf.need_free == false, EXIT_FAILURE);
-       scratchbuf_release(&sbuf);
-
-       scratchbuf_init(&sbuf, buf2, sizeof(buf2));
-       assert_return(scratchbuf_alloc(&sbuf, strlen(smallstr) + 1) == 0, EXIT_FAILURE);
-       assert_return(sbuf.need_free == false, EXIT_FAILURE);
-       scratchbuf_release(&sbuf);
-
-       memcpy(scratchbuf_str(&sbuf), smallstr, strlen(smallstr) + 1);
-       assert_return(strcmp(scratchbuf_str(&sbuf), smallstr) == 0, EXIT_FAILURE);
-
-       return 0;
-}
-DEFINE_TEST(test_scratchbuf_onlystack,
-           .description = "test scratchbuf for buffer on stack only");
-
-static int test_scratchbuf_heap(const struct test *t)
-{
-       struct scratchbuf sbuf;
-       const char *smallstr = "xyz";
-       const char *largestr = "xyzxyzxyz";
-       const char *largestr2 = "xyzxyzxyzxyzxyz";
-       char buf[3 + 1];
-
-       scratchbuf_init(&sbuf, buf, sizeof(buf));
-
-       /* Initially only on stack */
-       assert_return(scratchbuf_alloc(&sbuf, strlen(smallstr) + 1) == 0, EXIT_FAILURE);
-       assert_return(sbuf.need_free == false, EXIT_FAILURE);
-       memcpy(scratchbuf_str(&sbuf), smallstr, strlen(smallstr) + 1);
-
-       /* Grow once to heap */
-       assert_return(scratchbuf_alloc(&sbuf, strlen(largestr) + 1) == 0, EXIT_FAILURE);
-       assert_return(sbuf.need_free == true, EXIT_FAILURE);
-       assert_return(sbuf.size == strlen(largestr) + 1, EXIT_FAILURE);
-       assert_return(strcmp(scratchbuf_str(&sbuf), smallstr) == 0, EXIT_FAILURE);
-       memcpy(scratchbuf_str(&sbuf), largestr, strlen(largestr) + 1);
-       assert_return(strcmp(scratchbuf_str(&sbuf), largestr) == 0, EXIT_FAILURE);
-
-       /* Grow again - realloc should take place */
-       assert_return(scratchbuf_alloc(&sbuf, strlen(largestr2) + 1) == 0, EXIT_FAILURE);
-       assert_return(sbuf.need_free == true, EXIT_FAILURE);
-       assert_return(sbuf.size == strlen(largestr2) + 1, EXIT_FAILURE);
-       memcpy(scratchbuf_str(&sbuf), largestr2, strlen(largestr2) + 1);
-       assert_return(strcmp(scratchbuf_str(&sbuf), largestr2) == 0, EXIT_FAILURE);
-
-       scratchbuf_release(&sbuf);
-
-       return 0;
-}
-DEFINE_TEST(test_scratchbuf_heap,
-           .description = "test scratchbuf for buffer on that grows to heap");
-
-TESTSUITE_MAIN();