about summary refs log tree commit diff
path: root/Src/zsh.h
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2002-06-07 14:44:21 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2002-06-07 14:44:21 +0000
commit0e08b8c2e485c355acc4818c1b04a81bc7e150be (patch)
tree56936dedd0aa214d20a2909c7ea88db6737e1438 /Src/zsh.h
parent37199039b2666815e42072ba934001fadb53b183 (diff)
downloadzsh-0e08b8c2e485c355acc4818c1b04a81bc7e150be.tar.gz
zsh-0e08b8c2e485c355acc4818c1b04a81bc7e150be.tar.xz
zsh-0e08b8c2e485c355acc4818c1b04a81bc7e150be.zip
17299: Use reference counts in Eprogs so as to be able to free them as soon
as finished with.
Diffstat (limited to 'Src/zsh.h')
-rw-r--r--Src/zsh.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/Src/zsh.h b/Src/zsh.h
index 28a3c20e9..15b4c404a 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -497,10 +497,28 @@ struct funcdump {
     char *filename;
 };
 
+/*
+ * A note on the use of reference counts in Eprogs.
+ *
+ * When an Eprog is created, nref is set to -1 if the Eprog is on the
+ * heap; then no attempt is ever made to free it.  (This information is
+ * already present in EF_HEAP; we use the redundancy for debugging
+ * checks.)
+ *
+ * Otherwise, nref is initialised to 1.  Calling freeprog() decrements
+ * nref and frees the Eprog if the count is now zero.  When the Eprog
+ * is in use, we call useeprog() at the start and freeprog() at the
+ * end to increment and decrement the reference counts.  If an attempt
+ * is made to free the Eprog from within, this will then take place
+ * when execution is finished, typically in the call to freeeprog()
+ * in execode().  If the Eprog was on the heap, neither useeprog()
+ * nor freeeprog() has any effect.
+ */
 struct eprog {
     int flags;			/* EF_* below */
     int len;			/* total block length */
     int npats;			/* Patprog cache size */
+    int nref;			/* number of references: delete when zero */
     Patprog *pats;		/* the memory block, the patterns */
     Wordcode prog;		/* memory block ctd, the code */
     char *strs;			/* memory block ctd, the strings */