Generates a wrapper for native __len__ methods.
(cl: ClassIR, fn: FuncIR, emitter: Emitter)
| 571 | |
| 572 | |
| 573 | def generate_len_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: |
| 574 | """Generates a wrapper for native __len__ methods.""" |
| 575 | name = f"{DUNDER_PREFIX}{fn.name}{cl.name_prefix(emitter.names)}" |
| 576 | emitter.emit_line(f"static Py_ssize_t {name}(PyObject *self) {{") |
| 577 | emitter.emit_line( |
| 578 | "{}retval = {}{}{}(self);".format( |
| 579 | emitter.ctype_spaced(fn.ret_type), |
| 580 | emitter.get_group_prefix(fn.decl), |
| 581 | NATIVE_PREFIX, |
| 582 | fn.cname(emitter.names), |
| 583 | ) |
| 584 | ) |
| 585 | emitter.emit_error_check("retval", fn.ret_type, "return -1;") |
| 586 | if is_int_rprimitive(fn.ret_type): |
| 587 | emitter.emit_line("Py_ssize_t val = CPyTagged_AsSsize_t(retval);") |
| 588 | else: |
| 589 | emitter.emit_line("Py_ssize_t val = PyLong_AsSsize_t(retval);") |
| 590 | emitter.emit_dec_ref("retval", fn.ret_type) |
| 591 | emitter.emit_line("if (PyErr_Occurred()) return -1;") |
| 592 | emitter.emit_line("return val;") |
| 593 | emitter.emit_line("}") |
| 594 | |
| 595 | return name |
| 596 | |
| 597 | |
| 598 | def generate_bool_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: |
nothing calls this directly
no test coverage detected
searching dependent graphs…