(root)/
bison-3.8.2/
lib/
gl_xlist.h
       1  /* Abstract sequential list data type, with out-of-memory checking.
       2     Copyright (C) 2009-2021 Free Software Foundation, Inc.
       3     Written by Bruno Haible <bruno@clisp.org>, 2009.
       4  
       5     This program is free software: you can redistribute it and/or modify
       6     it under the terms of the GNU General Public License as published by
       7     the Free Software Foundation; either version 3 of the License, or
       8     (at your option) any later version.
       9  
      10     This program is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13     GNU General Public License for more details.
      14  
      15     You should have received a copy of the GNU General Public License
      16     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      17  
      18  #ifndef _GL_XLIST_H
      19  #define _GL_XLIST_H
      20  
      21  #include "gl_list.h"
      22  #include "xalloc.h"
      23  
      24  #ifndef _GL_INLINE_HEADER_BEGIN
      25   #error "Please include config.h first."
      26  #endif
      27  _GL_INLINE_HEADER_BEGIN
      28  #ifndef GL_XLIST_INLINE
      29  # define GL_XLIST_INLINE _GL_INLINE
      30  #endif
      31  
      32  #ifdef __cplusplus
      33  extern "C" {
      34  #endif
      35  
      36  /* These functions are thin wrappers around the corresponding functions with
      37     _nx_ infix from gl_list.h.  Upon out-of-memory, they invoke xalloc_die (),
      38     instead of returning an error indicator.  */
      39  #if 0 /* These are defined inline below.  */
      40  extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
      41                                         gl_listelement_equals_fn equals_fn,
      42                                         gl_listelement_hashcode_fn hashcode_fn,
      43                                         gl_listelement_dispose_fn dispose_fn,
      44                                         bool allow_duplicates)
      45    /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
      46    _GL_ATTRIBUTE_RETURNS_NONNULL;
      47  extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
      48                                   gl_listelement_equals_fn equals_fn,
      49                                   gl_listelement_hashcode_fn hashcode_fn,
      50                                   gl_listelement_dispose_fn dispose_fn,
      51                                   bool allow_duplicates,
      52                                   size_t count, const void **contents)
      53    /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
      54    _GL_ATTRIBUTE_RETURNS_NONNULL;
      55  extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
      56                                      const void *elt);
      57  extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
      58                                        const void *elt);
      59  extern gl_list_node_t gl_list_set_first (gl_list_t list, const void *elt);
      60  extern gl_list_node_t gl_list_set_last (gl_list_t list, const void *elt);
      61  extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
      62  extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
      63  extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
      64                                            const void *elt);
      65  extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
      66                                           const void *elt);
      67  extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
      68                                        const void *elt);
      69  extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
      70                                           gl_listelement_compar_fn compar,
      71                                           const void *elt);
      72  #endif
      73  
      74  GL_XLIST_INLINE
      75  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
      76  _GL_ATTRIBUTE_RETURNS_NONNULL
      77  gl_list_t
      78  gl_list_create_empty (gl_list_implementation_t implementation,
      79                        gl_listelement_equals_fn equals_fn,
      80                        gl_listelement_hashcode_fn hashcode_fn,
      81                        gl_listelement_dispose_fn dispose_fn,
      82                        bool allow_duplicates)
      83  {
      84    gl_list_t result =
      85      gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn,
      86                               allow_duplicates);
      87    if (result == NULL)
      88      xalloc_die ();
      89    return result;
      90  }
      91  
      92  GL_XLIST_INLINE
      93  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
      94  _GL_ATTRIBUTE_RETURNS_NONNULL
      95  gl_list_t
      96  gl_list_create (gl_list_implementation_t implementation,
      97                  gl_listelement_equals_fn equals_fn,
      98                  gl_listelement_hashcode_fn hashcode_fn,
      99                  gl_listelement_dispose_fn dispose_fn,
     100                  bool allow_duplicates,
     101                  size_t count, const void **contents)
     102  {
     103    gl_list_t result =
     104      gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn,
     105                         allow_duplicates, count, contents);
     106    if (result == NULL)
     107      xalloc_die ();
     108    return result;
     109  }
     110  
     111  GL_XLIST_INLINE void
     112  gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
     113  {
     114    int result = gl_list_node_nx_set_value (list, node, elt);
     115    if (result < 0)
     116      xalloc_die ();
     117  }
     118  
     119  GL_XLIST_INLINE gl_list_node_t
     120  gl_list_set_at (gl_list_t list, size_t position, const void *elt)
     121  {
     122    gl_list_node_t result = gl_list_nx_set_at (list, position, elt);
     123    if (result == NULL)
     124      xalloc_die ();
     125    return result;
     126  }
     127  
     128  GL_XLIST_INLINE gl_list_node_t
     129  gl_list_set_first (gl_list_t list, const void *elt)
     130  {
     131    gl_list_node_t result = gl_list_nx_set_first (list, elt);
     132    if (result == NULL)
     133      xalloc_die ();
     134    return result;
     135  }
     136  
     137  GL_XLIST_INLINE gl_list_node_t
     138  gl_list_set_last (gl_list_t list, const void *elt)
     139  {
     140    gl_list_node_t result = gl_list_nx_set_last (list, elt);
     141    if (result == NULL)
     142      xalloc_die ();
     143    return result;
     144  }
     145  
     146  GL_XLIST_INLINE gl_list_node_t
     147  gl_list_add_first (gl_list_t list, const void *elt)
     148  {
     149    gl_list_node_t result = gl_list_nx_add_first (list, elt);
     150    if (result == NULL)
     151      xalloc_die ();
     152    return result;
     153  }
     154  
     155  GL_XLIST_INLINE gl_list_node_t
     156  gl_list_add_last (gl_list_t list, const void *elt)
     157  {
     158    gl_list_node_t result = gl_list_nx_add_last (list, elt);
     159    if (result == NULL)
     160      xalloc_die ();
     161    return result;
     162  }
     163  
     164  GL_XLIST_INLINE gl_list_node_t
     165  gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
     166  {
     167    gl_list_node_t result = gl_list_nx_add_before (list, node, elt);
     168    if (result == NULL)
     169      xalloc_die ();
     170    return result;
     171  }
     172  
     173  GL_XLIST_INLINE gl_list_node_t
     174  gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
     175  {
     176    gl_list_node_t result = gl_list_nx_add_after (list, node, elt);
     177    if (result == NULL)
     178      xalloc_die ();
     179    return result;
     180  }
     181  
     182  GL_XLIST_INLINE gl_list_node_t
     183  gl_list_add_at (gl_list_t list, size_t position, const void *elt)
     184  {
     185    gl_list_node_t result = gl_list_nx_add_at (list, position, elt);
     186    if (result == NULL)
     187      xalloc_die ();
     188    return result;
     189  }
     190  
     191  GL_XLIST_INLINE gl_list_node_t
     192  gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar,
     193                     const void *elt)
     194  {
     195    gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt);
     196    if (result == NULL)
     197      xalloc_die ();
     198    return result;
     199  }
     200  
     201  #ifdef __cplusplus
     202  }
     203  #endif
     204  
     205  _GL_INLINE_HEADER_END
     206  
     207  #endif /* _GL_XLIST_H */