home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Headers / misckit / FREE.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-07  |  2.0 KB  |  47 lines

  1. //
  2. //    FREE.h -- useful macros
  3. //        Written and copyright 1994 by Raf Schietekat.
  4. //                Version 1.0.  All rights reserved.
  5. //        This notice may not be removed from this source code.
  6. //
  7. //    This code is included in the MiscKit by permission from the author
  8. //    and its use is governed by the MiscKit license, found in the file
  9. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  10. //    for a list of all applicable permissions and restrictions.
  11. //    
  12.  
  13. // These macros do not use the "MISC" prefix because that would ruin
  14. // their elegance.  If they cause you grief, just #define MISC_SKIP_FREE
  15. // before importing the MiscBase.h or misckit.h...
  16.  
  17. /*
  18. These are macros to free things that (ultimately) rely on resources allocated
  19. for them. The idea is to avoid dangling pointers at all times.
  20. Use FFREE_ (forced free) if you know that the resource is currently allocated.
  21. Use FREE_ if the resource might currently be allocated.
  22. Changes should be sent to Raf Schietekat, the author.
  23. This file may only be used in unchanged form.
  24. */
  25. #define FFREE_MALLOC(p) (free(p),p=NULL)
  26. #define  FREE_MALLOC(p) (p?FFREE_MALLOC(p):NULL)
  27. #define FFREE_FD(p) (close(p),p=-1)
  28. #define  FREE_FD(p) ((p!=-1)?FFREE_FD(p):-1)
  29. #define FFREE_FILE(p) ((fclose(p)?printf("FFREE_FILE error\n"):0),p=NULL)
  30. #define  FREE_FILE(p) (p?FFREE_FILE(p):NULL)
  31. #define FFREE_PIPE(p) (pclose(p),p=NULL)
  32. #define  FREE_PIPE(p) (p?FFREE_PIPE(p):NULL)
  33. #ifdef __OBJC__
  34. #define FFREE_OBJECT(id) ([id free],id=nil)
  35. #define  FREE_OBJECT(id) (id?FFREE_OBJECT(id):nil)
  36. #define FFREE_LIST(id) ([id freeObjects],[id free],id=nil)
  37. #define  FREE_LIST(id) (id?FFREE_LIST(id):nil)
  38. #endif
  39. #ifdef NeXT
  40. #define FFREE_MEMORYSTREAM(p) (NXCloseMemory(p,NX_FREEBUFFER),p=NULL)
  41. #define  FREE_MEMORYSTREAM(p) (p?FFREE_MEMORYSTREAM(p):NULL)
  42. #define FFREE_TYPEDSTREAM(p) (NXCloseTypedStream(p),p=NULL)
  43. #define  FREE_TYPEDSTREAM(p) (p?FFREE_TYPEDSTREAM(p):NULL)
  44. #define FFREE_POPUPLISTBUTTON(id) ([[id target] free],[id free],id=nil)
  45. #define  FREE_POPUPLISTBUTTON(id) (id?FFREE_POPUPLISTBUTTON(id):nil)
  46. #endif
  47.