Skip to content

bitv each() method loops forever #2363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nikomatsakis opened this issue May 7, 2012 · 2 comments
Closed

bitv each() method loops forever #2363

nikomatsakis opened this issue May 7, 2012 · 2 comments
Milestone

Comments

@nikomatsakis
Copy link
Contributor

This program:

use std;
    import std::bitv;

    fn main() {
        let bits = bitv::bitv(8u, false);
        io::println(bitv::to_str(bits));
    }

infinitely loops, probably due to this definition from bitv.rs:

fn each(v: bitv, f: fn(bool) -> bool) {
    let mut i = 0u;
    while i < v.nbits {
        if !f(get(v, i)) { break; }
    }
}

which never increments i.

@catamorphism
Copy link
Contributor

One reason why "never add code without adding a test case for it" is a good rule :-)

@ghost ghost assigned catamorphism May 11, 2012
@bkircher
Copy link
Contributor

This can be closed, see #2457.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
…oli-obk

Adding support for external C functions that have integer (or empty) args and/or returns

Starts addressing `@https://github.com/rust-lang/miri/issues/11`

### Implementation
Adding support for calling external C functions that have any number of integer arguments (types of integers: `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`) and an integer return type (or `void`).
As suggested in `@https://github.com/rust-lang/miri/issues/11,` the [`libffi` crate](https://docs.rs/libffi/latest/libffi/index.html) is used to dispatch the calls to external C functions.

#### Modifications
Main modifications are to:
* [helper.rs](https://github.com/emarteca/miri/blob/int-function-args-returns/src/helpers.rs) : adding a function `call_and_add_external_c_fct_to_context` to read the code pointer to the external C function, dispatch the call, and save the return in MIRI internal memory. Handles all conversions between MIRI and C values (using some macros, also defined in this file).
* [foreign_items.rs](https://github.com/emarteca/miri/blob/int-function-args-returns/src/shims/foreign_items.rs) : handles the calling of `call_and_add_external_c_fct_to_context` in [helper.rs](https://github.com/emarteca/miri/blob/int-function-args-returns/src/helpers.rs) when a foreign item is encountered. Also adds some structs to model C representations of arguments, and the signature of the external C call.

### Testing
Adds tests for the following external functions which are now supported:
* [int tests](https://github.com/emarteca/miri/blob/int-function-args-returns/tests/pass/external_C/int_c_tests.rs):
     - adds 2 to a provided int (no type of int specified, so autocasts)
     - takes the sum of its 12 arguments (tests stack spill)
     - adds 3 to a 16 bit int
     - adds an `i16` to an `i64`
     - returns -10 as an unsigned int
* [void tests](https://github.com/emarteca/miri/blob/int-function-args-returns/tests/pass/external_C/print_from_c.rs)
     - void function that prints from C

### Code review
The code in this PR was reviewed by `@maurer` on [another fork](maurer/miri#1) -- thanks!
tshepang added a commit to tshepang/rust that referenced this issue May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants