Skip to content

Conversation

thewon86
Copy link
Contributor

@thewon86 thewon86 commented Apr 21, 2022

拉取/合并请求描述:(PR description)

[
此宏用于版本兼容性更新。
或者,用于提前提示某特性将在某版本被抛弃

    /* priority */
#if (RTTHREAD_VERSION < RT_VERSION_CHECK(4, 1, 0))
    rt_uint8_t  init_priority;                            /**< init priority */
#endif
    rt_uint8_t  current_priority;                       /**< current priority */

或者,用于应用程序,在多个 kernel 版本间保证兼容性。

#if RTTHREAD_VERSION <= RT_VERSION_CHECK(4, 0, 3)
#include <dfs_poll.h>
#else
#include <poll.h>
#include <sys/ioctl.h>
#endif
#if RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0)
    rt_device_flush(dev);
#endif

等等
]

以下的内容不应该在提交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):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 本拉取/合并请求代码是高质量的 Code in this PR is of high quality
  • 本拉取/合并使用formatting等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@mysterywolf
Copy link
Member

好思路!!

@mysterywolf
Copy link
Member

关于版本这块,我发现了两个问题,都在这里列一下:
1 目前RT-Thread的版本宏有两个,以谁为准,是否最好能合并成一个:https://github.com/RT-Thread/rt-thread/pull/5847/files
2 rtdef.h里边的那个子版本宏定义不规范,详见:#5616 (comment)

/*
can be used like #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 0, 5))
*/
#define RT_VERSION_CHECK(major, minor, revise) ((major * 10000) + \
Copy link
Member

@Guozhanxin Guozhanxin Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名字不太好,这个的作用更像是计算/生成一个数字,而不是检查

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果要是有检查 warning error的功能就更好了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果要是有检查 warning error的功能就更好了

什么 waring error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就是定义一个宏定义,在文件底部或者文件的顶部,设置改文件最低允许的版本号,如果低于该版本号就会给出error或者waning,提示需要提升软件包版本或者降低内核版本。
我只是异想天开,仅供参考。

Copy link
Contributor Author

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

放文件开头,就这样用

Copy link
Contributor Author

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“ 不知道当初改这行代码的人啥想法。

Copy link
Member

@Guozhanxin Guozhanxin Apr 28, 2022

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的逻辑实现在宏的内部。

Copy link
Contributor Author

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 的含义就必须跟它是一样的。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最近有新的想法吗,希望在4.1.1上能把这个版本检查的功能合进去。

Copy link
Member

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 BernardXiong added the discussion This PR/issue needs to be discussed later label Apr 24, 2022
@thewon86
Copy link
Contributor Author

@BernardXiong 请问还有疑问吗?

@mysterywolf
Copy link
Member

@thewon86 再等两天,等我考完试我仔细看一下,我现在静不下心来看这个问题

@mysterywolf mysterywolf self-requested a review May 17, 2022 01:59
@mysterywolf mysterywolf added proposal proposal for future version v4.1.1 and removed discussion This PR/issue needs to be discussed later v4.1.1 proposal proposal for future version labels Jun 22, 2022
@Guozhanxin Guozhanxin added the +1 Agree +1 label Jun 30, 2022
@mysterywolf mysterywolf added important in progress PR/issue in progress. labels Jun 30, 2022
include/rtdef.h Outdated
Comment on lines 71 to 73
/*
can be used like #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 0, 5))
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个位置改成这样子:

Suggested change
/*
can be used like #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 0, 5))
*/
/* e.g. #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 1, 0) */

Copy link
Member

@mysterywolf mysterywolf Jul 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 我没有什么问题,通过比较LVGL的形式,我认为LVGL的检查方式版本关系已经被宏内定了,不是很灵活;出出这种方法即通过用户自己判定版本是大于还是小于是比较好的,而且看这个宏表达式的人也可以一眼知道这是什么意思。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要改一下上面的suggested change 并且解决一下冲突

@mysterywolf mysterywolf added change req change requestion fix_for_conflicting Please fix conflicting files. +2 Agree +2 and removed change req change requestion in progress PR/issue in progress. labels Jul 2, 2022
@mysterywolf mysterywolf removed the fix_for_conflicting Please fix conflicting files. label Jul 4, 2022
@Guozhanxin Guozhanxin merged commit 9359ab4 into RT-Thread:master Jul 4, 2022
@thewon86 thewon86 deleted the version_check branch February 23, 2023 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
important +1 Agree +1 +2 Agree +2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants