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 BASE_H | 5 #ifndef BASE_H |
6 #define BASE_H | 6 #define BASE_H |
7 | 7 |
8 /* | 8 /* |
9 * base.h | 9 * base.h |
10 * | 10 * |
11 * This header file contains basic prototypes and preprocessor | 11 * This header file contains basic prototypes and preprocessor |
12 * definitions used throughout nss but not available publicly. | 12 * definitions used throughout nss but not available publicly. |
13 */ | 13 */ |
14 | 14 |
15 #ifndef BASET_H | 15 #ifndef BASET_H |
16 #include "baset.h" | 16 #include "baset.h" |
17 #endif /* BASET_H */ | 17 #endif /* BASET_H */ |
18 | 18 |
19 #ifndef NSSBASE_H | 19 #ifndef NSSBASE_H |
20 #include "nssbase.h" | 20 #include "nssbase.h" |
21 #endif /* NSSBASE_H */ | 21 #endif /* NSSBASE_H */ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 * A constant PLHashAllocOps structure is available for users | 57 * A constant PLHashAllocOps structure is available for users |
58 * of the NSPL PLHashTable routines. | 58 * of the NSPL PLHashTable routines. |
59 * | 59 * |
60 * nssArenaHashAllocOps | 60 * nssArenaHashAllocOps |
61 */ | 61 */ |
62 | 62 |
63 /* | 63 /* |
64 * nssArena_Create | 64 * nssArena_Create |
65 * | 65 * |
66 * This routine creates a new memory arena. This routine may return | 66 * This routine creates a new memory arena. This routine may return |
67 * NULL upon error, in which case it will have set an error on the | 67 * NULL upon error, in which case it will have set an error on the |
68 * error stack. | 68 * error stack. |
69 * | 69 * |
70 * The error may be one of the following values: | 70 * The error may be one of the following values: |
71 * NSS_ERROR_NO_MEMORY | 71 * NSS_ERROR_NO_MEMORY |
72 * | 72 * |
73 * Return value: | 73 * Return value: |
74 * NULL upon error | 74 * NULL upon error |
75 * A pointer to an NSSArena upon success | 75 * A pointer to an NSSArena upon success |
76 */ | 76 */ |
77 | 77 |
78 /* | 78 /* |
79 * XXX fgmr | 79 * XXX fgmr |
80 * Arenas can be named upon creation; this is mostly of use when | 80 * Arenas can be named upon creation; this is mostly of use when |
81 * debugging. Should we expose that here, allowing an optional | 81 * debugging. Should we expose that here, allowing an optional |
82 * "const char *name" argument? Should the public version of this | 82 * "const char *name" argument? Should the public version of this |
83 * call (NSSArena_Create) have it too? | 83 * call (NSSArena_Create) have it too? |
84 */ | 84 */ |
85 | 85 |
86 NSS_EXTERN NSSArena * | 86 NSS_EXTERN NSSArena *nssArena_Create(void); |
87 nssArena_Create | |
88 ( | |
89 void | |
90 ); | |
91 | 87 |
92 extern const NSSError NSS_ERROR_NO_MEMORY; | 88 extern const NSSError NSS_ERROR_NO_MEMORY; |
93 | 89 |
94 /* | 90 /* |
95 * nssArena_Destroy | 91 * nssArena_Destroy |
96 * | 92 * |
97 * This routine will destroy the specified arena, freeing all memory | 93 * This routine will destroy the specified arena, freeing all memory |
98 * allocated from it. This routine returns a PRStatus value; if | 94 * allocated from it. This routine returns a PRStatus value; if |
99 * successful, it will return PR_SUCCESS. If unsuccessful, it will | 95 * successful, it will return PR_SUCCESS. If unsuccessful, it will |
100 * set an error on the error stack and return PR_FAILURE. | 96 * set an error on the error stack and return PR_FAILURE. |
101 * | 97 * |
102 * The error may be one of the following values: | 98 * The error may be one of the following values: |
103 * NSS_ERROR_INVALID_ARENA | 99 * NSS_ERROR_INVALID_ARENA |
104 * | 100 * |
105 * Return value: | 101 * Return value: |
106 * PR_SUCCESS | 102 * PR_SUCCESS |
107 * PR_FAILURE | 103 * PR_FAILURE |
108 */ | 104 */ |
109 | 105 |
110 NSS_EXTERN PRStatus | 106 NSS_EXTERN PRStatus nssArena_Destroy(NSSArena *arena); |
111 nssArena_Destroy | |
112 ( | |
113 NSSArena *arena | |
114 ); | |
115 | 107 |
116 extern const NSSError NSS_ERROR_INVALID_ARENA; | 108 extern const NSSError NSS_ERROR_INVALID_ARENA; |
117 | 109 |
118 /* | 110 /* |
119 * nssArena_Mark | 111 * nssArena_Mark |
120 * | 112 * |
121 * This routine "marks" the current state of an arena. Space | 113 * This routine "marks" the current state of an arena. Space |
122 * allocated after the arena has been marked can be freed by | 114 * allocated after the arena has been marked can be freed by |
123 * releasing the arena back to the mark with nssArena_Release, | 115 * releasing the arena back to the mark with nssArena_Release, |
124 * or committed by calling nssArena_Unmark. When successful, | 116 * or committed by calling nssArena_Unmark. When successful, |
125 * this routine returns a valid nssArenaMark pointer. This | 117 * this routine returns a valid nssArenaMark pointer. This |
126 * routine may return NULL upon error, in which case it will | 118 * routine may return NULL upon error, in which case it will |
127 * have set an error on the error stack. | 119 * have set an error on the error stack. |
128 * | 120 * |
129 * The error may be one of the following values: | 121 * The error may be one of the following values: |
130 * NSS_ERROR_INVALID_ARENA | 122 * NSS_ERROR_INVALID_ARENA |
131 * NSS_ERROR_NO_MEMORY | 123 * NSS_ERROR_NO_MEMORY |
132 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD | 124 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD |
133 * | 125 * |
134 * Return value: | 126 * Return value: |
135 * NULL upon failure | 127 * NULL upon failure |
136 * An nssArenaMark pointer upon success | 128 * An nssArenaMark pointer upon success |
137 */ | 129 */ |
138 | 130 |
139 NSS_EXTERN nssArenaMark * | 131 NSS_EXTERN nssArenaMark *nssArena_Mark(NSSArena *arena); |
140 nssArena_Mark | |
141 ( | |
142 NSSArena *arena | |
143 ); | |
144 | 132 |
145 extern const NSSError NSS_ERROR_INVALID_ARENA; | 133 extern const NSSError NSS_ERROR_INVALID_ARENA; |
146 extern const NSSError NSS_ERROR_NO_MEMORY; | 134 extern const NSSError NSS_ERROR_NO_MEMORY; |
147 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; | 135 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; |
148 | 136 |
149 /* | 137 /* |
150 * nssArena_Release | 138 * nssArena_Release |
151 * | 139 * |
152 * This routine invalidates and releases all memory allocated from | 140 * This routine invalidates and releases all memory allocated from |
153 * the specified arena after the point at which the specified mark | 141 * the specified arena after the point at which the specified mark |
154 * was obtained. This routine returns a PRStatus value; if successful, | 142 * was obtained. This routine returns a PRStatus value; if successful, |
155 * it will return PR_SUCCESS. If unsuccessful, it will set an error | 143 * it will return PR_SUCCESS. If unsuccessful, it will set an error |
156 * on the error stack and return PR_FAILURE. | 144 * on the error stack and return PR_FAILURE. |
157 * | 145 * |
158 * The error may be one of the following values: | 146 * The error may be one of the following values: |
159 * NSS_ERROR_INVALID_ARENA | 147 * NSS_ERROR_INVALID_ARENA |
160 * NSS_ERROR_INVALID_ARENA_MARK | 148 * NSS_ERROR_INVALID_ARENA_MARK |
161 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD | 149 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD |
162 * | 150 * |
163 * Return value: | 151 * Return value: |
164 * PR_SUCCESS | 152 * PR_SUCCESS |
165 * PR_FAILURE | 153 * PR_FAILURE |
166 */ | 154 */ |
167 | 155 |
168 NSS_EXTERN PRStatus | 156 NSS_EXTERN PRStatus nssArena_Release(NSSArena *arena, nssArenaMark *arenaMark); |
169 nssArena_Release | |
170 ( | |
171 NSSArena *arena, | |
172 nssArenaMark *arenaMark | |
173 ); | |
174 | 157 |
175 extern const NSSError NSS_ERROR_INVALID_ARENA; | 158 extern const NSSError NSS_ERROR_INVALID_ARENA; |
176 extern const NSSError NSS_ERROR_INVALID_ARENA_MARK; | 159 extern const NSSError NSS_ERROR_INVALID_ARENA_MARK; |
177 | 160 |
178 /* | 161 /* |
179 * nssArena_Unmark | 162 * nssArena_Unmark |
180 * | 163 * |
181 * This routine "commits" the indicated mark and any marks after | 164 * This routine "commits" the indicated mark and any marks after |
182 * it, making them unreleasable. Note that any earlier marks can | 165 * it, making them unreleasable. Note that any earlier marks can |
183 * still be released, and such a release will invalidate these | 166 * still be released, and such a release will invalidate these |
184 * later unmarked regions. If an arena is to be safely shared by | 167 * later unmarked regions. If an arena is to be safely shared by |
185 * more than one thread, all marks must be either released or | 168 * more than one thread, all marks must be either released or |
186 * unmarked. This routine returns a PRStatus value; if successful, | 169 * unmarked. This routine returns a PRStatus value; if successful, |
187 * it will return PR_SUCCESS. If unsuccessful, it will set an error | 170 * it will return PR_SUCCESS. If unsuccessful, it will set an error |
188 * on the error stack and return PR_FAILURE. | 171 * on the error stack and return PR_FAILURE. |
189 * | 172 * |
190 * The error may be one of the following values: | 173 * The error may be one of the following values: |
191 * NSS_ERROR_INVALID_ARENA | 174 * NSS_ERROR_INVALID_ARENA |
192 * NSS_ERROR_INVALID_ARENA_MARK | 175 * NSS_ERROR_INVALID_ARENA_MARK |
193 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD | 176 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD |
194 * | 177 * |
195 * Return value: | 178 * Return value: |
196 * PR_SUCCESS | 179 * PR_SUCCESS |
197 * PR_FAILURE | 180 * PR_FAILURE |
198 */ | 181 */ |
199 | 182 |
200 NSS_EXTERN PRStatus | 183 NSS_EXTERN PRStatus nssArena_Unmark(NSSArena *arena, nssArenaMark *arenaMark); |
201 nssArena_Unmark | |
202 ( | |
203 NSSArena *arena, | |
204 nssArenaMark *arenaMark | |
205 ); | |
206 | 184 |
207 extern const NSSError NSS_ERROR_INVALID_ARENA; | 185 extern const NSSError NSS_ERROR_INVALID_ARENA; |
208 extern const NSSError NSS_ERROR_INVALID_ARENA_MARK; | 186 extern const NSSError NSS_ERROR_INVALID_ARENA_MARK; |
209 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; | 187 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; |
210 | 188 |
211 #ifdef ARENA_DESTRUCTOR_LIST | 189 #ifdef ARENA_DESTRUCTOR_LIST |
212 | 190 |
213 /* | 191 /* |
214 * nssArena_registerDestructor | 192 * nssArena_registerDestructor |
215 * | 193 * |
216 * This routine stores a pointer to a callback and an arbitrary | 194 * This routine stores a pointer to a callback and an arbitrary |
217 * pointer-sized argument in the arena, at the current point in | 195 * pointer-sized argument in the arena, at the current point in |
218 * the mark stack. If the arena is destroyed, or an "earlier" | 196 * the mark stack. If the arena is destroyed, or an "earlier" |
219 * mark is released, then this destructor will be called at that | 197 * mark is released, then this destructor will be called at that |
220 * time. Note that the destructor will be called with the arena | 198 * time. Note that the destructor will be called with the arena |
221 * locked, which means the destructor may free memory in that | 199 * locked, which means the destructor may free memory in that |
222 * arena, but it may not allocate or cause to be allocated any | 200 * arena, but it may not allocate or cause to be allocated any |
223 * memory. This callback facility was included to support our | 201 * memory. This callback facility was included to support our |
224 * debug-version pointer-tracker feature; overuse runs counter to | 202 * debug-version pointer-tracker feature; overuse runs counter to |
225 * the the original intent of arenas. This routine returns a | 203 * the the original intent of arenas. This routine returns a |
226 * PRStatus value; if successful, it will return PR_SUCCESS. If | 204 * PRStatus value; if successful, it will return PR_SUCCESS. If |
227 * unsuccessful, it will set an error on the error stack and | 205 * unsuccessful, it will set an error on the error stack and |
228 * return PR_FAILURE. | 206 * return PR_FAILURE. |
229 * | 207 * |
230 * The error may be one of the following values: | 208 * The error may be one of the following values: |
231 * NSS_ERROR_INVALID_ARENA | 209 * NSS_ERROR_INVALID_ARENA |
232 * NSS_ERROR_NO_MEMORY | 210 * NSS_ERROR_NO_MEMORY |
233 * | 211 * |
234 * Return value: | 212 * Return value: |
235 * PR_SUCCESS | 213 * PR_SUCCESS |
236 * PR_FAILURE | 214 * PR_FAILURE |
237 */ | 215 */ |
238 | 216 |
239 NSS_EXTERN PRStatus | 217 NSS_EXTERN PRStatus nssArena_registerDestructor( |
240 nssArena_registerDestructor | 218 NSSArena *arena, void (*destructor)(void *argument), void *arg); |
241 ( | |
242 NSSArena *arena, | |
243 void (*destructor)(void *argument), | |
244 void *arg | |
245 ); | |
246 | 219 |
247 extern const NSSError NSS_ERROR_INVALID_ARENA; | 220 extern const NSSError NSS_ERROR_INVALID_ARENA; |
248 extern const NSSError NSS_ERROR_NO_MEMORY; | 221 extern const NSSError NSS_ERROR_NO_MEMORY; |
249 | 222 |
250 /* | 223 /* |
251 * nssArena_deregisterDestructor | 224 * nssArena_deregisterDestructor |
252 * | 225 * |
253 * This routine will remove the first destructor in the specified | 226 * This routine will remove the first destructor in the specified |
254 * arena which has the specified destructor and argument values. | 227 * arena which has the specified destructor and argument values. |
255 * The destructor will not be called. This routine returns a | 228 * The destructor will not be called. This routine returns a |
256 * PRStatus value; if successful, it will return PR_SUCCESS. If | 229 * PRStatus value; if successful, it will return PR_SUCCESS. If |
257 * unsuccessful, it will set an error on the error stack and | 230 * unsuccessful, it will set an error on the error stack and |
258 * return PR_FAILURE. | 231 * return PR_FAILURE. |
259 * | 232 * |
260 * The error may be one of the following values: | 233 * The error may be one of the following values: |
261 * NSS_ERROR_INVALID_ARENA | 234 * NSS_ERROR_INVALID_ARENA |
262 * NSS_ERROR_NOT_FOUND | 235 * NSS_ERROR_NOT_FOUND |
263 * | 236 * |
264 * Return value: | 237 * Return value: |
265 * PR_SUCCESS | 238 * PR_SUCCESS |
266 * PR_FAILURE | 239 * PR_FAILURE |
267 */ | 240 */ |
268 | 241 |
269 NSS_EXTERN PRStatus | 242 NSS_EXTERN PRStatus nssArena_deregisterDestructor( |
270 nssArena_deregisterDestructor | 243 NSSArena *arena, void (*destructor)(void *argument), void *arg); |
271 ( | |
272 NSSArena *arena, | |
273 void (*destructor)(void *argument), | |
274 void *arg | |
275 ); | |
276 | 244 |
277 extern const NSSError NSS_ERROR_INVALID_ITEM; | 245 extern const NSSError NSS_ERROR_INVALID_ITEM; |
278 extern const NSSError NSS_ERROR_INVALID_ARENA; | 246 extern const NSSError NSS_ERROR_INVALID_ARENA; |
279 extern const NSSError NSS_ERROR_NOT_FOUND; | 247 extern const NSSError NSS_ERROR_NOT_FOUND; |
280 | 248 |
281 #endif /* ARENA_DESTRUCTOR_LIST */ | 249 #endif /* ARENA_DESTRUCTOR_LIST */ |
282 | 250 |
283 /* | 251 /* |
284 * nss_ZAlloc | 252 * nss_ZAlloc |
285 * | 253 * |
286 * This routine allocates and zeroes a section of memory of the | 254 * This routine allocates and zeroes a section of memory of the |
287 * size, and returns to the caller a pointer to that memory. If | 255 * size, and returns to the caller a pointer to that memory. If |
288 * the optional arena argument is non-null, the memory will be | 256 * the optional arena argument is non-null, the memory will be |
289 * obtained from that arena; otherwise, the memory will be obtained | 257 * obtained from that arena; otherwise, the memory will be obtained |
290 * from the heap. This routine may return NULL upon error, in | 258 * from the heap. This routine may return NULL upon error, in |
291 * which case it will have set an error upon the error stack. The | 259 * which case it will have set an error upon the error stack. The |
292 * value specified for size may be zero; in which case a valid | 260 * value specified for size may be zero; in which case a valid |
293 * zero-length block of memory will be allocated. This block may | 261 * zero-length block of memory will be allocated. This block may |
294 * be expanded by calling nss_ZRealloc. | 262 * be expanded by calling nss_ZRealloc. |
295 * | 263 * |
296 * The error may be one of the following values: | 264 * The error may be one of the following values: |
297 * NSS_ERROR_INVALID_ARENA | 265 * NSS_ERROR_INVALID_ARENA |
298 * NSS_ERROR_NO_MEMORY | 266 * NSS_ERROR_NO_MEMORY |
299 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD | 267 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD |
300 * | 268 * |
301 * Return value: | 269 * Return value: |
302 * NULL upon error | 270 * NULL upon error |
303 * A pointer to the new segment of zeroed memory | 271 * A pointer to the new segment of zeroed memory |
304 */ | 272 */ |
305 | 273 |
306 NSS_EXTERN void * | 274 NSS_EXTERN void *nss_ZAlloc(NSSArena *arenaOpt, PRUint32 size); |
307 nss_ZAlloc | |
308 ( | |
309 NSSArena *arenaOpt, | |
310 PRUint32 size | |
311 ); | |
312 | 275 |
313 extern const NSSError NSS_ERROR_INVALID_ARENA; | 276 extern const NSSError NSS_ERROR_INVALID_ARENA; |
314 extern const NSSError NSS_ERROR_NO_MEMORY; | 277 extern const NSSError NSS_ERROR_NO_MEMORY; |
315 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; | 278 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; |
316 | 279 |
317 /* | 280 /* |
318 * nss_ZFreeIf | 281 * nss_ZFreeIf |
319 * | 282 * |
320 * If the specified pointer is non-null, then the region of memory | 283 * If the specified pointer is non-null, then the region of memory |
321 * to which it points -- which must have been allocated with | 284 * to which it points -- which must have been allocated with |
322 * nss_ZAlloc -- will be zeroed and released. This routine | 285 * nss_ZAlloc -- will be zeroed and released. This routine |
323 * returns a PRStatus value; if successful, it will return PR_SUCCESS. | 286 * returns a PRStatus value; if successful, it will return PR_SUCCESS. |
324 * If unsuccessful, it will set an error on the error stack and return | 287 * If unsuccessful, it will set an error on the error stack and return |
325 * PR_FAILURE. | 288 * PR_FAILURE. |
326 * | 289 * |
327 * The error may be one of the following values: | 290 * The error may be one of the following values: |
328 * NSS_ERROR_INVALID_POINTER | 291 * NSS_ERROR_INVALID_POINTER |
329 * | 292 * |
330 * Return value: | 293 * Return value: |
331 * PR_SUCCESS | 294 * PR_SUCCESS |
332 * PR_FAILURE | 295 * PR_FAILURE |
333 */ | 296 */ |
334 | 297 |
335 NSS_EXTERN PRStatus | 298 NSS_EXTERN PRStatus nss_ZFreeIf(void *pointer); |
336 nss_ZFreeIf | |
337 ( | |
338 void *pointer | |
339 ); | |
340 | 299 |
341 extern const NSSError NSS_ERROR_INVALID_POINTER; | 300 extern const NSSError NSS_ERROR_INVALID_POINTER; |
342 | 301 |
343 /* | 302 /* |
344 * nss_ZRealloc | 303 * nss_ZRealloc |
345 * | 304 * |
346 * This routine reallocates a block of memory obtained by calling | 305 * This routine reallocates a block of memory obtained by calling |
347 * nss_ZAlloc or nss_ZRealloc. The portion of memory | 306 * nss_ZAlloc or nss_ZRealloc. The portion of memory |
348 * between the new and old sizes -- which is either being newly | 307 * between the new and old sizes -- which is either being newly |
349 * obtained or released -- is in either case zeroed. This routine | 308 * obtained or released -- is in either case zeroed. This routine |
350 * may return NULL upon failure, in which case it will have placed | 309 * may return NULL upon failure, in which case it will have placed |
351 * an error on the error stack. | 310 * an error on the error stack. |
352 * | 311 * |
353 * The error may be one of the following values: | 312 * The error may be one of the following values: |
354 * NSS_ERROR_INVALID_POINTER | 313 * NSS_ERROR_INVALID_POINTER |
355 * NSS_ERROR_NO_MEMORY | 314 * NSS_ERROR_NO_MEMORY |
356 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD | 315 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD |
357 * | 316 * |
358 * Return value: | 317 * Return value: |
359 * NULL upon error | 318 * NULL upon error |
360 * A pointer to the replacement segment of memory | 319 * A pointer to the replacement segment of memory |
361 */ | 320 */ |
362 | 321 |
363 NSS_EXTERN void * | 322 NSS_EXTERN void *nss_ZRealloc(void *pointer, PRUint32 newSize); |
364 nss_ZRealloc | |
365 ( | |
366 void *pointer, | |
367 PRUint32 newSize | |
368 ); | |
369 | 323 |
370 extern const NSSError NSS_ERROR_INVALID_POINTER; | 324 extern const NSSError NSS_ERROR_INVALID_POINTER; |
371 extern const NSSError NSS_ERROR_NO_MEMORY; | 325 extern const NSSError NSS_ERROR_NO_MEMORY; |
372 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; | 326 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; |
373 | 327 |
374 /* | 328 /* |
375 * nss_ZNEW | 329 * nss_ZNEW |
376 * | 330 * |
377 * This preprocessor macro will allocate memory for a new object | 331 * This preprocessor macro will allocate memory for a new object |
378 * of the specified type with nss_ZAlloc, and will cast the | 332 * of the specified type with nss_ZAlloc, and will cast the |
379 * return value appropriately. If the optional arena argument is | 333 * return value appropriately. If the optional arena argument is |
380 * non-null, the memory will be obtained from that arena; otherwise, | 334 * non-null, the memory will be obtained from that arena; otherwise, |
381 * the memory will be obtained from the heap. This routine may | 335 * the memory will be obtained from the heap. This routine may |
382 * return NULL upon error, in which case it will have set an error | 336 * return NULL upon error, in which case it will have set an error |
383 * upon the error stack. | 337 * upon the error stack. |
384 * | 338 * |
385 * The error may be one of the following values: | 339 * The error may be one of the following values: |
386 * NSS_ERROR_INVALID_ARENA | 340 * NSS_ERROR_INVALID_ARENA |
387 * NSS_ERROR_NO_MEMORY | 341 * NSS_ERROR_NO_MEMORY |
388 * | 342 * |
389 * Return value: | 343 * Return value: |
390 * NULL upon error | 344 * NULL upon error |
391 * A pointer to the new segment of zeroed memory | 345 * A pointer to the new segment of zeroed memory |
392 */ | 346 */ |
393 | 347 |
394 /* The following line exceeds 72 characters, but emacs screws up if I split it.
*/ | |
395 #define nss_ZNEW(arenaOpt, type) ((type *)nss_ZAlloc((arenaOpt), sizeof(type))) | 348 #define nss_ZNEW(arenaOpt, type) ((type *)nss_ZAlloc((arenaOpt), sizeof(type))) |
396 | 349 |
397 /* | 350 /* |
398 * nss_ZNEWARRAY | 351 * nss_ZNEWARRAY |
399 * | 352 * |
400 * This preprocessor macro will allocate memory for an array of | 353 * This preprocessor macro will allocate memory for an array of |
401 * new objects, and will cast the return value appropriately. | 354 * new objects, and will cast the return value appropriately. |
402 * If the optional arena argument is non-null, the memory will | 355 * If the optional arena argument is non-null, the memory will |
403 * be obtained from that arena; otherwise, the memory will be | 356 * be obtained from that arena; otherwise, the memory will be |
404 * obtained from the heap. This routine may return NULL upon | 357 * obtained from the heap. This routine may return NULL upon |
405 * error, in which case it will have set an error upon the error | 358 * error, in which case it will have set an error upon the error |
406 * stack. The array size may be specified as zero. | 359 * stack. The array size may be specified as zero. |
407 * | 360 * |
408 * The error may be one of the following values: | 361 * The error may be one of the following values: |
409 * NSS_ERROR_INVALID_ARENA | 362 * NSS_ERROR_INVALID_ARENA |
410 * NSS_ERROR_NO_MEMORY | 363 * NSS_ERROR_NO_MEMORY |
411 * | 364 * |
412 * Return value: | 365 * Return value: |
413 * NULL upon error | 366 * NULL upon error |
414 * A pointer to the new segment of zeroed memory | 367 * A pointer to the new segment of zeroed memory |
415 */ | 368 */ |
416 | 369 |
417 /* The following line exceeds 72 characters, but emacs screws up if I split it.
*/ | 370 #define nss_ZNEWARRAY(arenaOpt, type, quantity) \ |
418 #define nss_ZNEWARRAY(arenaOpt, type, quantity) ((type *)nss_ZAlloc((arenaOpt),
sizeof(type) * (quantity))) | 371 ((type *)nss_ZAlloc((arenaOpt), sizeof(type) * (quantity))) |
419 | 372 |
420 /* | 373 /* |
421 * nss_ZREALLOCARRAY | 374 * nss_ZREALLOCARRAY |
422 * | 375 * |
423 * This preprocessor macro will reallocate memory for an array of | 376 * This preprocessor macro will reallocate memory for an array of |
424 * new objects, and will cast the return value appropriately. | 377 * new objects, and will cast the return value appropriately. |
425 * This routine may return NULL upon error, in which case it will | 378 * This routine may return NULL upon error, in which case it will |
426 * have set an error upon the error stack. | 379 * have set an error upon the error stack. |
427 * | 380 * |
428 * The error may be one of the following values: | 381 * The error may be one of the following values: |
429 * NSS_ERROR_INVALID_POINTER | 382 * NSS_ERROR_INVALID_POINTER |
430 * NSS_ERROR_NO_MEMORY | 383 * NSS_ERROR_NO_MEMORY |
431 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD | 384 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD |
432 * | 385 * |
433 * Return value: | 386 * Return value: |
434 * NULL upon error | 387 * NULL upon error |
435 * A pointer to the replacement segment of memory | 388 * A pointer to the replacement segment of memory |
436 */ | 389 */ |
437 #define nss_ZREALLOCARRAY(p, type, quantity) ((type *)nss_ZRealloc((p), sizeof(t
ype) * (quantity))) | 390 #define nss_ZREALLOCARRAY(p, type, quantity) \ |
| 391 ((type *)nss_ZRealloc((p), sizeof(type) * (quantity))) |
438 | 392 |
439 /* | 393 /* |
440 * nssArena_verifyPointer | 394 * nssArena_verifyPointer |
441 * | 395 * |
442 * This method is only present in debug builds. | 396 * This method is only present in debug builds. |
443 * | 397 * |
444 * If the specified pointer is a valid pointer to an NSSArena object, | 398 * If the specified pointer is a valid pointer to an NSSArena object, |
445 * this routine will return PR_SUCCESS. Otherwise, it will put an | 399 * this routine will return PR_SUCCESS. Otherwise, it will put an |
446 * error on the error stack and return PR_FAILURE. | 400 * error on the error stack and return PR_FAILURE. |
447 * | 401 * |
448 * The error may be one of the following values: | 402 * The error may be one of the following values: |
449 * NSS_ERROR_INVALID_ARENA | 403 * NSS_ERROR_INVALID_ARENA |
450 * | 404 * |
451 * Return value: | 405 * Return value: |
452 * PR_SUCCESS if the pointer is valid | 406 * PR_SUCCESS if the pointer is valid |
453 * PR_FAILURE if it isn't | 407 * PR_FAILURE if it isn't |
454 */ | 408 */ |
455 | 409 |
456 #ifdef DEBUG | 410 #ifdef DEBUG |
457 NSS_EXTERN PRStatus | 411 NSS_EXTERN PRStatus nssArena_verifyPointer(const NSSArena *arena); |
458 nssArena_verifyPointer | |
459 ( | |
460 const NSSArena *arena | |
461 ); | |
462 | 412 |
463 extern const NSSError NSS_ERROR_INVALID_ARENA; | 413 extern const NSSError NSS_ERROR_INVALID_ARENA; |
464 #endif /* DEBUG */ | 414 #endif /* DEBUG */ |
465 | 415 |
466 /* | 416 /* |
467 * nssArena_VERIFYPOINTER | 417 * nssArena_VERIFYPOINTER |
468 * | 418 * |
469 * This macro is always available. In debug builds it will call | 419 * This macro is always available. In debug builds it will call |
470 * nssArena_verifyPointer; in non-debug builds, it will merely | 420 * nssArena_verifyPointer; in non-debug builds, it will merely |
471 * check that the pointer is not null. Note that in non-debug | 421 * check that the pointer is not null. Note that in non-debug |
472 * builds it cannot place an error on the error stack. | 422 * builds it cannot place an error on the error stack. |
473 * | 423 * |
474 * Return value: | 424 * Return value: |
475 * PR_SUCCESS if the pointer is valid | 425 * PR_SUCCESS if the pointer is valid |
476 * PR_FAILURE if it isn't | 426 * PR_FAILURE if it isn't |
477 */ | 427 */ |
478 | 428 |
479 #ifdef DEBUG | 429 #ifdef DEBUG |
480 #define nssArena_VERIFYPOINTER(p) nssArena_verifyPointer(p) | 430 #define nssArena_VERIFYPOINTER(p) nssArena_verifyPointer(p) |
481 #else /* DEBUG */ | 431 #else /* DEBUG */ |
482 /* The following line exceeds 72 characters, but emacs screws up if I split it.
*/ | 432 |
483 #define nssArena_VERIFYPOINTER(p) (((NSSArena *)NULL == (p))?PR_FAILURE:PR_SUCCE
SS) | 433 #define nssArena_VERIFYPOINTER(p) \ |
| 434 (((NSSArena *)NULL == (p)) ? PR_FAILURE : PR_SUCCESS) |
484 #endif /* DEBUG */ | 435 #endif /* DEBUG */ |
485 | 436 |
486 /* | 437 /* |
487 * Private function to be called by NSS_Shutdown to cleanup nssArena | 438 * Private function to be called by NSS_Shutdown to cleanup nssArena |
488 * bookkeeping. | 439 * bookkeeping. |
489 */ | 440 */ |
490 extern PRStatus | 441 extern PRStatus nssArena_Shutdown(void); |
491 nssArena_Shutdown(void); | |
492 | 442 |
493 /* | 443 /* |
494 * nssArenaHashAllocOps | 444 * nssArenaHashAllocOps |
495 * | 445 * |
496 * This constant structure contains allocation callbacks designed for | 446 * This constant structure contains allocation callbacks designed for |
497 * use with the NSPL routine PL_NewHashTable. For example: | 447 * use with the NSPL routine PL_NewHashTable. For example: |
498 * | 448 * |
499 * NSSArena *hashTableArena = nssArena_Create(); | 449 * NSSArena *hashTableArena = nssArena_Create(); |
500 * PLHashTable *t = PL_NewHashTable(n, hasher, key_compare, | 450 * PLHashTable *t = PL_NewHashTable(n, hasher, key_compare, |
501 * value_compare, nssArenaHashAllocOps, hashTableArena); | 451 * value_compare, nssArenaHashAllocOps, hashTableArena); |
502 */ | 452 */ |
503 | 453 |
504 NSS_EXTERN_DATA PLHashAllocOps nssArenaHashAllocOps; | 454 NSS_EXTERN_DATA PLHashAllocOps nssArenaHashAllocOps; |
505 | 455 |
506 /* | 456 /* |
507 * The error stack | 457 * The error stack |
508 * | 458 * |
509 * The nonpublic methods relating to the error stack are: | 459 * The nonpublic methods relating to the error stack are: |
510 * | 460 * |
511 * nss_SetError | 461 * nss_SetError |
512 * nss_ClearErrorStack | 462 * nss_ClearErrorStack |
513 */ | 463 */ |
514 | 464 |
515 /* | 465 /* |
516 * nss_SetError | 466 * nss_SetError |
517 * | 467 * |
518 * This routine places a new error code on the top of the calling | 468 * This routine places a new error code on the top of the calling |
519 * thread's error stack. Calling this routine wiht an error code | 469 * thread's error stack. Calling this routine wiht an error code |
520 * of zero will clear the error stack. | 470 * of zero will clear the error stack. |
521 */ | 471 */ |
522 | 472 |
523 NSS_EXTERN void | 473 NSS_EXTERN void nss_SetError(PRUint32 error); |
524 nss_SetError | |
525 ( | |
526 PRUint32 error | |
527 ); | |
528 | 474 |
529 /* | 475 /* |
530 * nss_ClearErrorStack | 476 * nss_ClearErrorStack |
531 * | 477 * |
532 * This routine clears the calling thread's error stack. | 478 * This routine clears the calling thread's error stack. |
533 */ | 479 */ |
534 | 480 |
535 NSS_EXTERN void | 481 NSS_EXTERN void nss_ClearErrorStack(void); |
536 nss_ClearErrorStack | |
537 ( | |
538 void | |
539 ); | |
540 | 482 |
541 /* | 483 /* |
542 * nss_DestroyErrorStack | 484 * nss_DestroyErrorStack |
543 * | 485 * |
544 * This routine frees the calling thread's error stack. | 486 * This routine frees the calling thread's error stack. |
545 */ | 487 */ |
546 | 488 |
547 NSS_EXTERN void | 489 NSS_EXTERN void nss_DestroyErrorStack(void); |
548 nss_DestroyErrorStack | |
549 ( | |
550 void | |
551 ); | |
552 | 490 |
553 /* | 491 /* |
554 * NSSItem | 492 * NSSItem |
555 * | 493 * |
556 * nssItem_Create | 494 * nssItem_Create |
557 * nssItem_Duplicate | 495 * nssItem_Duplicate |
558 * nssItem_Equal | 496 * nssItem_Equal |
559 */ | 497 */ |
560 | 498 |
561 NSS_EXTERN NSSItem * | 499 NSS_EXTERN NSSItem *nssItem_Create(NSSArena *arenaOpt, NSSItem *rvOpt, |
562 nssItem_Create | 500 PRUint32 length, const void *data); |
563 ( | |
564 NSSArena *arenaOpt, | |
565 NSSItem *rvOpt, | |
566 PRUint32 length, | |
567 const void *data | |
568 ); | |
569 | 501 |
570 NSS_EXTERN void | 502 NSS_EXTERN void nssItem_Destroy(NSSItem *item); |
571 nssItem_Destroy | |
572 ( | |
573 NSSItem *item | |
574 ); | |
575 | 503 |
576 NSS_EXTERN NSSItem * | 504 NSS_EXTERN NSSItem *nssItem_Duplicate(NSSItem *obj, NSSArena *arenaOpt, |
577 nssItem_Duplicate | 505 NSSItem *rvOpt); |
578 ( | |
579 NSSItem *obj, | |
580 NSSArena *arenaOpt, | |
581 NSSItem *rvOpt | |
582 ); | |
583 | 506 |
584 NSS_EXTERN PRBool | 507 NSS_EXTERN PRBool nssItem_Equal(const NSSItem *one, const NSSItem *two, |
585 nssItem_Equal | 508 PRStatus *statusOpt); |
586 ( | |
587 const NSSItem *one, | |
588 const NSSItem *two, | |
589 PRStatus *statusOpt | |
590 ); | |
591 | 509 |
592 /* | 510 /* |
593 * NSSUTF8 | 511 * NSSUTF8 |
594 * | 512 * |
595 * nssUTF8_CaseIgnoreMatch | 513 * nssUTF8_CaseIgnoreMatch |
596 * nssUTF8_Duplicate | 514 * nssUTF8_Duplicate |
597 * nssUTF8_Size | 515 * nssUTF8_Size |
598 * nssUTF8_Length | 516 * nssUTF8_Length |
599 * nssUTF8_CopyIntoFixedBuffer | 517 * nssUTF8_CopyIntoFixedBuffer |
600 */ | 518 */ |
601 | 519 |
602 /* | 520 /* |
603 * nssUTF8_CaseIgnoreMatch | 521 * nssUTF8_CaseIgnoreMatch |
604 * | 522 * |
605 * Returns true if the two UTF8-encoded strings pointed to by the | 523 * Returns true if the two UTF8-encoded strings pointed to by the |
606 * two specified NSSUTF8 pointers differ only in typcase. | 524 * two specified NSSUTF8 pointers differ only in typcase. |
607 * | 525 * |
608 * The error may be one of the following values: | 526 * The error may be one of the following values: |
609 * NSS_ERROR_INVALID_POINTER | 527 * NSS_ERROR_INVALID_POINTER |
610 * | 528 * |
611 * Return value: | 529 * Return value: |
612 * PR_TRUE if the strings match, ignoring case | 530 * PR_TRUE if the strings match, ignoring case |
613 * PR_FALSE if they don't | 531 * PR_FALSE if they don't |
614 * PR_FALSE upon error | 532 * PR_FALSE upon error |
615 */ | 533 */ |
616 | 534 |
617 NSS_EXTERN PRBool | 535 NSS_EXTERN PRBool nssUTF8_CaseIgnoreMatch(const NSSUTF8 *a, const NSSUTF8 *b, |
618 nssUTF8_CaseIgnoreMatch | 536 PRStatus *statusOpt); |
619 ( | |
620 const NSSUTF8 *a, | |
621 const NSSUTF8 *b, | |
622 PRStatus *statusOpt | |
623 ); | |
624 | 537 |
625 /* | 538 /* |
626 * nssUTF8_Duplicate | 539 * nssUTF8_Duplicate |
627 * | 540 * |
628 * This routine duplicates the UTF8-encoded string pointed to by the | 541 * This routine duplicates the UTF8-encoded string pointed to by the |
629 * specified NSSUTF8 pointer. If the optional arenaOpt argument is | 542 * specified NSSUTF8 pointer. If the optional arenaOpt argument is |
630 * not null, the memory required will be obtained from that arena; | 543 * not null, the memory required will be obtained from that arena; |
631 * otherwise, the memory required will be obtained from the heap. | 544 * otherwise, the memory required will be obtained from the heap. |
632 * A pointer to the new string will be returned. In case of error, | 545 * A pointer to the new string will be returned. In case of error, |
633 * an error will be placed on the error stack and NULL will be | 546 * an error will be placed on the error stack and NULL will be |
634 * returned. | 547 * returned. |
635 * | 548 * |
636 * The error may be one of the following values: | 549 * The error may be one of the following values: |
637 * NSS_ERROR_INVALID_POINTER | 550 * NSS_ERROR_INVALID_POINTER |
638 * NSS_ERROR_INVALID_ARENA | 551 * NSS_ERROR_INVALID_ARENA |
639 * NSS_ERROR_NO_MEMORY | 552 * NSS_ERROR_NO_MEMORY |
640 */ | 553 */ |
641 | 554 |
642 NSS_EXTERN NSSUTF8 * | 555 NSS_EXTERN NSSUTF8 *nssUTF8_Duplicate(const NSSUTF8 *s, NSSArena *arenaOpt); |
643 nssUTF8_Duplicate | |
644 ( | |
645 const NSSUTF8 *s, | |
646 NSSArena *arenaOpt | |
647 ); | |
648 | 556 |
649 /* | 557 /* |
650 * nssUTF8_PrintableMatch | 558 * nssUTF8_PrintableMatch |
651 * | 559 * |
652 * Returns true if the two Printable strings pointed to by the | 560 * Returns true if the two Printable strings pointed to by the |
653 * two specified NSSUTF8 pointers match when compared with the | 561 * two specified NSSUTF8 pointers match when compared with the |
654 * rules for Printable String (leading and trailing spaces are | 562 * rules for Printable String (leading and trailing spaces are |
655 * disregarded, extents of whitespace match irregardless of length, | 563 * disregarded, extents of whitespace match irregardless of length, |
656 * and case is not significant), then PR_TRUE will be returned. | 564 * and case is not significant), then PR_TRUE will be returned. |
657 * Otherwise, PR_FALSE will be returned. Upon failure, PR_FALSE | 565 * Otherwise, PR_FALSE will be returned. Upon failure, PR_FALSE |
658 * will be returned. If the optional statusOpt argument is not | 566 * will be returned. If the optional statusOpt argument is not |
659 * NULL, then PR_SUCCESS or PR_FAILURE will be stored in that | 567 * NULL, then PR_SUCCESS or PR_FAILURE will be stored in that |
660 * location. | 568 * location. |
661 * | 569 * |
662 * The error may be one of the following values: | 570 * The error may be one of the following values: |
663 * NSS_ERROR_INVALID_POINTER | 571 * NSS_ERROR_INVALID_POINTER |
664 * | 572 * |
665 * Return value: | 573 * Return value: |
666 * PR_TRUE if the strings match, ignoring case | 574 * PR_TRUE if the strings match, ignoring case |
667 * PR_FALSE if they don't | 575 * PR_FALSE if they don't |
668 * PR_FALSE upon error | 576 * PR_FALSE upon error |
669 */ | 577 */ |
670 | 578 |
671 NSS_EXTERN PRBool | 579 NSS_EXTERN PRBool nssUTF8_PrintableMatch(const NSSUTF8 *a, const NSSUTF8 *b, |
672 nssUTF8_PrintableMatch | 580 PRStatus *statusOpt); |
673 ( | |
674 const NSSUTF8 *a, | |
675 const NSSUTF8 *b, | |
676 PRStatus *statusOpt | |
677 ); | |
678 | 581 |
679 /* | 582 /* |
680 * nssUTF8_Size | 583 * nssUTF8_Size |
681 * | 584 * |
682 * This routine returns the length in bytes (including the terminating | 585 * This routine returns the length in bytes (including the terminating |
683 * null) of the UTF8-encoded string pointed to by the specified | 586 * null) of the UTF8-encoded string pointed to by the specified |
684 * NSSUTF8 pointer. Zero is returned on error. | 587 * NSSUTF8 pointer. Zero is returned on error. |
685 * | 588 * |
686 * The error may be one of the following values: | 589 * The error may be one of the following values: |
687 * NSS_ERROR_INVALID_POINTER | 590 * NSS_ERROR_INVALID_POINTER |
688 * NSS_ERROR_VALUE_TOO_LARGE | 591 * NSS_ERROR_VALUE_TOO_LARGE |
689 * | 592 * |
690 * Return value: | 593 * Return value: |
691 * nonzero size of the string | 594 * nonzero size of the string |
692 * 0 on error | 595 * 0 on error |
693 */ | 596 */ |
694 | 597 |
695 NSS_EXTERN PRUint32 | 598 NSS_EXTERN PRUint32 nssUTF8_Size(const NSSUTF8 *s, PRStatus *statusOpt); |
696 nssUTF8_Size | |
697 ( | |
698 const NSSUTF8 *s, | |
699 PRStatus *statusOpt | |
700 ); | |
701 | 599 |
702 extern const NSSError NSS_ERROR_INVALID_POINTER; | 600 extern const NSSError NSS_ERROR_INVALID_POINTER; |
703 extern const NSSError NSS_ERROR_VALUE_TOO_LARGE; | 601 extern const NSSError NSS_ERROR_VALUE_TOO_LARGE; |
704 | 602 |
705 /* | 603 /* |
706 * nssUTF8_Length | 604 * nssUTF8_Length |
707 * | 605 * |
708 * This routine returns the length in characters (not including the | 606 * This routine returns the length in characters (not including the |
709 * terminating null) of the UTF8-encoded string pointed to by the | 607 * terminating null) of the UTF8-encoded string pointed to by the |
710 * specified NSSUTF8 pointer. | 608 * specified NSSUTF8 pointer. |
711 * | 609 * |
712 * The error may be one of the following values: | 610 * The error may be one of the following values: |
713 * NSS_ERROR_INVALID_POINTER | 611 * NSS_ERROR_INVALID_POINTER |
714 * NSS_ERROR_VALUE_TOO_LARGE | 612 * NSS_ERROR_VALUE_TOO_LARGE |
715 * NSS_ERROR_INVALID_STRING | 613 * NSS_ERROR_INVALID_STRING |
716 * | 614 * |
717 * Return value: | 615 * Return value: |
718 * length of the string (which may be zero) | 616 * length of the string (which may be zero) |
719 * 0 on error | 617 * 0 on error |
720 */ | 618 */ |
721 | 619 |
722 NSS_EXTERN PRUint32 | 620 NSS_EXTERN PRUint32 nssUTF8_Length(const NSSUTF8 *s, PRStatus *statusOpt); |
723 nssUTF8_Length | |
724 ( | |
725 const NSSUTF8 *s, | |
726 PRStatus *statusOpt | |
727 ); | |
728 | 621 |
729 extern const NSSError NSS_ERROR_INVALID_POINTER; | 622 extern const NSSError NSS_ERROR_INVALID_POINTER; |
730 extern const NSSError NSS_ERROR_VALUE_TOO_LARGE; | 623 extern const NSSError NSS_ERROR_VALUE_TOO_LARGE; |
731 extern const NSSError NSS_ERROR_INVALID_STRING; | 624 extern const NSSError NSS_ERROR_INVALID_STRING; |
732 | 625 |
733 /* | 626 /* |
734 * nssUTF8_Create | 627 * nssUTF8_Create |
735 * | 628 * |
736 * This routine creates a UTF8 string from a string in some other | 629 * This routine creates a UTF8 string from a string in some other |
737 * format. Some types of string may include embedded null characters, | 630 * format. Some types of string may include embedded null characters, |
738 * so for them the length parameter must be used. For string types | 631 * so for them the length parameter must be used. For string types |
739 * that are null-terminated, the length parameter is optional; if it | 632 * that are null-terminated, the length parameter is optional; if it |
740 * is zero, it will be ignored. If the optional arena argument is | 633 * is zero, it will be ignored. If the optional arena argument is |
741 * non-null, the memory used for the new string will be obtained from | 634 * non-null, the memory used for the new string will be obtained from |
742 * that arena, otherwise it will be obtained from the heap. This | 635 * that arena, otherwise it will be obtained from the heap. This |
743 * routine may return NULL upon error, in which case it will have | 636 * routine may return NULL upon error, in which case it will have |
744 * placed an error on the error stack. | 637 * placed an error on the error stack. |
745 * | 638 * |
746 * The error may be one of the following: | 639 * The error may be one of the following: |
747 * NSS_ERROR_INVALID_POINTER | 640 * NSS_ERROR_INVALID_POINTER |
748 * NSS_ERROR_NO_MEMORY | 641 * NSS_ERROR_NO_MEMORY |
749 * NSS_ERROR_UNSUPPORTED_TYPE | 642 * NSS_ERROR_UNSUPPORTED_TYPE |
750 * | 643 * |
751 * Return value: | 644 * Return value: |
752 * NULL upon error | 645 * NULL upon error |
753 * A non-null pointer to a new UTF8 string otherwise | 646 * A non-null pointer to a new UTF8 string otherwise |
754 */ | 647 */ |
755 | 648 |
756 NSS_EXTERN NSSUTF8 * | 649 NSS_EXTERN NSSUTF8 *nssUTF8_Create(NSSArena *arenaOpt, nssStringType type, |
757 nssUTF8_Create | 650 const void *inputString, |
758 ( | 651 PRUint32 size /* in bytes, not characters */ |
759 NSSArena *arenaOpt, | 652 ); |
760 nssStringType type, | |
761 const void *inputString, | |
762 PRUint32 size /* in bytes, not characters */ | |
763 ); | |
764 | 653 |
765 extern const NSSError NSS_ERROR_INVALID_POINTER; | 654 extern const NSSError NSS_ERROR_INVALID_POINTER; |
766 extern const NSSError NSS_ERROR_NO_MEMORY; | 655 extern const NSSError NSS_ERROR_NO_MEMORY; |
767 extern const NSSError NSS_ERROR_UNSUPPORTED_TYPE; | 656 extern const NSSError NSS_ERROR_UNSUPPORTED_TYPE; |
768 | 657 |
769 NSS_EXTERN NSSItem * | 658 NSS_EXTERN NSSItem *nssUTF8_GetEncoding(NSSArena *arenaOpt, NSSItem *rvOpt, |
770 nssUTF8_GetEncoding | 659 nssStringType type, NSSUTF8 *string); |
771 ( | |
772 NSSArena *arenaOpt, | |
773 NSSItem *rvOpt, | |
774 nssStringType type, | |
775 NSSUTF8 *string | |
776 ); | |
777 | 660 |
778 /* | 661 /* |
779 * nssUTF8_CopyIntoFixedBuffer | 662 * nssUTF8_CopyIntoFixedBuffer |
780 * | 663 * |
781 * This will copy a UTF8 string into a fixed-length buffer, making | 664 * This will copy a UTF8 string into a fixed-length buffer, making |
782 * sure that the all characters are valid. Any remaining space will | 665 * sure that the all characters are valid. Any remaining space will |
783 * be padded with the specified ASCII character, typically either | 666 * be padded with the specified ASCII character, typically either |
784 * null or space. | 667 * null or space. |
785 * | 668 * |
786 * Blah, blah, blah. | 669 * Blah, blah, blah. |
787 */ | 670 */ |
788 | 671 |
789 extern const NSSError NSS_ERROR_INVALID_POINTER; | 672 extern const NSSError NSS_ERROR_INVALID_POINTER; |
790 extern const NSSError NSS_ERROR_INVALID_ARGUMENT; | 673 extern const NSSError NSS_ERROR_INVALID_ARGUMENT; |
791 | 674 |
792 NSS_EXTERN PRStatus | 675 NSS_EXTERN PRStatus nssUTF8_CopyIntoFixedBuffer(NSSUTF8 *string, char *buffer, |
793 nssUTF8_CopyIntoFixedBuffer | 676 PRUint32 bufferSize, char pad); |
794 ( | |
795 NSSUTF8 *string, | |
796 char *buffer, | |
797 PRUint32 bufferSize, | |
798 char pad | |
799 ); | |
800 | 677 |
801 /* | 678 /* |
802 * nssUTF8_Equal | 679 * nssUTF8_Equal |
803 * | 680 * |
804 */ | 681 */ |
805 | 682 |
806 NSS_EXTERN PRBool | 683 NSS_EXTERN PRBool nssUTF8_Equal(const NSSUTF8 *a, const NSSUTF8 *b, |
807 nssUTF8_Equal | 684 PRStatus *statusOpt); |
808 ( | |
809 const NSSUTF8 *a, | |
810 const NSSUTF8 *b, | |
811 PRStatus *statusOpt | |
812 ); | |
813 | 685 |
814 /* | 686 /* |
815 * nssList | 687 * nssList |
816 * | 688 * |
817 * The goal is to provide a simple, optionally threadsafe, linked list | 689 * The goal is to provide a simple, optionally threadsafe, linked list |
818 * class. Since NSS did not seem to use the circularity of PRCList | 690 * class. Since NSS did not seem to use the circularity of PRCList |
819 * much before, this provides a list that appears to be a linear, | 691 * much before, this provides a list that appears to be a linear, |
820 * NULL-terminated list. | 692 * NULL-terminated list. |
821 */ | 693 */ |
822 | 694 |
823 /* | 695 /* |
824 * nssList_Create | 696 * nssList_Create |
825 * | 697 * |
826 * If threadsafe is true, the list will be locked during modifications | 698 * If threadsafe is true, the list will be locked during modifications |
827 * and traversals. | 699 * and traversals. |
828 */ | 700 */ |
829 NSS_EXTERN nssList * | 701 NSS_EXTERN nssList *nssList_Create(NSSArena *arenaOpt, PRBool threadSafe); |
830 nssList_Create | |
831 ( | |
832 NSSArena *arenaOpt, | |
833 PRBool threadSafe | |
834 ); | |
835 | 702 |
836 /* | 703 /* |
837 * nssList_Destroy | 704 * nssList_Destroy |
838 */ | 705 */ |
839 NSS_EXTERN PRStatus | 706 NSS_EXTERN PRStatus nssList_Destroy(nssList *list); |
840 nssList_Destroy | |
841 ( | |
842 nssList *list | |
843 ); | |
844 | 707 |
845 NSS_EXTERN void | 708 NSS_EXTERN void nssList_Clear(nssList *list, |
846 nssList_Clear | 709 nssListElementDestructorFunc destructor); |
847 ( | |
848 nssList *list, | |
849 nssListElementDestructorFunc destructor | |
850 ); | |
851 | 710 |
852 /* | 711 /* |
853 * nssList_SetCompareFunction | 712 * nssList_SetCompareFunction |
854 * | 713 * |
855 * By default, two list elements will be compared by comparing their | 714 * By default, two list elements will be compared by comparing their |
856 * data pointers. By setting this function, the user can control | 715 * data pointers. By setting this function, the user can control |
857 * how elements are compared. | 716 * how elements are compared. |
858 */ | 717 */ |
859 NSS_EXTERN void | 718 NSS_EXTERN void nssList_SetCompareFunction(nssList *list, |
860 nssList_SetCompareFunction | 719 nssListCompareFunc compareFunc); |
861 ( | |
862 nssList *list, | |
863 nssListCompareFunc compareFunc | |
864 ); | |
865 | 720 |
866 /* | 721 /* |
867 * nssList_SetSortFunction | 722 * nssList_SetSortFunction |
868 * | 723 * |
869 * Sort function to use for an ordered list. | 724 * Sort function to use for an ordered list. |
870 */ | 725 */ |
871 NSS_EXTERN void | 726 NSS_EXTERN void nssList_SetSortFunction(nssList *list, |
872 nssList_SetSortFunction | 727 nssListSortFunc sortFunc); |
873 ( | |
874 nssList *list, | |
875 nssListSortFunc sortFunc | |
876 ); | |
877 | 728 |
878 /* | 729 /* |
879 * nssList_Add | 730 * nssList_Add |
880 */ | 731 */ |
881 NSS_EXTERN PRStatus | 732 NSS_EXTERN PRStatus nssList_Add(nssList *list, void *data); |
882 nssList_Add | |
883 ( | |
884 nssList *list, | |
885 void *data | |
886 ); | |
887 | 733 |
888 /* | 734 /* |
889 * nssList_AddUnique | 735 * nssList_AddUnique |
890 * | 736 * |
891 * This will use the compare function to see if the element is already | 737 * This will use the compare function to see if the element is already |
892 * in the list. | 738 * in the list. |
893 */ | 739 */ |
894 NSS_EXTERN PRStatus | 740 NSS_EXTERN PRStatus nssList_AddUnique(nssList *list, void *data); |
895 nssList_AddUnique | |
896 ( | |
897 nssList *list, | |
898 void *data | |
899 ); | |
900 | 741 |
901 /* | 742 /* |
902 * nssList_Remove | 743 * nssList_Remove |
903 * | 744 * |
904 * Uses the compare function to locate the element and remove it. | 745 * Uses the compare function to locate the element and remove it. |
905 */ | 746 */ |
906 NSS_EXTERN PRStatus | 747 NSS_EXTERN PRStatus nssList_Remove(nssList *list, void *data); |
907 nssList_Remove(nssList *list, void *data); | |
908 | 748 |
909 /* | 749 /* |
910 * nssList_Get | 750 * nssList_Get |
911 * | 751 * |
912 * Uses the compare function to locate an element. Also serves as | 752 * Uses the compare function to locate an element. Also serves as |
913 * nssList_Exists. | 753 * nssList_Exists. |
914 */ | 754 */ |
915 NSS_EXTERN void * | 755 NSS_EXTERN void *nssList_Get(nssList *list, void *data); |
916 nssList_Get | |
917 ( | |
918 nssList *list, | |
919 void *data | |
920 ); | |
921 | 756 |
922 /* | 757 /* |
923 * nssList_Count | 758 * nssList_Count |
924 */ | 759 */ |
925 NSS_EXTERN PRUint32 | 760 NSS_EXTERN PRUint32 nssList_Count(nssList *list); |
926 nssList_Count | |
927 ( | |
928 nssList *list | |
929 ); | |
930 | 761 |
931 /* | 762 /* |
932 * nssList_GetArray | 763 * nssList_GetArray |
933 * | 764 * |
934 * Fill rvArray, up to maxElements, with elements in the list. The | 765 * Fill rvArray, up to maxElements, with elements in the list. The |
935 * array is NULL-terminated, so its allocated size must be maxElements + 1. | 766 * array is NULL-terminated, so its allocated size must be maxElements + 1. |
936 */ | 767 */ |
937 NSS_EXTERN PRStatus | 768 NSS_EXTERN PRStatus nssList_GetArray(nssList *list, void **rvArray, |
938 nssList_GetArray | 769 PRUint32 maxElements); |
939 ( | |
940 nssList *list, | |
941 void **rvArray, | |
942 PRUint32 maxElements | |
943 ); | |
944 | 770 |
945 /* | 771 /* |
946 * nssList_CreateIterator | 772 * nssList_CreateIterator |
947 * | 773 * |
948 * Create an iterator for list traversal. | 774 * Create an iterator for list traversal. |
949 */ | 775 */ |
950 NSS_EXTERN nssListIterator * | 776 NSS_EXTERN nssListIterator *nssList_CreateIterator(nssList *list); |
951 nssList_CreateIterator | |
952 ( | |
953 nssList *list | |
954 ); | |
955 | 777 |
956 NSS_EXTERN nssList * | 778 NSS_EXTERN nssList *nssList_Clone(nssList *list); |
957 nssList_Clone | |
958 ( | |
959 nssList *list | |
960 ); | |
961 | 779 |
962 /* | 780 /* |
963 * nssListIterator_Destroy | 781 * nssListIterator_Destroy |
964 */ | 782 */ |
965 NSS_EXTERN void | 783 NSS_EXTERN void nssListIterator_Destroy(nssListIterator *iter); |
966 nssListIterator_Destroy | |
967 ( | |
968 nssListIterator *iter | |
969 ); | |
970 | 784 |
971 /* | 785 /* |
972 * nssListIterator_Start | 786 * nssListIterator_Start |
973 * | 787 * |
974 * Begin a list iteration. After this call, if the list is threadSafe, | 788 * Begin a list iteration. After this call, if the list is threadSafe, |
975 * the list is *locked*. | 789 * the list is *locked*. |
976 */ | 790 */ |
977 NSS_EXTERN void * | 791 NSS_EXTERN void *nssListIterator_Start(nssListIterator *iter); |
978 nssListIterator_Start | |
979 ( | |
980 nssListIterator *iter | |
981 ); | |
982 | 792 |
983 /* | 793 /* |
984 * nssListIterator_Next | 794 * nssListIterator_Next |
985 * | 795 * |
986 * Continue a list iteration. | 796 * Continue a list iteration. |
987 */ | 797 */ |
988 NSS_EXTERN void * | 798 NSS_EXTERN void *nssListIterator_Next(nssListIterator *iter); |
989 nssListIterator_Next | |
990 ( | |
991 nssListIterator *iter | |
992 ); | |
993 | 799 |
994 /* | 800 /* |
995 * nssListIterator_Finish | 801 * nssListIterator_Finish |
996 * | 802 * |
997 * Complete a list iteration. This *must* be called in order for the | 803 * Complete a list iteration. This *must* be called in order for the |
998 * lock to be released. | 804 * lock to be released. |
999 */ | 805 */ |
1000 NSS_EXTERN PRStatus | 806 NSS_EXTERN PRStatus nssListIterator_Finish(nssListIterator *iter); |
1001 nssListIterator_Finish | |
1002 ( | |
1003 nssListIterator *iter | |
1004 ); | |
1005 | 807 |
1006 /* | 808 /* |
1007 * nssHash | 809 * nssHash |
1008 * | 810 * |
1009 * nssHash_Create | 811 * nssHash_Create |
1010 * nssHash_Destroy | 812 * nssHash_Destroy |
1011 * nssHash_Add | 813 * nssHash_Add |
1012 * nssHash_Remove | 814 * nssHash_Remove |
1013 * nssHash_Count | 815 * nssHash_Count |
1014 * nssHash_Exists | 816 * nssHash_Exists |
1015 * nssHash_Lookup | 817 * nssHash_Lookup |
1016 * nssHash_Iterate | 818 * nssHash_Iterate |
1017 */ | 819 */ |
1018 | 820 |
1019 /* | 821 /* |
1020 * nssHash_Create | 822 * nssHash_Create |
1021 * | 823 * |
1022 */ | 824 */ |
1023 | 825 |
1024 NSS_EXTERN nssHash * | 826 NSS_EXTERN nssHash *nssHash_Create(NSSArena *arenaOpt, PRUint32 numBuckets, |
1025 nssHash_Create | 827 PLHashFunction keyHash, |
1026 ( | 828 PLHashComparator keyCompare, |
1027 NSSArena *arenaOpt, | 829 PLHashComparator valueCompare); |
1028 PRUint32 numBuckets, | |
1029 PLHashFunction keyHash, | |
1030 PLHashComparator keyCompare, | |
1031 PLHashComparator valueCompare | |
1032 ); | |
1033 | 830 |
1034 NSS_EXTERN nssHash * | 831 NSS_EXTERN nssHash *nssHash_CreatePointer(NSSArena *arenaOpt, |
1035 nssHash_CreatePointer | 832 PRUint32 numBuckets); |
1036 ( | |
1037 NSSArena *arenaOpt, | |
1038 PRUint32 numBuckets | |
1039 ); | |
1040 | 833 |
1041 NSS_EXTERN nssHash * | 834 NSS_EXTERN nssHash *nssHash_CreateString(NSSArena *arenaOpt, |
1042 nssHash_CreateString | 835 PRUint32 numBuckets); |
1043 ( | |
1044 NSSArena *arenaOpt, | |
1045 PRUint32 numBuckets | |
1046 ); | |
1047 | 836 |
1048 NSS_EXTERN nssHash * | 837 NSS_EXTERN nssHash *nssHash_CreateItem(NSSArena *arenaOpt, PRUint32 numBuckets); |
1049 nssHash_CreateItem | |
1050 ( | |
1051 NSSArena *arenaOpt, | |
1052 PRUint32 numBuckets | |
1053 ); | |
1054 | 838 |
1055 /* | 839 /* |
1056 * nssHash_Destroy | 840 * nssHash_Destroy |
1057 * | 841 * |
1058 */ | 842 */ |
1059 NSS_EXTERN void | 843 NSS_EXTERN void nssHash_Destroy(nssHash *hash); |
1060 nssHash_Destroy | |
1061 ( | |
1062 nssHash *hash | |
1063 ); | |
1064 | 844 |
1065 /* | 845 /* |
1066 * nssHash_Add | 846 * nssHash_Add |
1067 * | 847 * |
1068 */ | 848 */ |
1069 | 849 |
1070 extern const NSSError NSS_ERROR_HASH_COLLISION; | 850 extern const NSSError NSS_ERROR_HASH_COLLISION; |
1071 | 851 |
1072 NSS_EXTERN PRStatus | 852 NSS_EXTERN PRStatus nssHash_Add(nssHash *hash, const void *key, |
1073 nssHash_Add | 853 const void *value); |
1074 ( | |
1075 nssHash *hash, | |
1076 const void *key, | |
1077 const void *value | |
1078 ); | |
1079 | 854 |
1080 /* | 855 /* |
1081 * nssHash_Remove | 856 * nssHash_Remove |
1082 * | 857 * |
1083 */ | 858 */ |
1084 NSS_EXTERN void | 859 NSS_EXTERN void nssHash_Remove(nssHash *hash, const void *it); |
1085 nssHash_Remove | |
1086 ( | |
1087 nssHash *hash, | |
1088 const void *it | |
1089 ); | |
1090 | 860 |
1091 /* | 861 /* |
1092 * nssHash_Count | 862 * nssHash_Count |
1093 * | 863 * |
1094 */ | 864 */ |
1095 NSS_EXTERN PRUint32 | 865 NSS_EXTERN PRUint32 nssHash_Count(nssHash *hash); |
1096 nssHash_Count | |
1097 ( | |
1098 nssHash *hash | |
1099 ); | |
1100 | 866 |
1101 /* | 867 /* |
1102 * nssHash_Exists | 868 * nssHash_Exists |
1103 * | 869 * |
1104 */ | 870 */ |
1105 NSS_EXTERN PRBool | 871 NSS_EXTERN PRBool nssHash_Exists(nssHash *hash, const void *it); |
1106 nssHash_Exists | |
1107 ( | |
1108 nssHash *hash, | |
1109 const void *it | |
1110 ); | |
1111 | 872 |
1112 /* | 873 /* |
1113 * nssHash_Lookup | 874 * nssHash_Lookup |
1114 * | 875 * |
1115 */ | 876 */ |
1116 NSS_EXTERN void * | 877 NSS_EXTERN void *nssHash_Lookup(nssHash *hash, const void *it); |
1117 nssHash_Lookup | |
1118 ( | |
1119 nssHash *hash, | |
1120 const void *it | |
1121 ); | |
1122 | 878 |
1123 /* | 879 /* |
1124 * nssHash_Iterate | 880 * nssHash_Iterate |
1125 * | 881 * |
1126 */ | 882 */ |
1127 NSS_EXTERN void | 883 NSS_EXTERN void nssHash_Iterate(nssHash *hash, nssHashIterator fcn, |
1128 nssHash_Iterate | 884 void *closure); |
1129 ( | |
1130 nssHash *hash, | |
1131 nssHashIterator fcn, | |
1132 void *closure | |
1133 ); | |
1134 | |
1135 | 885 |
1136 /* | 886 /* |
1137 * nssPointerTracker | 887 * nssPointerTracker |
1138 * | 888 * |
1139 * This type and these methods are only present in debug builds. | 889 * This type and these methods are only present in debug builds. |
1140 * | 890 * |
1141 * The nonpublic methods relating to this type are: | 891 * The nonpublic methods relating to this type are: |
1142 * | 892 * |
1143 * nssPointerTracker_initialize | 893 * nssPointerTracker_initialize |
1144 * nssPointerTracker_finalize | 894 * nssPointerTracker_finalize |
1145 * nssPointerTracker_add | 895 * nssPointerTracker_add |
1146 * nssPointerTracker_remove | 896 * nssPointerTracker_remove |
1147 * nssPointerTracker_verify | 897 * nssPointerTracker_verify |
1148 */ | 898 */ |
1149 | 899 |
1150 /* | 900 /* |
1151 * nssPointerTracker_initialize | 901 * nssPointerTracker_initialize |
1152 * | 902 * |
1153 * This method is only present in debug builds. | 903 * This method is only present in debug builds. |
1154 * | 904 * |
1155 * This routine initializes an nssPointerTracker object. Note that | 905 * This routine initializes an nssPointerTracker object. Note that |
1156 * the object must have been declared *static* to guarantee that it | 906 * the object must have been declared *static* to guarantee that it |
1157 * is in a zeroed state initially. This routine is idempotent, and | 907 * is in a zeroed state initially. This routine is idempotent, and |
1158 * may even be safely called by multiple threads simultaneously with | 908 * may even be safely called by multiple threads simultaneously with |
1159 * the same argument. This routine returns a PRStatus value; if | 909 * the same argument. This routine returns a PRStatus value; if |
1160 * successful, it will return PR_SUCCESS. On failure it will set an | 910 * successful, it will return PR_SUCCESS. On failure it will set an |
1161 * error on the error stack and return PR_FAILURE. | 911 * error on the error stack and return PR_FAILURE. |
1162 * | 912 * |
1163 * The error may be one of the following values: | 913 * The error may be one of the following values: |
1164 * NSS_ERROR_NO_MEMORY | 914 * NSS_ERROR_NO_MEMORY |
1165 * | 915 * |
1166 * Return value: | 916 * Return value: |
1167 * PR_SUCCESS | 917 * PR_SUCCESS |
1168 * PR_FAILURE | 918 * PR_FAILURE |
1169 */ | 919 */ |
1170 | 920 |
1171 #ifdef DEBUG | 921 #ifdef DEBUG |
1172 NSS_EXTERN PRStatus | 922 NSS_EXTERN PRStatus nssPointerTracker_initialize(nssPointerTracker *tracker); |
1173 nssPointerTracker_initialize | |
1174 ( | |
1175 nssPointerTracker *tracker | |
1176 ); | |
1177 | 923 |
1178 extern const NSSError NSS_ERROR_NO_MEMORY; | 924 extern const NSSError NSS_ERROR_NO_MEMORY; |
1179 #endif /* DEBUG */ | 925 #endif /* DEBUG */ |
1180 | 926 |
1181 /* | 927 /* |
1182 * nssPointerTracker_finalize | 928 * nssPointerTracker_finalize |
1183 * | 929 * |
1184 * This method is only present in debug builds. | 930 * This method is only present in debug builds. |
1185 * | 931 * |
1186 * This routine returns the nssPointerTracker object to the pre- | 932 * This routine returns the nssPointerTracker object to the pre- |
1187 * initialized state, releasing all resources used by the object. | 933 * initialized state, releasing all resources used by the object. |
1188 * It will *NOT* destroy the objects being tracked by the pointer | 934 * It will *NOT* destroy the objects being tracked by the pointer |
1189 * (should any remain), and therefore cannot be used to "sweep up" | 935 * (should any remain), and therefore cannot be used to "sweep up" |
1190 * remaining objects. This routine returns a PRStatus value; if | 936 * remaining objects. This routine returns a PRStatus value; if |
1191 * successful, it will return PR_SUCCES. On failure it will set an | 937 * successful, it will return PR_SUCCES. On failure it will set an |
1192 * error on the error stack and return PR_FAILURE. If any objects | 938 * error on the error stack and return PR_FAILURE. If any objects |
1193 * remain in the tracker when it is finalized, that will be treated | 939 * remain in the tracker when it is finalized, that will be treated |
1194 * as an error. | 940 * as an error. |
1195 * | 941 * |
1196 * The error may be one of the following values: | 942 * The error may be one of the following values: |
1197 * NSS_ERROR_TRACKER_NOT_EMPTY | 943 * NSS_ERROR_TRACKER_NOT_EMPTY |
1198 * | 944 * |
1199 * Return value: | 945 * Return value: |
1200 * PR_SUCCESS | 946 * PR_SUCCESS |
1201 * PR_FAILURE | 947 * PR_FAILURE |
1202 */ | 948 */ |
1203 | 949 |
1204 #ifdef DEBUG | 950 #ifdef DEBUG |
1205 NSS_EXTERN PRStatus | 951 NSS_EXTERN PRStatus nssPointerTracker_finalize(nssPointerTracker *tracker); |
1206 nssPointerTracker_finalize | |
1207 ( | |
1208 nssPointerTracker *tracker | |
1209 ); | |
1210 | 952 |
1211 extern const NSSError NSS_ERROR_TRACKER_NOT_EMPTY; | 953 extern const NSSError NSS_ERROR_TRACKER_NOT_EMPTY; |
1212 #endif /* DEBUG */ | 954 #endif /* DEBUG */ |
1213 | 955 |
1214 /* | 956 /* |
1215 * nssPointerTracker_add | 957 * nssPointerTracker_add |
1216 * | 958 * |
1217 * This method is only present in debug builds. | 959 * This method is only present in debug builds. |
1218 * | 960 * |
1219 * This routine adds the specified pointer to the nssPointerTracker | 961 * This routine adds the specified pointer to the nssPointerTracker |
1220 * object. It should be called in constructor objects to register | 962 * object. It should be called in constructor objects to register |
1221 * new valid objects. The nssPointerTracker is threadsafe, but this | 963 * new valid objects. The nssPointerTracker is threadsafe, but this |
1222 * call is not idempotent. This routine returns a PRStatus value; | 964 * call is not idempotent. This routine returns a PRStatus value; |
1223 * if successful it will return PR_SUCCESS. On failure it will set | 965 * if successful it will return PR_SUCCESS. On failure it will set |
1224 * an error on the error stack and return PR_FAILURE. | 966 * an error on the error stack and return PR_FAILURE. |
1225 * | 967 * |
1226 * The error may be one of the following values: | 968 * The error may be one of the following values: |
1227 * NSS_ERROR_NO_MEMORY | 969 * NSS_ERROR_NO_MEMORY |
1228 * NSS_ERROR_TRACKER_NOT_INITIALIZED | 970 * NSS_ERROR_TRACKER_NOT_INITIALIZED |
1229 * NSS_ERROR_DUPLICATE_POINTER | 971 * NSS_ERROR_DUPLICATE_POINTER |
1230 * | 972 * |
1231 * Return value: | 973 * Return value: |
1232 * PR_SUCCESS | 974 * PR_SUCCESS |
1233 * PR_FAILURE | 975 * PR_FAILURE |
1234 */ | 976 */ |
1235 | 977 |
1236 #ifdef DEBUG | 978 #ifdef DEBUG |
1237 NSS_EXTERN PRStatus | 979 NSS_EXTERN PRStatus nssPointerTracker_add(nssPointerTracker *tracker, |
1238 nssPointerTracker_add | 980 const void *pointer); |
1239 ( | |
1240 nssPointerTracker *tracker, | |
1241 const void *pointer | |
1242 ); | |
1243 | 981 |
1244 extern const NSSError NSS_ERROR_NO_MEMORY; | 982 extern const NSSError NSS_ERROR_NO_MEMORY; |
1245 extern const NSSError NSS_ERROR_TRACKER_NOT_INITIALIZED; | 983 extern const NSSError NSS_ERROR_TRACKER_NOT_INITIALIZED; |
1246 extern const NSSError NSS_ERROR_DUPLICATE_POINTER; | 984 extern const NSSError NSS_ERROR_DUPLICATE_POINTER; |
1247 #endif /* DEBUG */ | 985 #endif /* DEBUG */ |
1248 | 986 |
1249 /* | 987 /* |
1250 * nssPointerTracker_remove | 988 * nssPointerTracker_remove |
1251 * | 989 * |
1252 * This method is only present in debug builds. | 990 * This method is only present in debug builds. |
1253 * | 991 * |
1254 * This routine removes the specified pointer from the | 992 * This routine removes the specified pointer from the |
1255 * nssPointerTracker object. It does not call any destructor for the | 993 * nssPointerTracker object. It does not call any destructor for the |
1256 * object; rather, this should be called from the object's destructor. | 994 * object; rather, this should be called from the object's destructor. |
1257 * The nssPointerTracker is threadsafe, but this call is not | 995 * The nssPointerTracker is threadsafe, but this call is not |
1258 * idempotent. This routine returns a PRStatus value; if successful | 996 * idempotent. This routine returns a PRStatus value; if successful |
1259 * it will return PR_SUCCESS. On failure it will set an error on the | 997 * it will return PR_SUCCESS. On failure it will set an error on the |
1260 * error stack and return PR_FAILURE. | 998 * error stack and return PR_FAILURE. |
1261 * | 999 * |
1262 * The error may be one of the following values: | 1000 * The error may be one of the following values: |
1263 * NSS_ERROR_TRACKER_NOT_INITIALIZED | 1001 * NSS_ERROR_TRACKER_NOT_INITIALIZED |
1264 * NSS_ERROR_POINTER_NOT_REGISTERED | 1002 * NSS_ERROR_POINTER_NOT_REGISTERED |
1265 * | 1003 * |
1266 * Return value: | 1004 * Return value: |
1267 * PR_SUCCESS | 1005 * PR_SUCCESS |
1268 * PR_FAILURE | 1006 * PR_FAILURE |
1269 */ | 1007 */ |
1270 | 1008 |
1271 #ifdef DEBUG | 1009 #ifdef DEBUG |
1272 NSS_EXTERN PRStatus | 1010 NSS_EXTERN PRStatus nssPointerTracker_remove(nssPointerTracker *tracker, |
1273 nssPointerTracker_remove | 1011 const void *pointer); |
1274 ( | |
1275 nssPointerTracker *tracker, | |
1276 const void *pointer | |
1277 ); | |
1278 | 1012 |
1279 extern const NSSError NSS_ERROR_TRACKER_NOT_INITIALIZED; | 1013 extern const NSSError NSS_ERROR_TRACKER_NOT_INITIALIZED; |
1280 extern const NSSError NSS_ERROR_POINTER_NOT_REGISTERED; | 1014 extern const NSSError NSS_ERROR_POINTER_NOT_REGISTERED; |
1281 #endif /* DEBUG */ | 1015 #endif /* DEBUG */ |
1282 | 1016 |
1283 /* | 1017 /* |
1284 * nssPointerTracker_verify | 1018 * nssPointerTracker_verify |
1285 * | 1019 * |
1286 * This method is only present in debug builds. | 1020 * This method is only present in debug builds. |
1287 * | 1021 * |
1288 * This routine verifies that the specified pointer has been registered | 1022 * This routine verifies that the specified pointer has been registered |
1289 * with the nssPointerTracker object. The nssPointerTracker object is | 1023 * with the nssPointerTracker object. The nssPointerTracker object is |
1290 * threadsafe, and this call may be safely called from multiple threads | 1024 * threadsafe, and this call may be safely called from multiple threads |
1291 * simultaneously with the same arguments. This routine returns a | 1025 * simultaneously with the same arguments. This routine returns a |
1292 * PRStatus value; if the pointer is registered this will return | 1026 * PRStatus value; if the pointer is registered this will return |
1293 * PR_SUCCESS. Otherwise it will set an error on the error stack and | 1027 * PR_SUCCESS. Otherwise it will set an error on the error stack and |
1294 * return PR_FAILURE. Although the error is suitable for leaving on | 1028 * return PR_FAILURE. Although the error is suitable for leaving on |
1295 * the stack, callers may wish to augment the information available by | 1029 * the stack, callers may wish to augment the information available by |
1296 * placing a more type-specific error on the stack. | 1030 * placing a more type-specific error on the stack. |
1297 * | 1031 * |
1298 * The error may be one of the following values: | 1032 * The error may be one of the following values: |
1299 * NSS_ERROR_POINTER_NOT_REGISTERED | 1033 * NSS_ERROR_POINTER_NOT_REGISTERED |
1300 * | 1034 * |
1301 * Return value: | 1035 * Return value: |
1302 * PR_SUCCESS | 1036 * PR_SUCCESS |
1303 * PR_FAILRUE | 1037 * PR_FAILRUE |
1304 */ | 1038 */ |
1305 | 1039 |
1306 #ifdef DEBUG | 1040 #ifdef DEBUG |
1307 NSS_EXTERN PRStatus | 1041 NSS_EXTERN PRStatus nssPointerTracker_verify(nssPointerTracker *tracker, |
1308 nssPointerTracker_verify | 1042 const void *pointer); |
1309 ( | |
1310 nssPointerTracker *tracker, | |
1311 const void *pointer | |
1312 ); | |
1313 | 1043 |
1314 extern const NSSError NSS_ERROR_POINTER_NOT_REGISTERED; | 1044 extern const NSSError NSS_ERROR_POINTER_NOT_REGISTERED; |
1315 #endif /* DEBUG */ | 1045 #endif /* DEBUG */ |
1316 | 1046 |
1317 /* | 1047 /* |
1318 * libc | 1048 * libc |
1319 * | 1049 * |
1320 * nsslibc_memcpy | 1050 * nsslibc_memcpy |
1321 * nsslibc_memset | 1051 * nsslibc_memset |
1322 * nsslibc_offsetof | 1052 * nsslibc_offsetof |
1323 */ | 1053 */ |
1324 | 1054 |
1325 /* | 1055 /* |
1326 * nsslibc_memcpy | 1056 * nsslibc_memcpy |
1327 * | 1057 * |
1328 * Errors: | 1058 * Errors: |
1329 * NSS_ERROR_INVALID_POINTER | 1059 * NSS_ERROR_INVALID_POINTER |
1330 * | 1060 * |
1331 * Return value: | 1061 * Return value: |
1332 * NULL on error | 1062 * NULL on error |
1333 * The destination pointer on success | 1063 * The destination pointer on success |
1334 */ | 1064 */ |
1335 | 1065 |
1336 NSS_EXTERN void * | 1066 NSS_EXTERN void *nsslibc_memcpy(void *dest, const void *source, PRUint32 n); |
1337 nsslibc_memcpy | |
1338 ( | |
1339 void *dest, | |
1340 const void *source, | |
1341 PRUint32 n | |
1342 ); | |
1343 | 1067 |
1344 extern const NSSError NSS_ERROR_INVALID_POINTER; | 1068 extern const NSSError NSS_ERROR_INVALID_POINTER; |
1345 | 1069 |
1346 /* | 1070 /* |
1347 * nsslibc_memset | 1071 * nsslibc_memset |
1348 * | 1072 * |
1349 * Errors: | 1073 * Errors: |
1350 * NSS_ERROR_INVALID_POINTER | 1074 * NSS_ERROR_INVALID_POINTER |
1351 * | 1075 * |
1352 * Return value: | 1076 * Return value: |
1353 * NULL on error | 1077 * NULL on error |
1354 * The destination pointer on success | 1078 * The destination pointer on success |
1355 */ | 1079 */ |
1356 | 1080 |
1357 NSS_EXTERN void * | 1081 NSS_EXTERN void *nsslibc_memset(void *dest, PRUint8 byte, PRUint32 n); |
1358 nsslibc_memset | |
1359 ( | |
1360 void *dest, | |
1361 PRUint8 byte, | |
1362 PRUint32 n | |
1363 ); | |
1364 | 1082 |
1365 extern const NSSError NSS_ERROR_INVALID_POINTER; | 1083 extern const NSSError NSS_ERROR_INVALID_POINTER; |
1366 | 1084 |
1367 /* | 1085 /* |
1368 * nsslibc_memequal | 1086 * nsslibc_memequal |
1369 * | 1087 * |
1370 * Errors: | 1088 * Errors: |
1371 * NSS_ERROR_INVALID_POINTER | 1089 * NSS_ERROR_INVALID_POINTER |
1372 * | 1090 * |
1373 * Return value: | 1091 * Return value: |
1374 * PR_TRUE if they match | 1092 * PR_TRUE if they match |
1375 * PR_FALSE if they don't | 1093 * PR_FALSE if they don't |
1376 * PR_FALSE upon error | 1094 * PR_FALSE upon error |
1377 */ | 1095 */ |
1378 | 1096 |
1379 NSS_EXTERN PRBool | 1097 NSS_EXTERN PRBool nsslibc_memequal(const void *a, const void *b, PRUint32 len, |
1380 nsslibc_memequal | 1098 PRStatus *statusOpt); |
1381 ( | |
1382 const void *a, | |
1383 const void *b, | |
1384 PRUint32 len, | |
1385 PRStatus *statusOpt | |
1386 ); | |
1387 | 1099 |
1388 extern const NSSError NSS_ERROR_INVALID_POINTER; | 1100 extern const NSSError NSS_ERROR_INVALID_POINTER; |
1389 | 1101 |
1390 #define nsslibc_offsetof(str, memb) ((PRPtrdiff)(&(((str *)0)->memb))) | 1102 #define nsslibc_offsetof(str, memb) ((PRPtrdiff)(&(((str *)0)->memb))) |
1391 | 1103 |
1392 PR_END_EXTERN_C | 1104 PR_END_EXTERN_C |
1393 | 1105 |
1394 #endif /* BASE_H */ | 1106 #endif /* BASE_H */ |
OLD | NEW |