execute Python code, propagate Python errors to the backend */
| 1065 | |
| 1066 | /* execute Python code, propagate Python errors to the backend */ |
| 1067 | static PyObject * |
| 1068 | PLy_procedure_call(PLyProcedure *proc, const char *kargs, PyObject *vargs) |
| 1069 | { |
| 1070 | PyObject *rv = NULL; |
| 1071 | int volatile save_subxact_level = list_length(explicit_subtransactions); |
| 1072 | |
| 1073 | PyDict_SetItemString(proc->globals, kargs, vargs); |
| 1074 | |
| 1075 | PG_TRY(); |
| 1076 | { |
| 1077 | PLy_enter_python_intepreter = true; |
| 1078 | #if PY_VERSION_HEX >= 0x03020000 |
| 1079 | rv = PyEval_EvalCode(proc->code, |
| 1080 | proc->globals, proc->globals); |
| 1081 | #else |
| 1082 | rv = PyEval_EvalCode((PyCodeObject *) proc->code, |
| 1083 | proc->globals, proc->globals); |
| 1084 | #endif |
| 1085 | PLy_enter_python_intepreter = false; |
| 1086 | |
| 1087 | /* |
| 1088 | * Since plpy will only let you close subtransactions that you |
| 1089 | * started, you cannot *unnest* subtransactions, only *nest* them |
| 1090 | * without closing. |
| 1091 | */ |
| 1092 | Assert(list_length(explicit_subtransactions) >= save_subxact_level); |
| 1093 | } |
| 1094 | PG_FINALLY(); |
| 1095 | { |
| 1096 | PLy_enter_python_intepreter = false; |
| 1097 | PLy_abort_open_subtransactions(save_subxact_level); |
| 1098 | } |
| 1099 | PG_END_TRY(); |
| 1100 | |
| 1101 | /* If the Python code returned an error, propagate it */ |
| 1102 | if (rv == NULL) |
| 1103 | PLy_elog(ERROR, NULL); |
| 1104 | |
| 1105 | return rv; |
| 1106 | } |
| 1107 | |
| 1108 | /* |
| 1109 | * Abort lingering subtransactions that have been explicitly started |
no test coverage detected