Project

Profile

Help

Revision a65b315b

Added by O'Neil Delpratt almost 6 years ago

Saxon/C bug fixes. Some relating to environemtn path memory corruption

View differences:

latest9.6/hec/Saxon.C.API/SaxonCGlue.c
6 6
* If the SAXONC_HOME sxnc_environmental variable is set then use that as base.
7 7
*/
8 8
void setDllname(){
9
	if(getenv("SAXONC_HOME")!= NULL) {
10

  
11
		char * env = getenv("SAXONC_HOME");
12
		size_t env_len = strlen(env);
13
		size_t name_len =  15;
14
		size_t rDir_len = 11;
15
		//dllname =malloc(sizeof(char)*name_len);
16
		//resources_dir =malloc(sizeof(char)*rDir_len);
17
		memset(&dllname[0], 0, sizeof(dllname));
18
		memset(&resources_dir[0], 0, sizeof(resources_dir));
19
		strncat(resources_dir, env,  env_len);
20
		strncat(resources_dir, "/saxon-data", rDir_len);
21
		strncat(dllname, env, env_len);
22
		strncat(dllname, "/libsaxonhec.so", name_len); //rename according to product edition (-hec or -pec)
9
	size_t name_len  = strlen(tempDllname);
10
	size_t rDir_len  = strlen(tempResources_dir);
11
	char * env = getenv("SAXONC_HOME");
12
	size_t env_len;
13
	if(env!= NULL) {
14

  
15
		
16
		env_len = strlen(env);
17
		dllname =malloc(sizeof(char)*name_len+env_len+1);
18
		resources_dir =malloc(sizeof(char)*rDir_len+env_len+1);
19
		snprintf(dllname, env_len+name_len+1, "%s%s", env, tempDllname);
20
		snprintf(resources_dir, env_len+rDir_len+1, "%s%s", env, tempResources_dir);
21
		
23 22
#ifdef DEBUG	
24
		printf("resources_dir: %s\n", resources_dir);	
23
		
25 24
		printf("envDir: %s\n", env);
26
		printf("size of env %i\n", strlen(env));
27
		printf("size of dllname %i\n", strlen(dllname));
28
		printf("dllName: %s\n", dllname);
29
		printf("resources_dir: %s\n", resources_dir);
25
		
26
		
27
#endif
28

  
29
       } else {
30
		env_len = 8;
31
		dllname =malloc(sizeof(char)*name_len+env_len+1);
32
		resources_dir =malloc(sizeof(char)*rDir_len+env_len+1);
33
#ifdef DEBUG
34
		if(dllname == NULL || resources_dir == NULL)
35
		{
36
    		  // error
37
		  printf("Error in allocation of Dllname\n");
38
		}
30 39
#endif
40
		memset(&dllname[0], 0, sizeof(dllname));
41
		memset(&resources_dir[0], 0, sizeof(resources_dir));
42
#ifdef __linux__
43
		
44
       		snprintf(dllname, 8+name_len+1, "%s%s", "/usr/lib", tempDllname);
45
		snprintf(resources_dir, 8+rDir_len+1, "%s%s", "/usr/lib", tempResources_dir);
46
#elif  defined (__APPLE__) && defined(__MACH__)
47
       		snprintf(dllname, 8+name_len+1, "%s%s", "/usr/lib", tempDllname);
48
		snprintf(resources_dir, 8+rDir_len+1, "%s%s", "/usr/lib", tempResources_dir);
49
#else
50
		//TODO When windows version of Saxon/C is done we will have to fixup this
51
		strncpy(dllname, "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1", 42);
52
		strncpy(resources_dir, "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1", 42);
53
#endif
54

  
55
	
56

  
31 57
	}
58
		
59

  
32 60
#ifdef DEBUG	
33
		printf("resources_dir: %s\n", resources_dir);	
61

  
62
		printf("Library length: %i\n", name_len);
63
		printf("Env length: %i\n", env_len);
64
		printf("dllname length alloc: %i\n", (env_len+name_len+1));
65
		printf("resources length alloc: %i\n", (env_len+rDir_len+1));		
34 66
		printf("size of dllname %i\n", strlen(dllname));
35 67
		printf("dllName: %s\n", dllname);
36 68
		printf("resources_dir: %s\n", resources_dir);
......
43 75
	return dllname;
44 76
}
45 77

  
78
char * getResourceDirectory(){
79
	return resources_dir;
80
}
81

  
46 82
/*
47 83
 * Load dll using the default setting in Saxon/C
48 84
 * Recommended method to use to load library
latest9.6/hec/Saxon.C.API/SaxonCGlue.h
53 53

  
54 54
EXTERN_C
55 55

  
56
 
56 57

  
58
static char tempDllname[] =
59
#if defined (__linux__)
60
        "/libsaxoneec.so";  
61
    #elif  defined (__APPLE__) && defined(__MACH__)
62
        "/libsaxoneec.dylib";
63
    #else
64
         "\\libsaxoneec.dll";
65
    #endif
66

  
67
static char tempResources_dir[] = 
68
     #ifdef __linux__
69
        "/saxon-data";
70
    #elif  defined (__APPLE__) && defined(__MACH__)
71
        "/saxon-data";
72
    #else
73
         "\\saxon-data";
74
    #endif
57 75

  
58 76

  
59
static char dllname[] =
77
static char * dllname;/*[] =
60 78
    #ifdef __linux__
61 79
        "/usr/lib/libsaxonhec.so";  //rename according to product edition (hec or pec) Also make change in the c file
62 80
    #elif  defined (__APPLE__) && defined(__MACH__)
63 81
        "/usr/lib/libsaxoneec.dylib";
64 82
    #else
65 83
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1\\libsaxonhec.dll";
66
    #endif
84
    #endif*/
67 85

  
68
static char resources_dir[] = 
86
static char *resources_dir;/*[] = 
69 87
     #ifdef __linux__
70 88
        "/usr/lib/saxon-data";
71 89
    #elif  defined (__APPLE__) && defined(__MACH__)
72 90
        "/usr/lib/saxon-data";
73 91
    #else
74 92
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1\\saxon-data";
75
    #endif
93
    #endif*/
76 94

  
77 95
// Static variable used to track when jvm has been created. Used to prevent creation more than once.
78 96
static int jvmCreated =0;
......
126 144

  
127 145

  
128 146
/*
147
* Get Dll name.
148
*/
149

  
150
char * getResourceDirectory();
151

  
152
/*
129 153
* Set Dll name. Also set the saxon resources directory. 
130 154
* If the SAXON_HOME environmental variable is set then use that as base.
131 155
*/
latest9.6/hec/Saxon.C.API/SaxonProcessor.cpp
143 143
	jvmCreatedCPP=1;
144 144
    environ = new sxnc_environment;//(sxnc_environment *)malloc(sizeof(sxnc_environment));
145 145

  
146

  
146 147
    /*
147 148
     * First of all, load required component.
148 149
     * By the time of JET initialization, all components should be loaded.
......
264 265
			exceptionClear();
265 266
      		 }
266 267
   
267

  
268
 	  environ->env->DeleteLocalRef(stringArray1);
269
	  environ->env->DeleteLocalRef(stringArray2);
268 270
		
269 271
	}
270 272
}
......
336 338
}
337 339

  
338 340
const char * SaxonProcessor::getResourcesDirectory(){
339
	return resources_dir;
341
	return getResourceDirectory();
340 342
}
341 343

  
342 344

  
latest9.6/hec/Saxon.C.API/SaxonProcessor.h
1 1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2015 Saxonica Limited.
2
// Copyright (c) 2016 Saxonica Limited.
3 3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
latest9.6/hec/Saxon.C.API/SchemaValidator.cpp
471 471
}
472 472

  
473 473
void SchemaValidator::setProperty(const char * name, const char * value) {
474
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string(value)));
474
#ifdef DEBUG	
475
	if(value == NULL) {
476
		std::cerr<<"Validator setProperty is NULL"<<std::endl;
477
	}
478
#endif
479
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value== NULL ? "" : value))));
475 480
}
476 481

  
477 482
void SchemaValidator::clearParameters(bool delVal) {
latest9.6/hec/Saxon.C.API/XPathProcessor.cpp
365 365
}
366 366

  
367 367
void XPathProcessor::setProperty(const char * name, const char * value) {
368
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string(value)));
368
#ifdef DEBUG	
369
	if(value == NULL) {
370
		std::cerr<<"XPathProc setProperty is NULL"<<std::endl;
371
	}
372
#endif
373
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value == NULL ? "" : value))));
369 374
}
370 375

  
371 376
void XPathProcessor::clearParameters(bool delVal) {
latest9.6/hec/Saxon.C.API/XQueryProcessor.cpp
12 12
    XQueryProcessor::XQueryProcessor(SaxonProcessor *p, std::string curr) {
13 13
    proc = p;
14 14

  
15
    /*
16
     * Look for class.
17
     */
15
  
18 16
     cppClass = lookForClass(proc->environ->env, "net/sf/saxon/option/cpp/XQueryEngine");
19 17

  
20 18

  
......
125 123
     * @param value of the property
126 124
     */
127 125
    void XQueryProcessor::setProperty(const char * name, const char * value){
128
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string(value)));
126
#ifdef DEBUG	
127
	if(value == NULL) {
128
		std::cerr<<"XQueryProc setProperty is NULL"<<std::endl;
129
	}
130
#endif
131
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value== NULL ? "" : value))));
129 132
    }
130 133

  
131 134
    void XQueryProcessor::clearParameters(bool delVal){
latest9.6/hec/Saxon.C.API/XsltProcessor.cpp
96 96
}
97 97

  
98 98
void XsltProcessor::setProperty(const char* name, const char* value) {
99
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string(value)));
99
#ifdef DEBUG	
100
	if(value == NULL) {
101
		std::cerr<<"XSLTProc setProperty is NULL"<<std::endl;
102
	}
103
#endif
104
	properties.insert(std::pair<std::string, std::string>(std::string(name), std::string((value == NULL ? "" : value))));
100 105

  
101 106
}
102 107

  
latest9.6/hec/samples/cppTests/testXQuery.cpp
34 34
    if(result != NULL){
35 35
    	cout<<"Result :"<<result<<endl;
36 36
    } else {
37

  
37 38
	queryProc->checkException();
38 39
	
39 40
    }
41

  
42
return;
40 43
	queryProc->setcwd(".");
41 44
     queryProc->executeQueryToFile(NULL, "catOutput.xml", NULL);
42 45

  
......
229 232
{
230 233

  
231 234
    SaxonProcessor * processor = new SaxonProcessor(false);
232
    cout<<"Test: XQueryProcessor with Saxon version="<<processor->version()<<endl<<endl;
235
    //cout<<"Test: XQueryProcessor with Saxon version="<<processor->version()<<endl<<endl;
233 236
    XQueryProcessor * query = processor->newXQueryProcessor();
234 237
    
235 238

  
latest9.6/hec/samples/cppTests/testXSLT.cpp
419 419

  
420 420
void exampleSimple3(SaxonProcessor * saxonProc, XsltProcessor  *proc){
421 421
		cout<<"<b>exampleSimple3:</b><br/>"<<endl;
422
		//proc->clearParameters(true);
423
		//proc->clearProperties();
422
		proc->clearParameters(true);
423
		proc->clearProperties();
424 424
                XdmNode * xdmNode = saxonProc->parseXmlFromString("<doc><b>text value of out</b></doc>");
425 425
		if(xdmNode == NULL) {
426 426
			cout<<"xdmNode is null'"<<endl;

Also available in: Unified diff