Saxon-C CentOS8 编译

Saxon-C CentOS8 Compile

我正在尝试在 CentOS8 上评估 Saxon-C 1.2.1 HE,安装似乎没有问题。通过 cd samples/cppTests && build64-linux.sh 尝试示例虽然会导致无数编译错误,如下所示:

../../Saxon.C.API/SaxonProcessor.h:599:32:错误:division 'sizeof (JNINativeMethod*) / sizeof (JNINativeMethod)' 不计算数组元素的数量 [-Werror=sizeof-pointer-div] gMethods,sizeof(gMethods) / sizeof(gMethods[0]));

在我草率而信任地关闭 -Werror=sizeof-pointer-div 之前,我检查了源代码,那里发生的事情看起来很可疑。

bool registerCPPFunction(char * libName, JNINativeMethod * gMethods=NULL){
    if(libName != NULL) {
        setConfigurationProperty("extc", libName);

    }

    if(gMethods == NULL && nativeMethodVect.size()==0) {
    return false;
    } else {
        if(gMethods == NULL) {
            //copy vector to gMethods
            gMethods = new JNINativeMethod[nativeMethodVect.size()];
        }
        return registerNativeMethods(sxn_environ->env, "com/saxonica/functions/>
    gMethods, sizeof(gMethods) / sizeof(gMethods[0]));


    }
    return false;
}

更具体地说,sizeof(gMethods) / sizeof(gMethods[0]) 似乎无法计算出任何有用的东西。其意图可能是输出一些代码,这些代码将达到与 nativeMethodVect.size() 相同的值,但第一次看到该项目的源代码我可能会误会,而 division 实际上是故意的?

在下面的例子中,我倾向于猜测意图实际上更接近 b 而不是 a:

#include <cstdio>
struct test
{
    int x, y, z;
};
int main()
{
    test *a = new test[32], b[32];
    printf("%d %d\n", sizeof(a)/sizeof(a[0]), sizeof(b)/sizeof(b[0]));
    return 0;
}

哪个输出 0 32 预期作为 sizeof(a) 给出指针的大小而不是数组内存区域的大小。

那段代码是为了支持用户自定义的特性extension functions in XSLT stylesheets and XQuery queries. If a user is not using these features then they don't need that bit of code. In fact User defined extension functions is only available in Saxon-PE/C and Saxon-EE/C so it should not be in the Saxon-HE/C code base. I have created the following bug issue to investigate the error above and to https://saxonica.plan.io/issues/4477

我认为解决方法是,如果不使用扩展函数功能,则删除有问题的代码,或者删除编译标志 -Werror=sizeof-pointer-div.

原意代码如下:

jobject JNICALL cppNativeCall(jstring funcName, jobjectArray arguments, jobjectArray argTypes){
   //native call code here

}

JNINativeMethod cppMethods[] =
{
  {
     fname,
     funcParameters,
     (void *)&cppNativeCall
  }
};

bool nativeFound = processor->registerNativeMethods(env, "NativeCall",
cppMethods, sizeof(cppMethods) / sizeof(cppMethods[0]));