OpenCC 的 Emacs binding(试一试 Emacs 25 的 dynamic modules)

由于动态模块功能的引入,我们可以用 Emacs Lisp 以外的语言扩展 Emacs,比如 C、C++ 和 Objective-C。我用 OpenCC 的 C API 试了试这个功能,「Introduction to Emacs modules」上说

The two main advantages are better integration and speed (if you know what you are doing).

这两点我都没什么体会。

1 个赞

直接用c编出来的库,速度肯定要比el快。不过写一些没有触及性能瓶颈的应用应该没啥优势。但做一些cpu开销比较大的功能应该可以提高不少,比如 实时的对代码进行索引 ,实时的代码提示,这种功能应该都需要能有独立的线程去持续的跑,el目前应该就支持不好。

我也仿照着试了一下dynamc module,然后发现emacs core了。。。 能帮忙看看什么情况吗?

[email protected]:~/github/fork.el$ [xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
emacs: ../../src/xcb_io.c:274:poll_for_event: 假设 ‘!xcb_xlib_threads_sequence_lost’ 失败。

Backtrace:
emacs[0x5032b9]
emacs[0x4e9ee7]
emacs[0x501f7e]
emacs[0x5021a3]
emacs[0x502249]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x113d0)[0x7f0eee5e13d0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7f0eed911418]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f0eed91301a]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dbd7)[0x7f0eed909bd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f0eed909c82]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x3d199)[0x7f0eefddd199]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x3d24b)[0x7f0eefddd24b]
/usr/lib/x86_64-linux-gnu/libX11.so.6(_XReadEvents+0x19c)[0x7f0eefddd78c]
/usr/lib/x86_64-linux-gnu/libX11.so.6(XIfEvent+0xaa)[0x7f0eefdc50ba]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x6d8a3)[0x7f0eefe0d8a3]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x6e4d7)[0x7f0eefe0e4d7]
/usr/lib/x86_64-linux-gnu/libX11.so.6(_XimRead+0x51)[0x7f0eefe0e7b1]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x5d026)[0x7f0eefdfd026]
/usr/lib/x86_64-linux-gnu/libX11.so.6(XSetICValues+0xfc)[0x7f0eefdea94c]
emacs[0x4d098e]
emacs[0x4be382]
emacs[0x45a6e8]
emacs[0x4bd58c]
emacs[0x41a222]
emacs[0x41b5db]
emacs[0x41d6ad]
emacs[0x45052c]
emacs[0x4f4257]
emacs[0x4f6e96]
emacs[0x4f8afe]
emacs[0x55bbd2]
emacs[0x4ea29c]
emacs[0x55bb73]
emacs[0x4ea259]
emacs[0x4eea2b]
emacs[0x4eed78]
emacs[0x414517]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f0eed8fc830]
emacs[0x415079]
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
emacs: ../../src/xcb_io.c:274:poll_for_event: 假设 ‘!xcb_xlib_threads_sequence_lost’ 失败。

Backtrace:
emacs[0x5032b9]
emacs[0x4e9ee7]
emacs[0x501f7e]
emacs[0x5021a3]
emacs[0x502249]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x113d0)[0x7f0eee5e13d0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38)[0x7f0eed911418]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f0eed91301a]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dbd7)[0x7f0eed909bd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f0eed909c82]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x3d199)[0x7f0eefddd199]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x3d24b)[0x7f0eefddd24b]
/usr/lib/x86_64-linux-gnu/libX11.so.6(_XReadEvents+0x19c)[0x7f0eefddd78c]
/usr/lib/x86_64-linux-gnu/libX11.so.6(XIfEvent+0xaa)[0x7f0eefdc50ba]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x6d8a3)[0x7f0eefe0d8a3]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x6e4d7)[0x7f0eefe0e4d7]
/usr/lib/x86_64-linux-gnu/libX11.so.6(_XimRead+0x51)[0x7f0eefe0e7b1]
/usr/lib/x86_64-linux-gnu/libX11.so.6(+0x5d026)[0x7f0eefdfd026]
/usr/lib/x86_64-linux-gnu/libX11.so.6(XSetICValues+0xfc)[0x7f0eefdea94c]
emacs[0x4d098e]
emacs[0x4be382]
emacs[0x45a6e8]
emacs[0x4bd58c]
emacs[0x41a222]
emacs[0x41b5db]
emacs[0x41d6ad]
emacs[0x45052c]
emacs[0x4f4257]
emacs[0x4f6e96]
emacs[0x4f8afe]
emacs[0x55bbd2]
emacs[0x4ea29c]
emacs[0x55bb73]
emacs[0x4ea259]
emacs[0x4eea2b]
emacs[0x4eed78]
emacs[0x414517]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f0eed8fc830]
emacs[0x415079]


它居然是我是多线程的客户端,但是Emacs怎么可能多线程呢…

我不明白什么状况,据我非常有效的编程知识,系统调用 fork(3) 创建了一个 child process,它即将运行的代码与 parent process 运行的代码是一样的,之后你应该专门给它写些代码,不然没什么意义。另外,我也完全不懂「多线程」。

猜测可能是因为,创建kernel thread时实际是call了vfork这个系统调用。同样的,fork子进程时,也是call了vfork这个系统调用。Emacs发现我调用vfork后,以为我是要创建一个线程,因此提示我是多线程。只是不清楚Emacs是怎么发现调用了vfork的。