summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-03-15 14:57:59 (GMT)
committerFred Drake <fdrake@acm.org>2000-03-15 14:57:59 (GMT)
commitdee86c644ecdf6aba7ae85eccb58b90d95f214fc (patch)
tree2339d347586f7b66589710fdcb9ed63bf6ad3ee7 /Doc
parentdef77e53465d83216e145ca713fa043a05e7f07a (diff)
downloadcpython-dee86c644ecdf6aba7ae85eccb58b90d95f214fc.zip
cpython-dee86c644ecdf6aba7ae85eccb58b90d95f214fc.tar.gz
cpython-dee86c644ecdf6aba7ae85eccb58b90d95f214fc.tar.bz2
Script to annotate api.tex with reference count information.
Diffstat (limited to 'Doc')
-rwxr-xr-xDoc/tools/anno-api.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/Doc/tools/anno-api.py b/Doc/tools/anno-api.py
new file mode 100755
index 0000000..33f85fb
--- /dev/null
+++ b/Doc/tools/anno-api.py
@@ -0,0 +1,63 @@
+#! /usr/bin/env python
+"""Add reference count annotations to the Python/C API Reference."""
+__version__ = '$Revision$'
+
+import getopt
+import os
+import string
+import sys
+
+import refcounts
+
+
+PREFIX = r"\begin{cfuncdesc}{PyObject*}{"
+
+
+def main():
+ rcfile = os.path.join(os.path.dirname(refcounts.__file__), os.pardir,
+ "api", "refcounts.dat")
+ outfile = "-"
+ opts, args = getopt.getopt(sys.argv[1:], "o:r:", ["output=", "refcounts="])
+ for opt, arg in opts:
+ if opt in ("-o", "--output"):
+ outfile = arg
+ elif opt in ("-r", "--refcounts"):
+ rcfile = arg
+ rcdict = refcounts.load(rcfile)
+ if outfile == "-":
+ output = sys.stdout
+ else:
+ output = open(outfile, "w")
+ if not args:
+ args = ["-"]
+ prefix = PREFIX
+ prefix_len = len(prefix)
+ for infile in args:
+ if infile == "-":
+ input = sys.stdin
+ else:
+ input = open(infile)
+ while 1:
+ line = input.readline()
+ if not line:
+ break
+ if line[:prefix_len] == prefix:
+ s = string.split(line[prefix_len:], '}', 1)[0]
+ try:
+ info = rcdict[s]
+ except KeyError:
+ sys.stderr.write("No refcount data for %s\n" % s)
+ else:
+ if info.result_type == "PyObject*":
+ rc = info.result_refs and "New" or "Borrowed"
+ line = r"\begin{cfuncdesc}[%s]{PyObject*}{" % rc \
+ + line[prefix_len:]
+ output.write(line)
+ if infile != "-":
+ input.close()
+ if outfile != "-":
+ output.close()
+
+
+if __name__ == "__main__":
+ main()