OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 #ifndef NSSBASE_H | 5 #ifndef NSSBASE_H |
6 #define NSSBASE_H | 6 #define NSSBASE_H |
7 | 7 |
8 #ifdef DEBUG | 8 #ifdef DEBUG |
9 static const char NSSBASE_CVS_ID[] = "@(#) $RCSfile: nssbase.h,v $ $Revision: 1.
5 $ $Date: 2012/07/06 18:19:32 $"; | 9 static const char NSSBASE_CVS_ID[] = "@(#) $RCSfile: nssbase.h,v $ $Revision: 1.
5 $ $Date: 2012/07/06 18:19:32 $"; |
10 #endif /* DEBUG */ | 10 #endif /* DEBUG */ |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 PR_BEGIN_EXTERN_C | 23 PR_BEGIN_EXTERN_C |
24 | 24 |
25 /* | 25 /* |
26 * NSSArena | 26 * NSSArena |
27 * | 27 * |
28 * The public methods relating to this type are: | 28 * The public methods relating to this type are: |
29 * | 29 * |
30 * NSSArena_Create -- constructor | 30 * NSSArena_Create -- constructor |
31 * NSSArena_Destroy | 31 * NSSArena_Destroy |
| 32 * NSS_ZAlloc |
| 33 * NSS_ZRealloc |
| 34 * NSS_ZFreeIf |
32 */ | 35 */ |
33 | 36 |
34 /* | 37 /* |
35 * NSSArena_Create | 38 * NSSArena_Create |
36 * | 39 * |
37 * This routine creates a new memory arena. This routine may return | 40 * This routine creates a new memory arena. This routine may return |
38 * NULL upon error, in which case it will have created an error stack. | 41 * NULL upon error, in which case it will have created an error stack. |
39 * | 42 * |
40 * The top-level error may be one of the following values: | 43 * The top-level error may be one of the following values: |
41 * NSS_ERROR_NO_MEMORY | 44 * NSS_ERROR_NO_MEMORY |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 * NULL upon error, which is an implied NSS_ERROR_NO_MEMORY | 129 * NULL upon error, which is an implied NSS_ERROR_NO_MEMORY |
127 * A NON-caller-owned pointer to an array of NSSError values | 130 * A NON-caller-owned pointer to an array of NSSError values |
128 */ | 131 */ |
129 | 132 |
130 NSS_EXTERN NSSError * | 133 NSS_EXTERN NSSError * |
131 NSS_GetErrorStack | 134 NSS_GetErrorStack |
132 ( | 135 ( |
133 void | 136 void |
134 ); | 137 ); |
135 | 138 |
| 139 /* |
| 140 * NSS_ZNEW |
| 141 * |
| 142 * This preprocessor macro will allocate memory for a new object |
| 143 * of the specified type with nss_ZAlloc, and will cast the |
| 144 * return value appropriately. If the optional arena argument is |
| 145 * non-null, the memory will be obtained from that arena; otherwise, |
| 146 * the memory will be obtained from the heap. This routine may |
| 147 * return NULL upon error, in which case it will have set an error |
| 148 * upon the error stack. |
| 149 * |
| 150 * The error may be one of the following values: |
| 151 * NSS_ERROR_INVALID_ARENA |
| 152 * NSS_ERROR_NO_MEMORY |
| 153 * |
| 154 * Return value: |
| 155 * NULL upon error |
| 156 * A pointer to the new segment of zeroed memory |
| 157 */ |
| 158 |
| 159 /* The following line exceeds 72 characters, but emacs barfs if we split it. */ |
| 160 #define NSS_ZNEW(arenaOpt, type) ((type *)NSS_ZAlloc((arenaOpt), sizeof(type))) |
| 161 |
| 162 /* |
| 163 * NSS_ZNEWARRAY |
| 164 * |
| 165 * This preprocessor macro will allocate memory for an array of |
| 166 * new objects, and will cast the return value appropriately. |
| 167 * If the optional arena argument is non-null, the memory will |
| 168 * be obtained from that arena; otherwise, the memory will be |
| 169 * obtained from the heap. This routine may return NULL upon |
| 170 * error, in which case it will have set an error upon the error |
| 171 * stack. The array size may be specified as zero. |
| 172 * |
| 173 * The error may be one of the following values: |
| 174 * NSS_ERROR_INVALID_ARENA |
| 175 * NSS_ERROR_NO_MEMORY |
| 176 * |
| 177 * Return value: |
| 178 * NULL upon error |
| 179 * A pointer to the new segment of zeroed memory |
| 180 */ |
| 181 |
| 182 /* The following line exceeds 72 characters, but emacs barfs if we split it. */ |
| 183 #define NSS_ZNEWARRAY(arenaOpt, type, quantity) ((type *)NSS_ZAlloc((arenaOpt),
sizeof(type) * (quantity))) |
| 184 |
| 185 |
| 186 /* |
| 187 * NSS_ZAlloc |
| 188 * |
| 189 * This routine allocates and zeroes a section of memory of the |
| 190 * size, and returns to the caller a pointer to that memory. If |
| 191 * the optional arena argument is non-null, the memory will be |
| 192 * obtained from that arena; otherwise, the memory will be obtained |
| 193 * from the heap. This routine may return NULL upon error, in |
| 194 * which case it will have set an error upon the error stack. The |
| 195 * value specified for size may be zero; in which case a valid |
| 196 * zero-length block of memory will be allocated. This block may |
| 197 * be expanded by calling NSS_ZRealloc. |
| 198 * |
| 199 * The error may be one of the following values: |
| 200 * NSS_ERROR_INVALID_ARENA |
| 201 * NSS_ERROR_NO_MEMORY |
| 202 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD |
| 203 * |
| 204 * Return value: |
| 205 * NULL upon error |
| 206 * A pointer to the new segment of zeroed memory |
| 207 */ |
| 208 |
| 209 NSS_EXTERN void * |
| 210 NSS_ZAlloc |
| 211 ( |
| 212 NSSArena *arenaOpt, |
| 213 PRUint32 size |
| 214 ); |
| 215 |
| 216 /* |
| 217 * NSS_ZRealloc |
| 218 * |
| 219 * This routine reallocates a block of memory obtained by calling |
| 220 * nss_ZAlloc or nss_ZRealloc. The portion of memory |
| 221 * between the new and old sizes -- which is either being newly |
| 222 * obtained or released -- is in either case zeroed. This routine |
| 223 * may return NULL upon failure, in which case it will have placed |
| 224 * an error on the error stack. |
| 225 * |
| 226 * The error may be one of the following values: |
| 227 * NSS_ERROR_INVALID_POINTER |
| 228 * NSS_ERROR_NO_MEMORY |
| 229 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD |
| 230 * |
| 231 * Return value: |
| 232 * NULL upon error |
| 233 * A pointer to the replacement segment of memory |
| 234 */ |
| 235 |
| 236 NSS_EXTERN void * |
| 237 NSS_ZRealloc |
| 238 ( |
| 239 void *pointer, |
| 240 PRUint32 newSize |
| 241 ); |
| 242 |
| 243 |
| 244 /* |
| 245 * NSS_ZFreeIf |
| 246 * |
| 247 * If the specified pointer is non-null, then the region of memory |
| 248 * to which it points -- which must have been allocated with |
| 249 * nss_ZAlloc -- will be zeroed and released. This routine |
| 250 * returns a PRStatus value; if successful, it will return PR_SUCCESS. |
| 251 * If unsuccessful, it will set an error on the error stack and return |
| 252 * PR_FAILURE. |
| 253 * |
| 254 * The error may be one of the following values: |
| 255 * NSS_ERROR_INVALID_POINTER |
| 256 * |
| 257 * Return value: |
| 258 * PR_SUCCESS |
| 259 * PR_FAILURE |
| 260 */ |
| 261 |
| 262 NSS_EXTERN PRStatus |
| 263 NSS_ZFreeIf |
| 264 ( |
| 265 void *pointer |
| 266 ); |
| 267 |
136 PR_END_EXTERN_C | 268 PR_END_EXTERN_C |
137 | 269 |
138 #endif /* NSSBASE_H */ | 270 #endif /* NSSBASE_H */ |
OLD | NEW |