From 9546e9d43674f7d4ffcc1d10f64bd2880f4e6ea4 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:44:49 -0700 Subject: [PATCH] Try using PyObject_Call instead --- src/main/policy.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/policy.c b/src/main/policy.c index ba5e75ad0..1190b94d2 100644 --- a/src/main/policy.c +++ b/src/main/policy.c @@ -1254,12 +1254,18 @@ as_status call_py_callback(as_error *err, unsigned int py_listener_data_index, PyObject *py_args = NULL; if (py_arg) { py_args = PyTuple_New(1); - if (!py_args) { - return as_error_update( - err, AEROSPIKE_ERR, - "Unable to construct list of arguments for Python callback %s", - py_listener_data[py_listener_data_index].listener_name); - } + } + else { + py_args = PyTuple_New(0); + } + if (!py_args) { + return as_error_update( + err, AEROSPIKE_ERR, + "Unable to construct list of arguments for Python callback %s", + py_listener_data[py_listener_data_index].listener_name); + } + + if (py_arg) { int result = PyTuple_SetItem(py_args, 0, py_arg); if (result == -1) { PyErr_Clear(); @@ -1271,9 +1277,9 @@ as_status call_py_callback(as_error *err, unsigned int py_listener_data_index, } } - PyObject *py_result = PyObject_CallObject( - py_listener_data[py_listener_data_index].py_callback, py_args); - Py_XDECREF(py_args); + PyObject *py_result = PyObject_Call( + py_listener_data[py_listener_data_index].py_callback, py_args, NULL); + Py_DECREF(py_args); if (!py_result) { // Python callback threw an exception return as_error_update(