Rename ext/Devel/DProf to ext/Devel-DProf
[p5sagit/p5-mst-13.2.git] / ext / Devel / PPPort / parts / inc / memory
CommitLineData
0d0f8426 1################################################################################
2##
51d6c659 3## $Revision: 5 $
0d0f8426 4## $Author: mhx $
51d6c659 5## $Date: 2009/01/18 14:10:53 +0100 $
0d0f8426 6##
7################################################################################
8##
51d6c659 9## Version 3.x, Copyright (C) 2004-2009, Marcus Holland-Moritz.
0d0f8426 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
c07deaaf 40__UNDEFINED__ PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t))
41__UNDEFINED__ PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB)
42__UNDEFINED__ PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF)
43__UNDEFINED__ Poison(d,n,t) PoisonFree(d,n,t)
0d0f8426 44
45__UNDEFINED__ Newx(v,n,t) New(0,v,n,t)
46__UNDEFINED__ Newxc(v,n,t,c) Newc(0,v,n,t,c)
47__UNDEFINED__ Newxz(v,n,t) Newz(0,v,n,t)
48
49=xsubs
50
51int
52checkmem()
53 PREINIT:
54 char *p;
55
56 CODE:
57 RETVAL = 0;
58 Newx(p, 6, char);
59 CopyD("Hello", p, 6, char);
60 if (memEQ(p, "Hello", 6))
61 RETVAL++;
62 ZeroD(p, 6, char);
63 if (memEQ(p, "\0\0\0\0\0\0", 6))
64 RETVAL++;
65 Poison(p, 6, char);
66 if (memNE(p, "\0\0\0\0\0\0", 6))
67 RETVAL++;
68 Safefree(p);
69
70 Newxz(p, 6, char);
71 if (memEQ(p, "\0\0\0\0\0\0", 6))
72 RETVAL++;
73 Safefree(p);
74
75 Newxc(p, 3, short, char);
76 Safefree(p);
77
78 OUTPUT:
79 RETVAL
80
81=tests plan => 1
82
83ok(Devel::PPPort::checkmem(), 4);
84