| 5457 | |
| 5458 | |
| 5459 | static LIST * call_python_function( PYTHON_FUNCTION * function, FRAME * frame ) |
| 5460 | { |
| 5461 | LIST * result = 0; |
| 5462 | PyObject * arguments = 0; |
| 5463 | PyObject * kw = NULL; |
| 5464 | int32_t i; |
| 5465 | PyObject * py_result; |
| 5466 | FRAME * prev_frame_before_python_call; |
| 5467 | |
| 5468 | if ( function->base.formal_arguments ) |
| 5469 | { |
| 5470 | arguments = PyTuple_New( 0 ); |
| 5471 | kw = PyDict_New(); |
| 5472 | argument_list_to_python( function->base.formal_arguments, |
| 5473 | function->base.num_formal_arguments, &function->base, frame, kw ); |
| 5474 | } |
| 5475 | else |
| 5476 | { |
| 5477 | arguments = PyTuple_New( frame->args->count ); |
| 5478 | for ( i = 0; i < frame->args->count; ++i ) |
| 5479 | PyTuple_SetItem( arguments, i, list_to_python( lol_get( frame->args, |
| 5480 | i ) ) ); |
| 5481 | } |
| 5482 | |
| 5483 | frame->module = python_module(); |
| 5484 | |
| 5485 | prev_frame_before_python_call = frame_before_python_call; |
| 5486 | frame_before_python_call = frame; |
| 5487 | py_result = PyObject_Call( function->python_function, arguments, kw ); |
| 5488 | frame_before_python_call = prev_frame_before_python_call; |
| 5489 | Py_DECREF( arguments ); |
| 5490 | Py_XDECREF( kw ); |
| 5491 | if ( py_result != NULL ) |
| 5492 | { |
| 5493 | if ( PyList_Check( py_result ) ) |
| 5494 | { |
| 5495 | int32_t size = PyList_Size( py_result ); |
| 5496 | int32_t i; |
| 5497 | for ( i = 0; i < size; ++i ) |
| 5498 | { |
| 5499 | OBJECT * s = python_to_string( PyList_GetItem( py_result, i ) ); |
| 5500 | if ( !s ) |
| 5501 | err_printf( |
| 5502 | "Non-string object returned by Python call.\n" ); |
| 5503 | else |
| 5504 | result = list_push_back( result, s ); |
| 5505 | } |
| 5506 | } |
| 5507 | else if ( py_result == Py_None ) |
| 5508 | { |
| 5509 | result = L0; |
| 5510 | } |
| 5511 | else |
| 5512 | { |
| 5513 | OBJECT * const s = python_to_string( py_result ); |
| 5514 | if ( s ) |
| 5515 | result = list_new( s ); |
| 5516 | else |
no test coverage detected