Skip to content

Problem with function signatures of getpriority and setpriority for gnu linux #1767

Closed
@bvaisvil

Description

@bvaisvil

This issue is for version 0.2.70 compiling for x86_64-unknown-linux-gnu on 5.1.18-200.fc29.x86_64

The function signatures of getpriority and setpriority are defined as such:

    pub fn getpriority(which: ::__priority_which_t, who: ::id_t) -> ::c_int;
    pub fn setpriority(
        which: ::__priority_which_t,
        who: ::id_t,
        prio: ::c_int,
    ) -> ::c_int;

The issue is the first argument, which is defined as a __priority_which_t (a c_uint) however, the which constants (PRIO_PROCESS, etc) are defined as c_int.

So passing PRIO_PROCESS to either function results in a compiler error:

error[E0308]: mismatched types
 --> src/main.rs:6:34
  |
6 |         let result = getpriority(PRIO_PROCESS, pid);
  |                                  ^^^^^^^^^^^^ expected `u32`, found `i32`
  |
help: you can convert an `i32` to `u32` and panic if the converted value wouldn't fit
  |
6 |         let result = getpriority(PRIO_PROCESS.try_into().unwrap(), pid);
  |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Here's my code to reproduce the issue:

use libc::{getpriority, PRIO_PROCESS, id_t};

fn main() {
    let pid: id_t = 0;
    unsafe {
        let result = getpriority(PRIO_PROCESS, pid);
        println!("{}", result);
    }
}

Please let me know if there is anything else I can provide to help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions