| 1 |
/* |
| 2 |
* sysprof-allocator-private.h |
| 3 |
* |
| 4 |
* Copysysprofht 2024 Christian Hergert <[email protected]> |
| 5 |
* |
| 6 |
* This program is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation, either version 3 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 20 |
*/ |
| 21 |
|
| 22 |
#pragma once |
| 23 |
|
| 24 |
#include <glib.h> |
| 25 |
|
| 26 |
G_BEGIN_DECLS |
| 27 |
|
| 28 |
typedef struct _SysprofAllocator SysprofAllocator; |
| 29 |
|
| 30 |
SysprofAllocator *sysprof_allocator_new (void); |
| 31 |
SysprofAllocator *sysprof_allocator_ref (SysprofAllocator *self); |
| 32 |
void sysprof_allocator_unref (SysprofAllocator *self); |
| 33 |
gpointer sysprof_allocator_alloc (SysprofAllocator *self, |
| 34 |
gsize size); |
| 35 |
gconstpointer sysprof_allocator_cstring (SysprofAllocator *self, |
| 36 |
const char *str, |
| 37 |
gssize len); |
| 38 |
|
| 39 |
static inline gconstpointer |
| 40 |
sysprof_allocator_cstring_range (SysprofAllocator *self, |
| 41 |
const char *begin, |
| 42 |
const char *end) |
| 43 |
{ |
| 44 |
return sysprof_allocator_cstring (self, begin, end - begin); |
| 45 |
} |
| 46 |
|
| 47 |
static inline gpointer |
| 48 |
sysprof_allocator_alloc0 (SysprofAllocator *allocator, |
| 49 |
gsize size) |
| 50 |
{ |
| 51 |
gpointer v = sysprof_allocator_alloc (allocator, size); |
| 52 |
memset (v, 0, size); |
| 53 |
return v; |
| 54 |
} |
| 55 |
|
| 56 |
#define sysprof_allocator_new0(a,Type) \ |
| 57 |
((Type*)sysprof_allocator_alloc0(a, sizeof(Type))) |
| 58 |
|
| 59 |
static inline gpointer |
| 60 |
sysprof_allocator_dup (SysprofAllocator *allocator, |
| 61 |
gconstpointer src, |
| 62 |
gsize size) |
| 63 |
{ |
| 64 |
gpointer dst = sysprof_allocator_alloc (allocator, size); |
| 65 |
memcpy (dst, src, size); |
| 66 |
return dst; |
| 67 |
} |
| 68 |
|
| 69 |
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofAllocator, sysprof_allocator_unref); |
| 70 |
|
| 71 |
G_END_DECLS |