This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta - Remove all but one XXX notices
[perl5.git] / cpan / Devel-PPPort / parts / inc / memory
CommitLineData
0d0f8426
MHM
1################################################################################
2##
49ef49fe 3## $Revision: 7 $
0d0f8426 4## $Author: mhx $
49ef49fe 5## $Date: 2010/03/07 13:15:46 +0100 $
0d0f8426
MHM
6##
7################################################################################
8##
49ef49fe 9## Version 3.x, Copyright (C) 2004-2010, Marcus Holland-Moritz.
0d0f8426
MHM
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
49ef49fe
CBW
32__UNDEFINED__ memEQs(s1, l, s2) \
33 (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1)))
34__UNDEFINED__ memNEs(s1, l, s2) !memEQs(s1, l, s2)
35
0d0f8426
MHM
36__UNDEFINED__ MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t))
37__UNDEFINED__ CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
38#ifdef HAS_MEMSET
39__UNDEFINED__ ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t))
40#else
41__UNDEFINED__ ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)), d)
42#endif
43
c07deaaf
MHM
44__UNDEFINED__ PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t))
45__UNDEFINED__ PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB)
46__UNDEFINED__ PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF)
47__UNDEFINED__ Poison(d,n,t) PoisonFree(d,n,t)
0d0f8426
MHM
48
49__UNDEFINED__ Newx(v,n,t) New(0,v,n,t)
50__UNDEFINED__ Newxc(v,n,t,c) Newc(0,v,n,t,c)
51__UNDEFINED__ Newxz(v,n,t) Newz(0,v,n,t)
52
53=xsubs
54
55int
56checkmem()
57 PREINIT:
58 char *p;
59
60 CODE:
61 RETVAL = 0;
62 Newx(p, 6, char);
63 CopyD("Hello", p, 6, char);
64 if (memEQ(p, "Hello", 6))
65 RETVAL++;
66 ZeroD(p, 6, char);
67 if (memEQ(p, "\0\0\0\0\0\0", 6))
68 RETVAL++;
49ef49fe
CBW
69 if (memEQs(p, 6, "\0\0\0\0\0\0"))
70 RETVAL++;
0d0f8426
MHM
71 Poison(p, 6, char);
72 if (memNE(p, "\0\0\0\0\0\0", 6))
73 RETVAL++;
49ef49fe
CBW
74 if (memNEs(p, 6, "\0\0\0\0\0\0"))
75 RETVAL++;
0d0f8426
MHM
76 Safefree(p);
77
78 Newxz(p, 6, char);
79 if (memEQ(p, "\0\0\0\0\0\0", 6))
80 RETVAL++;
81 Safefree(p);
82
83 Newxc(p, 3, short, char);
84 Safefree(p);
85
86 OUTPUT:
87 RETVAL
88
89=tests plan => 1
90
49ef49fe 91ok(Devel::PPPort::checkmem(), 6);
0d0f8426 92