Annotation of parser3/src/lib/gc/include/gc.h, revision 1.7

1.2       paf         1: /* 
                      2:  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
                      3:  * Copyright (c) 1991-1995 by Xerox Corporation.  All rights reserved.
                      4:  * Copyright 1996-1999 by Silicon Graphics.  All rights reserved.
                      5:  * Copyright 1999 by Hewlett-Packard Company.  All rights reserved.
                      6:  *
                      7:  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
                      8:  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
                      9:  *
                     10:  * Permission is hereby granted to use or copy this program
                     11:  * for any purpose,  provided the above notices are retained on all copies.
                     12:  * Permission to modify the code and to distribute modified code is granted,
                     13:  * provided the above notices are retained, and a notice that the code was
                     14:  * modified is included with the above copyright notice.
                     15:  */
                     16: 
                     17: /*
                     18:  * Note that this defines a large number of tuning hooks, which can
                     19:  * safely be ignored in nearly all cases.  For normal use it suffices
                     20:  * to call only GC_MALLOC and perhaps GC_REALLOC.
                     21:  * For better performance, also look at GC_MALLOC_ATOMIC, and
                     22:  * GC_enable_incremental.  If you need an action to be performed
                     23:  * immediately before an object is collected, look at GC_register_finalizer.
                     24:  * If you are using Solaris threads, look at the end of this file.
                     25:  * Everything else is best ignored unless you encounter performance
                     26:  * problems.
                     27:  */
                     28:  
                     29: #ifndef _GC_H
                     30: 
                     31: # define _GC_H
                     32: 
                     33: # define __GC
                     34: # include <stddef.h>
1.4       moko       35: 
1.2       paf        36: # ifdef _WIN32_WCE
                     37: /* Yet more kluges for WinCE */
                     38: #   include <stdlib.h>         /* size_t is defined here */
                     39:     typedef long ptrdiff_t;    /* ptrdiff_t is not defined */
                     40: # endif
                     41: 
                     42: #if defined(__MINGW32__) && defined(_DLL) && !defined(GC_NOT_DLL)
                     43: # ifdef GC_BUILD
                     44: #   define GC_API __declspec(dllexport)
                     45: # else
                     46: #   define GC_API __declspec(dllimport)
                     47: # endif
                     48: #endif
                     49: 
1.4       moko       50: #if (defined(__DMC__) || defined(_MSC_VER)) && (defined(_DLL) && !defined(GC_NOT_DLL) || defined(GC_DLL))
1.2       paf        51: # ifdef GC_BUILD
                     52: #   define GC_API extern __declspec(dllexport)
                     53: # else
                     54: #   define GC_API __declspec(dllimport)
                     55: # endif
                     56: #endif
                     57: 
                     58: #ifndef GC_API
                     59: #define GC_API extern
                     60: #endif
                     61: 
                     62: # if defined(__STDC__) || defined(__cplusplus)
                     63: #   define GC_PROTO(args) args
                     64:     typedef void * GC_PTR;
                     65: #   define GC_CONST const
                     66: # else
                     67: #   define GC_PROTO(args) ()
                     68:     typedef char * GC_PTR;
                     69: #   define GC_CONST
                     70: #  endif
                     71: 
                     72: # ifdef __cplusplus
                     73:     extern "C" {
                     74: # endif
                     75: 
                     76: 
                     77: typedef unsigned long GC_word;
                     78: typedef long GC_signed_word;
                     79: 
                     80: /* Public procedures */
                     81: 
                     82: /* Initialize the collector.  This is only required when using thread-local
                     83:  * allocation, since unlike the regular allocation routines, GC_local_malloc
                     84:  * is not self-initializing.  If you use GC_local_malloc you should arrange
                     85:  * to call this somehow (e.g. from a constructor) before doing any allocation.
                     86:  */
                     87: GC_API void GC_init GC_PROTO((void));
                     88: 
1.4       moko       89: /* Disable garbage collection.  Even GC_gcollect calls will be          */
                     90: /* ineffective.                                                         */
                     91: GC_API void GC_disable(void);
                     92: 
                     93: /* Try to re-enable garbage collection.  GC_disable() and GC_enable()   */
                     94: /* calls nest.  Garbage collection is enabled if the number of calls to */
                     95: /* both functions is equal.                                             */
                     96: GC_API void GC_enable(void);
                     97: 
1.2       paf        98: /*
                     99:  * general purpose allocation routines, with roughly malloc calling conv.
                    100:  * The atomic versions promise that no relevant pointers are contained
                    101:  * in the object.  The nonatomic versions guarantee that the new object
                    102:  * is cleared.  GC_malloc_stubborn promises that no changes to the object
                    103:  * will occur after GC_end_stubborn_change has been called on the
                    104:  * result of GC_malloc_stubborn. GC_malloc_uncollectable allocates an object
                    105:  * that is scanned for pointers to collectable objects, but is not itself
                    106:  * collectable.  The object is scanned even if it does not appear to
                    107:  * be reachable.  GC_malloc_uncollectable and GC_free called on the resulting
                    108:  * object implicitly update GC_non_gc_bytes appropriately.
                    109:  */
                    110: GC_API GC_PTR GC_malloc GC_PROTO((size_t size_in_bytes));
                    111: GC_API GC_PTR GC_malloc_atomic GC_PROTO((size_t size_in_bytes));
                    112: 
                    113: /* Explicitly deallocate an object.  Dangerous if used incorrectly.     */
                    114: /* Requires a pointer to the base of an object.                                */
                    115: /* If the argument is stubborn, it should not be changeable when freed. */
                    116: /* An object should not be enable for finalization when it is          */
                    117: /* explicitly deallocated.                                             */
                    118: /* GC_free(0) is a no-op, as required by ANSI C for free.              */
                    119: GC_API void GC_free GC_PROTO((GC_PTR object_addr));
                    120: 
                    121: /* For compatibility with C library.  This is occasionally faster than */
                    122: /* a malloc followed by a bcopy.  But if you rely on that, either here */
                    123: /* or with the standard C library, your code is broken.  In my         */
                    124: /* opinion, it shouldn't have been invented, but now we're stuck. -HB  */
                    125: /* The resulting object has the same kind as the original.             */
                    126: /* If the argument is stubborn, the result will have changes enabled.  */
                    127: /* It is an error to have changes enabled for the original object.     */
                    128: /* Follows ANSI comventions for NULL old_object.                       */
1.4       moko      129: GC_API GC_PTR GC_realloc GC_PROTO((GC_PTR old_object, size_t new_size_in_bytes));
1.2       paf       130: 
                    131: /* Explicitly trigger a full, world-stop collection.   */
                    132: GC_API void GC_gcollect GC_PROTO((void));
                    133: 
1.6       moko      134: /* We try to make sure that we allocate at least N/GC_free_space_divisor bytes between collections */
                    135: GC_API void GC_set_free_space_divisor(GC_word);
                    136: GC_API GC_word GC_get_free_space_divisor(void);
                    137: 
1.2       paf       138: /* Return the number of bytes in the heap.  Excludes collector private */
                    139: /* data structures.  Includes empty blocks and fragmentation loss.     */
                    140: /* Includes some pages that were allocated but never written.          */
                    141: GC_API size_t GC_get_heap_size GC_PROTO((void));
                    142: 
                    143: /* Return a lower bound on the number of free bytes in the heap.       */
                    144: GC_API size_t GC_get_free_bytes GC_PROTO((void));
                    145: 
                    146: /* Return the number of bytes allocated since the last collection.     */
                    147: GC_API size_t GC_get_bytes_since_gc GC_PROTO((void));
                    148: 
                    149: /* Return the total number of bytes allocated in this process.         */
                    150: /* Never decreases.                                                    */
                    151: GC_API size_t GC_get_total_bytes GC_PROTO((void));
                    152: 
                    153: #if defined(__sgi) && !defined(__GNUC__) && _COMPILER_VERSION >= 720
                    154: #   define GC_ADD_CALLER
                    155: #   define GC_RETURN_ADDR (GC_word)__return_address
                    156: #endif
                    157: 
                    158: #ifdef GC_ADD_CALLER
                    159: #  define GC_EXTRAS GC_RETURN_ADDR, __FILE__, __LINE__
                    160: #  define GC_EXTRA_PARAMS GC_word ra, GC_CONST char * s, int i
                    161: #else
                    162: #  define GC_EXTRAS __FILE__, __LINE__
                    163: #  define GC_EXTRA_PARAMS GC_CONST char * s, int i
                    164: #endif
                    165: 
                    166: /* Debugging (annotated) allocation.  GC_gcollect will check           */
                    167: /* objects allocated in this way for overwrites, etc.                  */
1.4       moko      168: GC_API GC_PTR GC_debug_malloc GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
                    169: GC_API GC_PTR GC_debug_malloc_atomic GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
1.2       paf       170: GC_API void GC_debug_free GC_PROTO((GC_PTR object_addr));
1.4       moko      171: GC_API GC_PTR GC_debug_realloc GC_PROTO((GC_PTR old_object, size_t new_size_in_bytes, GC_EXTRA_PARAMS));
1.2       paf       172: 
                    173: /* Routines that allocate objects with debug information (like the     */
                    174: /* above), but just fill in dummy file and line number information.    */
                    175: /* Thus they can serve as drop-in malloc/realloc replacements.  This   */
                    176: /* can be useful for two reasons:                                      */
                    177: /* 1) It allows the collector to be built with DBG_HDRS_ALL defined    */
                    178: /*    even if some allocation calls come from 3rd party libraries      */
                    179: /*    that can't be recompiled.                                                */
                    180: /* 2) On some platforms, the file and line information is redundant,   */
                    181: /*    since it can be reconstructed from a stack trace.  On such       */
                    182: /*    platforms it may be more convenient not to recompile, e.g. for   */
                    183: /*    leak detection.  This can be accomplished by instructing the     */
                    184: /*    linker to replace malloc/realloc with these.                     */
                    185: GC_API GC_PTR GC_debug_malloc_replacement GC_PROTO((size_t size_in_bytes));
1.4       moko      186: GC_API GC_PTR GC_debug_realloc_replacement GC_PROTO((GC_PTR object_addr, size_t size_in_bytes));
                    187: 
1.2       paf       188: # ifdef GC_DEBUG
                    189: #   define GC_MALLOC(sz) GC_debug_malloc(sz, GC_EXTRAS)
                    190: #   define GC_MALLOC_ATOMIC(sz) GC_debug_malloc_atomic(sz, GC_EXTRAS)
                    191: #   define GC_REALLOC(old, sz) GC_debug_realloc(old, sz, GC_EXTRAS)
                    192: #   define GC_FREE(p) GC_debug_free(p)
                    193: # else
                    194: #   define GC_MALLOC(sz) GC_malloc(sz)
                    195: #   define GC_MALLOC_ATOMIC(sz) GC_malloc_atomic(sz)
                    196: #   define GC_REALLOC(old, sz) GC_realloc(old, sz)
                    197: #   define GC_FREE(p) GC_free(p)
                    198: # endif
                    199: /* The following are included because they are often convenient, and   */
                    200: /* reduce the chance for a misspecifed size argument.  But calls may   */
                    201: /* expand to something syntactically incorrect if t is a complicated   */
                    202: /* type expression.                                                    */
                    203: # define GC_NEW(t) (t *)GC_MALLOC(sizeof (t))
                    204: # define GC_NEW_ATOMIC(t) (t *)GC_MALLOC_ATOMIC(sizeof (t))
                    205: 
                    206: 
                    207: /* GC_set_warn_proc can be used to redirect or filter warning messages.        */
                    208: /* p may not be a NULL pointer.                                                */
                    209: typedef void (*GC_warn_proc) GC_PROTO((char *msg, GC_word arg));
1.3       moko      210: GC_API void GC_set_warn_proc GC_PROTO((GC_warn_proc p));
                    211: 
                    212: /* GC_ignore_warn_proc may be used as an argument for GC_set_warn_proc  */
                    213: /* to suppress all warnings (unless statistics printing is turned on).  */
                    214: GC_API void GC_ignore_warn_proc(char *, GC_word);
                    215: 
1.7     ! moko      216: /* abort_func is invoked on GC fatal aborts (just before OS-dependent   */
        !           217: /* abort or exit(1) is called).  Must be non-NULL.                      */
        !           218: typedef void (* GC_abort_func)(const char * /* msg */);
        !           219: GC_API void GC_set_abort_func(GC_abort_func fn);
        !           220: 
1.2       paf       221: #ifdef __cplusplus
                    222:     }  /* end of extern "C" */
                    223: #endif
                    224: 
                    225: #endif /* _GC_H */

E-mail: