Changeset 295


Ignore:
Timestamp:
Aug 3, 2011, 9:12:16 PM (13 years ago)
Author:
djay
Message:

Removing Py_DECREF frmo service_internal_python.c, should solve bug #29

File:
1 edited

Legend:

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

    r114 r295  
    7474  free(pythonpath);
    7575
     76  PyThreadState *mainstate;
     77  PyEval_InitThreads();
    7678  Py_Initialize();
     79  mainstate = PyThreadState_Swap(NULL);
     80  PyEval_ReleaseLock();
     81  PyGILState_STATE gstate;
     82  gstate = PyGILState_Ensure();
    7783  PyObject *pName, *pModule, *pFunc;
    7884  tmp=getMap(s->content,"serviceProvider");
     
    119125        dumpMaps(outputs);
    120126#endif
    121         Py_DECREF(arg1);
    122         Py_DECREF(arg2);
    123         Py_DECREF(arg3);
    124         Py_DECREF(pArgs);
    125         Py_DECREF(pValue);
    126         Py_XDECREF(pFunc);
    127         Py_DECREF(pModule);
    128127      }else{     
    129128        PyObject *ptype,*pvalue, *ptraceback;
     
    159158        addToMap(err,"code","NoApplicableCode");
    160159        printExceptionReportResponse(m,err);
    161         Py_DECREF(arg1);
    162         Py_DECREF(arg2);
    163         Py_DECREF(arg3);
    164         Py_XDECREF(pFunc);
    165         Py_DECREF(pArgs);
    166         Py_DECREF(pModule);
    167         Py_DECREF(ptraceback);
    168         Py_DECREF(ptype);
    169         Py_DECREF(pValue);
    170 #if not(defined(macintosh)) && not(defined(__MACH__) && defined(__APPLE__))
    171         Py_Finalize();
    172 #endif
    173         exit(-1);
     160        res=-1;
    174161      }
    175162    }
    176163    else{
    177164      char tmpS[1024];
    178       sprintf(tmpS, "Cannot find the %s function int the %s file.\n", s->name, tmp->value);
     165      sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value);
    179166      map* tmps=createMap("text",tmpS);
    180167      printExceptionReportResponse(m,tmps);
    181       Py_XDECREF(pFunc);
    182       Py_DECREF(pModule);
    183       exit(-1);
     168      res=-1;
    184169    }
    185170  } else{
     
    190175    if (PyErr_Occurred())
    191176      PyErr_Print();
    192     exit(-1);
     177    PyErr_Clear();
     178    res=-1;
     179    //exit(-1);
    193180  }
    194 #if not(defined(macintosh)) && not(defined(__MACH__) && defined(__APPLE__))
     181  PyGILState_Release(gstate);
     182  PyEval_AcquireLock();
     183  PyThreadState_Swap(mainstate);
    195184  Py_Finalize();
    196 #endif
    197185  return res;
    198186}
     
    202190  maps* tmp=t;
    203191  while(tmp!=NULL){
    204     PyObject* subc=(PyObject*)PyDict_FromMap(tmp->content);
    205     if(PyDict_SetItem(res,PyString_FromString(tmp->name),subc)<0){
    206       fprintf(stderr,"Unable to parse params...");
    207       exit(1);
    208     }
    209     Py_DECREF(subc);
     192    PyObject* value=(PyObject*)PyDict_FromMap(tmp->content);
     193    PyObject* name=PyString_FromString(tmp->name);
     194    if(PyDict_SetItem(res,name,value)<0){
     195      fprintf(stderr,"Unable to set map value ...");
     196      return NULL;
     197    }
     198    Py_DECREF(name);
    210199    tmp=tmp->next;
    211200  } 
     
    223212        PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value));
    224213        if(PyDict_SetItem(res,name,value)<0){
    225           fprintf(stderr,"Unable to parse params...");
    226           Py_DECREF(value);
    227           exit(1);
     214          fprintf(stderr,"Unable to set key value pair...");
     215          return NULL;
    228216        }
    229         Py_DECREF(value);
    230217      }
    231218      else{
    232219        PyObject* value=PyString_FromString(tmp->value);
    233220        if(PyDict_SetItem(res,name,value)<0){
    234           fprintf(stderr,"Unable to parse params...");
    235           Py_DECREF(value);
    236           exit(1);
     221          fprintf(stderr,"Unable to set key value pair...");
     222          return NULL;
    237223        }
    238         Py_DECREF(value);
    239224      }
    240225    }
     
    242227      PyObject* value=PyString_FromString(tmp->value);
    243228      if(PyDict_SetItem(res,name,value)<0){
    244         fprintf(stderr,"Unable to parse params...");
    245         Py_DECREF(value);
    246         exit(1);
    247       }
    248       Py_DECREF(value);
     229        fprintf(stderr,"Unable to set key value pair...");
     230        return NULL;
     231      }
    249232    }
    250233    Py_DECREF(name);
     
    272255    cursor=(maps*)malloc(MAPS_SIZE);
    273256    cursor->name=PyString_AsString(key);
    274 #ifdef DEBUG
    275     dumpMap(mapFromPyDict((PyDictObject*)value));
    276 #endif
    277257    cursor->content=mapFromPyDict((PyDictObject*)value);
     258#ifdef DEBUG
     259    dumpMap(cursor->content);
     260#endif
    278261    cursor->next=NULL;
    279262    if(res==NULL)
     
    284267    free(cursor->content);
    285268    free(cursor);
    286     Py_DECREF(value);
    287     Py_DECREF(key);
    288269#ifdef DEBUG
    289270    dumpMaps(res);
     
    291272#endif
    292273  }
    293   Py_DECREF(list);
    294274  return res;
    295275}
     
    330310        res=createMap(PyString_AsString(key),PyString_AsString(value));
    331311    }
    332     Py_DECREF(key);
    333   }
    334   Py_DECREF(list);
     312  }
    335313  return res;
    336314}
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