tmerr / i3ipc-rs

A Rust library for controlling i3-wm through its IPC interface
MIT License
106 stars 33 forks source link

Should Node.id have type usize instead of i64? #61

Open ohazi opened 4 years ago

ohazi commented 4 years ago

At first glance, I would assume that id should be a usize...

    /// The internal ID (actually a C pointer value) of this container. Do not make any
    /// assumptions about it. You can use it to (re-)identify and address containers when
    /// talking to i3.
    pub id: i64,

@leshow's implementation does it that way: https://github.com/leshow/tokio-i3ipc/blob/0a8be5fa88982851f9d924ddff7c60b4bfa51fe8/i3ipc-types/src/reply.rs#L40-L43

/// Tree/Node reply
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct Node {
    pub id: usize,

i3 appears to treat it as a uintptr_t: https://github.com/i3/i3/blob/f4964faef08d6add93afbd24cc00fef0c3f6c72a/src/ipc.c#L355-L358

void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
    y(map_open);
    ystr("id");
    y(integer, (uintptr_t)con);

https://github.com/i3/i3/blob/6339427f017e1265a022e6537e16a8b4a921e52f/include/yajl_utils.h#L18-L19

/* Shorter names for all those yajl_gen_* functions */
#define y(x, ...) yajl_gen_##x(gen, ##__VA_ARGS__)

...but then yajl treats it as a long long int / %lld? https://github.com/lloyd/yajl/blob/5e3a7856e643b4d6410ddc3f84bc2f38174f2872/src/yajl_gen.c#L208-L218

yajl_gen_status
yajl_gen_integer(yajl_gen g, long long int number)
{
    char i[32];
    ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
    sprintf(i, "%lld", number);
    g->print(g->ctx, i, (unsigned int)strlen(i));
    APPENDED_ATOM;
    FINAL_NEWLINE;
    return yajl_gen_status_ok;
}

I don't know anymore. Anyone care to verify this?