summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-12-29 16:56:30 +0100
committerYves Orton <demerphq@gmail.com>2023-01-12 09:11:51 +0100
commit17419a88100044035ee6dd9f8947f7d411d94863 (patch)
treea5d82e7a938961d35da7f4f12dca61e082ca1eac /handy.h
parent1052f3d04f55d33ed5952af431fb91ccbcf6669f (diff)
downloadperl-17419a88100044035ee6dd9f8947f7d411d94863.tar.gz
handy.h - add NewCopy() macro to combine New and Copy.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/handy.h b/handy.h
index 2e6d736550..8e3ec32b43 100644
--- a/handy.h
+++ b/handy.h
@@ -2674,6 +2674,10 @@ C<CopyD> is like C<Copy> but returns C<dest>. 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)