security/nss/lib/base/hashops.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/base/hashops.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/*
     1.9 + * hashops.c
    1.10 + *
    1.11 + * This file includes a set of PLHashAllocOps that use NSSArenas.
    1.12 + */
    1.13 +
    1.14 +#ifndef BASE_H
    1.15 +#include "base.h"
    1.16 +#endif /* BASE_H */
    1.17 +
    1.18 +static void * PR_CALLBACK
    1.19 +nss_arena_hash_alloc_table
    1.20 +(
    1.21 +  void *pool,
    1.22 +  PRSize size
    1.23 +)
    1.24 +{
    1.25 +  NSSArena *arena = (NSSArena *)NULL;
    1.26 +
    1.27 +#ifdef NSSDEBUG
    1.28 +  if( (void *)NULL != arena ) {
    1.29 +    if( PR_SUCCESS != nssArena_verifyPointer(arena) ) {
    1.30 +      return (void *)NULL;
    1.31 +    }
    1.32 +  }
    1.33 +#endif /* NSSDEBUG */
    1.34 +
    1.35 +  return nss_ZAlloc(arena, size);
    1.36 +}
    1.37 +
    1.38 +static void PR_CALLBACK
    1.39 +nss_arena_hash_free_table
    1.40 +(
    1.41 +  void *pool, 
    1.42 +  void *item
    1.43 +)
    1.44 +{
    1.45 +  (void)nss_ZFreeIf(item);
    1.46 +}
    1.47 +
    1.48 +static PLHashEntry * PR_CALLBACK
    1.49 +nss_arena_hash_alloc_entry
    1.50 +(
    1.51 +  void *pool,
    1.52 +  const void *key
    1.53 +)
    1.54 +{
    1.55 +  NSSArena *arena = NULL;
    1.56 +
    1.57 +#ifdef NSSDEBUG
    1.58 +  if( (void *)NULL != arena ) {
    1.59 +    if( PR_SUCCESS != nssArena_verifyPointer(arena) ) {
    1.60 +      return (void *)NULL;
    1.61 +    }
    1.62 +  }
    1.63 +#endif /* NSSDEBUG */
    1.64 +
    1.65 +  return nss_ZNEW(arena, PLHashEntry);
    1.66 +}
    1.67 +
    1.68 +static void PR_CALLBACK
    1.69 +nss_arena_hash_free_entry
    1.70 +(
    1.71 +  void *pool,
    1.72 +  PLHashEntry *he,
    1.73 +  PRUintn flag
    1.74 +)
    1.75 +{
    1.76 +  if( HT_FREE_ENTRY == flag ) {
    1.77 +    (void)nss_ZFreeIf(he);
    1.78 +  }
    1.79 +}
    1.80 +
    1.81 +NSS_IMPLEMENT_DATA PLHashAllocOps 
    1.82 +nssArenaHashAllocOps = {
    1.83 +  nss_arena_hash_alloc_table,
    1.84 +  nss_arena_hash_free_table,
    1.85 +  nss_arena_hash_alloc_entry,
    1.86 +  nss_arena_hash_free_entry
    1.87 +};

mercurial