epoc32/include/tools/stlport/stl/_alloc.c
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tools/stlport/stl/_alloc.c	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +/*
     1.5 + *
     1.6 + * Copyright (c) 1996,1997
     1.7 + * Silicon Graphics Computer Systems, Inc.
     1.8 + *
     1.9 + * Copyright (c) 1997
    1.10 + * Moscow Center for SPARC Technology
    1.11 + *
    1.12 + * Copyright (c) 1999
    1.13 + * Boris Fomitchev
    1.14 + *
    1.15 + * This material is provided "as is", with absolutely no warranty expressed
    1.16 + * or implied. Any use is at your own risk.
    1.17 + *
    1.18 + * Permission to use or copy this software for any purpose is hereby granted
    1.19 + * without fee, provided the above notices are retained on all copies.
    1.20 + * Permission to modify the code and to distribute modified code is granted,
    1.21 + * provided the above notices are retained, and a notice that the code was
    1.22 + * modified is included with the above copyright notice.
    1.23 + *
    1.24 + */
    1.25 +#ifndef _STLP_ALLOC_C
    1.26 +#define _STLP_ALLOC_C
    1.27 +
    1.28 +#ifndef _STLP_INTERNAL_ALLOC_H
    1.29 +#  include <stl/_alloc.h>
    1.30 +#endif
    1.31 +
    1.32 +#if defined (__WATCOMC__)
    1.33 +#  pragma warning 13 9
    1.34 +#  pragma warning 367 9
    1.35 +#  pragma warning 368 9
    1.36 +#endif
    1.37 +
    1.38 +_STLP_BEGIN_NAMESPACE
    1.39 +
    1.40 +template <class _Alloc>
    1.41 +void * _STLP_CALL __debug_alloc<_Alloc>::allocate(size_t __n) {
    1.42 +  size_t __total_extra = __extra_before_chunk() + __extra_after_chunk();
    1.43 +  size_t __real_n = __n + __total_extra;
    1.44 +  if (__real_n < __n) {
    1.45 +    //It means that we rolled on size_t, __n must be very large, lets hope
    1.46 +    //that allocating it will raised a bad_alloc exception:
    1.47 +    __real_n = __n + (__total_extra - __real_n - 1);
    1.48 +  }
    1.49 +  __alloc_header *__result = (__alloc_header *)__allocator_type::allocate(__real_n);
    1.50 +  memset((char*)__result, __shred_byte, __real_n * sizeof(value_type));
    1.51 +  __result->__magic = __magic;
    1.52 +  __result->__type_size = sizeof(value_type);
    1.53 +  __result->_M_size = (_STLP_UINT32_T)__n;
    1.54 +  return ((char*)__result) + (long)__extra_before;
    1.55 +}
    1.56 +
    1.57 +template <class _Alloc>
    1.58 +void  _STLP_CALL
    1.59 +__debug_alloc<_Alloc>::deallocate(void *__p, size_t __n) {
    1.60 +  __alloc_header * __real_p = (__alloc_header*)((char *)__p -(long)__extra_before);
    1.61 +  // check integrity
    1.62 +  _STLP_VERBOSE_ASSERT(__real_p->__magic != __deleted_magic, _StlMsg_DBA_DELETED_TWICE)
    1.63 +  _STLP_VERBOSE_ASSERT(__real_p->__magic == __magic, _StlMsg_DBA_NEVER_ALLOCATED)
    1.64 +  _STLP_VERBOSE_ASSERT(__real_p->__type_size == 1,_StlMsg_DBA_TYPE_MISMATCH)
    1.65 +  _STLP_VERBOSE_ASSERT(__real_p->_M_size == __n, _StlMsg_DBA_SIZE_MISMATCH)
    1.66 +  // check pads on both sides
    1.67 +  unsigned char* __tmp;
    1.68 +  for (__tmp = (unsigned char*)(__real_p + 1); __tmp < (unsigned char*)__p; ++__tmp) {
    1.69 +    _STLP_VERBOSE_ASSERT(*__tmp == __shred_byte, _StlMsg_DBA_UNDERRUN)
    1.70 +  }
    1.71 +
    1.72 +  size_t __real_n = __n + __extra_before_chunk() + __extra_after_chunk();
    1.73 +
    1.74 +  for (__tmp= ((unsigned char*)__p) + __n * sizeof(value_type);
    1.75 +       __tmp < ((unsigned char*)__real_p) + __real_n ; ++__tmp) {
    1.76 +    _STLP_VERBOSE_ASSERT(*__tmp == __shred_byte, _StlMsg_DBA_OVERRUN)
    1.77 +  }
    1.78 +
    1.79 +  // that may be unfortunate, just in case
    1.80 +  __real_p->__magic = __deleted_magic;
    1.81 +  memset((char*)__p, __shred_byte, __n * sizeof(value_type));
    1.82 +  __allocator_type::deallocate(__real_p, __real_n);
    1.83 +}
    1.84 +
    1.85 +_STLP_END_NAMESPACE
    1.86 +
    1.87 +#endif /*  _STLP_ALLOC_C */
    1.88 +
    1.89 +// Local Variables:
    1.90 +// mode:C++
    1.91 +// End: