LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / include / rtl / alloc.h
blob79a94704c222662f4a44c2cf2eb057a787e6fa14
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_RTL_ALLOC_H
25 #define INCLUDED_RTL_ALLOC_H
27 #include "sal/config.h"
29 #include "sal/saldllapi.h"
30 #include "sal/types.h"
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
37 /** Allocate memory.
39 A call to this function will return NULL upon the requested
40 memory size being either zero or larger than currently allocatable.
42 @param[in] Bytes memory size.
43 @return pointer to the allocated memory.
45 SAL_DLLPUBLIC void * SAL_CALL rtl_allocateMemory (
46 sal_Size Bytes
47 ) SAL_THROW_EXTERN_C();
50 /** Reallocate memory.
52 A call to this function with parameter 'Ptr' being NULL
53 is equivalent to a rtl_allocateMemory() call.
54 A call to this function with parameter 'Bytes' being 0
55 is equivalent to a rtl_freeMemory() call.
57 @see rtl_allocateMemory()
58 @see rtl_freeMemory()
60 @param[in] Ptr pointer to the previously allocated memory.
61 @param[in] Bytes new memory size.
62 @return pointer to the reallocated memory. May differ from Ptr.
64 SAL_DLLPUBLIC void * SAL_CALL rtl_reallocateMemory (
65 void * Ptr,
66 sal_Size Bytes
67 ) SAL_THROW_EXTERN_C();
70 /** Free memory.
71 @param[in] Ptr pointer to the previously allocated memory.
72 @return none. Memory is released. Ptr is invalid.
74 SAL_DLLPUBLIC void SAL_CALL rtl_freeMemory (
75 void * Ptr
76 ) SAL_THROW_EXTERN_C();
78 /** Allocate and zero memory.
80 A call to this function will return NULL upon the requested
81 memory size being either zero or larger than currently allocatable.
83 @param[in] Bytes memory size.
84 @return pointer to the allocated and zero'ed memory.
86 SAL_DLLPUBLIC void * SAL_CALL rtl_allocateZeroMemory (
87 sal_Size Bytes
88 ) SAL_THROW_EXTERN_C();
90 /** Zero memory
92 Fills a block of memory with zeros in a way that is guaranteed to be secure
94 @param[in] Ptr pointer to the previously allocated memory.
95 @param[in] Bytes memory size.
97 @since LibreOffice 5.0
99 SAL_DLLPUBLIC void SAL_CALL rtl_secureZeroMemory (
100 void * Ptr,
101 sal_Size Bytes
102 ) SAL_THROW_EXTERN_C();
105 /** Zero and free memory.
106 @param[in] Ptr pointer to the previously allocated memory.
107 @param[in] Bytes memory size.
108 @return none. Memory is zero'ed with rtl_secureZeroMemory() and released.
109 Ptr is invalid.
111 SAL_DLLPUBLIC void SAL_CALL rtl_freeZeroMemory (
112 void * Ptr,
113 sal_Size Bytes
114 ) SAL_THROW_EXTERN_C();
116 /** Allocate aligned memory.
118 A call to this function will return NULL upon the requested
119 memory size being either zero or larger than currently allocatable.
121 Memory obtained through this function must be freed with
122 rtl_freeAlignedMemory().
124 @param[in] Alignment alignment in bytes, must be a power of two multiple of
125 sizeof(void*).
126 @param[in] Bytes memory size.
127 @return pointer to the allocated memory.
129 @since LibreOffice 4.3
131 SAL_DLLPUBLIC void* SAL_CALL rtl_allocateAlignedMemory (
132 sal_Size Alignment,
133 sal_Size Bytes
134 ) SAL_THROW_EXTERN_C();
137 /** Free memory allocated with rtl_allocateAlignedMemory().
139 @param[in] Ptr pointer to the previously allocated memory.
140 @return none. Memory is released. Ptr is invalid.
142 @since LibreOffice 4.3
144 SAL_DLLPUBLIC void SAL_CALL rtl_freeAlignedMemory (
145 void * Ptr
146 ) SAL_THROW_EXTERN_C();
149 /** Opaque rtl_arena_type.
151 typedef struct SAL_DLLPUBLIC_RTTI rtl_arena_st rtl_arena_type;
153 #define RTL_ARENA_NAME_LENGTH 31
157 * @param[in] pName descriptive name; for debugging purposes.
158 * @param[in] quantum resource allocation unit / granularity; rounded up to next power of 2.
159 * @param[in] quantum_cache_max no longer used, should be 0.
160 * @param[in] source_arena passed as argument to source_alloc, source_free; usually NULL.
161 * @param[in] source_alloc function to allocate resources; usually rtl_arena_alloc.
162 * @param[in] source_free function to free resources; usually rtl_arena_free.
163 * @param[in] nFlags flags; usually 0.
165 * @return pointer to rtl_arena_type, or NULL upon failure.
167 * @see rtl_arena_destroy()
169 SAL_DLLPUBLIC rtl_arena_type * SAL_CALL rtl_arena_create (
170 const char * pName,
171 sal_Size quantum,
172 sal_Size quantum_cache_max,
173 rtl_arena_type * source_arena,
174 void * (SAL_CALL * source_alloc)(rtl_arena_type *, sal_Size *),
175 void (SAL_CALL * source_free) (rtl_arena_type *, void *, sal_Size),
176 int nFlags
177 ) SAL_THROW_EXTERN_C();
181 * @param[in] pArena the arena to destroy.
182 * @return None
184 * @see rtl_arena_create()
186 SAL_DLLPUBLIC void SAL_CALL rtl_arena_destroy (
187 rtl_arena_type * pArena
188 ) SAL_THROW_EXTERN_C();
192 * @param[in] pArena arena from which resource is allocated.
193 * @param[in,out] pBytes size of resource to allocate.
195 * @return allocated resource, or NULL upon failure.
197 * @see rtl_arena_free()
199 SAL_DLLPUBLIC void * SAL_CALL rtl_arena_alloc (
200 rtl_arena_type * pArena,
201 sal_Size * pBytes
202 ) SAL_THROW_EXTERN_C();
206 * @param[in] pArena arena from which resource was allocated.
207 * @param[in] pAddr resource to free.
208 * @param[in] nBytes size of resource.
210 * @return None.
212 * @see rtl_arena_alloc()
214 SAL_DLLPUBLIC void SAL_CALL rtl_arena_free (
215 rtl_arena_type * pArena,
216 void * pAddr,
217 sal_Size nBytes
218 ) SAL_THROW_EXTERN_C();
221 /** Opaque rtl_cache_type.
223 typedef struct rtl_cache_st rtl_cache_type;
225 #define RTL_CACHE_NAME_LENGTH 31
227 #define RTL_CACHE_FLAG_BULKDESTROY 1 /* obsolete */
230 * @param[in] pName descriptive name; for debugging purposes.
231 * @param[in] nObjSize object size.
232 * @param[in] nObjAlign object alignment; usually 0 for suitable default.
233 * @param[in] constructor object constructor callback function; returning 1 for success or 0 for failure.
234 * @param[in] destructor object destructor callback function.
235 * @param[in] reclaim reclaim callback function.
236 * @param[in] pUserArg opaque argument passed to callback functions.
237 * @param[in] pSource unused argument (should be null).
238 * @param[in] nFlags flags (unused).
240 * @return pointer to rtl_cache_type, or NULL upon failure.
242 * @see rtl_cache_destroy()
244 SAL_DLLPUBLIC rtl_cache_type * SAL_CALL rtl_cache_create (
245 const char * pName,
246 sal_Size nObjSize,
247 sal_Size nObjAlign,
248 int (SAL_CALL * constructor)(void * pObj, void * pUserArg),
249 void (SAL_CALL * destructor) (void * pObj, void * pUserArg),
250 void (SAL_CALL * reclaim) (void * pUserArg),
251 void * pUserArg,
252 rtl_arena_type * pSource,
253 int nFlags
254 ) SAL_THROW_EXTERN_C();
258 * @param[in] pCache the cache to destroy.
260 * @return None.
262 * @see rtl_cache_create()
264 SAL_DLLPUBLIC void SAL_CALL rtl_cache_destroy (
265 rtl_cache_type * pCache
266 ) SAL_THROW_EXTERN_C();
270 * @param[in] pCache cache from which object is allocated.
272 * @return pointer to the allocated object, or NULL upon failure.
274 SAL_DLLPUBLIC void * SAL_CALL rtl_cache_alloc (
275 rtl_cache_type * pCache
276 ) SAL_THROW_EXTERN_C();
280 * @param[in] pCache cache from which object was allocated.
281 * @param[in] pObj object to free.
283 * @return None.
285 * @see rtl_cache_alloc()
287 SAL_DLLPUBLIC void SAL_CALL rtl_cache_free (
288 rtl_cache_type * pCache,
289 void * pObj
290 ) SAL_THROW_EXTERN_C();
293 #ifdef LIBO_INTERNAL_ONLY
295 /** @cond INTERNAL */
296 /** rtl_alloc_preInit
298 * This function, is called at the beginning and again
299 * at the end of LibreOfficeKit pre-initialization to enable
300 * various optimizations.
302 * Its function is to annotate a section @start = true
303 * to end (@start = false) via. two calls. Inside this
304 * section string allocators are replaced with ones which cause the
305 * strings to be staticized at the end of the section.
307 * This brings a number of constraints - in particular no
308 * string allocated outside the section should be freed
309 * inside it, practically this means starting the section
310 * as early as possible. No string allocated inside the
311 * section will be freed subsequently as they are
312 * staticized.
314 * This method is not thread-safe, nor intended for use in
315 * a threaded context, cf. previous constraints.
317 * It is almost certainly not the method that you want,
318 * use with extraordinary care referring to the
319 * implementation.
321 * @since LibreOffice 6.1
323 SAL_DLLPUBLIC void SAL_CALL rtl_alloc_preInit (
324 sal_Bool start
325 ) SAL_THROW_EXTERN_C();
326 /** @endcond */
328 #endif
330 #ifdef __cplusplus
332 #endif
334 #endif // INCLUDED_RTL_ALLOC_H
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */