ReactOS 0.4.16-dev-125-g798ea90
_alloc.c
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) 1996,1997
4 * Silicon Graphics Computer Systems, Inc.
5 *
6 * Copyright (c) 1997
7 * Moscow Center for SPARC Technology
8 *
9 * Copyright (c) 1999
10 * Boris Fomitchev
11 *
12 * This material is provided "as is", with absolutely no warranty expressed
13 * or implied. Any use is at your own risk.
14 *
15 * Permission to use or copy this software for any purpose is hereby granted
16 * without fee, provided the above notices are retained on all copies.
17 * Permission to modify the code and to distribute modified code is granted,
18 * provided the above notices are retained, and a notice that the code was
19 * modified is included with the above copyright notice.
20 *
21 */
22#ifndef _STLP_ALLOC_C
23#define _STLP_ALLOC_C
24
25#ifndef _STLP_INTERNAL_ALLOC_H
26# include <stl/_alloc.h>
27#endif
28
29#if defined (__WATCOMC__)
30# pragma warning 13 9
31# pragma warning 367 9
32# pragma warning 368 9
33#endif
34
36
37template <class _Alloc>
39 size_t __total_extra = __extra_before_chunk() + __extra_after_chunk();
40 size_t __real_n = __n + __total_extra;
41 if (__real_n < __n) {
42 //It means that we rolled on size_t, __n must be very large:
44 }
45 __alloc_header *__result = (__alloc_header *)__allocator_type::allocate(__real_n);
46 memset((char*)__result, __shred_byte, __real_n * sizeof(value_type));
47 __result->__magic = __magic;
48 __result->__type_size = sizeof(value_type);
49 __result->_M_size = (_STLP_UINT32_T)__n;
50 return ((char*)__result) + (long)__extra_before;
51}
52
53template <class _Alloc>
54void _STLP_CALL
56 __alloc_header * __real_p = (__alloc_header*)((char *)__p -(long)__extra_before);
57 // check integrity
58 _STLP_VERBOSE_ASSERT(__real_p->__magic != __deleted_magic, _StlMsg_DBA_DELETED_TWICE)
59 _STLP_VERBOSE_ASSERT(__real_p->__magic == __magic, _StlMsg_DBA_NEVER_ALLOCATED)
60 _STLP_VERBOSE_ASSERT(__real_p->__type_size == 1,_StlMsg_DBA_TYPE_MISMATCH)
61 _STLP_VERBOSE_ASSERT(__real_p->_M_size == __n, _StlMsg_DBA_SIZE_MISMATCH)
62 // check pads on both sides
63 unsigned char* __tmp;
64 for (__tmp = (unsigned char*)(__real_p + 1); __tmp < (unsigned char*)__p; ++__tmp) {
65 _STLP_VERBOSE_ASSERT(*__tmp == __shred_byte, _StlMsg_DBA_UNDERRUN)
66 }
67
68 size_t __real_n = __n + __extra_before_chunk() + __extra_after_chunk();
69
70 for (__tmp= ((unsigned char*)__p) + __n * sizeof(value_type);
71 __tmp < ((unsigned char*)__real_p) + __real_n ; ++__tmp) {
72 _STLP_VERBOSE_ASSERT(*__tmp == __shred_byte, _StlMsg_DBA_OVERRUN)
73 }
74
75 // that may be unfortunate, just in case
76 __real_p->__magic = __deleted_magic;
77 memset((char*)__p, __shred_byte, __n * sizeof(value_type));
78 __allocator_type::deallocate(__real_p, __real_n);
79}
80
82
83#endif /* _STLP_ALLOC_C */
84
85// Local Variables:
86// mode:C++
87// End:
return __n
Definition: _algo.h:75
#define _STLP_UINT32_T
Definition: _apple.h:37
#define _STLP_CALL
Definition: _bc.h:131
#define _STLP_VERBOSE_ASSERT(expr, diagnostic)
Definition: _debug.h:439
#define _STLP_THROW_BAD_ALLOC
Definition: _new.h:116
static void *_STLP_CALL allocate(size_t)
Definition: _alloc.c:38
static void _STLP_CALL deallocate(void *, size_t)
Definition: _alloc.c:55
_Alloc::value_type value_type
Definition: _alloc.h:107
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define long
Definition: qsort.c:33
#define memset(x, y, z)
Definition: compat.h:39
_STLP_UINT32_T _M_size
Definition: _alloc.h:112