ftp.nice.ch/pub/next/text/tex/apps/TeXview-kp0.25.s.tar.gz#/HyperTeXview/FREE.h

This is FREE.h in view mode; [Download] [Up]

/*
Author: Raf Schietekat (RfSchtkt@maze.ruca.ua.ac.be on 1994-09-07)
Version: 1994-09-07
No warranty whatsoever.
You might like to know that the author uses these all the time.
Verbatim copying of this entire file allowed (please do!),
  all other rights reserved.
Send changes to the author, please (also problems, reports about
  similar efforts, or about other uses of (F)FREE as a prefix...).

These are macros to free things that (ultimately) rely on things allocated
for them (called handles and resources here). The idea is to record in the
handle itself whether or not the resource is still available, my means of a
special value when it is not.
Example: a pointer (the handle) to a memory region (the resource), which should
  either point to a valid memory region or be NULL; otherwise the pointer
  is said to dangle, and you might not immediately notice if you write
  though it, as opposed to writing through a NULL pointer, which (on many
  systems?) raises a signal.
Use FREE_ if the resource *might* currently be allocated.
Use FFREE_ (Forced Free) if you know that the resource is currently allocated.
  It's a tiny little bit faster, and you might by informed about wrong
  assumptions by an immediate failure. But the most useful
  property is that it is self-documenting: the author using these is saying
  ``look, I know I can get away with just FREE_, but I'm also telling you
  that I know that at this point this resource is still allocated''.
The handle will be set to nil/NULL/-1, whichever is appropriate for the
particular handle. You'll understand that this does not
protect you against invalid accesses from copies of these handles,
just to name one limitation, and the problem of reliable resource handling is
an extended one. But these macros should be useful.
*/

/* For malloc/free memory... */
#define FFREE_MALLOC(p) (free(p),p=NULL)
#define  FREE_MALLOC(p) (p?FFREE_MALLOC(p):NULL)

/* For Unix file descriptors... */
#define FFREE_FD(fd) (close(fd),fd=-1)
#define  FREE_FD(fd) ((fd!=-1)?FFREE_FD(fd):-1)

/* For fopen() streams... */
#define FFREE_FILE(p) ((fclose(p)?printf("FFREE_FILE error\n"):0),p=NULL)
#define  FREE_FILE(p) (p?FFREE_FILE(p):NULL)

/* For popen() streams (use (F)FREE_FD for pipe())... */
#define FFREE_PIPE(p) (pclose(p),p=NULL)
#define  FREE_PIPE(p) (p?FFREE_PIPE(p):NULL)

#ifdef __OBJC__

/* For an object, in situations where -free suffices... */
#define FFREE_OBJECT(id) ([id free],id=nil)
#define  FREE_OBJECT(id) (id?FFREE_OBJECT(id):nil)

/* For a List if you also want to free its contents... */
#define FFREE_LIST(id) ([id freeObjects],[id free],id=nil)
#define  FREE_LIST(id) (id?FFREE_LIST(id):nil)

/* For an object, in situations where -release suffices... */
#define FFREE_NSOBJECT(id) ([id release],id=nil)
#define  FREE_NSOBJECT(id) (id?FFREE_OBJECT(id):nil)

#endif

#ifdef NeXT

/* For NXStream streams... */
#define FFREE_NXSTREAM(p) (NXClose(p),p=NULL)
#define  FREE_NXSTREAM(p) (p?FFREE_NXSTREAM(p):NULL)

/* For NXStream streams opened on memory that you don't want to preserve... */
#define FFREE_MEMORYSTREAM(p) (NXCloseMemory(p,NX_FREEBUFFER),p=NULL)
#define  FREE_MEMORYSTREAM(p) (p?FFREE_MEMORYSTREAM(p):NULL)

/* For typed streams... */
#define FFREE_TYPEDSTREAM(p) (NXCloseTypedStream(p),p=NULL)
#define  FREE_TYPEDSTREAM(p) (p?FFREE_TYPEDSTREAM(p):NULL)

/* For a Button connected to a PopUpList... */
#define FFREE_POPUPLISTBUTTON(id) ([[id target] free],[id free],id=nil)
#define  FREE_POPUPLISTBUTTON(id) (id?FFREE_POPUPLISTBUTTON(id):nil)

/* For an NXZone... */
#define FFREE_NXZONE(zone) (NXDestroyZone(zone),zone=NULL)
#define  FREE_NXZONE(zone) (zone?FFREE_NXZONE(zone):NULL)

#endif

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.