Changeset 49
- Timestamp:
- Aug 23, 2005, 12:45:05 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cee/rappture_interface.h
r47 r49 13 13 void** rpChildren (PyObject* lib, const char* path, const char* flavor); 14 14 PyObject* rpChildren_f (PyObject* lib, const char* path, const char* flavor); 15 c onst char* rpGet (PyObject* lib, const char* path);15 char* rpGet (PyObject* lib, const char* path); 16 16 void rpPut (PyObject* lib, 17 17 const char* path, -
trunk/src/cee/rappture_interface.c
r47 r49 187 187 * 1) the return object will need to be cast as a char* 188 188 * to use it. 189 * 2) It is the caller's responsibility to free the returned pointer 189 190 * 190 * The Arguments lib and path are not optional.191 * The Arguments lib and path are not optional. 191 192 * If either value is NULL, NULL will be returned. 192 193 * … … 200 201 PyObject* mbr_fxn = NULL; /* pointer to fxn of class lib */ 201 202 PyObject* rslt = NULL; /* results from fxn call */ 203 char* tmpRetVal = NULL; /* fxn return value */ 204 char* tmpString = NULL; /* fxn return value */ 202 205 void* retVal = NULL; /* fxn return value */ 206 int retValSize = 0; 203 207 204 208 if (lib && path) { … … 236 240 // return a char* 237 241 // convert the result to c style strings 238 retVal = (void*) PyString_AsString(rslt); 242 // retVal = (void*) PyString_AsString(rslt); 243 tmpRetVal = PyString_AsString(rslt); 244 if (tmpRetVal) { 245 // get str length, add 1 for null termination 246 retValSize = strlen(tmpRetVal) + 1; 247 tmpString = (char*) calloc(retValSize,sizeof(char)); 248 if (tmpString) { 249 strncpy(tmpString,tmpRetVal,retValSize); 250 retVal = (void*) tmpString; 251 } 252 else { 253 // raise error, out of memory 254 } 255 } 239 256 Py_DECREF(rslt); 240 257 } … … 280 297 * 1) the return object will need to be case as a char* 281 298 * to use it. 299 * 2) It is the caller's responsibility to free the contents of 300 * the returned pointer (ie. free(*retVal)) 282 301 * 283 302 * The Arguments lib and pathare not optional. … … 299 318 char** rslt_arr_c = NULL; 300 319 void** rslt_arr = NULL; 320 char* tmpRetVal = NULL; 321 char* tmpString = 0; 322 int retValSize = 0; 323 301 324 302 325 if (lib && path) { … … 373 396 // we cannot deallocate the results of 374 397 // PyString_AsString() 375 rslt_arr_c[index] = PyString_AsString(list_item); 376 index++; 398 399 tmpRetVal = PyString_AsString(list_item); 400 if (tmpRetVal) { 401 // get str length, add 1 for null termination 402 retValSize = strlen(tmpRetVal) + 1; 403 tmpString = (char*) calloc(retValSize,sizeof(char)); 404 if (tmpString) { 405 strncpy(tmpString,tmpRetVal,retValSize); 406 rslt_arr_c[index] = tmpString; 407 tmpString = NULL; 408 index++; 409 } 410 } 411 412 // rslt_arr_c[index] = PyString_AsString(list_item); 413 // index++; 377 414 378 415 } … … 517 554 * NULL will be returned. 518 555 * 519 * Returns pointer (c onst char*) to the c style string representing the556 * Returns pointer (char*) to the c style string representing the 520 557 * xml text provided by the path of the Rappture object if 521 558 * successful, or NULL if something goes wrong. 522 559 * 523 * The return value's contents should not be changed because524 * it is a pointer being borrowed from python's buffer space525 * (hence the _const_)526 */ 527 c onst char* rpGet(PyObject* lib, const char* path)560 * It is the responsibility of the caller to free the 561 * returned pointer 562 * 563 */ 564 char* rpGet(PyObject* lib, const char* path) 528 565 { 529 566 PyObject* mbr_fxn = NULL; /* pointer to fxn of class lib */ 530 567 PyObject* rslt = NULL; /* results from fxn call */ 568 char* tmpRetVal = NULL; /* return value */ 531 569 char* retVal = NULL; /* return value */ 570 int retValSize = 0; 532 571 533 572 if (lib) { … … 543 582 if (rslt) { 544 583 // convert the result to c style strings 545 retVal = PyString_AsString(rslt); 546 // Py_DECREF(rslt); 584 tmpRetVal = PyString_AsString(rslt); 585 586 if (tmpRetVal) { 587 // get str length, add 1 for null termination 588 retValSize = strlen(tmpRetVal) + 1; 589 retVal = (char*) calloc(retValSize,sizeof(char)); 590 if (retVal) { 591 strncpy(retVal,tmpRetVal,retValSize); 592 } 593 else { 594 // raise error, out of memory 595 } 596 } 597 598 Py_DECREF(rslt); 547 599 } 548 600 … … 555 607 } 556 608 557 return (const char*)retVal;609 return retVal; 558 610 559 611 } … … 737 789 char* tmpretVal = NULL; /* return value */ 738 790 char* retVal = NULL; /* return value */ 791 int retValSize = 0; 739 792 740 793 if (lib) { … … 751 804 // convert the result to c style strings 752 805 tmpretVal = PyString_AsString(rslt); 753 retVal = (char*) calloc(strlen(tmpretVal),sizeof(char)); 754 strcpy(retVal,tmpretVal); 806 if (tmpretVal) { 807 // get str length, add 1 for null termination 808 retValSize = strlen(tmpretVal) + 1; 809 retVal = (char*) calloc(retValSize,sizeof(char)); 810 if (retVal) { 811 strncpy(retVal,tmpretVal,retValSize); 812 } 813 else { 814 // raise error, out of memory 815 } 816 } 755 817 Py_DECREF(rslt); 756 818 } -
trunk/src/fortran/rappture_fortran.c
r47 r49 514 514 } 515 515 *(retText+length_out-1) = ' '; 516 516 517 free(retObj); 518 retObj = NULL; 517 519 } 518 520 else {
Note: See TracChangeset
for help on using the changeset viewer.