Changeset 453 for trunk/zoo-project/zoo-kernel/service_internal_python.c
- Timestamp:
- Feb 12, 2014, 3:25:15 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal_python.c
r451 r453 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2009-201 3GeoLabs SARL4 * Copyright (c) 2009-2014 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 31 31 #if PY_MAJOR_VERSION >= 3 32 32 #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) 33 #define PyInt_FromLong PyLong_FromLong 34 #define PyInt_AsLong PyLong_AsLong 35 #define PyString_FromString PyUnicode_FromString 36 #define PyString_FromStringAndSize PyUnicode_FromStringAndSize 37 #define PyString_Check PyUnicode_Check 38 #define PyString_AsString _PyUnicode_AsString 39 #define PyString_Size PyUnicode_GetSize 33 40 #else 34 41 #define GETSTATE(m) (&_state) … … 88 95 89 96 d = PyModule_GetDict(module); 90 #if PY_MAJOR_VERSION >= 391 tmp = PyLong_FromLong(3);92 #else93 97 tmp = PyInt_FromLong(3); 94 #endif95 98 PyDict_SetItemString(d, "SERVICE_SUCCEEDED", tmp); 96 99 Py_DECREF(tmp); 97 100 98 #if PY_MAJOR_VERSION >= 399 tmp = PyLong_FromLong(4);100 #else101 101 tmp = PyInt_FromLong(4); 102 #endif103 102 PyDict_SetItemString(d, "SERVICE_FAILED", tmp); 104 103 Py_DECREF(tmp); … … 191 190 tmp=getMap(s->content,"serviceProvider"); 192 191 if(tmp!=NULL) 193 pName = 194 #if PY_MAJOR_VERSION >= 3 195 PyUnicode_FromString(tmp->value); 196 #else 197 PyString_FromString(tmp->value); 198 #endif 192 pName = PyString_FromString(tmp->value); 199 193 else{ 200 194 map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file."); … … 218 212 PyTuple_SetItem(pArgs, 1, (PyObject *)arg2); 219 213 PyTuple_SetItem(pArgs, 2, (PyObject *)arg3); 220 tmp=getMap(request,"storeExecuteResponse");221 #ifdef DEBUG222 fprintf(stderr,"RUN IN NORMAL MODE \n");223 fflush(stderr);224 #endif225 214 pValue = PyObject_CallObject(pFunc, pArgs); 226 215 if (pValue != NULL) { 227 #if PY_MAJOR_VERSION >= 3228 res=PyLong_AsLong(pValue);229 #else230 216 res=PyInt_AsLong(pValue); 231 #endif232 217 freeMaps(real_outputs); 233 218 free(*real_outputs); … … 237 222 *real_outputs=mapsFromPyDict(arg3); 238 223 #ifdef DEBUG 239 #if PY_MAJOR_VERSION >= 3240 fprintf(stderr,"Result of call: %i\n", PyLong_AsLong(pValue));241 #else242 224 fprintf(stderr,"Result of call: %i\n", PyInt_AsLong(pValue)); 243 #endif244 225 dumpMaps(inputs); 245 226 dumpMaps(*real_outputs); … … 250 231 PyObject *trace=PyObject_Str(pvalue); 251 232 char pbt[10240]; 252 #if PY_MAJOR_VERSION >= 3253 if(PyUnicode_Check(trace))254 sprintf(pbt,"TRACE : %s",_PyUnicode_AsString(trace));255 #else256 233 if(PyString_Check(trace)) 257 234 sprintf(pbt,"TRACE : %s",PyString_AsString(trace)); 258 #endif259 235 else 260 236 fprintf(stderr,"EMPTY TRACE ?"); 261 237 trace=NULL; 262 238 trace=PyObject_Str(ptype); 263 #if PY_MAJOR_VERSION >= 3264 if(PyUnicode_Check(trace)){265 #else266 239 if(PyString_Check(trace)){ 267 #endif 268 char *tpbt=strdup(pbt); 269 #if PY_MAJOR_VERSION >= 3 270 sprintf(pbt,"%s\n%s\0",tpbt,_PyUnicode_AsString(trace)); 271 #else 240 char *tpbt=zStrdup(pbt); 272 241 sprintf(pbt,"%s\n%s\0",tpbt,PyString_AsString(trace)); 273 #endif274 242 free(tpbt); 275 243 } … … 277 245 fprintf(stderr,"EMPTY TRACE ?"); 278 246 279 char *tpbt=strdup(pbt); 280 #if PY_MAJOR_VERSION >= 3 281 pName = PyUnicode_FromString("traceback"); 282 #else 247 char *tpbt=zStrdup(pbt); 283 248 pName = PyString_FromString("traceback"); 284 #endif285 249 pModule = PyImport_Import(pName); 286 250 pArgs = PyTuple_New(1); … … 290 254 trace=NULL; 291 255 trace=PyObject_Str(pValue); 292 #if PY_MAJOR_VERSION >= 3293 if(PyUnicode_Check(trace))294 sprintf(pbt,"%s\nUnable to run your python process properly. Please check the following messages : %s",tpbt,_PyUnicode_AsString(trace));295 #else296 256 if(PyString_Check(trace)) 297 257 sprintf(pbt,"%s\nUnable to run your python process properly. Please check the following messages : %s",tpbt,PyString_AsString(trace)); 298 #endif299 258 else 300 259 sprintf(pbt,"%s \n Unable to run your python process properly. Unable to provide any futher informations. %s",tpbt); … … 338 297 while(tmp!=NULL){ 339 298 PyObject* value=(PyObject*)PyDict_FromMap(tmp->content); 340 PyObject* name= 341 #if PY_MAJOR_VERSION >= 3 342 PyUnicode_FromString(tmp->name); 343 #else 344 PyString_FromString(tmp->name); 345 #endif 299 PyObject* name=PyString_FromString(tmp->name); 346 300 if(PyDict_SetItem(res,name,value)<0){ 347 301 fprintf(stderr,"Unable to set map value ..."); … … 362 316 map* tmap=getMapType(tmp); 363 317 while(tmp!=NULL){ 364 PyObject* name= 365 #if PY_MAJOR_VERSION >= 3 366 PyUnicode_FromString(tmp->name); 367 #else 368 PyString_FromString(tmp->name); 369 #endif 318 PyObject* name=PyString_FromString(tmp->name); 370 319 if(strcasecmp(tmp->name,"value")==0) { 371 320 if(isArray!=NULL){ … … 386 335 PyObject* lsvalue; 387 336 if(sMap==NULL){ 388 #if PY_MAJOR_VERSION >= 3389 lvalue=PyUnicode_FromString(vMap->value);390 #else391 337 lvalue=PyString_FromString(vMap->value); 392 #endif393 338 lsvalue=Py_None; 394 339 } 395 else{ 396 #if PY_MAJOR_VERSION >= 3 397 lvalue=PyUnicode_FromStringAndSize(vMap->value,atoi(sMap->value)); 398 lsvalue=PyUnicode_FromString(sMap->value); 399 #else 340 else{ 400 341 lvalue=PyString_FromStringAndSize(vMap->value,atoi(sMap->value)); 401 342 lsvalue=PyString_FromString(sMap->value); 402 #endif403 343 hasSize=1; 404 344 } … … 417 357 PyObject* lmvalue; 418 358 if(mMap!=NULL){ 419 #if PY_MAJOR_VERSION >= 3420 lmvalue=PyUnicode_FromString(mMap->value);421 #else422 359 lmvalue=PyString_FromString(mMap->value); 423 #endif424 360 }else 425 361 lmvalue=Py_None; … … 436 372 return NULL; 437 373 } 438 #if PY_MAJOR_VERSION >= 3439 if(PyDict_SetItem(res,PyUnicode_FromString(tmap->name),mvalue)<0){440 #else441 374 if(PyDict_SetItem(res,PyString_FromString(tmap->name),mvalue)<0){ 442 #endif443 375 fprintf(stderr,"Unable to set key value pair..."); 444 376 return NULL; 445 377 } 446 378 if(hasSize>0) 447 #if PY_MAJOR_VERSION >= 3448 if(PyDict_SetItem(res,PyUnicode_FromString("size"),svalue)<0){449 #else450 379 if(PyDict_SetItem(res,PyString_FromString("size"),svalue)<0){ 451 #endif452 380 fprintf(stderr,"Unable to set key value pair..."); 453 381 return NULL; … … 455 383 } 456 384 else if(size!=NULL){ 457 PyObject* value= 458 #if PY_MAJOR_VERSION >= 3 459 PyUnicode_FromStringAndSize(tmp->value,atoi(size->value)); 460 #else 461 PyString_FromStringAndSize(tmp->value,atoi(size->value)); 462 #endif 385 PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value)); 463 386 if(PyDict_SetItem(res,name,value)<0){ 464 387 fprintf(stderr,"Unable to set key value pair..."); … … 467 390 } 468 391 else{ 469 PyObject* value= 470 #if PY_MAJOR_VERSION >= 3 471 PyUnicode_FromString(tmp->value); 472 #else 473 PyString_FromString(tmp->value); 474 #endif 392 PyObject* value=PyString_FromString(tmp->value); 475 393 if(PyDict_SetItem(res,name,value)<0){ 476 394 fprintf(stderr,"Unable to set key value pair..."); … … 481 399 else{ 482 400 if(PyDict_GetItem(res,name)==NULL){ 483 PyObject* value= 484 #if PY_MAJOR_VERSION >= 3 485 PyUnicode_FromString(tmp->value); 486 #else 487 PyString_FromString(tmp->value); 488 #endif 401 PyObject* value=PyString_FromString(tmp->value); 489 402 if(PyDict_SetItem(res,name,value)<0){ 490 403 fprintf(stderr,"Unable to set key value pair..."); … … 516 429 #endif 517 430 cursor=(maps*)malloc(MAPS_SIZE); 518 #if PY_MAJOR_VERSION >= 3519 cursor->name=_PyUnicode_AsString(key);520 #else521 431 cursor->name=PyString_AsString(key); 522 #endif523 432 cursor->content=mapFromPyDict((PyDictObject*)value); 524 433 #ifdef DEBUG … … 553 462 PyString_AsString(key),PyString_AsString(value)); 554 463 #endif 555 #if PY_MAJOR_VERSION >= 3 556 if(strcmp(_PyUnicode_AsString(key),"value")==0){ 557 #else 464 558 465 if(strcmp(PyString_AsString(key),"value")==0){ 559 #endif560 466 char *buffer=NULL; 561 467 Py_ssize_t size; … … 566 472 #endif 567 473 if(res!=NULL){ 568 #if PY_MAJOR_VERSION >= 3569 addToMap(res,_PyUnicode_AsString(key),"");570 #else571 474 addToMap(res,PyString_AsString(key),""); 572 #endif573 475 }else{ 574 #if PY_MAJOR_VERSION >= 3575 res=createMap(_PyUnicode_AsString(key),"");576 #else577 476 res=createMap(PyString_AsString(key),""); 578 #endif579 477 } 580 478 map* tmpR=getMap(res,"value"); … … 589 487 if(res!=NULL){ 590 488 if(PyString_Size(value)>0) 591 #if PY_MAJOR_VERSION >= 3592 addToMap(res,_PyUnicode_AsString(key),_PyUnicode_AsString(value));593 #else594 489 addToMap(res,PyString_AsString(key),PyString_AsString(value)); 595 #endif596 490 } 597 491 else{ 598 492 if(PyString_Size(value)>0) 599 res= 600 #if PY_MAJOR_VERSION >= 3 601 createMap(_PyUnicode_AsString(key),_PyUnicode_AsString(value)); 602 #else 603 createMap(PyString_AsString(key),PyString_AsString(value)); 604 #endif 493 res=createMap(PyString_AsString(key),PyString_AsString(value)); 605 494 } 606 495 } … … 619 508 return NULL; 620 509 } 621 #if PY_MAJOR_VERSION >= 3622 return PyUnicode_FromString(_ss(str));623 #else624 510 return PyString_FromString(_ss(str)); 625 #endif626 511 } 627 512 … … 645 530 char tmpStatus[4]; 646 531 snprintf(tmpStatus, 4, "%i", istatus); 647 status = strdup(tmpStatus);532 status = zStrdup(tmpStatus); 648 533 } 649 534 /* now update the map */ … … 651 536 PyObject* lenv = PyMapping_GetItemString(confdict, "lenv"); 652 537 if (lenv && PyMapping_Check(lenv)){ 653 PyObject* valobj = 654 #if PY_MAJOR_VERSION >= 3 655 PyUnicode_FromString(status); 656 #else 657 PyString_FromString(status); 658 #endif 538 PyObject* valobj = PyString_FromString(status); 659 539 PyMapping_SetItemString(lenv, "status", valobj); 660 540 Py_DECREF(valobj);
Note: See TracChangeset
for help on using the changeset viewer.