Upgrade to Devel::PPPort 3.07
[p5sagit/p5-mst-13.2.git] / ext / Devel / PPPort / parts / inc / memory
1 ################################################################################
2 ##
3 ##  $Revision: 1 $
4 ##  $Author: mhx $
5 ##  $Date: 2005/10/30 11:26:42 +0100 $
6 ##
7 ################################################################################
8 ##
9 ##  Version 3.x, Copyright (C) 2004-2005, Marcus Holland-Moritz.
10 ##  Version 2.x, Copyright (C) 2001, Paul Marquess.
11 ##  Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
12 ##
13 ##  This program is free software; you can redistribute it and/or
14 ##  modify it under the same terms as Perl itself.
15 ##
16 ################################################################################
17
18 =provides
19
20 __UNDEFINED__
21
22 =implementation
23
24 #ifdef HAS_MEMCMP
25 __UNDEFINED__  memNE(s1,s2,l)  (memcmp(s1,s2,l))
26 __UNDEFINED__  memEQ(s1,s2,l)  (!memcmp(s1,s2,l))
27 #else
28 __UNDEFINED__  memNE(s1,s2,l)  (bcmp(s1,s2,l))
29 __UNDEFINED__  memEQ(s1,s2,l)  (!bcmp(s1,s2,l))
30 #endif
31
32 __UNDEFINED__  MoveD(s,d,n,t)  memmove((char*)(d),(char*)(s), (n) * sizeof(t))
33 __UNDEFINED__  CopyD(s,d,n,t)  memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
34 #ifdef HAS_MEMSET
35 __UNDEFINED__  ZeroD(d,n,t)    memzero((char*)(d), (n) * sizeof(t))
36 #else
37 __UNDEFINED__  ZeroD(d,n,t)    ((void)memzero((char*)(d), (n) * sizeof(t)), d)
38 #endif
39
40 __UNDEFINED__  Poison(d,n,t)   (void)memset((char*)(d), 0xAB, (n) * sizeof(t))
41
42 __UNDEFINED__  Newx(v,n,t)     New(0,v,n,t)
43 __UNDEFINED__  Newxc(v,n,t,c)  Newc(0,v,n,t,c)
44 __UNDEFINED__  Newxz(v,n,t)    Newz(0,v,n,t)
45
46 =xsubs
47
48 int
49 checkmem()
50   PREINIT:
51     char *p;
52
53   CODE:
54     RETVAL = 0;
55     Newx(p, 6, char);
56     CopyD("Hello", p, 6, char);
57     if (memEQ(p, "Hello", 6))
58       RETVAL++;
59     ZeroD(p, 6, char);
60     if (memEQ(p, "\0\0\0\0\0\0", 6))
61       RETVAL++;
62     Poison(p, 6, char);
63     if (memNE(p, "\0\0\0\0\0\0", 6))
64       RETVAL++;
65     Safefree(p);
66
67     Newxz(p, 6, char);
68     if (memEQ(p, "\0\0\0\0\0\0", 6))
69       RETVAL++;
70     Safefree(p);
71
72     Newxc(p, 3, short, char);
73     Safefree(p);
74
75   OUTPUT:
76     RETVAL
77
78 =tests plan => 1
79
80 ok(Devel::PPPort::checkmem(), 4);
81