1 #ifndef __mem_h
2 #define __mem_h
3
4 #ifndef MEM_ALIGN
5 #define MEM_ALIGN 16
6 #endif
7
8 typedef union { char __x[MEM_ALIGN]; double __y; } align_t;
9
10 void inline *mem_alloc(int bytes);
11 void inline mem_free(void *ptr);
12 void inline mem_register_gc(void *x, int (*fn)(void *));
13
14 /* the rest of this file contains compatability things */
15
16 /* memzero function */
17 #ifndef HAVE_MEMZERO
18 #if defined(HAVE_BZERO)
19 #define memzero(a,b) bzero(a,b)
20 #elif defined(HAVE_MEMSET)
21 #define memzero(a,b) memset(a,0,b)
22 #else
memzero(void * d,int len)23 void inline memzero(void *d, int len)
24 {
25 register char *x = (char *)d;
26 register int i;
27
28 for (i = 0; i < len;) {
29 *x = 0; x++;i++; if (i == len) break;
30 *x = 0; x++;i++; if (i == len) break;
31 *x = 0; x++;i++; if (i == len) break;
32 *x = 0; x++;i++; if (i == len) break;
33 *x = 0; x++;i++; if (i == len) break;
34 *x = 0; x++;i++; if (i == len) break;
35 *x = 0; x++;i++; if (i == len) break;
36 *x = 0; x++;i++;
37 }
38 }
39
40 #endif
41 #endif
42
43 /* memcpy function */
44 #ifndef HAVE_MEMCPY
45 #if defined(HAVE_BCOPY)
46 #define memcpy(a,b,c) bcopy(b,c,a)
47 #else
memcpy(void * d,const void * s,int len)48 void inline memcpy(void *d, const void *s, int len)
49 {
50 register const char *x = (const char *)s;
51 register char *y = (char *)d;
52 register int i;
53
54 for (i = 0; i < len;) {
55 *y = *x; x++;y++;i++; if (i == len) break;
56 *y = *x; x++;y++;i++; if (i == len) break;
57 *y = *x; x++;y++;i++; if (i == len) break;
58 *y = *x; x++;y++;i++; if (i == len) break;
59 *y = *x; x++;y++;i++; if (i == len) break;
60 *y = *x; x++;y++;i++; if (i == len) break;
61 *y = *x; x++;y++;i++; if (i == len) break;
62 *y = *x; x++;y++;i++;
63 }
64 }
65 #endif
66 #endif
67
68
69 /* more to come (hopefully not) */
70
71 #endif
72