Skip to content
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

object.c 中 rt_object_find 的修改存在 bug #8960

Closed
polarvid opened this issue May 20, 2024 · 11 comments
Closed

object.c 中 rt_object_find 的修改存在 bug #8960

polarvid opened this issue May 20, 2024 · 11 comments

Comments

@polarvid
Copy link
Contributor

object.c 中 rt_object_find 的修改存在 bug.

rt_device_find("uart1")

成功 , 但如果改用以下代码

char name[16] = "uart1";
rt_device_find(name);

则会失败

Originally posted by @liuyangzys in #8949 (comment)

@polarvid
Copy link
Contributor Author

Cannot re-produce on #8959

@liuyangzys

@polarvid
Copy link
Contributor Author

建议先检查你的工程中是否存在栈溢出问题。

@liuyangzys
Copy link
Contributor

liuyangzys commented May 20, 2024

Sorry, 我没有仔细分析我遇到的问题,描述的有误。 但 bug 应该是存在,我对比了一下提交修改,以下是分析

rt_object_find 函数判断
image
本意是判断需要 name 和 obj.name 不是同一个地址才会返回对象地址。

但如果用 rt_device_find(device.parent_obj.name) 这样的方式去寻找 dev, 将会失败返回 RT_NULL
例如 shell.c 中491 行
image

更新了改 commit 后我发现控制台无用了,当时测试了以下用常量字符串可以找到需要用控制台的串口,没有仔细分析就来提问了

我不了解为什么 rt_object_find 中最后需要这个判断。如果一定需要该判定,那我们应该去修改 shell.c 中的 rt_device_find 的引用方式,并在以后所有的使用中都要注意不能用 rt_device_find(device.parent_obj.name)这样调用方式

@polarvid
Copy link
Contributor Author

本意是判断需要 name 和 dev.name 不是同一个地址才会返回对象地址。

并不是。是判断 name 是否匹配,然后被更新。

@liuyangzys
Copy link
Contributor

liuyangzys commented May 20, 2024

本意是判断需要 name 和 dev.name 不是同一个地址才会返回对象地址。

并不是。是判断 name 是否匹配,然后被更新。

image

看看吧。我在更早的rtt版本上运行是正常的。这个commit 跑到 fins_set_device(console.parant.name) 就是有问题。不管是 uart1 还是 vcom

这个接口是 RTT的重要接口, 麻烦多考虑一下

@polarvid
Copy link
Contributor Author

补充的那个场景在 utest 复现了。

定位了一下,是因为一开始没考虑到 &object->name == object 的情况。
方便的话也拜托你验证一下。db404db

@polarvid
Copy link
Contributor Author

我不了解为什么 rt_object_find 中最后需要这个判断。如果一定需要该判定,那我们应该去修改 shell.c 中的 rt_device_find 的引用方式,并在以后所有的使用中都要注意不能用 rt_device_find(device.parent_obj.name)这样调用方式

原本的意思是复用一个地址来存参数 name 和匹配对象 obj。如果假定两个对象地址不会重名,那么这个地址被更新就说明匹配成功。不过之前没考虑到 rt_object 的 name 也放在 obj 起始地址上,所以 name 和 obj 两个指针有可能相同的情况。

@polarvid
Copy link
Contributor Author

顺便吐槽一下,拿到 object 还要用 object->parent->name 去找设备,这使用场景真的有点怪 😂

@liuyangzys
Copy link
Contributor

补充的那个场景在 utest 复现了。

定位了一下,是因为一开始没考虑到 &object->name == object 的情况。 方便的话也拜托你验证一下。db404db

可以了
这个iterate的语法糖感觉没什么必要

@polarvid
Copy link
Contributor Author

这个iterate的语法糖感觉没什么必要

第一,rt_object_for_each 有实际引用的,对应于场景{匹配所有符合某种模式的设备,如 ttyS\d+}。
第二,基于上述原因,rt_object_find 与 rt_object_for_each 其实就可以找到公共子流程。
既然如此,拷贝两份代码是冗余的。

@polarvid
Copy link
Contributor Author

#8959

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

2 participants