Displaying 20 results from an estimated 49 matches for "define_vector_type".
2023 Feb 22
2
[libnbd PATCH v3 05/29] vector: (mostly) factor out DEFINE_VECTOR_EMPTY
...; >
> >>>
> >>> Thinking higher-level now, your new macro is something where we have
> >>> to do a two-step declaration of macro types where we want the new
> >>> function. Would it make more sense to change the signature of the
> >>> DEFINE_VECTOR_TYPE() macro to take a third argument containing the
> >>> function name to call on cleanup paths, with the ability to easily
> >>> write/reuse a no-op function for vectors that don't need to call
> >>> free(), where we can then unconditionally declare name##_empt...
2023 Feb 15
1
[libnbd PATCH v3 05/29] vector: (mostly) factor out DEFINE_VECTOR_EMPTY
...sary, but the extra work is harmless, and
> arguably beneficial for clarity / consistency.)
Agreed that the extra cleanup is not going to affect our hot path.
>
> Expose the "name##_empty" function definition with a new, separate macro:
> DEFINE_VECTOR_EMPTY(). The existent DEFINE_VECTOR_TYPE() macro permits
> such element types that are not pointers, or are pointers to const- and/or
> volatile-qualified objects. Whereas "name##_empty" requires that the
> elements be pointers to dynamically allocated, non-const, non-volatile
> objects.
>
> Signed-off-by: Las...
2020 Apr 15
0
[PATCH nbdkit 1/9] common: Add a generic implementation of vectors.
...THERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <assert.h>
+
+#include "vector.h"
+
+DEFINE_VECTOR_TYPE(int64_vector, int64_t);
+DEFINE_VECTOR_TYPE(string_vector, char *);
+
+static void
+test_int64_vector (void)
+{
+ int64_vector v = empty_vector;
+ size_t i;
+
+ for (i = 0; i < 10; ++i)
+ assert (int64_vector_append (&v, i) == 0);
+ for (i = 0; i < 10; ++i)
+ assert (v.ptr[i] ==...
2020 Apr 15
1
Re: [PATCH nbdkit 2/9] floppy, iso, split, ssh: Use new vector type to store lists of strings.
...struct partition_entry {
> uint8_t bootable; /* 0x00 or 0x80 if bootable */
> @@ -130,6 +131,9 @@ struct dir_entry {
> uint32_t size; /* 0x1C - file size */
> } __attribute__((packed));
>
> +/* Appendable list of struct dir_entry. */
> +DEFINE_VECTOR_TYPE(dir_entries, struct dir_entry);
> +
...but the very first usage is a struct.
The code changes look reasonable.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
2020 Jul 07
0
[nbdkit PATCH 1/3] vector: Add VECT_remove
...\
name##_sort (name *v, \
diff --git a/common/utils/test-vector.c b/common/utils/test-vector.c
index 7b0a7424..a87f89ec 100644
--- a/common/utils/test-vector.c
+++ b/common/utils/test-vector.c
@@ -43,19 +43,43 @@
DEFINE_VECTOR_TYPE(int64_vector, int64_t);
DEFINE_VECTOR_TYPE(string_vector, char *);
+static int
+compare (const int64_t *a, const int64_t *b)
+{
+ return (*a > *b) - (*a < *b);
+}
+
static void
test_int64_vector (void)
{
int64_vector v = empty_vector;
size_t i;
int r;
+ int64_t tmp, *p;
fo...
2023 Mar 28
1
[nbdkit PATCH 1/2] common/utils: document empty_vector compound literal assignment
...a/common/utils/vector.h b/common/utils/vector.h
index ac28c0b5363a..7337d26893eb 100644
--- a/common/utils/vector.h
+++ b/common/utils/vector.h
@@ -55,28 +55,34 @@
/* Use of this macro defines a new type called ?name? containing an
* extensible vector of ?type? elements. For example:
*
* DEFINE_VECTOR_TYPE (string_vector, char *);
*
* defines a new type called ?string_vector? as a vector of ?char *?.
* You can create variables of this type:
*
* string_vector names = empty_vector;
*
+ * or
+ *
+ * string_vector names;
+ * names = (string_vector)empty_vector;
+ *
* where ?names.ptr[...
2023 Feb 22
1
[libnbd PATCH v3 05/29] vector: (mostly) factor out DEFINE_VECTOR_EMPTY
On 2/22/23 09:17, Richard W.M. Jones wrote:
> On Tue, Feb 21, 2023 at 05:23:52PM +0100, Laszlo Ersek wrote:
>> This is doable, but I hope it's not expected that
>> DEFINE_POINTER_VECTOR_TYPE() *enforce* that the element type be a pointer :)
>
>
> You might ignore this for a first draft, but it is apparently possible
> to statically detect this (at least, if using
2020 Jun 02
0
[PATCH nbdkit 3/5] vddk: Miscellaneous improvements to reexec code.
...ns(+), 22 deletions(-)
diff --git a/plugins/vddk/reexec.c b/plugins/vddk/reexec.c
index 5a5e9844..9641ee8c 100644
--- a/plugins/vddk/reexec.c
+++ b/plugins/vddk/reexec.c
@@ -48,6 +48,19 @@
char *reexeced; /* orig LD_LIBRARY_PATH on reexec */
+/* Extensible buffer (string). */
+DEFINE_VECTOR_TYPE(buffer, char);
+
+#define CLEANUP_FREE_BUFFER \
+ __attribute__((cleanup (cleanup_free_buffer)))
+
+static void
+cleanup_free_buffer (buffer *v)
+{
+ free (v->ptr);
+}
+
+/* List of strings. */
DEFINE_VECTOR_TYPE(string_vector, char *);
#define CLEANUP_FREE_STRING_VECTOR \
@@ -68,11 +81,13...
2020 Apr 15
1
Re: [PATCH nbdkit 4/9] common/regions: Use new vector type to store the list of regions.
...e of
> lack of closures in C.
> ---
> @@ -70,38 +72,35 @@ struct region {
> const char *description;
> };
>
> -/* Array of regions. */
> -struct regions {
> - struct region *regions;
> - size_t nr_regions;
> -};
> +/* Vector of struct region. */
> +DEFINE_VECTOR_TYPE(regions, struct region);
>
> -extern void init_regions (struct regions *regions)
> +extern void init_regions (regions *regions)
> __attribute__((__nonnull__ (1)));
This change makes sense (DEFINE_VECTOR_TYPE gives us a typedef, so you
lose the explicit 'struct').
>...
2020 Apr 15
18
[PATCH nbdkit 0/9] Generic vector, and pass $nbdkit_stdio_safe to shell scripts.
This was a rather longer trip around the houses than I anticipated!
The basic purpose of the patch series is to set $nbdkit_stdio_safe to
"0" or "1" in sh and eval plugin scripts.
To do that, I ended up adding a nicer way to manipulate environ lists,
and to do that, I ended up adding a whole generic vector
implementation which is applicable in a lot of different places.
2020 Apr 15
0
[PATCH nbdkit 2/9] floppy, iso, split, ssh: Use new vector type to store lists of strings.
..."
+#include "vector.h"
struct partition_entry {
uint8_t bootable; /* 0x00 or 0x80 if bootable */
@@ -130,6 +131,9 @@ struct dir_entry {
uint32_t size; /* 0x1C - file size */
} __attribute__((packed));
+/* Appendable list of struct dir_entry. */
+DEFINE_VECTOR_TYPE(dir_entries, struct dir_entry);
+
/* On disk directory entry (LFN). */
struct lfn_entry {
uint8_t seq; /* sequence number */
@@ -162,8 +166,7 @@ struct dir {
size_t nr_files;
/* On disk directory table. */
- struct dir_entry *table;
- size_t table_entries;
+ dir_ent...
2020 Apr 19
2
[PATCH nbdkit 1/2] vddk: Use new vector library to allocate the argv list.
...max.h"
#include "rounding.h"
+#include "vector.h"
#include "vddk-structs.h"
@@ -256,12 +257,23 @@ vddk_config (const char *key, const char *value)
* the caller prefers to proceed as if this had not been attempted.
* Thus, no return value is needed.
*/
+DEFINE_VECTOR_TYPE(string_vector, char *);
+
+#define CLEANUP_FREE_STRING_VECTOR \
+ __attribute__((cleanup (cleanup_free_string_vector)))
+
+static void
+cleanup_free_string_vector (string_vector *v)
+{
+ string_vector_iter (v, (void *) free);
+ free (v->ptr);
+}
+
static void
perform_reexec (const char *env...
2020 Apr 19
0
[PATCH nbdkit 2/2] Add insert function and use the new vector library in several places.
...gth, or
+ * NULL-terminated), and lists of numbers. It is generic so could be
+ * used for lists of anything (eg. structs) where being able to append
+ * easily is important.
*/
#ifndef NBDKIT_VECTOR_H
#define NBDKIT_VECTOR_H
#include <assert.h>
+#include <string.h>
#define DEFINE_VECTOR_TYPE(name, type) \
struct name { \
@@ -55,15 +57,23 @@
return generic_vector_extend ((struct generic_vector *)v, n, \
sizeof (type)); \
}...
2023 Mar 28
3
[nbdkit PATCH 0/2] various
I originally meant to post only the "vector.h" patch, but then
(independently) nbdkit wouldn't build. Hence the other (rust plugin)
patch.
Laszlo
Laszlo Ersek (2):
common/utils: document empty_vector compound literal assignment
plugins/rust: restrict predicates-{tree,core} to {1.0.7,1.0.5}
common/utils/vector.h | 8 +++++++-
plugins/rust/Cargo.toml | 2 ++
2 files changed,
2020 Oct 27
6
[PATCH libnbd 0/5] info: --map: Coalesce adjacent extents of the same type.
This adds coalescing of adjacent extents of the same type, as
mentioned by Eric Blake in the commit message here:
https://github.com/libguestfs/libnbd/commit/46072f6611f80245846a445766da071e457b00cd
The patch series is rather long because it detours through adding the
<vector.h> library from nbdkit into libnbd and replacing ad hoc uses
of realloc, char ** etc in various places.
Rich.
2020 Oct 27
0
[PATCH libnbd 1/5] common/utils: Copy simple vector library from nbdkit.
...ere being able to append
+ * easily is important.
+ */
+
+#ifndef NBDKIT_VECTOR_H
+#define NBDKIT_VECTOR_H
+
+#include <assert.h>
+#include <string.h>
+
+/* Use of this macro defines a new type called ‘name’ containing an
+ * extensible vector of ‘type’ elements. For example:
+ *
+ * DEFINE_VECTOR_TYPE(string_vector, char *)
+ *
+ * defines a new type called ‘string_vector’ as a vector of ‘char *’.
+ * You can create variables of this type:
+ *
+ * string_vector names = empty_vector;
+ *
+ * where ‘names.ptr[]’ will be an array of strings and ‘names.size’
+ * will be the number of strings. The...
2020 Apr 15
1
Re: [PATCH nbdkit 1/9] common: Add a generic implementation of vectors.
...ated), and lists of numbers. It is generic
> + * so could be used for lists of anything (eg. structs) where being
> + * able to append easily is important.
> + */
> +
> +#ifndef NBDKIT_VECTOR_H
> +#define NBDKIT_VECTOR_H
> +
> +#include <assert.h>
> +
> +#define DEFINE_VECTOR_TYPE(name, type) \
> + struct name { \
> + type *ptr; /* Pointer to array of items. */ \
> + size_t size; /* Number of valid items in the array. */ \
> + s...
2020 Apr 15
0
[PATCH nbdkit 3/9] server: Use new vector library when building the list of extents.
...100644
--- a/server/extents.c
+++ b/server/extents.c
@@ -42,6 +42,7 @@
#include <assert.h>
#include "minmax.h"
+#include "vector.h"
#include "internal.h"
@@ -51,9 +52,11 @@
*/
#define MAX_EXTENTS (1 * 1024 * 1024)
+/* Appendable list of extents. */
+DEFINE_VECTOR_TYPE(extents, struct nbdkit_extent);
+
struct nbdkit_extents {
- struct nbdkit_extent *extents;
- size_t nr_extents, allocated;
+ extents extents;
uint64_t start, end; /* end is one byte beyond the end of the range */
@@ -92,8 +95,7 @@ nbdkit_extents_new (uint64_t start, uint64_t end)
nb...
2020 Jun 02
0
[PATCH nbdkit 2/5] vddk: Move reexec code to a new file.
...ing.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#define NBDKIT_API_VERSION 2
+#include <nbdkit-plugin.h>
+
+#include "cleanup.h"
+#include "vector.h"
+
+#include "vddk.h"
+
+char *reexeced; /* orig LD_LIBRARY_PATH on reexec */
+
+DEFINE_VECTOR_TYPE(string_vector, char *);
+
+#define CLEANUP_FREE_STRING_VECTOR \
+ __attribute__((cleanup (cleanup_free_string_vector)))
+
+static void
+cleanup_free_string_vector (string_vector *v)
+{
+ string_vector_iter (v, (void *) free);
+ free (v->ptr);
+}
+
+/* Perform a re-exec that temporarily modifi...
2023 Jan 31
1
[PATCH libnbd] generator: Pass LISTEN_FDNAMES=nbd with systemd socket activation
...tion like
> this:
>
> > diff --git a/common/utils/string-vector.h b/common/utils/string-vector.h
> > index 80d7311debfb..5221c70e3f78 100644
> > --- a/common/utils/string-vector.h
> > +++ b/common/utils/string-vector.h
> > @@ -39,4 +39,10 @@
> >
> > DEFINE_VECTOR_TYPE(string_vector, char *);
> >
> > +static inline void
> > +string_free (char *string)
> > +{
> > + free (string);
> > +}
> > +
> > #endif /* STRING_VECTOR_H */
>
> Comments please :)
Agreed.
> (3) At the last hunk, the code suggests we'...