summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-03-10 19:42:40 (GMT)
committerGitHub <noreply@github.com>2024-03-10 19:42:40 (GMT)
commit729bfb3105c7ca2ad6150a6207786096732c3b9e (patch)
tree2c343996d67c2083df96fce5f5cca03059b7ca9b /Tools
parent5b2f21faf388d8de5b388996cfd4f03430085764 (diff)
downloadcpython-729bfb3105c7ca2ad6150a6207786096732c3b9e.zip
cpython-729bfb3105c7ca2ad6150a6207786096732c3b9e.tar.gz
cpython-729bfb3105c7ca2ad6150a6207786096732c3b9e.tar.bz2
gh-116417: Avoid PyFloat_AS_DOUBLE() in AC limited C API (#116568)
Argument Clinic no longer calls PyFloat_AS_DOUBLE() when the usage of the limited C API is requested.
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/clinic/clinic.py54
1 files changed, 36 insertions, 18 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 0a85462..8353941 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -3867,19 +3867,28 @@ class float_converter(CConverter):
def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> str | None:
if self.format_unit == 'f':
- return self.format_code("""
- if (PyFloat_CheckExact({argname})) {{{{
- {paramname} = (float) (PyFloat_AS_DOUBLE({argname}));
- }}}}
- else
- {{{{
+ if not limited_capi:
+ return self.format_code("""
+ if (PyFloat_CheckExact({argname})) {{{{
+ {paramname} = (float) (PyFloat_AS_DOUBLE({argname}));
+ }}}}
+ else
+ {{{{
+ {paramname} = (float) PyFloat_AsDouble({argname});
+ if ({paramname} == -1.0 && PyErr_Occurred()) {{{{
+ goto exit;
+ }}}}
+ }}}}
+ """,
+ argname=argname)
+ else:
+ return self.format_code("""
{paramname} = (float) PyFloat_AsDouble({argname});
if ({paramname} == -1.0 && PyErr_Occurred()) {{{{
goto exit;
}}}}
- }}}}
- """,
- argname=argname)
+ """,
+ argname=argname)
return super().parse_arg(argname, displayname, limited_capi=limited_capi)
class double_converter(CConverter):
@@ -3890,19 +3899,28 @@ class double_converter(CConverter):
def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> str | None:
if self.format_unit == 'd':
- return self.format_code("""
- if (PyFloat_CheckExact({argname})) {{{{
- {paramname} = PyFloat_AS_DOUBLE({argname});
- }}}}
- else
- {{{{
+ if not limited_capi:
+ return self.format_code("""
+ if (PyFloat_CheckExact({argname})) {{{{
+ {paramname} = PyFloat_AS_DOUBLE({argname});
+ }}}}
+ else
+ {{{{
+ {paramname} = PyFloat_AsDouble({argname});
+ if ({paramname} == -1.0 && PyErr_Occurred()) {{{{
+ goto exit;
+ }}}}
+ }}}}
+ """,
+ argname=argname)
+ else:
+ return self.format_code("""
{paramname} = PyFloat_AsDouble({argname});
if ({paramname} == -1.0 && PyErr_Occurred()) {{{{
goto exit;
}}}}
- }}}}
- """,
- argname=argname)
+ """,
+ argname=argname)
return super().parse_arg(argname, displayname, limited_capi=limited_capi)