home *** CD-ROM | disk | FTP | other *** search
- //
- // FREE.h -- useful macros
- // Written and copyright 1994 by Raf Schietekat.
- // Version 1.0. All rights reserved.
- // This notice may not be removed from this source code.
- //
- // This code is included in the MiscKit by permission from the author
- // and its use is governed by the MiscKit license, found in the file
- // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
-
- // These macros do not use the "MISC" prefix because that would ruin
- // their elegance. If they cause you grief, just #define MISC_SKIP_FREE
- // before importing the MiscBase.h or misckit.h...
-
- /*
- These are macros to free things that (ultimately) rely on resources allocated
- for them. The idea is to avoid dangling pointers at all times.
- Use FFREE_ (forced free) if you know that the resource is currently allocated.
- Use FREE_ if the resource might currently be allocated.
- Changes should be sent to Raf Schietekat, the author.
- This file may only be used in unchanged form.
- */
- #define FFREE_MALLOC(p) (free(p),p=NULL)
- #define FREE_MALLOC(p) (p?FFREE_MALLOC(p):NULL)
- #define FFREE_FD(p) (close(p),p=-1)
- #define FREE_FD(p) ((p!=-1)?FFREE_FD(p):-1)
- #define FFREE_FILE(p) ((fclose(p)?printf("FFREE_FILE error\n"):0),p=NULL)
- #define FREE_FILE(p) (p?FFREE_FILE(p):NULL)
- #define FFREE_PIPE(p) (pclose(p),p=NULL)
- #define FREE_PIPE(p) (p?FFREE_PIPE(p):NULL)
- #ifdef __OBJC__
- #define FFREE_OBJECT(id) ([id free],id=nil)
- #define FREE_OBJECT(id) (id?FFREE_OBJECT(id):nil)
- #define FFREE_LIST(id) ([id freeObjects],[id free],id=nil)
- #define FREE_LIST(id) (id?FFREE_LIST(id):nil)
- #endif
- #ifdef NeXT
- #define FFREE_MEMORYSTREAM(p) (NXCloseMemory(p,NX_FREEBUFFER),p=NULL)
- #define FREE_MEMORYSTREAM(p) (p?FFREE_MEMORYSTREAM(p):NULL)
- #define FFREE_TYPEDSTREAM(p) (NXCloseTypedStream(p),p=NULL)
- #define FREE_TYPEDSTREAM(p) (p?FFREE_TYPEDSTREAM(p):NULL)
- #define FFREE_POPUPLISTBUTTON(id) ([[id target] free],[id free],id=nil)
- #define FREE_POPUPLISTBUTTON(id) (id?FFREE_POPUPLISTBUTTON(id):nil)
- #endif
-