-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[kernel]add a macro RT_VERSION_CHECK #5850
Conversation
好思路!! |
关于版本这块,我发现了两个问题,都在这里列一下: |
/* | ||
can be used like #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 0, 5)) | ||
*/ | ||
#define RT_VERSION_CHECK(major, minor, revise) ((major * 10000) + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
名字不太好,这个的作用更像是计算/生成一个数字,而不是检查
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果要是有检查 warning error的功能就更好了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果要是有检查 warning error的功能就更好了
什么 waring error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就是定义一个宏定义,在文件底部或者文件的顶部,设置改文件最低允许的版本号,如果低于该版本号就会给出error或者waning,提示需要提升软件包版本或者降低内核版本。
我只是异想天开,仅供参考。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就是定义一个宏定义,在文件底部或者文件的顶部,设置改文件最低允许的版本号,如果低于该版本号就会给出error或者waning,提示需要提升软件包版本或者降低内核版本。 我只是异想天开,仅供参考。
#if RTTHREAD_VERSION < RT_VERSION_CHECK(5, 0, 0)
#error "kernel version must >= 5.0.0"
#endif
放文件开头,就这样用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Gives 1 if the x.y.z version is supported in the current version * Usage: * * - Require v6 * #if LV_VERSION_CHECK(6,0,0) * new_func_in_v6(); * #endif * * * - Require at least v5.3 * #if LV_VERSION_CHECK(5,3,0) * new_feature_from_v5_3(); * #endif * * * - Require v5.3.2 bugfixes * #if LV_VERSION_CHECK(5,3,2) * bugfix_in_v5_3_2(); * #endif * * */ #define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH)))
仔细看它这个实现,看例子挺清爽,但是不仔细看实现,也不知道这个宏实现功能是啥,而且只实现了 >= 的逻辑运算。这样使用的时候也挺受限制的。
所以,lvgl 源码里搜索一下,发现大量下面用法
#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0)
.subpx = LV_FONT_SUBPX_NONE,
#endif
”LV_VERSION_CHECK“对“非 6.0 版本” 这种情况表达无力,只能用 LVGL_VERSION_MAJOR LVGL_VERSION_MINOR 挨个比较。
还有
#if LV_VERSION_CHECK(7, 4, 0) || LVGL_VERSION_MAJOR >= 8
.underline_position = -1,
.underline_thickness = 1,
#endif
我没理解错的话,LV_VERSION_CHECK(7, 4, 0) 的意思就是 “大于等于 7.4.0 或者 7.4.0 以后的版本“。后面又混用了个 ”LVGL_VERSION_MAJOR >= 8“ 不知道当初改这行代码的人啥想法。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LV_VERSION_CHECK 的宏挺严谨的,里面包含了这三个版本值的 API 变更逻辑的。首先主版本号必须相同,然后,后面的版本号的变化 API 都是向前兼容的。所以这里才单独判断了下 || LVGL_VERSION_MAJOR >= 8
这里LV_VERSION_CHECK宏的名字就代表了他的功能,会把检查的逻辑写在宏内部。如果我们起名也要有check的话,就应该把check的逻辑实现在宏的内部。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多定义一个宏,就是减少 MAJOR MINOR 几个宏的使用
这样混用只能说明那个 LV_VERSION_CHECK 定义的不足。这样混合使用还不如全用 MAJOR MINOR 几个判断来的清晰
不是说 LV_VERSION_CHECK 这样定义,RT_VERSION_CHECK 的含义就必须跟它是一样的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最近有新的想法吗,希望在4.1.1上能把这个版本检查的功能合进去。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
过了段时间,我忽然感觉这种方式挺好的,如果只是站在使用者角度看,使用方法又灵活,又清晰。就是内部实现有点让人迷惑。如果没有更好的想法,这种方式我也可以接受
#if RTTHREAD_VERSION < RT_VERSION_CHECK(5, 0, 0)
#error "kernel version must >= 5.0.0"
#endif
@BernardXiong 请问还有疑问吗? |
@thewon86 再等两天,等我考完试我仔细看一下,我现在静不下心来看这个问题 |
include/rtdef.h
Outdated
/* | ||
can be used like #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 0, 5)) | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个位置改成这样子:
/* | |
can be used like #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 0, 5)) | |
*/ | |
/* e.g. #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 1, 0) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 我没有什么问题,通过比较LVGL的形式,我认为LVGL的检查方式版本关系已经被宏内定了,不是很灵活;出出这种方法即通过用户自己判定版本是大于还是小于是比较好的,而且看这个宏表达式的人也可以一眼知道这是什么意思。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要改一下上面的suggested change 并且解决一下冲突
拉取/合并请求描述:(PR description)
[
此宏用于版本兼容性更新。
或者,用于提前提示某特性将在某版本被抛弃
或者,用于应用程序,在多个 kernel 版本间保证兼容性。
等等
]
以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0
代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up