gh-104050: Argument clinic: annotate post_parsing() and cleanup() (#107225)

This commit is contained in:
Alex Waygood 2023-07-25 23:33:03 +01:00 committed by GitHub
parent 70dc009469
commit 33838fedf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3664,10 +3664,12 @@ class str_converter(CConverter):
if NoneType in accept and self.c_default == "Py_None": if NoneType in accept and self.c_default == "Py_None":
self.c_default = "NULL" self.c_default = "NULL"
def post_parsing(self): def post_parsing(self) -> str:
if self.encoding: if self.encoding:
name = self.name name = self.name
return f"PyMem_FREE({name});\n" return f"PyMem_FREE({name});\n"
else:
return ""
def parse_arg(self, argname: str, displayname: str) -> str: def parse_arg(self, argname: str, displayname: str) -> str:
if self.format_unit == 's': if self.format_unit == 's':
@ -3845,8 +3847,10 @@ class Py_UNICODE_converter(CConverter):
fail("Py_UNICODE_converter: illegal 'accept' argument " + repr(accept)) fail("Py_UNICODE_converter: illegal 'accept' argument " + repr(accept))
self.c_default = "NULL" self.c_default = "NULL"
def cleanup(self): def cleanup(self) -> str:
if not self.length: if self.length:
return ""
else:
return """\ return """\
PyMem_Free((void *){name}); PyMem_Free((void *){name});
""".format(name=self.name) """.format(name=self.name)