| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qplatformdefs.h" | - |
| 43 | | - |
| 44 | #include <stdlib.h> | - |
| 45 | | - |
| 46 | /* | - |
| 47 | Define the container allocation functions in a separate file, so that our | - |
| 48 | users can easily override them. | - |
| 49 | */ | - |
| 50 | | - |
| 51 | QT_BEGIN_NAMESPACE | - |
| 52 | | - |
| 53 | #if !QT_DEPRECATED_SINCE(5, 0) | - |
| 54 | // Make sure they're defined to be exported | - |
| 55 | Q_CORE_EXPORT void *qMalloc(size_t size) Q_ALLOC_SIZE(1); | - |
| 56 | Q_CORE_EXPORT void qFree(void *ptr); | - |
| 57 | Q_CORE_EXPORT void *qRealloc(void *ptr, size_t size) Q_ALLOC_SIZE(2); | - |
| 58 | #endif | - |
| 59 | | - |
| 60 | | - |
| 61 | void *qMalloc(size_t size) | - |
| 62 | { | - |
| 63 | return ::malloc(size); never executed: return ::malloc(size); | 0 |
| 64 | } | - |
| 65 | | - |
| 66 | void qFree(void *ptr) | - |
| 67 | { | - |
| 68 | ::free(ptr); never executed (the execution status of this line is deduced): ::free(ptr); | - |
| 69 | } | 0 |
| 70 | | - |
| 71 | void *qRealloc(void *ptr, size_t size) | - |
| 72 | { | - |
| 73 | return ::realloc(ptr, size); never executed: return ::realloc(ptr, size); | 0 |
| 74 | } | - |
| 75 | | - |
| 76 | void *qMallocAligned(size_t size, size_t alignment) | - |
| 77 | { | - |
| 78 | return qReallocAligned(0, size, 0, alignment); executed: return qReallocAligned(0, size, 0, alignment);Execution Count:1440 | 1440 |
| 79 | } | - |
| 80 | | - |
| 81 | void *qReallocAligned(void *oldptr, size_t newsize, size_t oldsize, size_t alignment) | - |
| 82 | { | - |
| 83 | // fake an aligned allocation | - |
| 84 | Q_UNUSED(oldsize); executed (the execution status of this line is deduced): (void)oldsize;; | - |
| 85 | | - |
| 86 | void *actualptr = oldptr ? static_cast<void **>(oldptr)[-1] : 0; partially evaluated: oldptr| no Evaluation Count:0 | yes Evaluation Count:1440 |
| 0-1440 |
| 87 | if (alignment <= sizeof(void*)) { evaluated: alignment <= sizeof(void*)| yes Evaluation Count:239 | yes Evaluation Count:1201 |
| 239-1201 |
| 88 | // special, fast case | - |
| 89 | void **newptr = static_cast<void **>(realloc(actualptr, newsize + sizeof(void*))); executed (the execution status of this line is deduced): void **newptr = static_cast<void **>(realloc(actualptr, newsize + sizeof(void*))); | - |
| 90 | if (!newptr) partially evaluated: !newptr| no Evaluation Count:0 | yes Evaluation Count:239 |
| 0-239 |
| 91 | return 0; never executed: return 0; | 0 |
| 92 | if (newptr == actualptr) { partially evaluated: newptr == actualptr| no Evaluation Count:0 | yes Evaluation Count:239 |
| 0-239 |
| 93 | // realloc succeeded without reallocating | - |
| 94 | return oldptr; never executed: return oldptr; | 0 |
| 95 | } | - |
| 96 | | - |
| 97 | *newptr = newptr; executed (the execution status of this line is deduced): *newptr = newptr; | - |
| 98 | return newptr + 1; executed: return newptr + 1;Execution Count:239 | 239 |
| 99 | } | - |
| 100 | | - |
| 101 | // malloc returns pointers aligned at least at sizeof(size_t) boundaries | - |
| 102 | // but usually more (8- or 16-byte boundaries). | - |
| 103 | // So we overallocate by alignment-sizeof(size_t) bytes, so we're guaranteed to find a | - |
| 104 | // somewhere within the first alignment-sizeof(size_t) that is properly aligned. | - |
| 105 | | - |
| 106 | // However, we need to store the actual pointer, so we need to allocate actually size + | - |
| 107 | // alignment anyway. | - |
| 108 | | - |
| 109 | void *real = realloc(actualptr, newsize + alignment); executed (the execution status of this line is deduced): void *real = realloc(actualptr, newsize + alignment); | - |
| 110 | if (!real) partially evaluated: !real| no Evaluation Count:0 | yes Evaluation Count:1201 |
| 0-1201 |
| 111 | return 0; never executed: return 0; | 0 |
| 112 | | - |
| 113 | quintptr faked = reinterpret_cast<quintptr>(real) + alignment; executed (the execution status of this line is deduced): quintptr faked = reinterpret_cast<quintptr>(real) + alignment; | - |
| 114 | faked &= ~(alignment - 1); executed (the execution status of this line is deduced): faked &= ~(alignment - 1); | - |
| 115 | | - |
| 116 | void **faked_ptr = reinterpret_cast<void **>(faked); executed (the execution status of this line is deduced): void **faked_ptr = reinterpret_cast<void **>(faked); | - |
| 117 | | - |
| 118 | // now save the value of the real pointer at faked-sizeof(void*) | - |
| 119 | // by construction, alignment > sizeof(void*) and is a power of 2, so | - |
| 120 | // faked-sizeof(void*) is properly aligned for a pointer | - |
| 121 | faked_ptr[-1] = real; executed (the execution status of this line is deduced): faked_ptr[-1] = real; | - |
| 122 | | - |
| 123 | return faked_ptr; executed: return faked_ptr;Execution Count:1201 | 1201 |
| 124 | } | - |
| 125 | | - |
| 126 | void qFreeAligned(void *ptr) | - |
| 127 | { | - |
| 128 | if (!ptr) evaluated: !ptr| yes Evaluation Count:2 | yes Evaluation Count:1437 |
| 2-1437 |
| 129 | return; executed: return;Execution Count:2 | 2 |
| 130 | void **ptr2 = static_cast<void **>(ptr); executed (the execution status of this line is deduced): void **ptr2 = static_cast<void **>(ptr); | - |
| 131 | free(ptr2[-1]); executed (the execution status of this line is deduced): free(ptr2[-1]); | - |
| 132 | } executed: }Execution Count:1437 | 1437 |
| 133 | | - |
| 134 | QT_END_NAMESPACE | - |
| 135 | | - |
| 136 | | - |
| | |