]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
make allocator helpers inlines
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 20 Dec 2023 00:30:13 +0000 (19:30 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 20 Dec 2023 00:30:15 +0000 (19:30 -0500)
this gets us better log messages when using -fsanitize=address

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
tools-util.c
tools-util.h

index 5b0c1bf5d5dddf3f8c04462472608ee76ef86166..8e25cac8b5b1fb16267b10168074731ea7f1bb86 100644 (file)
@@ -51,36 +51,6 @@ char *mprintf(const char *fmt, ...)
        return str;
 }
 
-void *xcalloc(size_t count, size_t size)
-{
-       void *p = calloc(count, size);
-
-       if (!p)
-               die("insufficient memory");
-
-       return p;
-}
-
-void *xmalloc(size_t size)
-{
-       void *p = malloc(size);
-
-       if (!p)
-               die("insufficient memory");
-
-       memset(p, 0, size);
-       return p;
-}
-
-void *xrealloc(void *p, size_t size)
-{
-       p = realloc(p, size);
-       if (!p)
-               die("insufficient memory");
-
-       return p;
-}
-
 void xpread(int fd, void *buf, size_t count, off_t offset)
 {
        while (count) {
index 7a04c1080beb9ae5dc0df82ae40579ad3c20c7d4..174b4e0e9eefc547b268020adbcd5360d392d9e0 100644 (file)
@@ -28,15 +28,42 @@ void die(const char *, ...)
        __attribute__ ((format (printf, 1, 2))) noreturn;
 char *mprintf(const char *, ...)
        __attribute__ ((format (printf, 1, 2)));
-void *xcalloc(size_t, size_t);
-void *xmalloc(size_t);
-void *xrealloc(void *, size_t);
 void xpread(int, void *, size_t, off_t);
 void xpwrite(int, const void *, size_t, off_t, const char *);
 struct stat xfstatat(int, const char *, int);
 struct stat xfstat(int);
 struct stat xstat(const char *);
 
+static inline void *xmalloc(size_t size)
+{
+       void *p = malloc(size);
+
+       if (!p)
+               die("insufficient memory");
+
+       memset(p, 0, size);
+       return p;
+}
+
+static inline void *xcalloc(size_t count, size_t size)
+{
+       void *p = calloc(count, size);
+
+       if (!p)
+               die("insufficient memory");
+
+       return p;
+}
+
+static inline void *xrealloc(void *p, size_t size)
+{
+       p = realloc(p, size);
+       if (!p)
+               die("insufficient memory");
+
+       return p;
+}
+
 #define xopenat(_dirfd, _path, ...)                                    \
 ({                                                                     \
        int _fd = openat((_dirfd), (_path), __VA_ARGS__);               \