DEFINE_SPARSE_ARRAY_OF.pod 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 openssl generic
  9. #include "crypto/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. =begin comment
  27. POD is pretty good at recognising function names and making them appropriately
  28. bold... however, when part of the function name is variable, we have to help
  29. the processor along
  30. =end comment
  31. SPARSE_ARRAY_OF() returns the name for a sparse array of the specified
  32. B<I<TYPE>>. DEFINE_STACK_OF() creates set of functions for a sparse
  33. array of B<I<TYPE>>. This will mean that a pointer to type B<I<TYPE>>
  34. is stored in each element of a sparse array, the type is referenced by
  35. B<SPARSE_ARRAY_OF>(B<I<TYPE>>) and each function name begins with
  36. B<ossl_sa_I<TYPE>_>. For example:
  37. TYPE *ossl_sa_TYPE_get(SPARSE_ARRAY_OF(TYPE) *sa, ossl_uintmax_t idx);
  38. B<ossl_sa_I<TYPE>_num>() returns the number of elements in I<sa> or 0 if I<sa>
  39. is NULL.
  40. B<ossl_sa_I<TYPE>_get>() returns element I<idx> in I<sa>, where I<idx> starts
  41. at zero. If I<idx> refers to a value that has not been set then NULL is
  42. returned.
  43. B<ossl_sa_I<TYPE>_set>() sets element I<idx> in I<sa> to I<value>, where I<idx>
  44. starts at zero. The sparse array will be resized as required.
  45. B<ossl_sa_I<TYPE>_new>() allocates a new empty sparse array.
  46. B<ossl_sa_I<TYPE>_free>() frees up the I<sa> structure. It does I<not> free up any
  47. elements of I<sa>. After this call I<sa> is no longer valid.
  48. B<ossl_sa_I<TYPE>_free_leaves>() frees up the I<sa> structure and all of its
  49. elements. After this call I<sa> is no longer valid.
  50. B<ossl_sa_I<TYPE>_doall>() calls the function I<leaf> for each element in I<sa>
  51. in ascending index order. The index position, within the sparse array,
  52. of each item is passed as the first argument to the leaf function and a
  53. pointer to the associated value is is passed as the second argument.
  54. B<ossl_sa_I<TYPE>_doall_arg>() calls the function I<leaf> for each element in
  55. I<sa> in ascending index order. The index position, within the sparse
  56. array, of each item is passed as the first argument to the leaf function,
  57. a pointer to the associated value is passed as the second argument and
  58. the third argument is the user supplied I<arg>.
  59. =head1 NOTES
  60. Sparse arrays are an internal data structure and should B<not> be used by user
  61. applications.
  62. Care should be taken when accessing sparse arrays in multi-threaded
  63. environments. The B<ossl_sa_I<TYPE>_set>() operation can cause the internal
  64. structure of the sparse array to change which causes race conditions if the
  65. sparse array is accessed in a different thread.
  66. SPARSE_ARRAY_OF() and DEFINE_SPARSE_ARRAY_OF() are implemented as macros.
  67. The underlying utility B<OPENSSL_SA_> API should not be used directly. It
  68. defines these functions: OPENSSL_SA_doall, OPENSSL_SA_doall_arg,
  69. OPENSSL_SA_free, OPENSSL_SA_free_leaves, OPENSSL_SA_get, OPENSSL_SA_new,
  70. OPENSSL_SA_num and OPENSSL_SA_set.
  71. =head1 RETURN VALUES
  72. B<ossl_sa_I<TYPE>_num>() returns the number of elements in the sparse array or
  73. B<0> if the passed sparse array is NULL.
  74. B<ossl_sa_I<TYPE>_get>() returns a pointer to a sparse array element or NULL if
  75. the element has not be set.
  76. B<ossl_sa_I<TYPE>_set>() return B<1> on success and B<0> on error. In the latter
  77. case, the elements of the sparse array remain unchanged, although the internal
  78. structures might have.
  79. B<ossl_sa_I<TYPE>_new>() returns an empty sparse array or NULL if an error
  80. occurs.
  81. B<ossl_sa_I<TYPE>_doall>(), B<ossl_sa_I<TYPE>_doall_arg>(),
  82. B<ossl_sa_I<TYPE>_free>() and B<ossl_sa_I<TYPE>_free_leaves>()
  83. do not return values.
  84. =head1 HISTORY
  85. This functionality was added to OpenSSL 3.0.
  86. =head1 COPYRIGHT
  87. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. Copyright
  88. (c) 2019, Oracle and/or its affiliates. All rights reserved.
  89. Licensed under the Apache License 2.0 (the "License"). You may not use this
  90. file except in compliance with the License. You can obtain a copy in the file
  91. LICENSE in the source distribution or at
  92. L<https://www.openssl.org/source/license.html>.
  93. =cut