DEFINE_SPARSE_ARRAY_OF.pod 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. =pod
  2. =head1 NAME
  3. DEFINE_SPARSE_ARRAY_OF, ossl_sa_TYPE_new, ossl_sa_TYPE_free,
  4. ossl_sa_TYPE_free_leaves, ossl_sa_TYPE_num, ossl_sa_TYPE_doall,
  5. ossl_sa_TYPE_doall_arg, ossl_sa_TYPE_get, ossl_sa_TYPE_set
  6. - sparse array container
  7. =head1 SYNOPSIS
  8. =for comment generic
  9. #include "internal/sparse_array.h"
  10. typedef struct sparse_array_st OPENSSL_SA;
  11. SPARSE_ARRAY_OF(TYPE)
  12. DEFINE_SPARSE_ARRAY_OF(TYPE)
  13. SPARSE_ARRAY_OF(TYPE) *ossl_sa_TYPE_new(void);
  14. void ossl_sa_TYPE_free(const SPARSE_ARRAY_OF(TYPE) *sa);
  15. void ossl_sa_TYPE_free_leaves(const SPARSE_ARRAY_OF(TYPE) *sa);
  16. size_t ossl_sa_TYPE_num(const SPARSE_ARRAY_OF(TYPE) *sa);
  17. void ossl_sa_TYPE_doall(const OPENSSL_SA *sa, void (*leaf)(ossl_uintmax_t,
  18. void *));
  19. void ossl_sa_TYPE_doall_arg(const OPENSSL_SA *sa,
  20. void (*leaf)(ossl_uintmax_t, void *, void *),
  21. void *arg);
  22. TYPE *ossl_sa_TYPE_get(const SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx);
  23. int ossl_sa_TYPE_set(SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx,
  24. TYPE *value);
  25. =head1 DESCRIPTION
  26. SPARSE_ARRAY_OF() returns the name for a sparse array of the specified
  27. B<TYPE>. DEFINE_STACK_OF() creates set of functions for a sparse array of
  28. B<TYPE>. This will mean that a pointer to type B<TYPE> is stored in each
  29. element of a sparse array, the type is referenced by SPARSE_ARRAY_OF(TYPE) and
  30. each function name begins with I<ossl_sa_TYPE_>. For example:
  31. TYPE *ossl_sa_TYPE_get(SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx);
  32. ossl_sa_TYPE_num() returns the number of elements in B<sa> or 0 if B<sa> is
  33. B<NULL>.
  34. ossl_sa_TYPE_get() returns element B<idx> in B<sa>, where B<idx> starts at
  35. zero. If B<idx> refers to a value that has not been set then B<NULL> is
  36. returned.
  37. ossl_sa_TYPE_set() sets element B<idx> in B<sa> to B<value>, where B<idx>
  38. starts at zero. The sparse array will be resized as required.
  39. ossl_sa_TYPE_new() allocates a new empty sparse array.
  40. ossl_sa_TYPE_free() frees up the B<sa> structure. It does B<not> free up any
  41. elements of B<sa>. After this call B<sa> is no longer valid.
  42. ossl_sa_TYPE_free_leaves() frees up the B<sa> structure and all of its
  43. elements. After this call B<sa> is no longer valid.
  44. ossl_sa_TYPE_doall() calls the function B<leaf> for each element in B<sa>
  45. in ascending index order. The index position, within the sparse array,
  46. of each item is passed as the first argument to the leaf function and a
  47. pointer to the associated value is is passed as the second argument.
  48. ossl_sa_TYPE_doall_arg() calls the function B<leaf> for each element in
  49. B<sa> in ascending index order. The index position, within the sparse
  50. array, of each item is passed as the first argument to the leaf function,
  51. a pointer to the associated value is passed as the second argument and
  52. the third argument is the user supplied B<arg>.
  53. =head1 NOTES
  54. Sparse arrays are an internal data structure and should B<not> be used by user
  55. applications.
  56. Care should be taken when accessing sparse arrays in multi-threaded
  57. environments. The ossl_sa_TYPE_set operation can cause the internal structure
  58. of the sparse array to change which causes race conditions if the sparse array
  59. is accessed in a different thread.
  60. SPARSE_ARRAY_OF() and DEFINE_SPARSE_ARRAY_OF() are implemented as macros.
  61. The underlying utility B<OPENSSL_SA_> API should not be used directly. It
  62. defines these functions: OPENSSL_SA_doall, OPENSSL_SA_doall_arg,
  63. OPENSSL_SA_free, OPENSSL_SA_free_leaves, OPENSSL_SA_get, OPENSSL_SA_new,
  64. OPENSSL_SA_num and OPENSSL_SA_set.
  65. =head1 RETURN VALUES
  66. ossl_sa_TYPE_num() returns the number of elements in the sparse array or B<0>
  67. if the passed sparse array is B<NULL>.
  68. ossl_sa_TYPE_get() returns a pointer to a sparse array element or B<NULL> if
  69. the element has not be set.
  70. ossl_sa_TYPE_set() return B<1> on success and B<0> on error. In the latter
  71. case, the elements of the sparse array remain unchanged, although the internal
  72. structures might have.
  73. ossl_sa_TYPE_new() returns an empty sparse array or B<NULL> if an error
  74. occurs.
  75. ossl_sa_TYPE_doall, ossl_sa_TYPE_doall_arg, ossl_sa_TYPE_free() and
  76. ossl_sa_TYPE_free_leaves() do not return values.
  77. =head1 HISTORY
  78. This functionality was added to OpenSSL 3.0.0.
  79. =head1 COPYRIGHT
  80. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. Copyright
  81. (c) 2019, Oracle and/or its affiliates. All rights reserved.
  82. Licensed under the Apache License 2.0 (the "License"). You may not use this
  83. file except in compliance with the License. You can obtain a copy in the file
  84. LICENSE in the source distribution or at
  85. L<https://www.openssl.org/source/license.html>.
  86. =cut