saxonsaxon-c

Saxon-C CentOS8 Compile


I am trying to evaluate Saxon-C 1.2.1 HE on CentOS8 and installation seems to have gone ok. Trying out the samples by cd samples/cppTests && build64-linux.sh though leads to a myriad of compilation errors to the tune of the following:

../../Saxon.C.API/SaxonProcessor.h:599:32: error: division ‘sizeof (JNINativeMethod*) / sizeof (JNINativeMethod)’ does not compute the number of array elements [-Werror=sizeof-pointer-div] gMethods, sizeof(gMethods) / sizeof(gMethods[0]));

Before I summarily and trustfully switched off -Werror=sizeof-pointer-div i checked the source code and what's going on there do seem dubious.

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;
}

more specifically sizeof(gMethods) / sizeof(gMethods[0]) would not seem to calculate anything useful by any margin. The intention was probably rather to output some code that would arrive at the same value as nativeMethodVect.size() but seeing this project's source for the very first time i might be mistaking and the division is in fact intentional ?

I am inclined to guess the intention was in fact closer to b than to a in the following example:

#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;
}

which output 0 32 which is expected as the sizeof(a) gives the size of a pointer not the size of an array's memory region.


Solution

  • That bit of code is to support the feature of user defined 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

    I would think the workaround would be to either remove the code in question if the extension function feature is not used or remove the compile flag -Werror=sizeof-pointer-div.

    The intent was code is as follows:

    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]));