tboox / tbox

🎁 A glib-like multi-platform c library
https://docs.tboox.org
Apache License 2.0
4.87k stars 722 forks source link

`tb_dynamic_init`应该设法返回错误信息 #256

Open jingkaimori opened 6 months ago

jingkaimori commented 6 months ago

你在什么场景下需要该功能?

目前tb_dynamic_init在posix上会检查dlerror并丢弃其返回值,而dlerror第二次调用时一定返回空指针;因此如果加载动态链接库时出现错误,无法通过tbox或者系统API获取错误信息。

描述可能的解决方案

tb_dynamic_init以结构体的形式,打包返回符号表句柄和错误消息指针;

// definiton
typedef struct {
    tb_dynamic_ref_t library;
    tb_char_t* msg;
}tb_dynamic_init_result_t;
tb_dynamic_init_result_t tb_dynamic_init(const tb_char_t* name);

// usage
tb_dynamic_init_result_t res = tb_dynamic_init("/path/to/library");

描述你认为的候选方案

tb_dynamic_init添加指针参数

// definiton
tb_dynamic_ref_t tb_dynamic_init(const tb_char_t* name, tb_char_t** msg);

// usage
tb_char_t *msg=tb_null;
tb_dynamic_ref_t res = tb_dynamic_init("/path/to/library", msg);

其他信息

dlerror(3p)

Issues-translate-bot commented 6 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: tb_dynamic_init should try to return an error message