Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cee/rappture_interface.c

    r20 r28  
    1 #include "../include/rappture_interface.h"
     1#include "rappture_interface.h"
    22
    33/**********************************************************************/
     
    102102    PyObject* retVal    = NULL;      /* fxn return value */
    103103
     104    long int fileLength = 0;
     105    char* fileContents = NULL;
     106    FILE* fp = NULL;
     107
    104108
    105109    if (rpObj) {
    106110        if (path) {
    107             // setup our arguments in a Python tuple
    108             args = PyTuple_New(1);
    109             stringarg = PyString_FromString(path);
    110             PyTuple_SetItem(args, 0, stringarg);
    111                    
    112             // call the class ... lib = Rappture.library("...")
    113             lib = PyObject_CallObject(rpObj, args);
    114            
    115             // following line could cause a segfault if used in place of above
    116             // maybe path could == NULL or bad memory
    117             // lib = PyObject_CallFunction(rpObj,"(s)", path);
    118 
    119             if (lib) {
    120                 // return the Rappture instantiation.
    121                 retVal = lib;
     111
     112            fp = fopen(path,"rb");
     113            if (fp) {
     114                fseek(fp, 0, SEEK_END);
     115                fileLength = ftell(fp);
     116                rewind(fp);
     117            }
     118            fileContents = (char*) calloc(fileLength,sizeof(char));
     119
     120            if (fp && fileContents) {
     121                fread((void*)fileContents,sizeof(char),fileLength,fp);
     122                fclose(fp);
     123                fp = NULL;
     124
     125                // setup our arguments in a Python tuple
     126                args = PyTuple_New(1);
     127                stringarg = PyString_FromString(fileContents);
     128               
     129                // clean up used memory
     130                free (fileContents);
     131                fileContents = NULL;
     132               
     133                PyTuple_SetItem(args, 0, stringarg);
     134                       
     135                // call the class ... lib = Rappture.library("...")
     136                lib = PyObject_CallObject(rpObj, args);
     137               
     138                // following line could cause a segfault if used in place of above
     139                // maybe path could == NULL or bad memory
     140                // lib = PyObject_CallFunction(rpObj,"(s)", path);
     141
     142                if (lib) {
     143                    // return the Rappture instantiation.
     144                    retVal = lib;
     145                }
     146                else {
     147                    // lib was not successfully created
     148                }
     149
     150                Py_DECREF(stringarg);
     151                Py_DECREF(args);
    122152            }
    123153            else {
    124                 // lib was not successfully created
    125             }
    126 
    127             Py_DECREF(stringarg);
    128             Py_DECREF(args);
     154                // fp or fileContents were NULL;
     155            }
    129156        }
    130157        else {
Note: See TracChangeset for help on using the changeset viewer.