Generates a wrapper for a native __contains__ method.
(cl: ClassIR, fn: FuncIR, emitter: Emitter)
| 717 | |
| 718 | |
| 719 | def generate_contains_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: |
| 720 | """Generates a wrapper for a native __contains__ method.""" |
| 721 | name = f"{DUNDER_PREFIX}{fn.name}{cl.name_prefix(emitter.names)}" |
| 722 | emitter.emit_line(f"static int {name}(PyObject *self, PyObject *obj_item) {{") |
| 723 | generate_arg_check("item", fn.args[1].type, emitter, ReturnHandler("-1")) |
| 724 | emitter.emit_line( |
| 725 | "{}val = {}(self, arg_item);".format( |
| 726 | emitter.ctype_spaced(fn.ret_type), emitter.native_function_call(fn.decl) |
| 727 | ) |
| 728 | ) |
| 729 | emitter.emit_error_check("val", fn.ret_type, "return -1;") |
| 730 | if is_bool_rprimitive(fn.ret_type): |
| 731 | emitter.emit_line("return val;") |
| 732 | else: |
| 733 | emitter.emit_line("int boolval = PyObject_IsTrue(val);") |
| 734 | emitter.emit_dec_ref("val", fn.ret_type) |
| 735 | emitter.emit_line("return boolval;") |
| 736 | emitter.emit_line("}") |
| 737 | |
| 738 | return name |
| 739 | |
| 740 | |
| 741 | # Helpers |
nothing calls this directly
no test coverage detected
searching dependent graphs…