Skip to content

Plan: Migrate to C++98/MIT. 计划迁移到C++98/MIT. #33

Open
@winlinvip

Description

We plan to replace it progressively by C++ 98 code and switch to MIT license.

Summary

关于ST,我计划一点点换成C++ 98/MIT的,它目前有几个痛点:

  1. 不维护了,最初的作者们估计都退休了,很多新的CPU和系统无法支持,这也是srs分支做了很多修改的原因。
  2. 协议是MPL,其实是Mozilla的协议,Firefox也是这个协议,和LGPL类似,是OSI的标准协议,但这个用的少,不知道有什么坑没有。
  3. 那些宏很奇怪,都是操作结构体的,之前展示过,应该换成C++ 98的,和C没什么差别,只是基本封装。C++也可以继续暴露C的API。

其实本身ST的LICENSE就是分多部分授权的:

  1. ST的库是MPL授权。
  2. ST的头文件,和一般的做法一样,是免责可以随便用。GPL的Linux也一样。
  3. Example是BSD授权的。

原始LICENSE是这么说的:

The State Threads library is ...... Mozilla Public License (MPL) version 1.1 
or the GNU General Public License (GPL) version 2 or later.

All source code in the "examples" directory is distributed under the BSD style license.

参考:State-Threads LICENSE

Why C++98?

为何选择C++ 98?其实我们并不想换语言,C有最好的一致性,另外就是C++ 98了,它实际上也是C++ ANSI标准C++。估计支持最广泛的C++,就是C++98了。

此外,我们只使用C++98中的封装功能,只使用class和成员变量和函数,不使用虚函数,不使用继承,不使用模板,不使用任何高级能力。因为本质上ST在语言上,使用C是最合适的,但是它有大量的宏,本质上就是实现了C++的封装能力,但造成了无法维护的问题,比如:

/* Insert element "_e" into the list, after "_l" */
#define ST_INSERT_AFTER(_e,_l)     \
    ST_BEGIN_MACRO         \
    (_e)->next = (_l)->next; \
    (_e)->prev = (_l);     \
    (_l)->next->prev = (_e); \
    (_l)->next = (_e);     \
    ST_END_MACRO

/* Insert an element "_e" at the head of the list "_l" */
#define ST_INSERT_LINK(_e,_l) ST_INSERT_AFTER(_e,_l)

#define _ST_RUNQ                        (_st_this_vp.run_q)
#define _ST_IOQ                         (_st_this_vp.io_q)
#define _ST_ZOMBIEQ                     (_st_this_vp.zombie_q)

#define _ST_ADD_SLEEPQ(_thr, _timeout)  _st_add_sleep_q(_thr, _timeout)
#define _ST_DEL_SLEEPQ(_thr)        _st_del_sleep_q(_thr)

#define _ST_EPOLL_READ_CNT(fd)   (_st_epoll_data->fd_data[fd].rd_ref_cnt)
#define _ST_EPOLL_WRITE_CNT(fd)  (_st_epoll_data->fd_data[fd].wr_ref_cnt)
#define _ST_EPOLL_EXCEP_CNT(fd)  (_st_epoll_data->fd_data[fd].ex_ref_cnt)
#define _ST_EPOLL_REVENTS(fd)    (_st_epoll_data->fd_data[fd].revents)

除非天天看这些代码,偶然看一次,修一修bug,是非常难以理解这些宏定义的。

LICENSE

Original files of State-Threads:

  • examples: BSD, Eliminated.
  • common.h: MPL-1.1 OR GPL-2.0-or-later
  • md.h: MPL-1.1 OR GPL-2.0-or-later
  • public.h: MPL-1.1 OR GPL-2.0-or-later
  • event.c: MPL-1.1 OR GPL-2.0-or-later
  • io.c: MPL-1.1 OR GPL-2.0-or-later
  • key.c: MPL-1.1 OR GPL-2.0-or-later
  • sched.c: MPL-1.1 OR GPL-2.0-or-later
  • stk.c: MPL-1.1 OR GPL-2.0-or-later
  • sync.c: MPL-1.1 OR GPL-2.0-or-later
  • md_linux.S or md.S: MPL-1.1 OR GPL-2.0-or-later

New files and directories:

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions