Commit a135ad2f
a135ad2f5989Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Convert a Bigint argument to a scalar at the FFI integer-arg boundary
An integer-typed FFI argument (ffi_func :f, [:int], ...) emitted
((int)(expr)) for any non-poly operand. When the operand was an
overflow-promoted integer (sp_Bigint *), that cast the pointer to int
rather than the integer value: a -Wpointer-to-int-cast warning and a
wrong runtime value (and, under a strict toolchain, a hard error).
This is what blocked tep: Sock.sphttp_sleep_ms(backoff) where
backoff comes from a retry loop (d = d * @multiplier) that the
analyzer promotes to Bigint. Narrow it through sp_bigint_to_int so the
FFI call receives the integer the C function expects.
Refs #1409
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- a135ad2f5989
- Parent
- 6191a06ecdba
src/codegen_call.cmodifiedView file
buf_puts(&call_buf, "(("); buf_puts(&call_buf, ffi_c_type(spec)); buf_puts(&call_buf, ")("); emit_expr(c, argv[ai], &call_buf); buf_puts(&call_buf, ").v.i)"); } else if (at == TY_BIGINT) { /* An overflow-promoted integer (e.g. a backoff computed by repeated *2) arrives as sp_Bigint*. Narrow it to the C integer the FFI arg expects, not the pointer value. */ buf_puts(&call_buf, "(("); buf_puts(&call_buf, ffi_c_type(spec)); buf_puts(&call_buf, ")sp_bigint_to_int("); emit_expr(c, argv[ai], &call_buf); buf_puts(&call_buf, "))"); } else { buf_puts(&call_buf, "(("); buf_puts(&call_buf, ffi_c_type(spec)); buf_puts(&call_buf, ")("); emit_expr(c, argv[ai], &call_buf); buf_puts(&call_buf, "))"); } } }test/ffi_int_arg_bigint.rbaddedView file
Loading diff…
test/ffi_int_arg_bigint.rb.expectedaddedView file
Loading diff…