summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorlarryhastings <larry@hastings.org>2022-10-06 19:23:20 (GMT)
committerGitHub <noreply@github.com>2022-10-06 19:23:20 (GMT)
commit6bfb0be80486c614cd60dce44c9fe7b3e6c76e3b (patch)
tree49b1db448d47e8dfddceac156981292c698fc551 /Objects
parent23e83a84651bbcf1f3778baf3ab0b4cbfead75e3 (diff)
downloadcpython-6bfb0be80486c614cd60dce44c9fe7b3e6c76e3b.zip
cpython-6bfb0be80486c614cd60dce44c9fe7b3e6c76e3b.tar.gz
cpython-6bfb0be80486c614cd60dce44c9fe7b3e6c76e3b.tar.bz2
gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (#97949)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/funcobject.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 7f257a9..ccc6d0b 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -311,7 +311,6 @@ func_get_annotation_dict(PyFunctionObject *op)
}
Py_SETREF(op->func_annotations, ann_dict);
}
- Py_INCREF(op->func_annotations);
assert(PyDict_Check(op->func_annotations));
return op->func_annotations;
}
@@ -543,7 +542,11 @@ func_get_annotations(PyFunctionObject *op, void *Py_UNUSED(ignored))
if (op->func_annotations == NULL)
return NULL;
}
- return func_get_annotation_dict(op);
+ PyObject *d = func_get_annotation_dict(op);
+ if (d) {
+ Py_INCREF(d);
+ }
+ return d;
}
static int