| 4919 | |
| 4920 | |
| 4921 | static LIST * call_python_function( PYTHON_FUNCTION * function, FRAME * frame ) |
| 4922 | { |
| 4923 | LIST * result = 0; |
| 4924 | PyObject * arguments = 0; |
| 4925 | PyObject * kw = NULL; |
| 4926 | int i; |
| 4927 | PyObject * py_result; |
| 4928 | FRAME * prev_frame_before_python_call; |
| 4929 | |
| 4930 | if ( function->base.formal_arguments ) |
| 4931 | { |
| 4932 | arguments = PyTuple_New( 0 ); |
| 4933 | kw = PyDict_New(); |
| 4934 | argument_list_to_python( function->base.formal_arguments, |
| 4935 | function->base.num_formal_arguments, &function->base, frame, kw ); |
| 4936 | } |
| 4937 | else |
| 4938 | { |
| 4939 | arguments = PyTuple_New( frame->args->count ); |
| 4940 | for ( i = 0; i < frame->args->count; ++i ) |
| 4941 | PyTuple_SetItem( arguments, i, list_to_python( lol_get( frame->args, |
| 4942 | i ) ) ); |
| 4943 | } |
| 4944 | |
| 4945 | frame->module = python_module(); |
| 4946 | |
| 4947 | prev_frame_before_python_call = frame_before_python_call; |
| 4948 | frame_before_python_call = frame; |
| 4949 | py_result = PyObject_Call( function->python_function, arguments, kw ); |
| 4950 | frame_before_python_call = prev_frame_before_python_call; |
| 4951 | Py_DECREF( arguments ); |
| 4952 | Py_XDECREF( kw ); |
| 4953 | if ( py_result != NULL ) |
| 4954 | { |
| 4955 | if ( PyList_Check( py_result ) ) |
| 4956 | { |
| 4957 | int size = PyList_Size( py_result ); |
| 4958 | int i; |
| 4959 | for ( i = 0; i < size; ++i ) |
| 4960 | { |
| 4961 | OBJECT * s = python_to_string( PyList_GetItem( py_result, i ) ); |
| 4962 | if ( !s ) |
| 4963 | err_printf( |
| 4964 | "Non-string object returned by Python call.\n" ); |
| 4965 | else |
| 4966 | result = list_push_back( result, s ); |
| 4967 | } |
| 4968 | } |
| 4969 | else if ( py_result == Py_None ) |
| 4970 | { |
| 4971 | result = L0; |
| 4972 | } |
| 4973 | else |
| 4974 | { |
| 4975 | OBJECT * const s = python_to_string( py_result ); |
| 4976 | if ( s ) |
| 4977 | result = list_new( s ); |
| 4978 | else |
no test coverage detected