1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
39
* Simple arena allocator for xpt (which avoids using NSPR).
42
#ifndef __xpt_arena_h__
43
#define __xpt_arena_h__
50
* The linkage of XPT API functions differs depending on whether the file is
51
* used within the XPT library or not. Any source file within the XPT
52
* library should define EXPORT_XPT_API whereas any client of the library
56
#define XPT_PUBLIC_API(t) PR_IMPLEMENT(t)
57
#define XPT_PUBLIC_DATA(t) PR_IMPLEMENT_DATA(t)
60
# define XPT_PUBLIC_API(t) __declspec(dllimport) t
61
# define XPT_PUBLIC_DATA(t) __declspec(dllimport) t
63
# define XPT_PUBLIC_API(t) PR_IMPLEMENT(t)
64
# define XPT_PUBLIC_DATA(t) t
67
#define XPT_FRIEND_API(t) XPT_PUBLIC_API(t)
68
#define XPT_FRIEND_DATA(t) XPT_PUBLIC_DATA(t)
73
* Simple Arena support. Use with caution!
76
typedef struct XPTArena XPTArena;
78
XPT_PUBLIC_API(XPTArena *)
79
XPT_NewArena(PRUint32 block_size, size_t alignment, const char* name);
82
XPT_DestroyArena(XPTArena *arena);
85
XPT_DumpStats(XPTArena *arena);
87
XPT_PUBLIC_API(void *)
88
XPT_ArenaMalloc(XPTArena *arena, size_t size);
90
XPT_PUBLIC_API(char *)
91
XPT_ArenaStrDup(XPTArena *arena, const char * s);
94
XPT_NotifyDoneLoading(XPTArena *arena);
97
XPT_ArenaFree(XPTArena *arena, void* block);
99
/* --------------------------------------------------------- */
101
#define XPT_MALLOC(_arena, _bytes) \
102
XPT_ArenaMalloc((_arena), (_bytes))
105
#define XPT_FREE(_arena, _ptr) \
106
XPT_ArenaFree((_arena), (_ptr))
108
#define XPT_FREE(_arena, _ptr) \
112
#define XPT_STRDUP(_arena, _s) \
113
XPT_ArenaStrDup((_arena), (_s))
115
#define XPT_CALLOC(_arena, _size) XPT_MALLOC((_arena), (_size))
116
#define XPT_NEW(_arena, _struct) ((_struct *) XPT_MALLOC((_arena), sizeof(_struct)))
117
#define XPT_NEWZAP(_arena, _struct) XPT_NEW((_arena), _struct)
118
#define XPT_DELETE(_arena, _ptr) do{XPT_FREE((_arena), (_ptr)); ((_ptr)) = NULL;}while(0)
119
#define XPT_FREEIF(_arena, _ptr) do{if ((_ptr)) XPT_FREE((_arena), (_ptr));}while(0)
121
/* --------------------------------------------------------- */
125
XPT_AssertFailed(const char *s, const char *file, PRUint32 lineno);
126
#define XPT_ASSERT(_expr) \
127
((_expr)?((void)0):XPT_AssertFailed(# _expr, __FILE__, __LINE__))
129
#define XPT_ASSERT(_expr) ((void)0)
134
#endif /* __xpt_arena_h__ */