VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prmem.h@ 50011

Last change on this file since 50011 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
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
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
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 MPL, 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 MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/*
39** File: prmem.h
40** Description: API to NSPR 2.0 memory management functions
41**
42*/
43#ifndef prmem_h___
44#define prmem_h___
45
46#include "prtypes.h"
47#include <stddef.h>
48#include <stdlib.h>
49
50#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
51#define PR_Malloc VBoxNsprPR_Malloc
52#define PR_Calloc VBoxNsprPR_Calloc
53#define PR_Realloc VBoxNsprPR_Realloc
54#define PR_Free VBoxNsprPR_Free
55#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
56
57PR_BEGIN_EXTERN_C
58
59/*
60** Thread safe memory allocation.
61**
62** NOTE: pr wraps up malloc, free, calloc, realloc so they are already
63** thread safe (and are not declared here - look in stdlib.h).
64*/
65
66/*
67** PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free have the same signatures
68** as their libc equivalent malloc, calloc, realloc, and free, and have
69** the same semantics. (Note that the argument type size_t is replaced
70** by PRUint32.) Memory allocated by PR_Malloc, PR_Calloc, or PR_Realloc
71** must be freed by PR_Free.
72*/
73
74NSPR_API(void *) PR_Malloc(PRUint32 size);
75
76NSPR_API(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize);
77
78NSPR_API(void *) PR_Realloc(void *ptr, PRUint32 size);
79
80NSPR_API(void) PR_Free(void *ptr);
81
82/*
83** The following are some convenience macros defined in terms of
84** PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free.
85*/
86
87/***********************************************************************
88** FUNCTION: PR_MALLOC()
89** DESCRIPTION:
90** PR_NEW() allocates an untyped item of size _size from the heap.
91** INPUTS: _size: size in bytes of item to be allocated
92** OUTPUTS: untyped pointer to the node allocated
93** RETURN: pointer to node or error returned from malloc().
94***********************************************************************/
95#define PR_MALLOC(_bytes) (PR_Malloc((_bytes)))
96
97/***********************************************************************
98** FUNCTION: PR_NEW()
99** DESCRIPTION:
100** PR_NEW() allocates an item of type _struct from the heap.
101** INPUTS: _struct: a data type
102** OUTPUTS: pointer to _struct
103** RETURN: pointer to _struct or error returns from malloc().
104***********************************************************************/
105#define PR_NEW(_struct) ((_struct *) PR_MALLOC(sizeof(_struct)))
106
107/***********************************************************************
108** FUNCTION: PR_REALLOC()
109** DESCRIPTION:
110** PR_REALLOC() re-allocates _ptr bytes from the heap as a _size
111** untyped item.
112** INPUTS: _ptr: pointer to node to reallocate
113** _size: size of node to allocate
114** OUTPUTS: pointer to node allocated
115** RETURN: pointer to node allocated
116***********************************************************************/
117#define PR_REALLOC(_ptr, _size) (PR_Realloc((_ptr), (_size)))
118
119/***********************************************************************
120** FUNCTION: PR_CALLOC()
121** DESCRIPTION:
122** PR_CALLOC() allocates a _size bytes untyped item from the heap
123** and sets the allocated memory to all 0x00.
124** INPUTS: _size: size of node to allocate
125** OUTPUTS: pointer to node allocated
126** RETURN: pointer to node allocated
127***********************************************************************/
128#define PR_CALLOC(_size) (PR_Calloc(1, (_size)))
129
130/***********************************************************************
131** FUNCTION: PR_NEWZAP()
132** DESCRIPTION:
133** PR_NEWZAP() allocates an item of type _struct from the heap
134** and sets the allocated memory to all 0x00.
135** INPUTS: _struct: a data type
136** OUTPUTS: pointer to _struct
137** RETURN: pointer to _struct
138***********************************************************************/
139#define PR_NEWZAP(_struct) ((_struct*)PR_Calloc(1, sizeof(_struct)))
140
141/***********************************************************************
142** FUNCTION: PR_DELETE()
143** DESCRIPTION:
144** PR_DELETE() unallocates an object previosly allocated via PR_NEW()
145** or PR_NEWZAP() to the heap.
146** INPUTS: pointer to previously allocated object
147** OUTPUTS: the referenced object is returned to the heap
148** RETURN: void
149***********************************************************************/
150#define PR_DELETE(_ptr) { PR_Free(_ptr); (_ptr) = NULL; }
151
152/***********************************************************************
153** FUNCTION: PR_FREEIF()
154** DESCRIPTION:
155** PR_FREEIF() conditionally unallocates an object previously allocated
156** vial PR_NEW() or PR_NEWZAP(). If the pointer to the object is
157** equal to zero (0), the object is not released.
158** INPUTS: pointer to previously allocated object
159** OUTPUTS: the referenced object is conditionally returned to the heap
160** RETURN: void
161***********************************************************************/
162#define PR_FREEIF(_ptr) if (_ptr) PR_DELETE(_ptr)
163
164PR_END_EXTERN_C
165
166#endif /* prmem_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette