]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/alloc/x/: X*ALLOC(): Reimplement in terms of exit_if_null()
authorAlejandro Colomar <alx@kernel.org>
Sun, 8 Dec 2024 11:09:15 +0000 (12:09 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 27 Oct 2025 13:32:06 +0000 (14:32 +0100)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/alloc/x/xcalloc.c
lib/alloc/x/xcalloc.h
lib/alloc/x/xmalloc.c
lib/alloc/x/xmalloc.h
lib/alloc/x/xrealloc.c
lib/alloc/x/xrealloc.h

index e236e7eccc46c8c2255acab9c89d69573d8dd898..107f054908b769cbc7fdfab45b72582ab7f22e7c 100644 (file)
@@ -1,7 +1,3 @@
-// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
-// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
-// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
-// SPDX-FileCopyrightText: 2008     , Nicolas François
 // SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
@@ -9,28 +5,3 @@
 #include "config.h"
 
 #include "alloc/x/xcalloc.h"
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "defines.h"
-#include "shadowlog.h"
-
-
-void *
-xcalloc(size_t nmemb, size_t size)
-{
-       void  *p;
-
-       p = calloc(nmemb, size);
-       if (p == NULL)
-               goto x;
-
-       return p;
-
-x:
-       fprintf(log_get_logfd(), _("%s: %s\n"),
-               log_get_progname(), strerror(errno));
-       exit(13);
-}
index 03f6c3e7858ac74fce209b854d5a759937893092..849d0728b3027942141d9db6f87b5f79c6be8eda 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
 
@@ -8,21 +8,11 @@
 
 #include "config.h"
 
-#include <stddef.h>
-#include <stdlib.h>
+#include "alloc/calloc.h"
+#include "exit_if_null.h"
 
-#include "attr.h"
 
-
-#define XCALLOC(n, type)                                                      \
-(                                                                             \
-       (type *) xcalloc(n, sizeof(type))                                     \
-)
-
-
-ATTR_ALLOC_SIZE(1, 2)
-ATTR_MALLOC(free)
-void *xcalloc(size_t nmemb, size_t size);
+#define XCALLOC(n, type)  exit_if_null(CALLOC(n, type))
 
 
 #endif  // include guard
index 6d19a660951f1ba41a0bfbdd163c4b9b3c065faf..ab03820b753f886d8661797a4d5f96b1b99cc6db 100644 (file)
@@ -1,7 +1,3 @@
-// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
-// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
-// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
-// SPDX-FileCopyrightText: 2008     , Nicolas François
 // SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
@@ -9,8 +5,3 @@
 #include "config.h"
 
 #include "alloc/x/xmalloc.h"
-
-#include <stddef.h>
-
-
-extern inline void *xmallocarray(size_t nmemb, size_t size);
index 06664a8b880b9cbddb925d12da3ae3581c77a761..5a1c13bc4baf4846886926c7c53c6f3727d285b7 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
 
@@ -8,28 +8,11 @@
 
 #include "config.h"
 
-#include <stddef.h>
+#include "alloc/malloc.h"
+#include "exit_if_null.h"
 
-#include "alloc/x/xrealloc.h"
-#include "attr.h"
 
-
-#define XMALLOC(n, type)                                                      \
-(                                                                             \
-       (type *) xmallocarray(n, sizeof(type))                                \
-)
-
-
-ATTR_ALLOC_SIZE(1, 2)
-ATTR_MALLOC(free)
-inline void *xmallocarray(size_t nmemb, size_t size);
-
-
-inline void *
-xmallocarray(size_t nmemb, size_t size)
-{
-       return xreallocarray(NULL, nmemb, size);
-}
+#define XMALLOC(n, type)  exit_if_null(MALLOC(n, type))
 
 
 #endif  // include guard
index 7269f5c981fc99a5e9b8299edd20045f2bee8332..d04ed24869f54ee60a1f142350b54e6dc5b89257 100644 (file)
@@ -1,7 +1,3 @@
-// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
-// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
-// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
-// SPDX-FileCopyrightText: 2008     , Nicolas François
 // SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
@@ -9,27 +5,3 @@
 #include "config.h"
 
 #include "alloc/x/xrealloc.h"
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "alloc/reallocf.h"
-#include "defines.h"
-#include "shadowlog.h"
-
-
-void *
-xreallocarray(void *p, size_t nmemb, size_t size)
-{
-       p = reallocarrayf(p, nmemb, size);
-       if (p == NULL)
-               goto x;
-
-       return p;
-
-x:
-       fprintf(log_get_logfd(), _("%s: %s\n"),
-               log_get_progname(), strerror(errno));
-       exit(13);
-}
index c8d126eb19982826658d5fdc465d9b1b77da94f6..c395a7308112780d682d08c4eab00591c584a2cd 100644 (file)
@@ -1,31 +1,18 @@
-// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
 
-#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
-#define SHADOW_INCLUDE_LIB_MALLOC_H_
+#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XREALLOC_H_
+#define SHADOW_INCLUDE_LIB_ALLOC_X_XREALLOC_H_
 
 
 #include "config.h"
 
-#include <assert.h>
-#include <errno.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
+#include "alloc/realloc.h"
+#include "exit_if_null.h"
 
-#include "attr.h"
 
-
-#define XREALLOC(ptr, n, type)                                                \
-(                                                                             \
-       _Generic(ptr, type *:  (type *) xreallocarray(ptr, n, sizeof(type)))  \
-)
-
-
-ATTR_ALLOC_SIZE(2, 3)
-ATTR_MALLOC(free)
-void *xreallocarray(void *p, size_t nmemb, size_t size);
+#define XREALLOC(p, n, type)  exit_if_null(REALLOC(p, n, type))
 
 
 #endif  // include guard