Project

Profile

Help

Revision a69dd173

Added by O'Neil Delpratt 6 months ago

Saxon/C update

View differences:

src/main/c/Saxon.C.API/XsltExecutable.cpp
49 49
        if (selectionV->getRefCount() == 0) {
50 50
            delete selectionV;
51 51
        }
52
    } else {
53
        if (selection) {
54
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
55
        }
52 56
    }
53 57
    SaxonProcessor::sxn_environ->env->DeleteGlobalRef(executableObject);
54 58

  
......
129 133

  
130 134
void XsltExecutable::setInitialMatchSelectionAsFile(const char *filename) {
131 135
    if (filename != nullptr) {
132
        selection = SaxonProcessor::sxn_environ->env->NewStringUTF(filename);
136
        selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
137

  
133 138
    }
134 139
}
135 140

  
......
169 174
void XsltExecutable::setInitialTemplateParameters(std::map<std::string, XdmValue *> _itparameters, bool _tunnel) {
170 175
    for (std::map<std::string, XdmValue *>::iterator itr = _itparameters.begin(); itr != _itparameters.end(); itr++) {
171 176
        parameters["itparam:" + std::string(itr->first)] = itr->second;
177
        itr->second->incrementRefCount();
172 178
    }
173 179
    tunnel = _tunnel;
174 180
    if (tunnel) {
......
246 252
            }
247 253
        }
248 254

  
249
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(selection);
255
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
250 256
        selection = nullptr;
251 257
    } else {
252 258
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
......
1026 1032
    if (tftMID == nullptr) {
1027 1033
        tftMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
1028 1034
                                                                                 "transformToString",
1029
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
1035
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)[B");
1030 1036
    }
1031 1037
    if (!tftMID) {
1032
        std::cerr << "Error: " << getDllname() << "transformFileToString" << " not found\n"
1038
        std::cerr << "Error: " << getDllname() << "transformToString" << " not found\n"
1033 1039
                  << std::endl;
1034 1040

  
1035 1041
    } else {
1036 1042
        JParameters comboArrays;
1037 1043
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1038 1044

  
1039
        jstring result = nullptr;
1045
        jbyteArray result = nullptr;
1040 1046
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, tftMID,
1041 1047
                                                                               SaxonProcessor::sxn_environ->env->NewStringUTF(
1042 1048
                                                                                       cwdXE.c_str()), nullptr,
......
1044 1050
                                                                               (source != nullptr
1045 1051
                                                                                ? SaxonProcessor::sxn_environ->env->NewStringUTF(
1046 1052
                                                                                               source) : nullptr),
1053
                                                                               nullptr,
1047 1054
                                                                               comboArrays.stringArray,
1048 1055
                                                                               comboArrays.objectArray);
1049 1056
        if (comboArrays.stringArray != nullptr) {
......
1051 1058
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
1052 1059
        }
1053 1060
        if (obj) {
1054
            result = (jstring) obj;
1061
            result = (jbyteArray) obj;
1055 1062
        }
1056 1063
        if (result) {
1057
            const char *str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
1058
                                                                                  nullptr);
1064

  
1065
            jboolean isCopy = false;
1066
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
1067
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
1068

  
1069
            const char *str = new char[num_bytes];
1070
            memcpy ((void *) str, b , num_bytes );
1071

  
1059 1072
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
1060 1073
            return str;
1061 1074
        }

Also available in: Unified diff