This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add/fix character classification macros, like isDIGIT
[perl5.git] / dist / Devel-PPPort / parts / inc / memory
CommitLineData
0d0f8426
MHM
1################################################################################
2##
b2049988 3## Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
0d0f8426
MHM
4## Version 2.x, Copyright (C) 2001, Paul Marquess.
5## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
6##
7## This program is free software; you can redistribute it and/or
8## modify it under the same terms as Perl itself.
9##
10################################################################################
11
12=provides
13
14__UNDEFINED__
15
16=implementation
17
18#ifdef HAS_MEMCMP
19__UNDEFINED__ memNE(s1,s2,l) (memcmp(s1,s2,l))
20__UNDEFINED__ memEQ(s1,s2,l) (!memcmp(s1,s2,l))
21#else
22__UNDEFINED__ memNE(s1,s2,l) (bcmp(s1,s2,l))
23__UNDEFINED__ memEQ(s1,s2,l) (!bcmp(s1,s2,l))
24#endif
25
49ef49fe
CBW
26__UNDEFINED__ memEQs(s1, l, s2) \
27 (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1)))
28__UNDEFINED__ memNEs(s1, l, s2) !memEQs(s1, l, s2)
29
0d0f8426
MHM
30__UNDEFINED__ MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t))
31__UNDEFINED__ CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
32#ifdef HAS_MEMSET
33__UNDEFINED__ ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t))
34#else
35__UNDEFINED__ ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)), d)
36#endif
37
c07deaaf
MHM
38__UNDEFINED__ PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t))
39__UNDEFINED__ PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB)
40__UNDEFINED__ PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF)
41__UNDEFINED__ Poison(d,n,t) PoisonFree(d,n,t)
0d0f8426
MHM
42
43__UNDEFINED__ Newx(v,n,t) New(0,v,n,t)
44__UNDEFINED__ Newxc(v,n,t,c) Newc(0,v,n,t,c)
45__UNDEFINED__ Newxz(v,n,t) Newz(0,v,n,t)
46
47=xsubs
48
49int
50checkmem()
51 PREINIT:
52 char *p;
53
54 CODE:
55 RETVAL = 0;
56 Newx(p, 6, char);
57 CopyD("Hello", p, 6, char);
58 if (memEQ(p, "Hello", 6))
59 RETVAL++;
60 ZeroD(p, 6, char);
61 if (memEQ(p, "\0\0\0\0\0\0", 6))
62 RETVAL++;
49ef49fe
CBW
63 if (memEQs(p, 6, "\0\0\0\0\0\0"))
64 RETVAL++;
0d0f8426
MHM
65 Poison(p, 6, char);
66 if (memNE(p, "\0\0\0\0\0\0", 6))
67 RETVAL++;
49ef49fe
CBW
68 if (memNEs(p, 6, "\0\0\0\0\0\0"))
69 RETVAL++;
0d0f8426
MHM
70 Safefree(p);
71
72 Newxz(p, 6, char);
73 if (memEQ(p, "\0\0\0\0\0\0", 6))
74 RETVAL++;
75 Safefree(p);
76
77 Newxc(p, 3, short, char);
78 Safefree(p);
79
80 OUTPUT:
81 RETVAL
82
83=tests plan => 1
84
49ef49fe 85ok(Devel::PPPort::checkmem(), 6);