【问题标题】:reply_t vs request_t - passing them in interchangeably?reply_t vs request_t - 交替传递它们?
【发布时间】:2016-05-08 01:46:36
【问题描述】:

我遇到了 XCB 的问题。我不明白 *_reply_t*_request_t 类型之间的区别。

似乎*_reply_t 代替*_response_t 传递,但结构非常不同。

例如:

xcb_randr_get_screen_resources_current_reply_t *reply = xcb_randr_get_screen_resources_current_reply(
        connection, xcb_randr_get_screen_resources_current(connection, root), NULL);

所以现在reply*_reply_t 的类型。但现在我需要使用xcb_randr_get_screen_resources_current_outputs,它希望第一个参数的类型为xcb_randr_get_screen_resources_current_request_t,根据此处的文档:

http://www.linuxhowtos.org/manpages/3/xcb_randr_get_screen_resources_current_outputs.htm

          xcb_randr_output_t *xcb_randr_get_screen_resources_current_outputs(
            const xcb_randr_get_screen_resources_current_request_t *reply
          );

但是,第一次调用的响应类型为 xcb_randr_get_screen_resources_current_reply_t (*_reply_t)。如何在不强制转换的情况下将其传递给输出调用?根据文档,结构完全不同:

typedef struct xcb_randr_get_screen_resources_current_reply_t {
    uint8_t         response_type;
    uint8_t         pad0;
    uint16_t        sequence;
    uint32_t        length;
    xcb_timestamp_t timestamp;
    xcb_timestamp_t config_timestamp;
    uint16_t        num_crtcs;
    uint16_t        num_outputs;
    uint16_t        num_modes;
    uint16_t        names_len;
    uint8_t         pad1[8];
} xcb_randr_get_screen_resources_current_reply_t;

*_request_t 的结构不在我从这里的源代码中获得的文档中:

https://xcb.freedesktop.org/manual/randr_8h_source.html#l00896

   typedef struct xcb_randr_get_screen_resources_current_request_t {
       uint8_t      major_opcode; 
       uint8_t      minor_opcode; 
       uint16_t     length; 
       xcb_window_t window; 
   } xcb_randr_get_screen_resources_current_request_t;

我做 ctypes,所以我必须事先声明我要传入的类型,以用于方法的签名。所以我很困惑一个完全不同的结构(reply)如何进入第二个结构为request的调用。

【问题讨论】:

    标签: xcb


    【解决方案1】:

    我认为您偶然发现的只是一个文档错误。所有声称采用*_request_t 的功能实际上都期望*_reply_t。从您链接的源代码中,只需查看实际的函数定义(而不是手册页所说的),您就会发现

    xcb_randr_output_t *
        xcb_randr_get_screen_resources_current_outputs (const xcb_randr_get_screen_resources_current_reply_t *R  );
    

    您找到的结构实际上并没有在文件中的任何地方使用,因此它可能是一些被遗忘的剩余部分,或者可能出于兼容性原因仍然保留。

    【讨论】:

    • 哦对了!方法签名不在该代码文件中使用它。肯定是文档错误。非常感谢!将帖子中的response 修复为request :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 2012-10-31
    • 2012-05-05
    • 2012-11-27
    • 1970-01-01
    • 2012-05-19
    • 2016-06-20
    相关资源
    最近更新 更多