Emit module methods (the static PyMethodDef table).
(
self, emitter: Emitter, module_name: str, module_prefix: str, module: ModuleIR
)
| 1145 | emitter.emit_line("};") |
| 1146 | |
| 1147 | def emit_module_methods( |
| 1148 | self, emitter: Emitter, module_name: str, module_prefix: str, module: ModuleIR |
| 1149 | ) -> None: |
| 1150 | """Emit module methods (the static PyMethodDef table).""" |
| 1151 | emitter.emit_line(f"static PyMethodDef {module_prefix}module_methods[] = {{") |
| 1152 | for fn in module.functions: |
| 1153 | if fn.class_name is not None or fn.name == TOP_LEVEL_NAME: |
| 1154 | continue |
| 1155 | # Coroutines are added to the module dict when the module is initialized. |
| 1156 | if fn.decl.is_coroutine: |
| 1157 | continue |
| 1158 | name = short_id_from_name(fn.name, fn.decl.shortname, fn.line) |
| 1159 | if is_fastcall_supported(fn, emitter.capi_version): |
| 1160 | flag = "METH_FASTCALL" |
| 1161 | else: |
| 1162 | flag = "METH_VARARGS" |
| 1163 | doc = native_function_doc_initializer(fn) |
| 1164 | emitter.emit_line( |
| 1165 | ( |
| 1166 | '{{"{name}", (PyCFunction){prefix}{cname}, {flag} | METH_KEYWORDS, ' |
| 1167 | "PyDoc_STR({doc}) /* docstring */}}," |
| 1168 | ).format( |
| 1169 | name=name, cname=fn.cname(emitter.names), prefix=PREFIX, flag=flag, doc=doc |
| 1170 | ) |
| 1171 | ) |
| 1172 | emitter.emit_line("{NULL, NULL, 0, NULL}") |
| 1173 | emitter.emit_line("};") |
| 1174 | emitter.emit_line() |
| 1175 | |
| 1176 | def emit_module_def_struct( |
| 1177 | self, emitter: Emitter, module_name: str, module_prefix: str |
no test coverage detected