Annotation of gcc/objc/record.h, revision 1.1

1.1     ! root        1: /* Implement a vector type that indicates its used size and allocated size.
        !             2:    Copyright (C) 1992 Free Software Foundation, Inc.
        !             3: 
        !             4: This file is part of GNU CC.
        !             5: 
        !             6: GNU CC is free software; you can redistribute it and/or modify
        !             7: it under the terms of the GNU General Public License as published by
        !             8: the Free Software Foundation; either version 2, or (at your option)
        !             9: any later version.
        !            10: 
        !            11: GNU CC is distributed in the hope that it will be useful,
        !            12: but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            14: GNU General Public License for more details.
        !            15: 
        !            16: You should have received a copy of the GNU General Public License
        !            17: along with GNU CC; see the file COPYING.  If not, write to
        !            18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
        !            19: 
        !            20: /* As a special exception, if you link this library with files
        !            21:    compiled with GCC to produce an executable, this does not cause
        !            22:    the resulting executable to be covered by the GNU General Public License.
        !            23:    This exception does not however invalidate any other reasons why
        !            24:    the executable file might be covered by the GNU General Public License.  */
        !            25: 
        !            26: 
        !            27: #ifndef __record_INCLUDE_GNU
        !            28: #define __record_INCLUDE_GNU
        !            29: 
        !            30: #include "assert.h"
        !            31: 
        !            32: 
        !            33: /* Structure to hold records.  */
        !            34: struct record
        !            35: {  
        !            36:   unsigned int capacity;
        !            37:   unsigned int used;
        !            38:   void **records;
        !            39: };
        !            40:   
        !            41: 
        !            42: extern void *__objc_xmalloc (unsigned int);
        !            43: extern void *__objc_xcalloc (unsigned int, unsigned int);
        !            44: extern void *__objc_xrealloc (void *, unsigned int);
        !            45: 
        !            46: /* Allocate, initialize and return a new record structure.  */
        !            47: 
        !            48: static inline struct record *
        !            49: record_new ()
        !            50: {
        !            51:   struct record *record;
        !            52: 
        !            53:   record = (struct record *) __objc_xcalloc (1, sizeof (struct record));
        !            54:   record->capacity = 8;
        !            55:   record ->records
        !            56:     = (void **) __objc_xcalloc (record->capacity, sizeof (void *));
        !            57: 
        !            58:   return record;
        !            59: }
        !            60: 
        !            61: 
        !            62: /* Delete the record.  */
        !            63: static inline void
        !            64: record_delete (struct record *record)
        !            65: {
        !            66:   free (record->records);
        !            67:   free (record);
        !            68: }
        !            69: 
        !            70: 
        !            71: /* Return the number of entries in the record.  */
        !            72: 
        !            73: static inline unsigned int
        !            74: record_entries (struct record *record)
        !            75: {
        !            76:   return record->used;
        !            77: }
        !            78: 
        !            79: 
        !            80: /* Return the capacity of the record.  */
        !            81: 
        !            82: static inline unsigned int
        !            83: record_capacity (struct record *record)
        !            84: {
        !            85:   return record->capacity;
        !            86: }
        !            87: 
        !            88: 
        !            89: /* Store an entry at the specified record location.  */
        !            90: 
        !            91: static inline void
        !            92: record_store_at (unsigned int i, void *value, struct record *record)
        !            93: {
        !            94:   assert (i);
        !            95:   assert (i <= record_entries (record));
        !            96: 
        !            97:   record->records[i] = value;
        !            98: }
        !            99: 
        !           100: 
        !           101: /* Make a record entry.  Expand the record's size if full.  */
        !           102: 
        !           103: static inline void
        !           104: record_store (void *value, struct record *record)
        !           105: {
        !           106:   ++record->used;
        !           107:   if (record_entries (record) == record_capacity (record))
        !           108:     {
        !           109:       record->capacity *= 2;
        !           110:       record->records
        !           111:        = (void **) __objc_xrealloc (record->records,
        !           112:                                     record_capacity (record) * sizeof (void *));
        !           113:     }
        !           114:   record_store_at (record_entries (record), value, record);
        !           115: }
        !           116: 
        !           117: 
        !           118: /* Get a value from the record.  */
        !           119: 
        !           120: static inline void *
        !           121: record_get (unsigned int i, struct record *record)
        !           122: {
        !           123:   assert (i);
        !           124:   assert (i <= record_entries (record));
        !           125:   return record->records[i];
        !           126: }
        !           127: 
        !           128: #endif /* not __record_INCLUDE_GNU */
        !           129: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.