yihui / mime

Map filenames to MIME types
https://cran.rstudio.com/package=mime
32 stars 15 forks source link

add init.c #8

Closed tomatoiscoding closed 7 years ago

tomatoiscoding commented 7 years ago

额,无意中看到了论坛,我今年的时候也是遇到这个note,Uwe以死相逼,我不得不去看我看不懂的那段话,然后改了。。。当然,世界也随之清净了。对于内涵,我只能理解一半,大概就是动态库的初始化要有个入口,这个文件就是个入口,定义好C函数的名字以及变量的类型blabla...好处是编译速度更快以及在运行时就可以查错(官方说的...)

又改了改...

yihui commented 7 years ago

多谢!大概意思我明白,只是代码对我来说是天书。

劳烦 @yixuan 再帮忙看一眼?

tomatoiscoding commented 7 years ago

多一嘴,据说R3.4中可以这样:tools::package_native_routine_registration_skeleton(".", "src/init.c")一键生成这个文件,但我不是3.4,所以就没试......

yihui commented 7 years ago

这一嘴多得极好。我是 3.4.1。生成的 init.c 长这样:

#include <R.h>
#include <Rinternals.h>
#include <stdlib.h> // for NULL
#include <R_ext/Rdynload.h>

/* FIXME: 
   Check these declarations against the C/Fortran source code.
*/

/* .Call calls */
extern SEXP rawmatch(SEXP, SEXP);

static const R_CallMethodDef CallEntries[] = {
    {"rawmatch", (DL_FUNC) &rawmatch, 2},
    {NULL, NULL, 0}
};

void R_init_mime(DllInfo *dll)
{
    R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
    R_useDynamicSymbols(dll, FALSE);
}
tomatoiscoding commented 7 years ago

嗯,好,我这个PR可以关了,你自己贴上去吧,没毛病了。

yihui commented 7 years ago

别介。我明天起来看看再并,现在脑子不是很清醒。

yixuan commented 7 years ago

赞番茄,我也觉得没有问题。