Re: [perl #34493] h2ph `extern inline' problems
[p5sagit/p5-mst-13.2.git] / handy.h
diff --git a/handy.h b/handy.h
index b88c729..339653f 100644 (file)
--- a/handy.h
+++ b/handy.h
@@ -159,6 +159,14 @@ typedef U64TYPE U64;
 #   endif
 #endif
 
+/* H.Merijn Brand [ 01 Nov 2004 ] */
+#if defined(HAS_STRLCAT) || defined(HAS_STRLCPY)
+/* Not (yet) used at top level, but mention them for metaconfig
+ * Read http://www.courtesan.com/todd/papers/strlcpy.html
+ * for the discussion of why replacing strncat/strncpy with
+ * strlcat/strlcpy would be wise */
+#endif
+
 /* Mention I8SIZE, U8SIZE, I16SIZE, U16SIZE, I32SIZE, U32SIZE,
    I64SIZE, and U64SIZE here so that metaconfig pulls them in. */
 
@@ -559,16 +567,30 @@ The XSUB-writer's interface to the C C<memmove> function.  The C<src> is the
 source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
 the type.  Can do overlapping moves.  See also C<Copy>.
 
+=for apidoc Am|void *|MoveD|void* src|void* dest|int nitems|type
+Like C<Move> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
 =for apidoc Am|void|Copy|void* src|void* dest|int nitems|type
 The XSUB-writer's interface to the C C<memcpy> function.  The C<src> is the
 source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
 the type.  May fail on overlapping copies.  See also C<Move>.
 
+=for apidoc Am|void *|CopyD|void* src|void* dest|int nitems|type
+
+Like C<Copy> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
 =for apidoc Am|void|Zero|void* dest|int nitems|type
 
 The XSUB-writer's interface to the C C<memzero> function.  The C<dest> is the
 destination, C<nitems> is the number of items, and C<type> is the type.
 
+=for apidoc Am|void *|ZeroD|void* dest|int nitems|type
+
+Like C<Zero> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
 =for apidoc Am|void|StructCopy|type src|type dest|type
 This is an architecture-independent macro to copy one structure to another.
 
@@ -601,10 +623,19 @@ hopefully catches attempts to access uninitialized memory.
          (v = (MEM_WRAP_CHECK(n,t), (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))))
 #define Safefree(d)    safefree((Malloc_t)(d))
 
-#define Move(s,d,n,t)  (MEM_WRAP_CHECK(n,t), (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t)))
-#define Copy(s,d,n,t)  (MEM_WRAP_CHECK(n,t), (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t)))
+#define Move(s,d,n,t)  (MEM_WRAP_CHECK(n,t), (void)memmove((char*)(d),(const char*)(s), (n) * sizeof(t)))
+#define Copy(s,d,n,t)  (MEM_WRAP_CHECK(n,t), (void)memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)))
 #define Zero(d,n,t)    (MEM_WRAP_CHECK(n,t), (void)memzero((char*)(d), (n) * sizeof(t)))
 
+#define MoveD(s,d,n,t) (MEM_WRAP_CHECK(n,t), memmove((char*)(d),(const char*)(s), (n) * sizeof(t)))
+#define CopyD(s,d,n,t) (MEM_WRAP_CHECK(n,t), memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)))
+#ifdef HAS_MEMSET
+#define ZeroD(d,n,t)   (MEM_WRAP_CHECK(n,t), memzero((char*)(d), (n) * sizeof(t)))
+#else
+/* Using bzero(), which returns void.  */
+#define ZeroD(d,n,t)   (MEM_WRAP_CHECK(n,t), memzero((char*)(d), (n) * sizeof(t)),d)
+#endif
+
 #define Poison(d,n,t)  (MEM_WRAP_CHECK(n,t), (void)memset((char*)(d), 0xAB, (n) * sizeof(t)))
 
 #else
@@ -623,10 +654,18 @@ hopefully catches attempts to access uninitialized memory.
          (v = (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
 #define Safefree(d)    safefree((Malloc_t)(d))
 
-#define Move(s,d,n,t)  (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
-#define Copy(s,d,n,t)  (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
+#define Move(s,d,n,t)  (void)memmove((char*)(d),(const char*)(s), (n) * sizeof(t))
+#define Copy(s,d,n,t)  (void)memcpy((char*)(d),(const char*)(s), (n) * sizeof(t))
 #define Zero(d,n,t)    (void)memzero((char*)(d), (n) * sizeof(t))
 
+#define MoveD(s,d,n,t) memmove((char*)(d),(const char*)(s), (n) * sizeof(t))
+#define CopyD(s,d,n,t) memcpy((char*)(d),(const char*)(s), (n) * sizeof(t))
+#ifdef HAS_MEMSET
+#define ZeroD(d,n,t)   memzero((char*)(d), (n) * sizeof(t))
+#else
+#define ZeroD(d,n,t)   ((void)memzero((char*)(d), (n) * sizeof(t)),d)
+#endif
+
 #define Poison(d,n,t)  (void)memset((char*)(d), 0xAB, (n) * sizeof(t))
 
 #endif
@@ -640,6 +679,9 @@ hopefully catches attempts to access uninitialized memory.
 #define Move(s,d,n,t)
 #define Copy(s,d,n,t)
 #define Zero(d,n,t)
+#define MoveD(s,d,n,t) d
+#define CopyD(s,d,n,t) d
+#define ZeroD(d,n,t)   d
 #define Poison(d,n,t)
 #define Safefree(d)    (d) = (d)
 
@@ -665,3 +707,19 @@ hopefully catches attempts to access uninitialized memory.
 # endif
 #endif
 
+/* convenience debug macros */
+#ifdef USE_ITHREADS
+#define pTHX_FORMAT  "Perl interpreter: 0x%p"
+#define pTHX__FORMAT ", Perl interpreter: 0x%p"
+#define pTHX_VALUE_   (unsigned long)my_perl,
+#define pTHX_VALUE    (unsigned long)my_perl
+#define pTHX__VALUE_ ,(unsigned long)my_perl,
+#define pTHX__VALUE  ,(unsigned long)my_perl
+#else
+#define pTHX_FORMAT 
+#define pTHX__FORMAT
+#define pTHX_VALUE_ 
+#define pTHX_VALUE
+#define pTHX__VALUE_ 
+#define pTHX__VALUE
+#endif /* USE_ITHREADS */