MCPcopy Create free account
hub / github.com/python/cpython / CReturnConverter

Class CReturnConverter

Tools/clinic/libclinic/return_converters.py:44–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class CReturnConverter(metaclass=CReturnConverterAutoRegister):
45
46 # The C type to use for this variable.
47 # 'type' should be a Python string specifying the type, e.g. "int".
48 # If this is a pointer type, the type string should end with ' *'.
49 type = 'PyObject *'
50
51 # The Python default value for this parameter, as a Python value.
52 # Or the magic value "unspecified" if there is no default.
53 default: object = None
54
55 def __init__(
56 self,
57 *,
58 py_default: str | None = None,
59 **kwargs: Any
60 ) -> None:
61 self.py_default = py_default
62 try:
63 self.return_converter_init(**kwargs)
64 except TypeError as e:
65 s = ', '.join(name + '=' + repr(value) for name, value in kwargs.items())
66 sys.exit(self.__class__.__name__ + '(' + s + ')\n' + str(e))
67
68 def return_converter_init(self) -> None: ...
69
70 def declare(self, data: CRenderData) -> None:
71 line: list[str] = []
72 add = line.append
73 add(self.type)
74 if not self.type.endswith('*'):
75 add(' ')
76 add(data.converter_retval + ';')
77 data.declarations.append(''.join(line))
78 data.return_value = data.converter_retval
79
80 def err_occurred_if(
81 self,
82 expr: str,
83 data: CRenderData
84 ) -> None:
85 line = f'if (({expr}) && PyErr_Occurred()) {{\n goto exit;\n}}\n'
86 data.return_conversion.append(line)
87
88 def err_occurred_if_null_pointer(
89 self,
90 variable: str,
91 data: CRenderData
92 ) -> None:
93 line = f'if ({variable} == NULL) {{\n goto exit;\n}}\n'
94 data.return_conversion.append(line)
95
96 def render(
97 self,
98 function: Function,
99 data: CRenderData
100 ) -> None: ...
101

Callers 2

parse_cloned_functionMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…