Changeset 738


Ignore:
Timestamp:
Jul 13, 2015, 3:42:39 PM (9 years ago)
Author:
knut
Message:

Redefined the API function addToMapWithSize to fix problem with Python/PHP support. Added some variable initializations and NULL pointer checks.

Location:
trunk/zoo-project/zoo-kernel
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/caching.c

    r725 r738  
    303303 */
    304304int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){
    305   char* fcontent;
     305  char* fcontent = NULL;
    306306  char* cached=isInCache(*m,url);
    307307  char *mimeType=NULL;
     
    353353
    354354  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
    355   if(tmpMap->value==NULL)
     355  if(tmpMap->value==NULL || fcontent == NULL)
    356356    return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
    357357  memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
  • trunk/zoo-project/zoo-kernel/response_print.c

    r725 r738  
    786786void printDescribeProcessForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
    787787  xmlNsPtr ns,ns_ows,ns_xlink;
    788   xmlNodePtr n,nc1,nc2;
     788  xmlNodePtr n,nc1;
     789  xmlNodePtr nc2 = NULL;
    789790  map* version=getMapFromMaps(m,"main","rversion");
    790791  int vid=getVersionId(version->value);
     
    872873  if(vid==0)
    873874    xmlAddChild(n,nc);
    874   else{
     875  else if (nc2 != NULL) {         
    875876    xmlAddChild(nc2,nc);
    876877    xmlAddChild(n,nc2);
  • trunk/zoo-project/zoo-kernel/service.c

    r712 r738  
    455455 * @param v the corresponding value to add
    456456 * @param size the size of the given value
    457  */
    458 void addToMapWithSize(map* m,const char* n,const char* v,int size){
     457 * @return a pointer to the updated map m
     458 */
     459map* addToMapWithSize(map* m,const char* n,const char* v,int size){
    459460  if(hasKey(m,n)==false){
    460461    map* _cursor=m;
     
    477478  sprintf(sin,"%d",size);
    478479  addToMap(m,sname,sin);
     480  return m;
    479481}
    480482
  • trunk/zoo-project/zoo-kernel/service.h

    r712 r738  
    292292  ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*);
    293293  ZOO_DLL_EXPORT void addIntToMap(map*,const char*,const int);
    294   ZOO_DLL_EXPORT void addToMapWithSize(map*,const char*,const char*,int);
     294  ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int);
    295295  ZOO_DLL_EXPORT void addMapToMap(map**,map*);
    296296  ZOO_DLL_EXPORT void addMapToIoType(iotype**,map*);
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r730 r738  
    189189  sprintf (fbkpid, "%s/%s.status", r_inputs->value, lid);
    190190  FILE* f0 = fopen (fbkpid, "r");
    191   if(f0!=NULL){
    192     semid lockid;
     191  if(f0!=NULL){   
     192    semid lockid = NULL;
    193193    char* stat;
    194194    long flen;
     
    270270  if(status!=NULL && msg!=NULL &&
    271271     status->value!=NULL && msg->value!=NULL &&
    272      strlen(status->value)>0 && strlen(msg->value)>1){
    273     semid lockid;
     272     strlen(status->value)>0 && strlen(msg->value)>1){   
     273    semid lockid = NULL;
    274274    char* stat=getStatusId(conf,sid->value);
    275275    if(stat!=NULL){
  • trunk/zoo-project/zoo-kernel/service_internal_php.c

    r712 r738  
    432432    convert_to_string(&tmpcopy);
    433433    if(strncmp(key,"value",5)==0){
    434       len=Z_STRLEN_P(&tmpcopy);
    435       addToMapWithSize(final_res,key,Z_STRVAL_P(&tmpcopy),len);
     434      len=Z_STRLEN_P(&tmpcopy);     
     435          final_res = addToMapWithSize(final_res,key,Z_STRVAL_P(&tmpcopy),len);
    436436    }
    437437    else{
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r682 r738  
    563563
    564564/**
     565 * Convert a Python dictionary to a maps
     566 *
     567 * @param t the PyDictObject to convert
     568 * @return a new maps containing the converted PyDictObject
     569 * @warning make sure to free resources returned by this function
     570 */
     571maps* _mapsFromPyDict(PyDictObject* t){
     572       
     573        PyObject* list = PyDict_Keys((PyObject*)t); // new ref 
     574        int nb = PyList_Size(list);     
     575       
     576        if (nb < 1) {
     577                Py_DECREF(list);
     578                return NULL;
     579        }
     580
     581        maps* ptr = (maps*) malloc(MAPS_SIZE);
     582        maps* res = ptr;       
     583       
     584        PyObject* key;
     585        PyObject* value;
     586       
     587        for(int i = 0; i < nb; i++) {
     588               
     589                key = PyList_GetItem(list,i); // borrowed ref
     590                value = PyDict_GetItem((PyObject*) t, key); // borrowed ref
     591               
     592                ptr->name = zStrdup(PyString_AsString(key));
     593                ptr->content = mapFromPyDict((PyDictObject*) value);
     594               
     595                ptr->next = i < nb - 1 ? (maps*) malloc(MAPS_SIZE) : NULL;
     596                ptr = ptr->next;
     597        }
     598        Py_DECREF(list);
     599
     600        return res;
     601} // mapsFromPyDict
     602
     603/**
    565604 * Convert a Python dictionary to a map
    566605 *
     
    597636        }
    598637        else{
     638#ifdef DEBUG
    599639          fprintf(stderr,"Unsupported return value.");
     640#endif
    600641          return NULL;
    601642        }
    602643#else
    603644      PyString_AsStringAndSize(value,&buffer,&size);
    604 #endif
    605       addToMapWithSize(res,PyString_AsString(key),buffer,size);
     645#endif     
     646          res = addToMapWithSize(res,PyString_AsString(key),buffer,size);
    606647    }else{
    607648      char* lkey=PyString_AsString(key);
     
    622663
    623664/**
     665 * Convert a Python dictionary to a map
     666 *
     667 * @param t the PyDictObject to convert
     668 * @return a new map containing the converted PyDictObject
     669 * @warning make sure to free resources returned by this function
     670 */
     671map* _mapFromPyDict(PyDictObject* t) {
     672       
     673        PyObject* list = PyDict_Keys((PyObject*) t); // new ref
     674        int nb = PyList_Size(list);
     675       
     676        if (nb < 1) {
     677                Py_DECREF(list);
     678                return NULL;
     679        }       
     680       
     681        map* ptr = (map*) malloc(MAP_SIZE);
     682        map* res = ptr;
     683       
     684        PyObject* key;
     685        PyObject* value;
     686        char *buffer = NULL;
     687        Py_ssize_t size;
     688        for(int i = 0; i < nb; i++) {
     689               
     690                key = PyList_GetItem(list, i); // borrowed ref
     691                value = PyDict_GetItem((PyObject*) t, key); // borrowed ref             
     692                               
     693                ptr->name = zStrdup(PyString_AsString(key));           
     694                map* msize = NULL;
     695               
     696        #if PY_MAJOR_VERSION >= 3
     697                if (PyBytes_Check(value)) {
     698                // value is byte array
     699                        size = PyBytes_Size(value);                             
     700                        buffer = PyBytes_AsString(value); // pointer to internal buffer
     701                        char sz[32];
     702                        sprintf(sz, "%d", (int) size); 
     703                        msize = createMap("size", sz);                 
     704                }
     705                else if (PyUnicode_Check(value) && PyUnicode_READY(value) == 0) {
     706                // value is string object               
     707                        buffer = PyUnicode_AsUTF8AndSize(value, &size);
     708                        size++;
     709                }
     710                else {
     711                        printf("Type not recognized\n");
     712                        // error handling
     713                        // ...
     714                }
     715        #else   
     716                PyString_AsStringAndSize(value, &buffer, &size);
     717                size++;
     718                // to do: handle byte arrays
     719        #endif
     720               
     721                ptr->value = (char*) malloc(size); // check for NULL pointer
     722                memmove(ptr->value, buffer, size);
     723                       
     724                if (msize != NULL) {
     725                        ptr->next = msize;
     726                        ptr = ptr->next;
     727                }                                               
     728               
     729                ptr->next = i < nb - 1 ? (map*) malloc(MAP_SIZE) : NULL;
     730                ptr = ptr->next;
     731        }       
     732        Py_DECREF(list);
     733                       
     734        return res;
     735} // mapFromPyDict
     736
     737/**
    624738 * Use the ZOO-Services messages translation function from the Python
    625739 * environment
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r725 r738  
    961961      setenv ("LC_ALL", tmp, 1);
    962962#else
    963       char tmp1[12];
     963          char tmp1[13];
    964964      sprintf (tmp1, "LC_ALL=%s", tmp);
    965965      putenv (tmp1);
     
    973973      setenv ("LC_ALL", "en_US", 1);
    974974#else
    975       char tmp1[12];
     975          char tmp1[13];
    976976      sprintf (tmp1, "LC_ALL=en_US");
    977977      putenv (tmp1);
     
    14731473          {
    14741474            map* version=getMapFromMaps(m,"main","rversion");
    1475             int vid=getVersionId(version->value);
    1476             int len,j=0;
     1475            int vid=getVersionId(version->value);           
     1476                int len = 0;
     1477                int j = 0;
    14771478            for(j=0;j<nbSupportedRequests;j++){
    14781479              if(requests[vid][j]!=NULL)
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