Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /*
6 * hashops.c
7 *
8 * This file includes a set of PLHashAllocOps that use NSSArenas.
9 */
11 #ifndef BASE_H
12 #include "base.h"
13 #endif /* BASE_H */
15 static void * PR_CALLBACK
16 nss_arena_hash_alloc_table
17 (
18 void *pool,
19 PRSize size
20 )
21 {
22 NSSArena *arena = (NSSArena *)NULL;
24 #ifdef NSSDEBUG
25 if( (void *)NULL != arena ) {
26 if( PR_SUCCESS != nssArena_verifyPointer(arena) ) {
27 return (void *)NULL;
28 }
29 }
30 #endif /* NSSDEBUG */
32 return nss_ZAlloc(arena, size);
33 }
35 static void PR_CALLBACK
36 nss_arena_hash_free_table
37 (
38 void *pool,
39 void *item
40 )
41 {
42 (void)nss_ZFreeIf(item);
43 }
45 static PLHashEntry * PR_CALLBACK
46 nss_arena_hash_alloc_entry
47 (
48 void *pool,
49 const void *key
50 )
51 {
52 NSSArena *arena = NULL;
54 #ifdef NSSDEBUG
55 if( (void *)NULL != arena ) {
56 if( PR_SUCCESS != nssArena_verifyPointer(arena) ) {
57 return (void *)NULL;
58 }
59 }
60 #endif /* NSSDEBUG */
62 return nss_ZNEW(arena, PLHashEntry);
63 }
65 static void PR_CALLBACK
66 nss_arena_hash_free_entry
67 (
68 void *pool,
69 PLHashEntry *he,
70 PRUintn flag
71 )
72 {
73 if( HT_FREE_ENTRY == flag ) {
74 (void)nss_ZFreeIf(he);
75 }
76 }
78 NSS_IMPLEMENT_DATA PLHashAllocOps
79 nssArenaHashAllocOps = {
80 nss_arena_hash_alloc_table,
81 nss_arena_hash_free_table,
82 nss_arena_hash_alloc_entry,
83 nss_arena_hash_free_entry
84 };