2 """Add reference count annotations to the Python/C API Reference."""
3 __version__
= '$Revision$'
12 PREFIX_1
= r
"\begin{cfuncdesc}{PyObject*}{"
13 PREFIX_2
= r
"\begin{cfuncdesc}{PyVarObject*}{"
17 rcfile
= os
.path
.join(os
.path
.dirname(refcounts
.__file
__), os
.pardir
,
18 "api", "refcounts.dat")
20 opts
, args
= getopt
.getopt(sys
.argv
[1:], "o:r:", ["output=", "refcounts="])
22 if opt
in ("-o", "--output"):
24 elif opt
in ("-r", "--refcounts"):
26 rcdict
= refcounts
.load(rcfile
)
30 output
= open(outfile
, "w")
39 line
= input.readline()
43 if line
.startswith(PREFIX_1
):
45 elif line
.startswith(PREFIX_2
):
48 s
= line
[len(prefix
):].split('}', 1)[0]
52 sys
.stderr
.write("No refcount data for %s\n" % s
)
54 if info
.result_type
in ("PyObject*", "PyVarObject*"):
55 if info
.result_refs
is None:
58 rc
= info
.result_refs
and "New" or "Borrowed"
59 rc
= rc
+ " reference"
60 line
= (r
"\begin{cfuncdesc}[%s]{%s}{"
61 % (rc
, info
.result_type
)) \
70 if __name__
== "__main__":