Project

Profile

Help

Revision 4ee4355d

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes with exception handling and other

View differences:

src/main/c/Saxon.C.API/XsltExecutable.cpp
49 49
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
50 50
        selection = nullptr;
51 51
    }
52

  
53 52
    SaxonProcessor::sxn_environ->env->DeleteGlobalRef(executableObject);
54

  
53
    SaxonProcessor::sxn_environ->env->ExceptionClear(); // This is as a precaution to avoid crashing out if JNI gets into an unclean state.
55 54
}
56 55

  
57 56

  
......
97 96
    return SaxonProcessor::sxn_environ->env->ExceptionCheck();
98 97
}
99 98

  
100
const char *XsltExecutable::getErrorCode() {
101
    SaxonApiException *exception = SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass,
102
                                                                        nullptr);
103
    if (exception == nullptr) { return nullptr; }
104
    return exception->getErrorCode();
105
}
106

  
107 99

  
108 100
void XsltExecutable::setGlobalContextItem(XdmItem *value) {
109 101
    if (value != nullptr) {
......
158 150
                XdmValue *valuei = it->second;
159 151
                if(valuei != nullptr) {
160 152
                    valuei->decrementRefCount();
161
                    if (valuei->getRefCount() < 1) {
162
                        delete value;
163
                    }
164 153
                    parameters.erase(skey);
165 154
                    parameters[skey] = value;
166 155
                }
......
242 231

  
243 232
            XdmValue *value = itr->second;
244 233
            if(value != nullptr) {
245
                value->decrementRefCount();
246 234
#ifdef DEBUG
247 235
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
248 236
#endif
249
                if (value->getRefCount() < 1) {
250 237
                    delete value;
251
                }
252 238
            }
253 239
        }
254

  
255

  
256
    } else {
257
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
258
            parameters.erase(itr);
259
            /*if(value != NULL) {
260
                value->decrementRefCount();
261
            }*/
262

  
263
        }
264

  
265 240
    }
266 241
    parameters.clear();
267

  
268 242
}
269 243

  
270 244
void XsltExecutable::clearProperties() {
......
336 310
    if (!atmID) {
337 311
        std::cerr << "Error: " << getDllname() << ".applyTemplatesReturningFile" << " not found\n"
338 312
                  << std::endl;
339

  
313
        SaxonProcessor::sxn_environ->env->ExceptionClear();
340 314
    } else {
341 315
        JParameters comboArrays;
342 316
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
377 351
    if (!atsmID) {
378 352
        std::cerr << "Error: " << getDllname() << "applyTemplatesAsString" << " not found\n"
379 353
                  << std::endl;
380

  
354
        SaxonProcessor::sxn_environ->env->ExceptionClear();
381 355
    } else {
382 356
        JParameters comboArrays;
383 357
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
431 405
    if (!atsvmID) {
432 406
        std::cerr << "Error: " << getDllname() << "applyTemplatesAsValue" << " not found\n"
433 407
                  << std::endl;
434

  
408
        SaxonProcessor::sxn_environ->env->ExceptionClear();
435 409
    } else {
436 410
        JParameters comboArrays;
437 411
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
505 479
    if (!afmID) {
506 480
        std::cerr << "Error: " << getDllname() << "callFunctionReturningFile" << " not found\n"
507 481
                  << std::endl;
482
        SaxonProcessor::sxn_environ->env->ExceptionClear();
508 483
        return;
509 484
    } else {
510 485
        JParameters comboArrays;
......
553 528
    if (!afsmID) {
554 529
        std::cerr << "Error: " << getDllname() << "callFunctionReturningString" << " not found\n"
555 530
                  << std::endl;
556

  
531
        SaxonProcessor::sxn_environ->env->ExceptionClear();
557 532
    } else {
558 533
        JParameters comboArrays;
559 534
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
605 580
    if (!cfvmID) {
606 581
        std::cerr << "Error: " << getDllname() << "callFunctionReturningValue" << " not found\n"
607 582
                  << std::endl;
608

  
583
        SaxonProcessor::sxn_environ->env->ExceptionClear();
609 584
    } else {
610 585
        JParameters comboArrays;
611 586
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
682 657
    if (!ctmID) {
683 658
        std::cerr << "Error: " << getDllname() << "callTemplateReturningFile" << " not found\n"
684 659
                  << std::endl;
685

  
660
        SaxonProcessor::sxn_environ->env->ExceptionClear();
686 661
    } else {
687 662
        JParameters comboArrays;
688 663
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
721 696
    if (!ctsmID) {
722 697
        std::cerr << "Error: " << getDllname() << "callTemplateReturningString" << " not found\n"
723 698
                  << std::endl;
724

  
699
        SaxonProcessor::sxn_environ->env->ExceptionClear();
725 700
    } else {
726 701
        JParameters comboArrays;
727 702
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
774 749
    if (!ctsvmID) {
775 750
        std::cerr << "Error: " << getDllname() << "callTemplateReturningValue" << " not found\n"
776 751
                  << std::endl;
777

  
752
        SaxonProcessor::sxn_environ->env->ExceptionClear();
778 753
    } else {
779 754
        JParameters comboArrays;
780 755
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
853 828
    if (!tfvMID) {
854 829
        std::cerr << "Error: " << getDllname() << ".transformtoValue" << " not found\n"
855 830
                  << std::endl;
856

  
831
        SaxonProcessor::sxn_environ->env->ExceptionClear();
857 832
    } else {
858 833
        JParameters comboArrays;
859 834
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
936 911
    if (!tffMID) {
937 912
        std::cerr << "Error: " << getDllname() << "transformToFile" << " not found\n"
938 913
                  << std::endl;
939

  
914
        SaxonProcessor::sxn_environ->env->ExceptionClear();
940 915
    } else {
941 916
        JParameters comboArrays;
942 917
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
972 947
        if (!messageID) {
973 948
            std::cerr << "Error: "<<"SaxonCMessageListener" << " in " <<getDllname() << " not found\n"
974 949
                      << std::endl;
975

  
950
            SaxonProcessor::sxn_environ->env->ExceptionClear();
976 951
        }
977 952

  
978 953
        if (filename == nullptr) {
......
999 974
        if (!getmessageID) {
1000 975
            std::cerr << "Error: " << getDllname() << ".getXslMessages" << " not found\n"
1001 976
                      << std::endl;
1002

  
977
            SaxonProcessor::sxn_environ->env->ExceptionClear();
1003 978
        } else {
1004 979
            jobjectArray results = (jobjectArray) (
1005 980
                    SaxonProcessor::sxn_environ->env->CallObjectMethod(saxonMessageListenerObj, getmessageID));
......
1035 1010
    if (!tftMID) {
1036 1011
        std::cerr << "Error: " << getDllname() << "transformToString" << " not found\n"
1037 1012
                  << std::endl;
1038

  
1013
        SaxonProcessor::sxn_environ->env->ExceptionClear();
1039 1014
    } else {
1040 1015
        JParameters comboArrays;
1041 1016
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
......
1103 1078
    transformFileToFile(nullptr, nullptr);
1104 1079
}
1105 1080

  
1106
const char *XsltExecutable::getErrorMessage() {
1107
    SaxonApiException *exception = SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass,
1108
                                                                        nullptr);
1109
    if (exception == nullptr) { return nullptr; }
1110
    return exception->getMessage();
1111
}
1112

  
1113 1081

  
1114 1082
SaxonApiException *XsltExecutable::getException() {
1115 1083
    return SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, nullptr);

Also available in: Unified diff