bump product version to 7.6.3.2-android
[LibreOffice.git] / external / skia / source / SkMemory_malloc.cxx
blob9e2da3c200232acb304180853aa37a6c116b1eb3
1 /*
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
6 #include "include/core/SkTypes.h"
7 #include "include/private/SkMalloc.h"
9 #include <sal/log.hxx>
10 #include <rtl/alloc.h>
12 // Based on SkMemory_malloc.cpp :
14 static inline void sk_out_of_memory(size_t size)
16 SAL_WARN("skia", "sk_out_of_memory (asked for " << size << " bytes)");
17 abort();
20 static inline void* throw_on_failure(size_t size, void* p)
22 if (size > 0 && p == nullptr)
24 // If we've got a nullptr here, the only reason we should have failed is running out of RAM.
25 sk_out_of_memory(size);
27 return p;
30 void sk_abort_no_print()
32 SAL_WARN("skia", "sk_abort_no_print");
33 abort();
36 void sk_out_of_memory(void)
38 SAL_WARN("skia", "sk_out_of_memory");
39 abort();
42 void* sk_realloc_throw(void* addr, size_t size)
44 return throw_on_failure(size, rtl_reallocateMemory(addr, size));
47 void sk_free(void* p) { rtl_freeMemory(p); }
49 void* sk_malloc_flags(size_t size, unsigned flags)
51 void* p;
52 if (flags & SK_MALLOC_ZERO_INITIALIZE)
54 p = rtl_allocateZeroMemory(size);
56 else
58 p = rtl_allocateMemory(size);
60 if (flags & SK_MALLOC_THROW)
62 return throw_on_failure(size, p);
64 else
66 return p;