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

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: 
                    134: /* Return the number of bytes in the heap.  Excludes collector private */
                    135: /* data structures.  Includes empty blocks and fragmentation loss.     */
                    136: /* Includes some pages that were allocated but never written.          */
                    137: GC_API size_t GC_get_heap_size GC_PROTO((void));
                    138: 
                    139: /* Return a lower bound on the number of free bytes in the heap.       */
                    140: GC_API size_t GC_get_free_bytes GC_PROTO((void));
                    141: 
                    142: /* Return the number of bytes allocated since the last collection.     */
                    143: GC_API size_t GC_get_bytes_since_gc GC_PROTO((void));
                    144: 
                    145: /* Return the total number of bytes allocated in this process.         */
                    146: /* Never decreases.                                                    */
                    147: GC_API size_t GC_get_total_bytes GC_PROTO((void));
                    148: 
                    149: #if defined(__sgi) && !defined(__GNUC__) && _COMPILER_VERSION >= 720
                    150: #   define GC_ADD_CALLER
                    151: #   define GC_RETURN_ADDR (GC_word)__return_address
                    152: #endif
                    153: 
                    154: #ifdef GC_ADD_CALLER
                    155: #  define GC_EXTRAS GC_RETURN_ADDR, __FILE__, __LINE__
                    156: #  define GC_EXTRA_PARAMS GC_word ra, GC_CONST char * s, int i
                    157: #else
                    158: #  define GC_EXTRAS __FILE__, __LINE__
                    159: #  define GC_EXTRA_PARAMS GC_CONST char * s, int i
                    160: #endif
                    161: 
                    162: /* Debugging (annotated) allocation.  GC_gcollect will check           */
                    163: /* objects allocated in this way for overwrites, etc.                  */
1.4     ! moko      164: GC_API GC_PTR GC_debug_malloc GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
        !           165: GC_API GC_PTR GC_debug_malloc_atomic GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
1.2       paf       166: GC_API void GC_debug_free GC_PROTO((GC_PTR object_addr));
1.4     ! moko      167: 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       168: 
                    169: /* Routines that allocate objects with debug information (like the     */
                    170: /* above), but just fill in dummy file and line number information.    */
                    171: /* Thus they can serve as drop-in malloc/realloc replacements.  This   */
                    172: /* can be useful for two reasons:                                      */
                    173: /* 1) It allows the collector to be built with DBG_HDRS_ALL defined    */
                    174: /*    even if some allocation calls come from 3rd party libraries      */
                    175: /*    that can't be recompiled.                                                */
                    176: /* 2) On some platforms, the file and line information is redundant,   */
                    177: /*    since it can be reconstructed from a stack trace.  On such       */
                    178: /*    platforms it may be more convenient not to recompile, e.g. for   */
                    179: /*    leak detection.  This can be accomplished by instructing the     */
                    180: /*    linker to replace malloc/realloc with these.                     */
                    181: GC_API GC_PTR GC_debug_malloc_replacement GC_PROTO((size_t size_in_bytes));
1.4     ! moko      182: GC_API GC_PTR GC_debug_realloc_replacement GC_PROTO((GC_PTR object_addr, size_t size_in_bytes));
        !           183: 
1.2       paf       184: # ifdef GC_DEBUG
                    185: #   define GC_MALLOC(sz) GC_debug_malloc(sz, GC_EXTRAS)
                    186: #   define GC_MALLOC_ATOMIC(sz) GC_debug_malloc_atomic(sz, GC_EXTRAS)
                    187: #   define GC_REALLOC(old, sz) GC_debug_realloc(old, sz, GC_EXTRAS)
                    188: #   define GC_FREE(p) GC_debug_free(p)
                    189: # else
                    190: #   define GC_MALLOC(sz) GC_malloc(sz)
                    191: #   define GC_MALLOC_ATOMIC(sz) GC_malloc_atomic(sz)
                    192: #   define GC_REALLOC(old, sz) GC_realloc(old, sz)
                    193: #   define GC_FREE(p) GC_free(p)
                    194: # endif
                    195: /* The following are included because they are often convenient, and   */
                    196: /* reduce the chance for a misspecifed size argument.  But calls may   */
                    197: /* expand to something syntactically incorrect if t is a complicated   */
                    198: /* type expression.                                                    */
                    199: # define GC_NEW(t) (t *)GC_MALLOC(sizeof (t))
                    200: # define GC_NEW_ATOMIC(t) (t *)GC_MALLOC_ATOMIC(sizeof (t))
                    201: 
                    202: 
                    203: /* GC_set_warn_proc can be used to redirect or filter warning messages.        */
                    204: /* p may not be a NULL pointer.                                                */
                    205: typedef void (*GC_warn_proc) GC_PROTO((char *msg, GC_word arg));
1.3       moko      206: GC_API void GC_set_warn_proc GC_PROTO((GC_warn_proc p));
                    207: 
                    208: /* GC_ignore_warn_proc may be used as an argument for GC_set_warn_proc  */
                    209: /* to suppress all warnings (unless statistics printing is turned on).  */
                    210: GC_API void GC_ignore_warn_proc(char *, GC_word);
                    211: 
1.2       paf       212: 
1.4     ! moko      213: GC_API int GC_pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void * /* arg */);
1.2       paf       214: 
                    215: #if defined(GC_WIN32_THREADS)
                    216: # include <windows.h>
                    217: # include <winbase.h>
                    218: 
                    219:   /*
                    220:    * All threads must be created using GC_CreateThread, so that they will be
                    221:    * recorded in the thread table.  For backwards compatibility, this is not
                    222:    * technically true if the GC is built as a dynamic library, since it can
                    223:    * and does then use DllMain to keep track of thread creations.  But new code
                    224:    * should be built to call GC_CreateThread.
                    225:    */
                    226:   HANDLE WINAPI GC_CreateThread(
                    227:       LPSECURITY_ATTRIBUTES lpThreadAttributes,
                    228:       DWORD dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
                    229:       LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId );
                    230: 
                    231: # if defined(_WIN32_WCE)
                    232:   /*
                    233:    * win32_threads.c implements the real WinMain, which will start a new thread
                    234:    * to call GC_WinMain after initializing the garbage collector.
                    235:    */
                    236:   int WINAPI GC_WinMain(
                    237:       HINSTANCE hInstance,
                    238:       HINSTANCE hPrevInstance,
                    239:       LPWSTR lpCmdLine,
                    240:       int nCmdShow );
                    241: 
                    242: #  ifndef GC_BUILD
                    243: #    define WinMain GC_WinMain
                    244: #    define CreateThread GC_CreateThread
                    245: #  endif
                    246: # endif /* defined(_WIN32_WCE) */
                    247: 
                    248: #endif /* defined(GC_WIN32_THREADS) */
                    249: 
                    250: #ifdef __cplusplus
                    251:     }  /* end of extern "C" */
                    252: #endif
                    253: 
                    254: #endif /* _GC_H */

E-mail: