ucx/cx/allocator.h

Fri, 19 Dec 2025 17:22:03 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 19 Dec 2025 17:22:03 +0100
changeset 31
287484519844
parent 30
d33eaaec15da
permissions
-rw-r--r--

update ucx

0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 /**
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
29 * @file allocator.h
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 * Interface for custom allocators.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 */
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #ifndef UCX_ALLOCATOR_H
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #define UCX_ALLOCATOR_H
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "common.h"
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #ifdef __cplusplus
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 extern "C" {
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #endif
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 * The class definition for an allocator.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 */
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 typedef struct {
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 * The allocator's malloc() implementation.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
49 void *(*malloc)(void *data, size_t n);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 * The allocator's realloc() implementation.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
54 void *(*realloc)(void *data, void *mem, size_t n);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 * The allocator's calloc() implementation.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
59 void *(*calloc)(void *data, size_t nmemb, size_t size);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 * The allocator's free() implementation.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
64 void (*free)(void *data, void *mem);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 } cx_allocator_class;
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 * Structure holding the data for an allocator.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 */
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 struct cx_allocator_s {
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 * A pointer to the instance of the allocator class.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 */
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 cx_allocator_class *cl;
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 * A pointer to the data this allocator uses.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 */
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 void *data;
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 };
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 * High-Level type alias for the allocator type.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 */
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 typedef struct cx_allocator_s CxAllocator;
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 /**
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
87 * A pre-defined allocator using standard library malloc() etc.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
89 CX_EXPORT extern const CxAllocator * const cxStdlibAllocator;
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
90
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
91 /**
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
92 * The default allocator that is used by UCX.
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
93 * Initialized with cxStdlibAllocator, but you may change it.
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
94 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
95 CX_EXPORT extern const CxAllocator * cxDefaultAllocator;
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 * Function pointer type for destructor functions.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 * A destructor function deallocates possible contents and MAY free the memory
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
101 * pointed to by @p memory. Read the documentation of the respective function
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
102 * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
103 * that particular implementation.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 * @param memory a pointer to the object to destruct
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 */
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
107 typedef void (*cx_destructor_func)(void *memory);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 /**
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 * Function pointer type for destructor functions.
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 * A destructor function deallocates possible contents and MAY free the memory
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
113 * pointed to by @p memory. Read the documentation of the respective function
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
114 * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
115 * that particular implementation.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 * @param data an optional pointer to custom data
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 * @param memory a pointer to the object to destruct
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
120 typedef void (*cx_destructor_func2)(void *data, void *memory);
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
121
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
122
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
123 /**
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
124 * Function pointer type for clone functions.
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
125 *
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
126 * A clone function is supposed to create a deep copy of the memory pointed to
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
127 * by the @p source pointer.
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
128 * If the @p target pointer is non-null, the clone function is supposed to store
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
129 * the copy into that memory region.
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
130 * Otherwise, the clone function shall use the specified @p allocator to create
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
131 * a new object.
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
132 *
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
133 * The return value of a clone function is always a pointer to the target
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
134 * memory region, or @c NULL if any allocation failed.
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
135 * A clone function SHOULD NOT fail for any other reason than an allocation
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
136 * failure.
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
137 *
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
138 * @param target the target memory or @c NULL, if memory shall be allocated
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
139 * @param source the source memory
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
140 * @param allocator the allocator that shall be used
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
141 * @param data optional additional data
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
142 * @return either the specified @p target, a pointer to the allocated memory,
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
143 * or @c NULL, if any error occurred
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
144 */
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
145 typedef void*(*cx_clone_func)(void *target, const void *source,
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
146 const CxAllocator *allocator, void *data);
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
147
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
148 /**
30
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
149 * Returns the system's memory page size.
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
150 *
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
151 * If the page size cannot be retrieved from the system,
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
152 * a default of 4096 bytes is assumed.
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
153 *
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
154 * @return the system's memory page size in bytes
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
155 */
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
156 cx_attr_nodiscard
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
157 CX_EXPORT unsigned long cx_system_page_size(void);
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
158
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
159 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
160 * Reallocate a previously allocated block.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
161 *
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
162 * Internal function - do not use.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
163 *
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
164 * @param mem pointer to the pointer to allocated block
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
165 * @param n the new size in bytes
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
166 * @retval zero success
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
167 * @retval non-zero failure
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
168 * @see cx_reallocatearray()
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
169 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
170 cx_attr_nonnull cx_attr_nodiscard
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
171 CX_EXPORT int cx_reallocate_(void **mem, size_t n);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
174 * Reallocate a previously allocated block.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
175 *
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
176 * Internal function - do not use.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
177 *
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
178 * @param mem pointer to the pointer to allocated block
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
179 * @param nmemb the number of elements
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
180 * @param size the size of each element
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
181 * @retval zero success
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
182 * @retval non-zero failure
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
183 * @see cx_reallocate()
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
184 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
185 cx_attr_nonnull cx_attr_nodiscard
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
186 CX_EXPORT int cx_reallocatearray_(void **mem, size_t nmemb, size_t size);
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
187
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
188 /**
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
189 * Reallocate a previously allocated block and changes the pointer in-place,
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
190 * if necessary.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 *
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
192 * @note This will use stdlib reallocate and @em not the cxDefaultAllocator.
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
193 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
194 * @par Error handling
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
195 * @c errno will be set by realloc() on failure.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
197 * @param mem (@c void**) pointer to the pointer to allocated block
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
198 * @param n (@c size_t) the new size in bytes
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
199 * @retval zero success
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
200 * @retval non-zero failure
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
201 * @see cx_reallocatearray()
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 */
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
203 #define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n)
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
204
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
205 /**
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
206 * Reallocate a previously allocated block and changes the pointer in-place,
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
207 * if necessary.
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
208 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
209 * The size is calculated by multiplying @p nemb and @p size.
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
210 *
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
211 * @note This will use stdlib reallocate and @em not the cxDefaultAllocator.
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
212 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
213 * @par Error handling
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
214 * @c errno will be set by realloc() on failure or when the multiplication of
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
215 * @p nmemb and @p size overflows.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
216 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
217 * @param mem (@c void**) pointer to the pointer to allocated block
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
218 * @param nmemb (@c size_t) the number of elements
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
219 * @param size (@c size_t) the size of each element
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
220 * @retval zero success
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
221 * @retval non-zero failure
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
222 */
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
223 #define cx_reallocatearray(mem, nmemb, size) \
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
224 cx_reallocatearray_((void**)(mem), nmemb, size)
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
225
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
226 /**
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
227 * Allocates memory and sets every byte to zero.
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
228 *
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
229 * @param n (@c size_t) the number of bytes
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
230 * @return (@c void*) a pointer to the allocated memory
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
231 */
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
232 #define cx_zalloc(n) calloc(1, n)
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
233
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
234 /**
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
235 * Free a block allocated by this allocator.
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
236 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
237 * @note Freeing a block of a different allocator is undefined.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
238 *
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
239 * @param allocator the allocator
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
240 * @param mem a pointer to the block to free
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
241 */
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
242 cx_attr_nonnull_arg(1)
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
243 CX_EXPORT void cxFree(const CxAllocator *allocator, void *mem);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 /**
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
246 * Allocate @p n bytes of memory.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 * @param allocator the allocator
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 * @param n the number of bytes
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 * @return a pointer to the allocated memory
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
252 cx_attr_nodiscard cx_attr_nonnull
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
253 cx_attr_malloc cx_attr_dealloc_ucx cx_attr_allocsize(2)
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
254 CX_EXPORT void *cxMalloc(const CxAllocator *allocator, size_t n);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 /**
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
257 * Reallocate the previously allocated block in @p mem, making the new block
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
258 * @p n bytes long.
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
259 * This function may return the same pointer passed to it if moving
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
260 * the memory was not necessary.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
262 * @note Re-allocating a block allocated by a different allocator is undefined.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 *
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
264 * @attention This function is bug-prone. Consider using cxReallocate().
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
265 *
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 * @param allocator the allocator
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 * @param mem pointer to the previously allocated block
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 * @param n the new size in bytes
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
269 * @return a pointer to the reallocated memory
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
271 cx_attr_nodiscard cx_attr_nonnull_arg(1)
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
272 cx_attr_dealloc_ucx cx_attr_allocsize(3)
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
273 CX_EXPORT void *cxRealloc(const CxAllocator *allocator, void *mem, size_t n);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
276 * Reallocate the previously allocated block in @p mem.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
277 *
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
278 * This function may return the same pointer passed to it if moving
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
279 * the memory was not necessary.
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
280 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
281 * The size is calculated by multiplying @p nemb and @p size.
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
282 * If that multiplication overflows, this function returns @c NULL, and @c errno
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
283 * will be set.
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
284 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
285 * @note Re-allocating a block allocated by a different allocator is undefined.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
286 *
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
287 * @attention This function is bug-prone. Consider using cxReallocateArray().
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
288 *
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
289 * @param allocator the allocator
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
290 * @param mem pointer to the previously allocated block
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
291 * @param nmemb the number of elements
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
292 * @param size the size of each element
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
293 * @return a pointer to the reallocated memory
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
294 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
295 cx_attr_nodiscard cx_attr_nonnull_arg(1)
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
296 cx_attr_dealloc_ucx cx_attr_allocsize(3, 4)
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
297 CX_EXPORT void *cxReallocArray(const CxAllocator *allocator,
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
298 void *mem, size_t nmemb, size_t size);
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
299
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
300 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
301 * Reallocate a previously allocated block.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 *
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
303 * Internal function - do not use.
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 *
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 * @param allocator the allocator
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 * @param mem pointer to the pointer to allocated block
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 * @param n the new size in bytes
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
308 * @retval zero success
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
309 * @retval non-zero failure
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
311 cx_attr_nodiscard cx_attr_nonnull
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
312 CX_EXPORT int cxReallocate_(const CxAllocator *allocator, void **mem, size_t n);
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
313
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
314 /**
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
315 * Reallocate a previously allocated block and changes the pointer in-place,
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
316 * if necessary.
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
317 * This function acts like cxRealloc() using the pointer pointed to by @p mem.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
318 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
319 * @note Re-allocating a block allocated by a different allocator is undefined.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
320 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
321 * @par Error handling
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
322 * @c errno will be set if the underlying realloc function does so.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
323 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
324 * @param allocator (@c CxAllocator*) the allocator
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
325 * @param mem (@c void**) pointer to the pointer to allocated block
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
326 * @param n (@c size_t) the new size in bytes
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
327 * @retval zero success
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
328 * @retval non-zero failure
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
329 */
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
330 #define cxReallocate(allocator, mem, n) \
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
331 cxReallocate_(allocator, (void**)(mem), n)
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
332
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
333 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
334 * Reallocate a previously allocated block.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
335 *
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
336 * Internal function - do not use.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
337 *
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
338 * @param allocator the allocator
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
339 * @param mem pointer to the pointer to allocated block
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
340 * @param nmemb the number of elements
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
341 * @param size the size of each element
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
342 * @retval zero success
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
343 * @retval non-zero on failure
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
344 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
345 cx_attr_nodiscard cx_attr_nonnull
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
346 CX_EXPORT int cxReallocateArray_(const CxAllocator *allocator,
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
347 void **mem, size_t nmemb, size_t size);
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
348
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
349 /**
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
350 * Reallocate a previously allocated block and changes the pointer in-place,
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
351 * if necessary.
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
352 * This function acts like cxReallocArray() using the pointer pointed to
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
353 * by @p mem.
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
354 *
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
355 * @note Re-allocating a block allocated by a different allocator is undefined.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
356 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
357 * @par Error handling
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
358 * @c errno will be set, if the underlying realloc function does so or the
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
359 * multiplication of @p nmemb and @p size overflows.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
360 *
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
361 * @param allocator (@c CxAllocator*) the allocator
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
362 * @param mem (@c void**) pointer to the pointer to allocated block
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
363 * @param nmemb (@c size_t) the number of elements
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
364 * @param size (@c size_t) the size of each element
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
365 * @retval zero success
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
366 * @retval non-zero failure
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
367 */
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
368 #define cxReallocateArray(allocator, mem, nmemb, size) \
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
369 cxReallocateArray_(allocator, (void**) (mem), nmemb, size)
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
370
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
371 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
372 * Allocate @p nmemb elements of @p size bytes each, all initialized to zero.
11
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
373 *
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
374 * @param allocator the allocator
0aa8cbd7912e refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
375 * @param nmemb the number of elements
16
04c9f8d8f03b update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 11
diff changeset
376 * @param size the size of each element in bytes
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 * @return a pointer to the allocated memory
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
379 cx_attr_nonnull_arg(1) cx_attr_nodiscard
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
380 cx_attr_malloc cx_attr_dealloc_ucx cx_attr_allocsize(2, 3)
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
381 CX_EXPORT void *cxCalloc(const CxAllocator *allocator, size_t nmemb, size_t size);
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
383 /**
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
384 * Allocate @p n bytes of memory and sets every byte to zero.
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
385 *
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
386 * @param allocator the allocator
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
387 * @param n the number of bytes
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
388 * @return a pointer to the allocated memory
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
389 */
22
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
390 cx_attr_nodiscard cx_attr_nonnull
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
391 cx_attr_malloc cx_attr_dealloc_ucx cx_attr_allocsize(2)
112b85020dc9 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
392 CX_EXPORT void *cxZalloc(const CxAllocator *allocator, size_t n);
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
393
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
394 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
395 * Allocate @p n bytes of memory.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
396 *
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
397 * Convenience macro that invokes cxMalloc() with the cxDefaultAllocator.
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
398 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
399 * @param n (@c size_t) the number of bytes
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
400 * @return (@c void*) a pointer to the allocated memory
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
401 */
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
402 #define cxMallocDefault(n) cxMalloc(cxDefaultAllocator, n)
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
403
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
404 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
405 * Allocate @p n bytes of memory and sets every byte to zero.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
406 *
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
407 * Convenience macro that invokes cxZalloc() with the cxDefaultAllocator.
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
408 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
409 * @param n (@c size_t) the number of bytes
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
410 * @return (@c void*) a pointer to the allocated memory
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
411 */
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
412 #define cxZallocDefault(n) cxZalloc(cxDefaultAllocator, n)
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
413
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
414 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
415 * Allocate @p nmemb elements of @p size bytes each, all initialized to zero.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
416 *
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
417 * Convenience macro that invokes cxCalloc() with the cxDefaultAllocator.
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
418 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
419 * @param nmemb (@c size_t) the number of elements
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
420 * @param size (@c size_t) the size of each element in bytes
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
421 * @return (@c void*) a pointer to the allocated memory
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
422 */
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
423 #define cxCallocDefault(nmemb, size) cxCalloc(cxDefaultAllocator, nmemb, size)
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
424
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
425 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
426 * Reallocate the previously allocated block in @p mem.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
427 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
428 * This function may return the same pointer passed to it if moving
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
429 * the memory was not necessary.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
430 *
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
431 * Convenience macro that invokes cxRealloc() with the cxDefaultAllocator.
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
432 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
433 * @attention This function is bug-prone. Consider using cxReallocateDefault().
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
434 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
435 * @param mem (@c void*) pointer to the previously allocated block
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
436 * @param n (@c size_t) the new size in bytes
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
437 * @return (@c void*) a pointer to the reallocated memory
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
438 */
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
439 #define cxReallocDefault(mem, n) cxRealloc(cxDefaultAllocator, mem, n)
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
440
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
441 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
442 * Reallocate a previously allocated block and changes the pointer in-place,
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
443 * if necessary.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
444 * This function acts like cxRealloc() using the pointer pointed to by @p mem.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
445 *
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
446 * Convenience macro that invokes cxReallocate() with the cxDefaultAllocator.
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
447 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
448 * @note Re-allocating a block allocated by a different allocator is undefined.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
449 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
450 * @par Error handling
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
451 * @c errno will be set if the underlying realloc function does so.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
452 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
453 * @param mem (@c void**) pointer to the pointer to allocated block
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
454 * @param n (@c size_t) the new size in bytes
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
455 * @retval zero success
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
456 * @retval non-zero failure
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
457 */
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
458 #define cxReallocateDefault(mem, n) cxReallocate(cxDefaultAllocator, mem, n)
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
459
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
460 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
461 * Reallocate a previously allocated block and changes the pointer in-place,
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
462 * if necessary.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
463 * This function acts like cxReallocArray() using the pointer pointed to
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
464 * by @p mem.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
465 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
466 * Convenience macro that invokes cxReallocateArray() with the cxDefaultAllocator.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
467 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
468 * @note Re-allocating a block allocated by a different allocator is undefined.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
469 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
470 * @par Error handling
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
471 * @c errno will be set, if the underlying realloc function does so or the
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
472 * multiplication of @p nmemb and @p size overflows.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
473 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
474 * @param mem (@c void**) pointer to the pointer to allocated block
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
475 * @param nmemb (@c size_t) the number of elements
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
476 * @param size (@c size_t) the size of each element
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
477 * @retval zero success
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
478 * @retval non-zero failure
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
479 */
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
480 #define cxReallocateArrayDefault(mem, nmemb, size) \
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
481 cxReallocateArray(cxDefaultAllocator, mem, nmemb, size)
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
482
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
483 /**
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
484 * Reallocate the previously allocated block in @p mem.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
485 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
486 * Convenience macro that invokes cxReallocArray() with the cxDefaultAllocator.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
487 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
488 * This function may return the same pointer passed to it if moving
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
489 * the memory was not necessary.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
490 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
491 * The size is calculated by multiplying @p nemb and @p size.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
492 * If that multiplication overflows, this function returns @c NULL, and @c errno
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
493 * will be set.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
494 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
495 * @note Re-allocating a block allocated by a different allocator is undefined.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
496 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
497 * @attention This function is bug-prone. Consider using cxReallocateArrayDefault().
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
498 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
499 * @param mem (@c void*) pointer to the previously allocated block
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
500 * @param nmemb (@c size_t) the number of elements
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
501 * @param size (@c size_t) the size of each element
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
502 * @return (@c void*) a pointer to the reallocated memory
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
503 */
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
504 #define cxReallocArrayDefault(mem, nmemb, size) cxReallocArray(cxDefaultAllocator, mem, nmemb, size)
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
505
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
506 /**
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
507 * Free a block of memory.
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
508 *
30
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
509 * Convenience function that invokes cxFree() with the cxDefaultAllocator.
31
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
510 *
287484519844 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
511 * @param mem the memory to deallocate
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
512 */
30
d33eaaec15da update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
513 CX_EXPORT void cxFreeDefault(void *mem);
21
5ea41679e15d update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
514
0
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515 #ifdef __cplusplus
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 } // extern "C"
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517 #endif
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518
1a157da63d7c add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
519 #endif // UCX_ALLOCATOR_H

mercurial