Ignore:
Timestamp:
Jan 6, 2011, 10:50:56 PM (14 years ago)
Author:
djay
Message:

Small fix for binary string support in dupMaps function to ensure that the binary value willbe passed to various laguages correctly. Memory cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/service_internal_python.c

    r58 r59  
    106106        freeMaps(real_outputs);
    107107        free(*real_outputs);
    108         //*real_inputs=mapsFromPyDict(arg2);
    109         //createMapsFromPyDict(real_outputs,arg3);
     108        freeMaps(main_conf);
     109        free(*main_conf);
    110110        *main_conf=mapsFromPyDict(arg1);
    111111        *real_outputs=mapsFromPyDict(arg3);
     
    134134        trace=NULL;
    135135        trace=PyObject_Str(ptype);
    136         if(PyString_Check(trace))
    137           sprintf(pbt,"%s\nTRACE : %s",strdup(pbt),PyString_AsString(trace));
     136        if(PyString_Check(trace)){
     137          char *tpbt=strdup(pbt);
     138          sprintf(pbt,"%s\nTRACE : %s",tpbt,PyString_AsString(trace));
     139          free(tpbt);
     140        }
    138141        else
    139142          fprintf(stderr,"EMPTY TRACE ?");
     
    148151        trace=PyObject_Str(pValue);
    149152        if(PyString_Check(trace))
    150           sprintf(pbt,"%s\nUnable to run your python process properly. Please check the following messages : %s",strdup(pbt),PyString_AsString(trace));
     153          sprintf(pbt,"%s\nUnable to run your python process properly. Please check the following messages : %s",pbt,PyString_AsString(trace));
    151154        else
    152           sprintf(pbt,"%s \n Unable to run your python process properly. Unable to provide any futher informations.",strdup(pbt));
     155          sprintf(pbt,"%s \n Unable to run your python process properly. Unable to provide any futher informations.",pbt);
    153156        map* err=createMap("text",pbt);
    154157        addToMap(err,"code","NoApplicableCode");
    155158        printExceptionReportResponse(m,err);
     159        Py_DECREF(arg1);
     160        Py_DECREF(arg2);
     161        Py_DECREF(arg3);
    156162        Py_XDECREF(pFunc);
    157163        Py_DECREF(pArgs);
    158164        Py_DECREF(pModule);
     165        Py_DECREF(ptraceback);
     166        Py_DECREF(ptype);
     167        Py_DECREF(pValue);
     168        Py_Finalize();
    159169        exit(-1);
    160170      }
     
    178188    exit(-1);
    179189  }
    180 #ifndef DEBUG
    181   // Failed when DEBUG is defined
    182190  Py_Finalize();
    183 #endif
    184191  return res;
    185192}
     
    189196  maps* tmp=t;
    190197  while(tmp!=NULL){
    191     if(PyDict_SetItem(res,PyString_FromString(tmp->name),(PyObject*)PyDict_FromMap(tmp->content))<0){
     198    PyObject* subc=PyDict_FromMap(tmp->content);
     199    if(PyDict_SetItem(res,PyString_FromString(tmp->name),subc)<0){
    192200      fprintf(stderr,"Unable to parse params...");
    193201      exit(1);
    194202    }
     203    Py_DECREF(subc);
    195204    tmp=tmp->next;
    196205  } 
     
    202211  map* tmp=t;
    203212  map* size=getMap(tmp,"size");
    204   dumpMap(t);
    205213  while(tmp!=NULL){
    206     fprintf(stderr,"%s => %s\n"),tmp->name,tmp->value;
     214    PyObject* name=PyString_FromString(tmp->name);
    207215    if(strcasecmp(tmp->name,"value")==0){
    208216      if(size!=NULL){
    209         if(PyDict_SetItem(res,PyString_FromString(tmp->name),PyString_FromStringAndSize(tmp->value,(Py_ssize_t) atoi(size->value)))<0){
     217        PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value));
     218        if(PyDict_SetItem(res,name,value)<0){
    210219          fprintf(stderr,"Unable to parse params...");
    211220          exit(1);
    212221        }
     222        Py_DECREF(value);
    213223      }
    214       else
    215         if(PyDict_SetItem(res,PyString_FromString(tmp->name),PyString_FromString(tmp->value))<0){
     224      else{
     225        PyObject* value=PyString_FromString(tmp->value);
     226        if(PyDict_SetItem(res,name,value)<0){
    216227          fprintf(stderr,"Unable to parse params...");
    217228          exit(1);
    218229        }
    219     }
    220     else
    221       if(PyDict_SetItem(res,PyString_FromString(tmp->name),PyString_FromString(tmp->value))<0){
     230        Py_DECREF(value);
     231      }
     232    }
     233    else{
     234      PyObject* value=PyString_FromString(tmp->value);
     235      if(PyDict_SetItem(res,name,value)<0){
    222236        fprintf(stderr,"Unable to parse params...");
    223237        exit(1);
    224238      }
     239      Py_DECREF(value);
     240    }
     241    Py_DECREF(name);
    225242    tmp=tmp->next;
    226243  }
     
    244261            PyString_AsString(key),PyString_AsString(value));
    245262#endif
    246     while(cursor!=NULL){
    247       cursor=cursor->next;
    248     }
    249263    cursor=(maps*)malloc(MAPS_SIZE);
    250264    cursor->name=PyString_AsString(key);
     
    255269    cursor->next=NULL;
    256270    if(res==NULL)
    257       res=cursor;
     271      res=dupMaps(&cursor);
    258272    else
    259273      addMapsToMaps(&res,cursor);
     274    freeMap(&cursor->content);
     275    free(cursor->content);
     276    free(cursor);
    260277#ifdef DEBUG
    261278    dumpMaps(res);
     
    263280#endif
    264281  }
     282  Py_DECREF(list);
    265283  return res;
    266284}
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png