Changeset 846 for trunk/src/corelib/global/qmalloc.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/corelib/global/qmalloc.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 91 91 } 92 92 93 union { void *ptr; void **pptr; quintptr n; } real, faked;94 95 93 // qMalloc returns pointers aligned at least at sizeof(size_t) boundaries 96 94 // but usually more (8- or 16-byte boundaries). … … 101 99 // alignment anyway. 102 100 103 real.ptr= qRealloc(actualptr, newsize + alignment);104 if (!real .ptr)101 = qRealloc(actualptr, newsize + alignment); 102 if (!real) 105 103 return 0; 106 104 107 faked.n = real.n + alignment; 108 faked.n &= ~(alignment - 1); 105 quintptr faked = reinterpret_cast<quintptr>(real) + alignment; 106 faked &= ~(alignment - 1); 107 108 void **faked_ptr = reinterpret_cast<void **>(faked); 109 109 110 110 // now save the value of the real pointer at faked-sizeof(void*) 111 111 // by construction, alignment > sizeof(void*) and is a power of 2, so 112 112 // faked-sizeof(void*) is properly aligned for a pointer 113 faked .pptr[-1] = real.ptr;113 faked; 114 114 115 return faked .ptr;115 return fakedptr; 116 116 } 117 117 … … 125 125 126 126 QT_END_NAMESPACE 127
Note:
See TracChangeset
for help on using the changeset viewer.