ucx/cx/allocator.h

5 weeks ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Feb 2025 13:11:32 +0100 (5 weeks ago)
changeset 854
1c8401ece69e
parent 852
83fdf679df99
permissions
-rw-r--r--

update ucx to version 3.1

747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
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
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
29 * @file allocator.h
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 * Interface for custom allocators.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #ifndef UCX_ALLOCATOR_H
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #define UCX_ALLOCATOR_H
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "common.h"
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #ifdef __cplusplus
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 extern "C" {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #endif
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 * The class definition for an allocator.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 typedef struct {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 * The allocator's malloc() implementation.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 void *(*malloc)(
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 void *data,
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 size_t n
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 );
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 * The allocator's realloc() implementation.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 void *(*realloc)(
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 void *data,
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 void *mem,
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 size_t n
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
61 );
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 * The allocator's calloc() implementation.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 void *(*calloc)(
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 void *data,
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
68 size_t nmemb,
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
69 size_t size
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 );
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 * The allocator's free() implementation.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 void (*free)(
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 void *data,
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 void *mem
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
78 );
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 } cx_allocator_class;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 * Structure holding the data for an allocator.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 struct cx_allocator_s {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 * A pointer to the instance of the allocator class.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 cx_allocator_class *cl;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 * A pointer to the data this allocator uses.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 void *data;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 };
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 * High-Level type alias for the allocator type.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 typedef struct cx_allocator_s CxAllocator;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 * A default allocator using standard library malloc() etc.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 */
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
103 cx_attr_export
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
104 extern const CxAllocator * const cxDefaultAllocator;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 * Function pointer type for destructor functions.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 * A destructor function deallocates possible contents and MAY free the memory
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
110 * pointed to by @p memory. Read the documentation of the respective function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
111 * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
112 * that particular implementation.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 * @param memory a pointer to the object to destruct
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
116 typedef void (*cx_destructor_func)(void *memory);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 /**
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 * Function pointer type for destructor functions.
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 * A destructor function deallocates possible contents and MAY free the memory
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
122 * pointed to by @p memory. Read the documentation of the respective function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
123 * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
124 * that particular implementation.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 * @param data an optional pointer to custom data
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 * @param memory a pointer to the object to destruct
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 */
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 typedef void (*cx_destructor_func2)(
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 void *data,
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 void *memory
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
132 );
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
135 * Reallocate a previously allocated block and changes the pointer in-place,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
136 * if necessary.
775
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
137 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
138 * @par Error handling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
139 * @c errno will be set by realloc() on failure.
775
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
140 *
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
141 * @param mem pointer to the pointer to allocated block
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
142 * @param n the new size in bytes
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
143 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
144 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
145 * @see cx_reallocatearray()
775
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
146 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
147 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
148 cx_attr_nodiscard
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
149 cx_attr_export
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
150 int cx_reallocate_(
775
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
151 void **mem,
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
152 size_t n
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
153 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
154
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
155 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
156 * Reallocate a previously allocated block and changes the pointer in-place,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
157 * if necessary.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
158 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
159 * The size is calculated by multiplying @p nemb and @p size.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
160 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
161 * @par Error handling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
162 * @c errno will be set by realloc() on failure or when the multiplication of
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
163 * @p nmemb and @p size overflows.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
164 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
165 * @param mem pointer to the pointer to allocated block
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
166 * @param nmemb the number of elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
167 * @param size the size of each element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
168 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
169 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
170 * @see cx_reallocate()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
171 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
172 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
173 cx_attr_nodiscard
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
174 cx_attr_export
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
175 int cx_reallocatearray_(
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
176 void **mem,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
177 size_t nmemb,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
178 size_t size
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
179 );
775
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
180
e5909dff0dbf update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
181 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
182 * Reallocate a previously allocated block and changes the pointer in-place,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
183 * if necessary.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
184 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
185 * @par Error handling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
186 * @c errno will be set by realloc() on failure.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
187 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
188 * @param mem (@c void**) pointer to the pointer to allocated block
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
189 * @param n (@c size_t) the new size in bytes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
190 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
191 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
192 * @see cx_reallocatearray()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
193 */
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
194 #define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n)
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
195
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
196 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
197 * Reallocate a previously allocated block and changes the pointer in-place,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
198 * if necessary.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
199 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
200 * The size is calculated by multiplying @p nemb and @p size.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
201 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
202 * @par Error handling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
203 * @c errno will be set by realloc() on failure or when the multiplication of
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
204 * @p nmemb and @p size overflows.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
205 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
206 * @param mem (@c void**) pointer to the pointer to allocated block
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
207 * @param nmemb (@c size_t) the number of elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
208 * @param size (@c size_t) the size of each element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
209 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
210 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
211 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
212 #define cx_reallocatearray(mem, nmemb, size) \
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
213 cx_reallocatearray_((void**)(mem), nmemb, size)
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
214
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
215 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
216 * Free a block allocated by this allocator.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
217 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
218 * @note Freeing a block of a different allocator is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
219 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
220 * @param allocator the allocator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
221 * @param mem a pointer to the block to free
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
222 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
223 cx_attr_nonnull_arg(1)
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
224 cx_attr_export
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
225 void cxFree(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
226 const CxAllocator *allocator,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
227 void *mem
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
228 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
229
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
230 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
231 * Allocate @p n bytes of memory.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 * @param allocator the allocator
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 * @param n the number of bytes
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 * @return a pointer to the allocated memory
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
237 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
238 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
239 cx_attr_malloc
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
240 cx_attr_dealloc_ucx
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
241 cx_attr_allocsize(2)
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
242 cx_attr_export
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 void *cxMalloc(
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
244 const CxAllocator *allocator,
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 size_t n
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
246 );
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
249 * Reallocate the previously allocated block in @p mem, making the new block
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
250 * @p n bytes long.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
251 * This function may return the same pointer that was passed to it, if moving
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
252 * the memory was not necessary.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
254 * @note Re-allocating a block allocated by a different allocator is undefined.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 * @param allocator the allocator
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 * @param mem pointer to the previously allocated block
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 * @param n the new size in bytes
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
259 * @return a pointer to the reallocated memory
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
261 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
262 cx_attr_nonnull_arg(1)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
263 cx_attr_dealloc_ucx
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
264 cx_attr_allocsize(3)
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
265 cx_attr_export
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 void *cxRealloc(
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
267 const CxAllocator *allocator,
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 void *mem,
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 size_t n
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
270 );
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
273 * Reallocate the previously allocated block in @p mem, making the new block
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
274 * @p n bytes long.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
275 * This function may return the same pointer that was passed to it, if moving
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
276 * the memory was not necessary.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
277 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
278 * The size is calculated by multiplying @p nemb and @p size.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
279 * If that multiplication overflows, this function returns @c NULL and @c errno
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
280 * will be set.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
281 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
282 * @note Re-allocating a block allocated by a different allocator is undefined.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
284 * @param allocator the allocator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
285 * @param mem pointer to the previously allocated block
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
286 * @param nmemb the number of elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
287 * @param size the size of each element
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
288 * @return a pointer to the reallocated memory
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
289 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
290 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
291 cx_attr_nonnull_arg(1)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
292 cx_attr_dealloc_ucx
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
293 cx_attr_allocsize(3, 4)
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
294 cx_attr_export
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
295 void *cxReallocArray(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
296 const CxAllocator *allocator,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
297 void *mem,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
298 size_t nmemb,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
299 size_t size
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
300 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
301
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
302 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
303 * Reallocate a previously allocated block and changes the pointer in-place,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
304 * if necessary.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
305 * This function acts like cxRealloc() using the pointer pointed to by @p mem.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
307 * @note Re-allocating a block allocated by a different allocator is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
308 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
309 * @par Error handling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
310 * @c errno will be set, if the underlying realloc function does so.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 * @param allocator the allocator
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 * @param mem pointer to the pointer to allocated block
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 * @param n the new size in bytes
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
315 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
316 * @retval non-zero failure
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
318 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
319 cx_attr_nonnull
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
320 cx_attr_export
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
321 int cxReallocate_(
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
322 const CxAllocator *allocator,
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 void **mem,
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 size_t n
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
325 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
326
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
327 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
328 * Reallocate a previously allocated block and changes the pointer in-place,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
329 * if necessary.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
330 * This function acts like cxRealloc() using the pointer pointed to by @p mem.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
331 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
332 * @note Re-allocating a block allocated by a different allocator is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
333 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
334 * @par Error handling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
335 * @c errno will be set, if the underlying realloc function does so.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
336 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
337 * @param allocator (@c CxAllocator*) the allocator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
338 * @param mem (@c void**) pointer to the pointer to allocated block
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
339 * @param n (@c size_t) the new size in bytes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
340 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
341 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
342 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
343 #define cxReallocate(allocator, mem, n) \
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
344 cxReallocate_(allocator, (void**)(mem), n)
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
347 * Reallocate a previously allocated block and changes the pointer in-place,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
348 * if necessary.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
349 * This function acts like cxReallocArray() using the pointer pointed to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
350 * by @p mem.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
351 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
352 * @note Re-allocating a block allocated by a different allocator is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
353 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
354 * @par Error handling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
355 * @c errno will be set, if the underlying realloc function does so or the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
356 * multiplication of @p nmemb and @p size overflows.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
357 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
358 * @param allocator the allocator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
359 * @param mem pointer to the pointer to allocated block
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
360 * @param nmemb the number of elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
361 * @param size the size of each element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
362 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
363 * @retval non-zero on failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
364 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
365 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
366 cx_attr_nonnull
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
367 cx_attr_export
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
368 int cxReallocateArray_(
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
369 const CxAllocator *allocator,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
370 void **mem,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
371 size_t nmemb,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
372 size_t size
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
373 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
374
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
375 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
376 * Reallocate a previously allocated block and changes the pointer in-place,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
377 * if necessary.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
378 * This function acts like cxReallocArray() using the pointer pointed to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
379 * by @p mem.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
380 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
381 * @note Re-allocating a block allocated by a different allocator is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
382 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
383 * @par Error handling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
384 * @c errno will be set, if the underlying realloc function does so or the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
385 * multiplication of @p nmemb and @p size overflows.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
386 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
387 * @param allocator (@c CxAllocator*) the allocator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
388 * @param mem (@c void**) pointer to the pointer to allocated block
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
389 * @param nmemb (@c size_t) the number of elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
390 * @param size (@c size_t) the size of each element
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
391 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
392 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
393 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
394 #define cxReallocateArray(allocator, mem, nmemb, size) \
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
395 cxReallocateArray_(allocator, (void**) (mem), nmemb, size)
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
396
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
397 /**
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
398 * Allocate @p nmemb elements of @p n bytes each, all initialized to zero.
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 *
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400 * @param allocator the allocator
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
401 * @param nmemb the number of elements
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
402 * @param size the size of each element in bytes
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 * @return a pointer to the allocated memory
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
405 cx_attr_nonnull_arg(1)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
406 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
407 cx_attr_malloc
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
408 cx_attr_dealloc_ucx
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
409 cx_attr_allocsize(2, 3)
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
410 cx_attr_export
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 void *cxCalloc(
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
412 const CxAllocator *allocator,
854
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
413 size_t nmemb,
1c8401ece69e update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 852
diff changeset
414 size_t size
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 775
diff changeset
415 );
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 #ifdef __cplusplus
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418 } // extern "C"
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 #endif
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 #endif // UCX_ALLOCATOR_H

mercurial