Project

Profile

Help

Revision 00082f6f

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes

View differences:

src/main/c/Saxon.C.API/SaxonCGlue.c
272 272

  
273 273
	MID_init = (*penv)->GetMethodID(penv, myClassInDll, "<init>", "()V");
274 274
	if (!MID_init) {
275
		printf("Error: MyClassInDll.<init>() not found\n");
275
		printf("Error: SaxoncDll.%s <init>() not found\n", name);
276 276
		return;
277 277
	}
278 278

  
279 279
	obj = (*penv)->NewObject(penv, myClassInDll, MID_init);
280 280
	if (!obj) {
281
		printf("Error: failed to allocate an object\n");
281
		printf("Error: failed to allocate an object - please check if an exception was thrown\n");
282 282
		return;
283 283
	}
284 284

  
......
321 321

  
322 322
	MID_initj = (jmethodID)(*penv)->GetMethodID(penv, myClassInDll, "<init>", arguments);
323 323
	if (!MID_initj) {
324
		printf("Error: MyClassInDll.<init>() not found\n");
324
		printf("Error: SaxoncDll.<init>() not found\n");
325 325
		fflush(stdout);
326 326
		return 0;
327 327
	}
......
340 340

  
341 341
	MID_initi = (jmethodID)(*(penv))->GetMethodID(penv, myClassInDll, "<init>", arguments);
342 342
	if (!MID_initi) {
343
		printf("Error: MyClassInDll.<init>() not found\n");
343
		printf("Error: SaxoncDll.<init>() not found\n");
344 344
		return NULL;
345 345
	}
346 346

  
......
353 353
		obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi, license);
354 354
	}
355 355
	if (!obj) {
356
		printf("Error: failed to allocate an object\n");
356
		printf("Error: failed to allocate an object - please check if an exception was thrown\n");
357 357
		return NULL;
358 358
	}
359 359
	return obj;
......
371 371

  
372 372
	MID_initi = (jmethodID)(*(penv))->GetMethodID(penv, myClassInDll, "<init>", arguments);
373 373
	if (!MID_initi) {
374
		printf("Error: MyClassInDll.<init>() not found\n");
374
		printf("Error: SaxoncDll.<init>() not found\n");
375 375
		return NULL;
376 376
	}
377 377

  
......
384 384
		obj = (jobject)(*(penv))->NewObject(penv, myClassInDll, MID_initi);
385 385
	}
386 386
	if (!obj) {
387
		printf("Error: failed to allocate an object\n");
387
		printf("Error: failed to allocate an object - please check if an exception was thrown\n");
388 388
		return NULL;
389 389
	}
390 390
	return obj;
src/main/c/Saxon.C.API/SaxonProcessor.cpp
28 28
int SaxonProcessor::jvmCreatedCPP = 0;
29 29

  
30 30
bool SaxonProcessor::exceptionOccurred() {
31
    bool found = SaxonProcessor::sxn_environ->env->ExceptionCheck();
32
    return found;
31
    return SaxonProcessor::sxn_environ->env->ExceptionCheck() || exception != nullptr;
33 32
}
34 33

  
35 34
const char *SaxonProcessor::checkException(jobject cpp) {
......
39 38
}
40 39

  
41 40
SaxonApiException *SaxonProcessor::checkAndCreateException(jclass cppClass) {
42
    if (exceptionOccurred()) {
41
    if (SaxonProcessor::sxn_environ->env->ExceptionCheck()) {
43 42
        SaxonApiException *exception = checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, nullptr);
44 43
#ifdef DEBUG
45 44
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
......
60 59

  
61 60
void SaxonProcessor::exceptionClear() {
62 61
    SaxonProcessor::sxn_environ->env->ExceptionClear();
63
    /* if(exception != nullptr && clearCPPException) {
64
        delete exception;
65
    } */
62

  
66 63
}
67 64

  
68 65

  
......
629 626

  
630 627

  
631 628
    if (!proc) {
632
        std::cout << "proc is null in SaxonProcessor.setCatalog" << std::endl;
629
        exception = new SaxonApiException("Processor is null in SaxonProcessor.setCatalog");
633 630
        return;
634 631
    }
635 632

  
......
645 642
#ifdef DEBUG
646 643
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
647 644
#endif
645

  
648 646
}
649 647

  
650 648

  
src/main/c/Saxon.C.API/XdmItem.cpp
14 14

  
15 15

  
16 16
XdmItem::XdmItem(jobject obj){
17
	value = obj;
17
	value = SaxonProcessor::sxn_environ->env->NewGlobalRef(obj);
18 18
	xdmSize =1;
19 19
	refCount =0;
20 20
}
......
97 97
XdmItem::~XdmItem() {
98 98
    decrementRefCount();
99 99
    std::cerr<<std::endl<<"XdmItem destructor called, refCount"<<getRefCount()<<std::endl;
100
    std::cout << std::endl << "cpp0-1" << std::endl;
101
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
102

  
100 103
    if(getRefCount()<1){
101 104
        if(value !=nullptr && SaxonProcessor::jvmCreatedCPP>0) {
102 105
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(value);
103 106
        }
104

  
107
        std::cout << std::endl << "cpp0-1" << std::endl;
108
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
105 109
        if(stringValue.empty()) {
106 110
            stringValue.clear();
107 111
        }
src/main/c/Saxon.C.API/XdmValue.cpp
147 147
	if (valueType != nullptr) { delete valueType; }
148 148
	if (jValues) {
149 149
        std::cout<<"xdmValue jni"<<getRefCount()<<std::endl;
150
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);  //TODO check - this maybe should be DeleteGlobalRef  - check where it is created
150
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);
151 151
	}
152 152
	xdmSize = 0;
153 153

  
......
165 165
		values.push_back(val);
166 166
        val->incrementRefCount();
167 167
		xdmSize++;
168
		jValues = nullptr; //TODO clear jni array from memory if needed
168
        if (jValues) {
169
            std::cout<<"xdmValue jni"<<getRefCount()<<std::endl;
170
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);  //TODO check - this maybe should be DeleteGlobalRef  - check where it is created
171
            jValues = nullptr;
172
        }
173

  
169 174
	}
170 175
}
171 176

  
......
212 217
		}
213 218
		jclass objectClass = lookForClass(env,
214 219
			"net/sf/saxon/s9api/XdmItem");
215
		jValues = (jobjectArray)env->NewObjectArray((jint)count, objectClass, 0);
220
		jobjectArray jValuesi = (jobjectArray)env->NewObjectArray((jint)count, objectClass, 0);
221

  
216 222

  
217 223
		for (i = 0; i < count; i++) {
218
			env->SetObjectArrayElement(jValues, i, values[i]->getUnderlyingValue());
224
			env->SetObjectArrayElement(jValuesi, i, values[i]->getUnderlyingValue());
219 225
		}
226
        jValues = (jobjectArray)SaxonProcessor::sxn_environ->env->NewGlobalRef(jValuesi);
220 227
	} 
221 228
	return (jobject)jValues;
222 229
}
src/main/c/Saxon.C.API/Xslt30Processor.cpp
22 22
Xslt30Processor::Xslt30Processor(SaxonProcessor * p, std::string curr) {
23 23

  
24 24
	proc = p;
25
    tunnel = false;
26
    jitCompilation = false;
27
    exception = nullptr;
25 28

  
26 29
	/*
27 30
	 * Look for class.
......
37 40
	SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
38 41
    
39 42
#endif
40
	tunnel = false;
41
	jitCompilation = false;
42
	exception = nullptr;
43

  
44
	if(cppXT == nullptr) {
45
	    exception = proc->checkAndCreateException(cppClass);
46
	}
43 47

  
44 48
	if(!(proc->cwd.empty()) && curr.empty()){
45 49
		cwdXT = proc->cwd;
......
83 87

  
84 88

  
85 89
bool Xslt30Processor::exceptionOccurred() {
86
	return proc->exceptionOccurred();
90
	return proc->exceptionOccurred() || exception != nullptr;
87 91
}
88 92

  
89 93
const char * Xslt30Processor::getErrorCode() {
......
198 202
					"(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V");
199 203
	}
200 204
	if (!cAndSNodemID) {
201
		std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
202
				<< " not found\n" << std::endl;
205
		std::cerr<<"Error: "<<getDllname<<"compileFromStringAndSave funtion not found"<<std::endl;
203 206

  
204 207
	} else {
205

  
208
        if(cppXT == nullptr) {
209
#if defined(DEBUG)
210
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
211
#endif
212
            return;
213
        }
206 214
		
207 215
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSNodemID,
208 216
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
......
224 232
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
225 233
	}
226 234
	if (!cAndSStringmID) {
227
		std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
228
				<< " not found\n" << std::endl;
235
		exception = new SaxonApiException("Error: compileFromStringAndSave function not found\n");
229 236

  
230 237
	} else {
231

  
238
        if(cppXT == nullptr) {
239
#if defined(DEBUG)
240
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
241
#endif
242
            return;
243
        }
232 244
		
233 245
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSStringmID,
234 246
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
......
251 263
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
252 264
	}
253 265
	if (!cAndFStringmID) {
254
		std::cerr << "Error: "<<getDllname() << ".compileFromFileAndSave"
255
				<< " not found\n" << std::endl;
266
		exception = new SaxonApiException("Error: compileFromFileAndSave function not found");
256 267

  
257 268
	} else {
258 269

  
259
		
270
        if(cppXT == nullptr) {
271
#if defined(DEBUG)
272
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
273
#endif
274
            return;
275
        }
260 276
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
261 277
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
262 278
						SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
......
276 292
	}
277 293
					
278 294
	if (cStringmID== nullptr) {
279
		std::cerr << "Error: "<<getDllname() << ".compileFromString"
280
				<< " not found\n" << std::endl;
295
		exception = new SaxonApiException(strcat(getDllname(), ".compileFromString funtion not found"));
281 296
		return nullptr;
282 297

  
283 298
	} else {
284

  
299
        if(cppXT == nullptr) {
300
#if defined(DEBUG)
301
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
302
#endif
303
            return nullptr;
304
        }
285 305
		JParameters comboArrays;
286 306
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
287 307
		jobject executableObject = (jobject)(
......
317 337
		return nullptr;
318 338

  
319 339
	} else {
340
	    if(node == nullptr) {
341
	        exception = new SaxonApiException("Error in compileFromXdmNode - node argument is NULL");
342
	        return nullptr;
343
	    }
344
        if(cppXT == nullptr) {
345
#if defined(DEBUG)
346
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
347
#endif
348
            return nullptr;
349
        }
320 350
		JParameters comboArrays;
321 351
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
322 352
		jobject executableObject = (jobject)(
......
354 384
	} else {
355 385
		
356 386
		if(source == nullptr) {
357
			std::cerr << "Error in compileFromFile method - The Stylesheet file is nullptr" <<std::endl;
387
			exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is NULL");
358 388
			return nullptr;
359 389
		}
390
        if(cppXT == nullptr) {
391
#if defined(DEBUG)
392
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
393
#endif
394
            return nullptr;
395
        }
360 396
		JParameters comboArrays;
361 397
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
362 398
		jobject executableObject = (jobject)(
......
387 423
					"compileFromFile",
388 424
					"(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
389 425
	}
426

  
390 427
	if (!cFilemID) {
391 428
		std::cerr << "Error: "<<getDllname() << ".compileFromFile"
392 429
				<< " not found\n" << std::endl;
430
        std::cerr<<"cp0 -testCatalog"<<std::endl;
393 431
		return nullptr;
394 432

  
395 433
	} else {
396

  
397 434
        if (stylesheet == nullptr) {
398
            std::cerr << "Error in compileFromFile method - The Stylesheet file is nullptr" << std::endl;
435
            exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is nullptr");
436
            return nullptr;
437
        }
438
        if(cppXT == nullptr) {
439
#if defined(DEBUG)
440
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
441
#endif
442

  
399 443
            return nullptr;
400 444
        }
445

  
401 446
        JParameters comboArrays;
402 447
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
403 448
        jobject executableObject = (jobject) (
......
453 498
					"(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;)Lnet/sf/saxon/s9api/XdmValue;");
454 499
	}
455 500
	if (!mtvID) {
456
		std::cerr << "Error: "<< getDllname() << ".transformtoValue" << " not found\n"
457
				<< std::endl;
501
        std::cerr<<"Error: "<<getDllname<<".transformtoValue function not found"<<std::endl;
458 502

  
459 503
	} else {
504
        if(cppXT == nullptr) {
505
#if defined(DEBUG)
506
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
507
#endif
508
            return nullptr;
509
        }
460 510
	    JParameters comboArrays;
461 511
		comboArrays = SaxonProcessor::createParameterJArray2(parameters);
462 512

  
......
537 587
					"(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/String;[Ljava/lang/Object;)V");
538 588
	}
539 589
	if (!mtfID) {
540
		std::cerr << "Error: "<<getDllname() << "transformToFile" << " not found\n"
541
				<< std::endl;
590
        std::cerr<<"Error: "<<getDllname<<".transformToFile function not found"<<std::endl;
542 591

  
543 592
	} else {
593
        if(cppXT == nullptr) {
594
#if defined(DEBUG)
595
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
596
#endif
597
            return;
598
        }
544 599
	    JParameters comboArrays;
545 600
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
546 601

  
......
579 634
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
580 635
	}
581 636
	if (!mtsID) {
582
		std::cerr << "Error: "<<getDllname() << "transformFileToString" << " not found\n"
583
				<< std::endl;
637
        std::cerr<<"Error: "<<getDllname<<".transformFileToString not found"<<std::endl;
584 638

  
585 639
	} else {
640
        if(cppXT == nullptr) {
641
#if defined(DEBUG)
642
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
643
#endif
644
            return nullptr;
645
        }
586 646
    JParameters comboArrays;
587 647
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
588 648

  
src/main/c/samples/cppTests/testXSLT30.cpp
189 189

  
190 190

  
191 191
    sresult->failure++;
192
    cout << endl << "cpp1" << endl;
192 193
    sresult->failureList.push_back("testApplyTemplates2a");
193 194
    fflush(stdout);
194 195
    delete executable;
......
284 285
void testTransformToString4(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
285 286

  
286 287
    cout << endl << "Test: testTransformToString4:" << endl;
288
    cout << endl << "cpp0-1" << endl;
289
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
290

  
287 291
    trans->clearParameters(true);
292
    cout << endl << "cpp0-2" << endl;
293
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
288 294

  
289 295
    XdmNode *input = processor->parseXmlFromString(
290 296
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
......
302 308
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(6));
303 309
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(7));
304 310

  
305

  
311
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
306 312

  
307 313
   /* XdmNode *sheet = processor->parseXmlFromFile("test2.xsl");
308 314

  
......
1390 1396

  
1391 1397
void testCatalog(const char * cwd, SaxonProcessor * proc, sResultCount *sresult) {
1392 1398

  
1399

  
1393 1400
    cout << endl << "Test: testCatalog" << endl;
1394 1401
    bool trace = false;
1395 1402
    proc->setcwd(cwd);
......
1397 1404

  
1398 1405
    Xslt30Processor * trans = proc->newXslt30Processor();
1399 1406

  
1400

  
1401 1407
    XsltExecutable  * executable = trans->compileFromFile("../php/catalog-test/test1.xsl");
1402 1408

  
1403 1409
    if(executable == nullptr) {
1410

  
1404 1411
        if (trans->exceptionOccurred()) {
1405
            const char *message = trans->getErrorMessage();
1406
            cout << "exception=" << message << endl;
1407
        }
1412

  
1413
            if(trans->getErrorMessage() != nullptr) {
1414
                const char *message = trans->getErrorMessage();
1415
                cout << "exception=" << message << endl;
1416
            } else {
1417
                const char *message = proc->getErrorMessage();
1418
                if(message != nullptr) {
1419
                    cout << "exception=" << message << endl;
1420
                }
1421
            }
1422
            }
1408 1423
        return;
1409 1424
    }
1410 1425

  
......
1528 1543
    testApplyTemplates2a(processor, trans, sresult);
1529 1544

  
1530 1545
    testTransformToString4(processor, trans, sresult);
1531
    processor->release();
1532
    return 0;
1546

  
1533 1547

  
1534 1548
    testCatalog(cwd, processor,  sresult);
1549
    processor->release();
1550
    return 0;
1535 1551

  
1536 1552
    testTransformToString2b(processor, trans, sresult);
1537 1553

  

Also available in: Unified diff