From 17419a88100044035ee6dd9f8947f7d411d94863 Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Thu, 29 Dec 2022 16:56:30 +0100 Subject: handy.h - add NewCopy() macro to combine New and Copy. --- handy.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'handy.h') diff --git a/handy.h b/handy.h index 2e6d736550..8e3ec32b43 100644 --- a/handy.h +++ b/handy.h @@ -2674,6 +2674,10 @@ C is like C but returns C. Useful for encouraging compilers to tail-call optimise. +=for apidoc Am|void |NewCopy |void* src|void* dest|int nitems|type +Combines Newx() and Copy() into a single macro. Dest will be allocated +using Newx() and then src will be copied into it. + =for apidoc Am|void |Zero |void* dest|int nitems|type =for apidoc_item |void *|ZeroD|void* dest|int nitems|type @@ -2881,6 +2885,11 @@ enum mem_log_type { #define CopyD(s,d,n,t) (MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), memcpy((char*)(d),(const char*)(s), (n) * sizeof(t))) #define ZeroD(d,n,t) (MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), memzero((char*)(d), (n) * sizeof(t))) +#define NewCopy(s,d,n,t) STMT_START { \ + Newx(d,n,t); \ + Copy(s,d,n,t); \ +} STMT_END + #define PoisonWith(d,n,t,b) (MEM_WRAP_CHECK_(n,t) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t))) #define PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB) #define PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF) -- cgit v1.2.1